aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2011-04-14 16:42:46 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-04-14 16:42:46 -0400
commit98346f7db014614a4814eb60639f651f8bbc591d (patch)
treeac353de7c9c645ef5134dfffb5d09df03741855f /drivers/usb/gadget
parentdb8fa2852ed5b46c05148db87be135300f17b8ce (diff)
Revert "usb: usb_storage: do not align length of request for CBW to maxp size"
This reverts commit 806e8f8fcc27e1753947bd9f059ba2316cf8f92a. To quote Alan Stern: The necessity for this patch has been under discussion. It turns out the UDC that Mian has been working on and Felipe's UDC have contradictory requirements. Mian's UDC driver wants a bulk-OUT transfer length to be shorter than the maxpacket size if a short packet is expected, whereas Felipe's UDC hardware always needs bulk-OUT transfer lengths to be evenly divisible by the maxpacket size. Mian has agreed to go back over the driver to resolve this conflict. This means we probably will not want this patch after all. (In fact, we may ultimately decide to change the gadget framework to require that bulk-OUT transfer lengths _always_ be divisible by the maxpacket size -- only the g_file_storage and g_mass_storage gadgets would need to be changed.) Cc: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> Cc: Michal Nazarewicz <mina86@mina86.com> Cc: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/f_mass_storage.c24
-rw-r--r--drivers/usb/gadget/file_storage.c28
-rw-r--r--drivers/usb/gadget/storage_common.c7
3 files changed, 49 insertions, 10 deletions
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 7d95a2cf58a3..01ae27b60d4c 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -474,6 +474,20 @@ static int exception_in_progress(struct fsg_common *common)
474 return common->state > FSG_STATE_IDLE; 474 return common->state > FSG_STATE_IDLE;
475} 475}
476 476
477/* Make bulk-out requests be divisible by the maxpacket size */
478static void set_bulk_out_req_length(struct fsg_common *common,
479 struct fsg_buffhd *bh, unsigned int length)
480{
481 unsigned int rem;
482
483 bh->bulk_out_intended_length = length;
484 rem = length % common->bulk_out_maxpacket;
485 if (rem > 0)
486 length += common->bulk_out_maxpacket - rem;
487 bh->outreq->length = length;
488}
489
490
477/*-------------------------------------------------------------------------*/ 491/*-------------------------------------------------------------------------*/
478 492
479static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) 493static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
@@ -572,9 +586,9 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
572 struct fsg_buffhd *bh = req->context; 586 struct fsg_buffhd *bh = req->context;
573 587
574 dump_msg(common, "bulk-out", req->buf, req->actual); 588 dump_msg(common, "bulk-out", req->buf, req->actual);
575 if (req->status || req->actual != req->length) 589 if (req->status || req->actual != bh->bulk_out_intended_length)
576 DBG(common, "%s --> %d, %u/%u\n", __func__, 590 DBG(common, "%s --> %d, %u/%u\n", __func__,
577 req->status, req->actual, req->length); 591 req->status, req->actual, bh->bulk_out_intended_length);
578 if (req->status == -ECONNRESET) /* Request was cancelled */ 592 if (req->status == -ECONNRESET) /* Request was cancelled */
579 usb_ep_fifo_flush(ep); 593 usb_ep_fifo_flush(ep);
580 594
@@ -966,6 +980,7 @@ static int do_write(struct fsg_common *common)
966 * the bulk-out maxpacket size 980 * the bulk-out maxpacket size
967 */ 981 */
968 bh->outreq->length = amount; 982 bh->outreq->length = amount;
983 bh->bulk_out_intended_length = amount;
969 bh->outreq->short_not_ok = 1; 984 bh->outreq->short_not_ok = 1;
970 if (!start_out_transfer(common, bh)) 985 if (!start_out_transfer(common, bh))
971 /* Dunno what to do if common->fsg is NULL */ 986 /* Dunno what to do if common->fsg is NULL */
@@ -1611,6 +1626,7 @@ static int throw_away_data(struct fsg_common *common)
1611 * the bulk-out maxpacket size. 1626 * the bulk-out maxpacket size.
1612 */ 1627 */
1613 bh->outreq->length = amount; 1628 bh->outreq->length = amount;
1629 bh->bulk_out_intended_length = amount;
1614 bh->outreq->short_not_ok = 1; 1630 bh->outreq->short_not_ok = 1;
1615 if (!start_out_transfer(common, bh)) 1631 if (!start_out_transfer(common, bh))
1616 /* Dunno what to do if common->fsg is NULL */ 1632 /* Dunno what to do if common->fsg is NULL */
@@ -2279,8 +2295,8 @@ static int get_next_command(struct fsg_common *common)
2279 } 2295 }
2280 2296
2281 /* Queue a request to read a Bulk-only CBW */ 2297 /* Queue a request to read a Bulk-only CBW */
2282 bh->outreq->length = USB_BULK_CB_WRAP_LEN; 2298 set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN);
2283 bh->outreq->short_not_ok = 0; 2299 bh->outreq->short_not_ok = 1;
2284 if (!start_out_transfer(common, bh)) 2300 if (!start_out_transfer(common, bh))
2285 /* Don't know what to do if common->fsg is NULL */ 2301 /* Don't know what to do if common->fsg is NULL */
2286 return -EIO; 2302 return -EIO;
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index aebfb81f3ba4..fcfc77c7ad70 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -497,6 +497,19 @@ static int exception_in_progress(struct fsg_dev *fsg)
497 return (fsg->state > FSG_STATE_IDLE); 497 return (fsg->state > FSG_STATE_IDLE);
498} 498}
499 499
500/* Make bulk-out requests be divisible by the maxpacket size */
501static void set_bulk_out_req_length(struct fsg_dev *fsg,
502 struct fsg_buffhd *bh, unsigned int length)
503{
504 unsigned int rem;
505
506 bh->bulk_out_intended_length = length;
507 rem = length % fsg->bulk_out_maxpacket;
508 if (rem > 0)
509 length += fsg->bulk_out_maxpacket - rem;
510 bh->outreq->length = length;
511}
512
500static struct fsg_dev *the_fsg; 513static struct fsg_dev *the_fsg;
501static struct usb_gadget_driver fsg_driver; 514static struct usb_gadget_driver fsg_driver;
502 515
@@ -717,9 +730,10 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
717 struct fsg_buffhd *bh = req->context; 730 struct fsg_buffhd *bh = req->context;
718 731
719 dump_msg(fsg, "bulk-out", req->buf, req->actual); 732 dump_msg(fsg, "bulk-out", req->buf, req->actual);
720 if (req->status || req->actual != req->length) 733 if (req->status || req->actual != bh->bulk_out_intended_length)
721 DBG(fsg, "%s --> %d, %u/%u\n", __func__, 734 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
722 req->status, req->actual, req->length); 735 req->status, req->actual,
736 bh->bulk_out_intended_length);
723 if (req->status == -ECONNRESET) // Request was cancelled 737 if (req->status == -ECONNRESET) // Request was cancelled
724 usb_ep_fifo_flush(ep); 738 usb_ep_fifo_flush(ep);
725 739
@@ -1335,7 +1349,8 @@ static int do_write(struct fsg_dev *fsg)
1335 1349
1336 /* amount is always divisible by 512, hence by 1350 /* amount is always divisible by 512, hence by
1337 * the bulk-out maxpacket size */ 1351 * the bulk-out maxpacket size */
1338 bh->outreq->length = amount; 1352 bh->outreq->length = bh->bulk_out_intended_length =
1353 amount;
1339 bh->outreq->short_not_ok = 1; 1354 bh->outreq->short_not_ok = 1;
1340 start_transfer(fsg, fsg->bulk_out, bh->outreq, 1355 start_transfer(fsg, fsg->bulk_out, bh->outreq,
1341 &bh->outreq_busy, &bh->state); 1356 &bh->outreq_busy, &bh->state);
@@ -1964,7 +1979,8 @@ static int throw_away_data(struct fsg_dev *fsg)
1964 1979
1965 /* amount is always divisible by 512, hence by 1980 /* amount is always divisible by 512, hence by
1966 * the bulk-out maxpacket size */ 1981 * the bulk-out maxpacket size */
1967 bh->outreq->length = amount; 1982 bh->outreq->length = bh->bulk_out_intended_length =
1983 amount;
1968 bh->outreq->short_not_ok = 1; 1984 bh->outreq->short_not_ok = 1;
1969 start_transfer(fsg, fsg->bulk_out, bh->outreq, 1985 start_transfer(fsg, fsg->bulk_out, bh->outreq,
1970 &bh->outreq_busy, &bh->state); 1986 &bh->outreq_busy, &bh->state);
@@ -2643,8 +2659,8 @@ static int get_next_command(struct fsg_dev *fsg)
2643 } 2659 }
2644 2660
2645 /* Queue a request to read a Bulk-only CBW */ 2661 /* Queue a request to read a Bulk-only CBW */
2646 bh->outreq->length = USB_BULK_CB_WRAP_LEN; 2662 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN);
2647 bh->outreq->short_not_ok = 0; 2663 bh->outreq->short_not_ok = 1;
2648 start_transfer(fsg, fsg->bulk_out, bh->outreq, 2664 start_transfer(fsg, fsg->bulk_out, bh->outreq,
2649 &bh->outreq_busy, &bh->state); 2665 &bh->outreq_busy, &bh->state);
2650 2666
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 86fcebd89abe..109635a84888 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -286,6 +286,13 @@ struct fsg_buffhd {
286 enum fsg_buffer_state state; 286 enum fsg_buffer_state state;
287 struct fsg_buffhd *next; 287 struct fsg_buffhd *next;
288 288
289 /*
290 * The NetChip 2280 is faster, and handles some protocol faults
291 * better, if we don't submit any short bulk-out read requests.
292 * So we will record the intended request length here.
293 */
294 unsigned int bulk_out_intended_length;
295
289 struct usb_request *inreq; 296 struct usb_request *inreq;
290 int inreq_busy; 297 int inreq_busy;
291 struct usb_request *outreq; 298 struct usb_request *outreq;