|
|
@@ -146,7 +146,8 @@ struct ehci_bulk {
|
|
|
unsigned int addr;
|
|
|
unsigned int ep;
|
|
|
unsigned int mps;
|
|
|
- unsigned int buf_len;
|
|
|
+ unsigned int buf_len; /* capacity of the HCD's IN bounce buffer */
|
|
|
+ unsigned int armed_len; /* length the current IN qTD was armed with */
|
|
|
unsigned int toggle;
|
|
|
unsigned int arm_ms;
|
|
|
int armed;
|
|
|
@@ -450,6 +451,7 @@ static void bulk_reset(struct ehci_bulk *b)
|
|
|
b->ep = 0;
|
|
|
b->mps = 0;
|
|
|
b->buf_len = 0;
|
|
|
+ b->armed_len = 0;
|
|
|
b->toggle = 0;
|
|
|
}
|
|
|
|
|
|
@@ -464,6 +466,7 @@ static void bulk_configure(struct ehci_bulk *b, unsigned int addr,
|
|
|
b->ep = ep;
|
|
|
b->mps = mps;
|
|
|
b->buf_len = buf_len;
|
|
|
+ b->armed_len = 0;
|
|
|
b->toggle = 0; /* first packet is DATA0 */
|
|
|
qh_init(b->qh); /* keeps the link pointer out of it */
|
|
|
qh_configure(b->qh, addr, ep, mps, 0);
|
|
|
@@ -596,7 +599,7 @@ static int ehci_bulk_in(unsigned int ctrl, unsigned int addr,
|
|
|
{
|
|
|
struct ehci_ctrl *c;
|
|
|
struct ehci_bulk *b;
|
|
|
- unsigned int token, raw, packets, actual, i;
|
|
|
+ unsigned int token, raw, packets, actual, i, alen;
|
|
|
|
|
|
if (ctrl >= n_ctrls || !buf || !len)
|
|
|
return -1;
|
|
|
@@ -612,7 +615,16 @@ static int ehci_bulk_in(unsigned int ctrl, unsigned int addr,
|
|
|
bulk_configure(b, addr, ep, mps, EHCI_RX_MAX);
|
|
|
|
|
|
if (!b->armed) {
|
|
|
- qtd_fill(b->qtd, c->rx_buf, b->buf_len, QTD_PID_IN, 0);
|
|
|
+ /* Arm exactly the length this call is waiting for. A device
|
|
|
+ * that ends a transfer which is an exact multiple of the max
|
|
|
+ * packet size without a zero-length packet leaves a larger
|
|
|
+ * qTD active forever (the ION's SanDisk does this for every
|
|
|
+ * 512-byte sector read). Do not pre-arm the next transfer:
|
|
|
+ * the next call's length can be smaller, because a BOT data
|
|
|
+ * stage's final chunk need not fill the whole bounce buffer. */
|
|
|
+ alen = len > EHCI_RX_MAX ? EHCI_RX_MAX : len;
|
|
|
+ b->armed_len = alen;
|
|
|
+ qtd_fill(b->qtd, c->rx_buf, alen, QTD_PID_IN, 0);
|
|
|
bulk_arm(b);
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -630,8 +642,8 @@ static int ehci_bulk_in(unsigned int ctrl, unsigned int addr,
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- raw = QTD_LEN(token) <= b->buf_len ?
|
|
|
- b->buf_len - QTD_LEN(token) : 0;
|
|
|
+ raw = QTD_LEN(token) <= b->armed_len ?
|
|
|
+ b->armed_len - QTD_LEN(token) : 0;
|
|
|
actual = raw;
|
|
|
if (actual > len)
|
|
|
actual = len;
|
|
|
@@ -644,8 +656,6 @@ static int ehci_bulk_in(unsigned int ctrl, unsigned int addr,
|
|
|
b->toggle ^= packets & 1u;
|
|
|
|
|
|
qh_disarm(b->qh);
|
|
|
- qtd_fill(b->qtd, c->rx_buf, b->buf_len, QTD_PID_IN, 0);
|
|
|
- bulk_arm(b);
|
|
|
return (int)actual;
|
|
|
}
|
|
|
|