aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorMichal Nazarewicz <m.nazarewicz@samsung.com>2009-10-28 11:57:19 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 14:55:19 -0500
commit93bcf12e7123f20d30757d35d8052832e3c4d647 (patch)
tree71a8ccbd467d3de3c8485c03a9465d49ea72d763 /drivers/usb
parentd5e2b67aae79f01720d8b962c23b0abc7063201c (diff)
USB: g_mass_storage: testing code from f_mass_storage.c removed
Removed code that was included when CONFIG_USB_FILE_STORAGE_TEST was defined. If this functionality is required one may still use the original File-backed Storage Gadget. It has been agreed that testing functionality is not required in the composite function. Also removed fsg_suspend() and fsg_resume() which were no operations. Moreover, storage_common.c has been modified in such a way that defining certain macros skips parts of the file. Those macros are: * FSG_NO_INTR_EP -- skips interrupt endpoint descriptors * FSG_NO_DEVICE_STRINGS -- skips certain strings * FSG_NO_OTG -- skips OTG descriptor Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/f_mass_storage.c662
-rw-r--r--drivers/usb/gadget/storage_common.c50
2 files changed, 140 insertions, 572 deletions
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 7998402b1840..ed16a9538753 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -50,14 +50,6 @@
50 * access is always read-only.) The gadget will indicate that it has 50 * access is always read-only.) The gadget will indicate that it has
51 * removable media if the optional "removable" module parameter is set. 51 * removable media if the optional "removable" module parameter is set.
52 * 52 *
53 * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
54 * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
55 * by the optional "transport" module parameter. It also supports the
56 * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
57 * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
58 * the optional "protocol" module parameter. In addition, the default
59 * Vendor ID, Product ID, and release number can be overridden.
60 *
61 * There is support for multiple logical units (LUNs), each of which has 53 * There is support for multiple logical units (LUNs), each of which has
62 * its own backing file. The number of LUNs can be set using the optional 54 * its own backing file. The number of LUNs can be set using the optional
63 * "luns" module parameter (anywhere from 1 to 8), and the corresponding 55 * "luns" module parameter (anywhere from 1 to 8), and the corresponding
@@ -99,20 +91,6 @@
99 * bulk endpoints 91 * bulk endpoints
100 * cdrom Default false, boolean for whether to emulate 92 * cdrom Default false, boolean for whether to emulate
101 * a CD-ROM drive 93 * a CD-ROM drive
102 * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
103 * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
104 * ATAPI, QIC, UFI, 8070, or SCSI;
105 * also 1 - 6)
106 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
107 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
108 * release=0xRRRR Override the USB release number (bcdDevice)
109 * buflen=N Default N=16384, buffer size used (will be
110 * rounded down to a multiple of
111 * PAGE_CACHE_SIZE)
112 *
113 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro",
114 * "removable", "luns", "stall", and "cdrom" options are available; default
115 * values are used for everything else.
116 * 94 *
117 * The pathnames of the backing files and the ro settings are available in 95 * The pathnames of the backing files and the ro settings are available in
118 * the attribute files "file" and "ro" in the lun<n> subdirectory of the 96 * the attribute files "file" and "ro" in the lun<n> subdirectory of the
@@ -279,6 +257,8 @@ static const char fsg_string_config[] = "Self-powered";
279static const char fsg_string_interface[] = "Mass Storage"; 257static const char fsg_string_interface[] = "Mass Storage";
280 258
281 259
260#define FSG_NO_INTR_EP 1
261
282#include "storage_common.c" 262#include "storage_common.c"
283 263
284 264
@@ -309,28 +289,11 @@ static struct {
309 int can_stall; 289 int can_stall;
310 int cdrom; 290 int cdrom;
311 291
312 char *transport_parm;
313 char *protocol_parm;
314 unsigned short vendor;
315 unsigned short product;
316 unsigned short release; 292 unsigned short release;
317 unsigned int buflen;
318
319 int transport_type;
320 char *transport_name;
321 int protocol_type;
322 char *protocol_name;
323
324} mod_data = { // Default values 293} mod_data = { // Default values
325 .transport_parm = "BBB",
326 .protocol_parm = "SCSI",
327 .removable = 0, 294 .removable = 0,
328 .can_stall = 1, 295 .can_stall = 1,
329 .cdrom = 0, 296 .cdrom = 0,
330 .vendor = FSG_VENDOR_ID,
331 .product = FSG_PRODUCT_ID,
332 .release = 0xffff, // Use controller chip type
333 .buflen = 16384,
334 }; 297 };
335 298
336 299
@@ -354,54 +317,6 @@ module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
354MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); 317MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
355 318
356 319
357/* In the non-TEST version, only the module parameters listed above
358 * are available. */
359#ifdef CONFIG_USB_FILE_STORAGE_TEST
360
361module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
362MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
363
364module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
365MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
366 "8070, or SCSI)");
367
368module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
369MODULE_PARM_DESC(vendor, "USB Vendor ID");
370
371module_param_named(product, mod_data.product, ushort, S_IRUGO);
372MODULE_PARM_DESC(product, "USB Product ID");
373
374module_param_named(release, mod_data.release, ushort, S_IRUGO);
375MODULE_PARM_DESC(release, "USB release number");
376
377module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
378MODULE_PARM_DESC(buflen, "I/O buffer size");
379
380#endif /* CONFIG_USB_FILE_STORAGE_TEST */
381
382
383/*
384 * These definitions will permit the compiler to avoid generating code for
385 * parts of the driver that aren't used in the non-TEST version. Even gcc
386 * can recognize when a test of a constant expression yields a dead code
387 * path.
388 */
389
390#ifdef CONFIG_USB_FILE_STORAGE_TEST
391
392#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
393#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
394#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
395
396#else
397
398#define transport_is_bbb() 1
399#define transport_is_cbi() 0
400#define protocol_is_scsi() 1
401
402#endif /* CONFIG_USB_FILE_STORAGE_TEST */
403
404
405/*-------------------------------------------------------------------------*/ 320/*-------------------------------------------------------------------------*/
406 321
407 322
@@ -421,10 +336,6 @@ struct fsg_dev {
421 unsigned int ep0_req_tag; 336 unsigned int ep0_req_tag;
422 const char *ep0req_name; 337 const char *ep0req_name;
423 338
424 struct usb_request *intreq; // For interrupt responses
425 int intreq_busy;
426 struct fsg_buffhd *intr_buffhd;
427
428 unsigned int bulk_out_maxpacket; 339 unsigned int bulk_out_maxpacket;
429 enum fsg_state state; // For exception handling 340 enum fsg_state state; // For exception handling
430 unsigned int exception_req_tag; 341 unsigned int exception_req_tag;
@@ -434,7 +345,6 @@ struct fsg_dev {
434 unsigned int running : 1; 345 unsigned int running : 1;
435 unsigned int bulk_in_enabled : 1; 346 unsigned int bulk_in_enabled : 1;
436 unsigned int bulk_out_enabled : 1; 347 unsigned int bulk_out_enabled : 1;
437 unsigned int intr_in_enabled : 1;
438 unsigned int phase_error : 1; 348 unsigned int phase_error : 1;
439 unsigned int short_packet_received : 1; 349 unsigned int short_packet_received : 1;
440 unsigned int bad_lun_okay : 1; 350 unsigned int bad_lun_okay : 1;
@@ -442,11 +352,9 @@ struct fsg_dev {
442 unsigned long atomic_bitflags; 352 unsigned long atomic_bitflags;
443#define REGISTERED 0 353#define REGISTERED 0
444#define IGNORE_BULK_OUT 1 354#define IGNORE_BULK_OUT 1
445#define SUSPENDED 2
446 355
447 struct usb_ep *bulk_in; 356 struct usb_ep *bulk_in;
448 struct usb_ep *bulk_out; 357 struct usb_ep *bulk_out;
449 struct usb_ep *intr_in;
450 358
451 struct fsg_buffhd *next_buffhd_to_fill; 359 struct fsg_buffhd *next_buffhd_to_fill;
452 struct fsg_buffhd *next_buffhd_to_drain; 360 struct fsg_buffhd *next_buffhd_to_drain;
@@ -466,14 +374,6 @@ struct fsg_dev {
466 u32 residue; 374 u32 residue;
467 u32 usb_amount_left; 375 u32 usb_amount_left;
468 376
469 /* The CB protocol offers no way for a host to know when a command
470 * has completed. As a result the next command may arrive early,
471 * and we will still have to handle it. For that reason we need
472 * a buffer to store new commands when using CB (or CBI, which
473 * does not oblige a host to wait for command completion either). */
474 int cbbuf_cmnd_size;
475 u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
476
477 unsigned int nluns; 377 unsigned int nluns;
478 struct fsg_lun *luns; 378 struct fsg_lun *luns;
479 struct fsg_lun *curlun; 379 struct fsg_lun *curlun;
@@ -737,161 +637,53 @@ static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
737} 637}
738 638
739 639
740#ifdef CONFIG_USB_FILE_STORAGE_TEST
741static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
742{
743 struct fsg_dev *fsg = ep->driver_data;
744 struct fsg_buffhd *bh = req->context;
745
746 if (req->status || req->actual != req->length)
747 DBG(fsg, "%s --> %d, %u/%u\n", __func__,
748 req->status, req->actual, req->length);
749 if (req->status == -ECONNRESET) // Request was cancelled
750 usb_ep_fifo_flush(ep);
751
752 /* Hold the lock while we update the request and buffer states */
753 smp_wmb();
754 spin_lock(&fsg->lock);
755 fsg->intreq_busy = 0;
756 bh->state = BUF_STATE_EMPTY;
757 wakeup_thread(fsg);
758 spin_unlock(&fsg->lock);
759}
760
761#else
762static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
763{}
764#endif /* CONFIG_USB_FILE_STORAGE_TEST */
765
766
767/*-------------------------------------------------------------------------*/ 640/*-------------------------------------------------------------------------*/
768 641
769/* Ep0 class-specific handlers. These always run in_irq. */ 642/* Ep0 class-specific handlers. These always run in_irq. */
770 643
771#ifdef CONFIG_USB_FILE_STORAGE_TEST
772static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
773{
774 struct usb_request *req = fsg->ep0req;
775 static u8 cbi_reset_cmnd[6] = {
776 SC_SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
777
778 /* Error in command transfer? */
779 if (req->status || req->length != req->actual ||
780 req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
781
782 /* Not all controllers allow a protocol stall after
783 * receiving control-out data, but we'll try anyway. */
784 fsg_set_halt(fsg, fsg->ep0);
785 return; // Wait for reset
786 }
787
788 /* Is it the special reset command? */
789 if (req->actual >= sizeof cbi_reset_cmnd &&
790 memcmp(req->buf, cbi_reset_cmnd,
791 sizeof cbi_reset_cmnd) == 0) {
792
793 /* Raise an exception to stop the current operation
794 * and reinitialize our state. */
795 DBG(fsg, "cbi reset request\n");
796 raise_exception(fsg, FSG_STATE_RESET);
797 return;
798 }
799
800 VDBG(fsg, "CB[I] accept device-specific command\n");
801 spin_lock(&fsg->lock);
802
803 /* Save the command for later */
804 if (fsg->cbbuf_cmnd_size)
805 WARNING(fsg, "CB[I] overwriting previous command\n");
806 fsg->cbbuf_cmnd_size = req->actual;
807 memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
808
809 wakeup_thread(fsg);
810 spin_unlock(&fsg->lock);
811}
812
813#else
814static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
815{}
816#endif /* CONFIG_USB_FILE_STORAGE_TEST */
817
818
819static int class_setup_req(struct fsg_dev *fsg, 644static int class_setup_req(struct fsg_dev *fsg,
820 const struct usb_ctrlrequest *ctrl) 645 const struct usb_ctrlrequest *ctrl)
821{ 646{
822 struct usb_request *req = fsg->ep0req; 647 struct usb_request *req = fsg->ep0req;
823 int value = -EOPNOTSUPP;
824 u16 w_index = le16_to_cpu(ctrl->wIndex); 648 u16 w_index = le16_to_cpu(ctrl->wIndex);
825 u16 w_value = le16_to_cpu(ctrl->wValue); 649 u16 w_value = le16_to_cpu(ctrl->wValue);
826 u16 w_length = le16_to_cpu(ctrl->wLength); 650 u16 w_length = le16_to_cpu(ctrl->wLength);
827 651
828 if (!fsg->config) 652 if (!fsg->config)
829 return value; 653 return -EOPNOTSUPP;
830 654
831 /* Handle Bulk-only class-specific requests */ 655 switch (ctrl->bRequest) {
832 if (transport_is_bbb()) {
833 switch (ctrl->bRequest) {
834
835 case USB_BULK_RESET_REQUEST:
836 if (ctrl->bRequestType != (USB_DIR_OUT |
837 USB_TYPE_CLASS | USB_RECIP_INTERFACE))
838 break;
839 if (w_index != 0 || w_value != 0) {
840 value = -EDOM;
841 break;
842 }
843
844 /* Raise an exception to stop the current operation
845 * and reinitialize our state. */
846 DBG(fsg, "bulk reset request\n");
847 raise_exception(fsg, FSG_STATE_RESET);
848 value = DELAYED_STATUS;
849 break;
850 656
851 case USB_BULK_GET_MAX_LUN_REQUEST: 657 case USB_BULK_RESET_REQUEST:
852 if (ctrl->bRequestType != (USB_DIR_IN | 658 if (ctrl->bRequestType !=
853 USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 659 (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
854 break;
855 if (w_index != 0 || w_value != 0) {
856 value = -EDOM;
857 break;
858 }
859 VDBG(fsg, "get max LUN\n");
860 *(u8 *) req->buf = fsg->nluns - 1;
861 value = 1;
862 break; 660 break;
863 } 661 if (w_index != 0 || w_value != 0)
864 } 662 return -EDOM;
865 663
866 /* Handle CBI class-specific requests */ 664 /* Raise an exception to stop the current operation
867 else { 665 * and reinitialize our state. */
868 switch (ctrl->bRequest) { 666 DBG(fsg, "bulk reset request\n");
667 raise_exception(fsg, FSG_STATE_RESET);
668 return DELAYED_STATUS;
869 669
870 case USB_CBI_ADSC_REQUEST: 670 case USB_BULK_GET_MAX_LUN_REQUEST:
871 if (ctrl->bRequestType != (USB_DIR_OUT | 671 if (ctrl->bRequestType !=
872 USB_TYPE_CLASS | USB_RECIP_INTERFACE)) 672 (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
873 break;
874 if (w_index != 0 || w_value != 0) {
875 value = -EDOM;
876 break;
877 }
878 if (w_length > MAX_COMMAND_SIZE) {
879 value = -EOVERFLOW;
880 break;
881 }
882 value = w_length;
883 fsg->ep0req->context = received_cbi_adsc;
884 break; 673 break;
885 } 674 if (w_index != 0 || w_value != 0)
886 } 675 return -EDOM;
887 676 VDBG(fsg, "get max LUN\n");
888 if (value == -EOPNOTSUPP) 677 *(u8 *) req->buf = fsg->nluns - 1;
889 VDBG(fsg, 678 return 1;
890 "unknown class-specific control req " 679 }
891 "%02x.%02x v%04x i%04x l%u\n", 680
892 ctrl->bRequestType, ctrl->bRequest, 681 VDBG(fsg,
893 le16_to_cpu(ctrl->wValue), w_index, w_length); 682 "unknown class-specific control req "
894 return value; 683 "%02x.%02x v%04x i%04x l%u\n",
684 ctrl->bRequestType, ctrl->bRequest,
685 le16_to_cpu(ctrl->wValue), w_index, w_length);
686 return -EOPNOTSUPP;
895} 687}
896 688
897 689
@@ -1063,8 +855,6 @@ static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
1063 855
1064 if (ep == fsg->bulk_in) 856 if (ep == fsg->bulk_in)
1065 dump_msg(fsg, "bulk-in", req->buf, req->length); 857 dump_msg(fsg, "bulk-in", req->buf, req->length);
1066 else if (ep == fsg->intr_in)
1067 dump_msg(fsg, "intr-in", req->buf, req->length);
1068 858
1069 spin_lock_irq(&fsg->lock); 859 spin_lock_irq(&fsg->lock);
1070 *pbusy = 1; 860 *pbusy = 1;
@@ -1159,7 +949,7 @@ static int do_read(struct fsg_dev *fsg)
1159 * the next page. 949 * the next page.
1160 * If this means reading 0 then we were asked to read past 950 * If this means reading 0 then we were asked to read past
1161 * the end of file. */ 951 * the end of file. */
1162 amount = min((unsigned int) amount_left, mod_data.buflen); 952 amount = min(amount_left, FSG_BUFLEN);
1163 amount = min((loff_t) amount, 953 amount = min((loff_t) amount,
1164 curlun->file_length - file_offset); 954 curlun->file_length - file_offset);
1165 partial_page = file_offset & (PAGE_CACHE_SIZE - 1); 955 partial_page = file_offset & (PAGE_CACHE_SIZE - 1);
@@ -1304,7 +1094,7 @@ static int do_write(struct fsg_dev *fsg)
1304 * If this means getting 0, then we were asked 1094 * If this means getting 0, then we were asked
1305 * to write past the end of file. 1095 * to write past the end of file.
1306 * Finally, round down to a block boundary. */ 1096 * Finally, round down to a block boundary. */
1307 amount = min(amount_left_to_req, mod_data.buflen); 1097 amount = min(amount_left_to_req, FSG_BUFLEN);
1308 amount = min((loff_t) amount, curlun->file_length - 1098 amount = min((loff_t) amount, curlun->file_length -
1309 usb_offset); 1099 usb_offset);
1310 partial_page = usb_offset & (PAGE_CACHE_SIZE - 1); 1100 partial_page = usb_offset & (PAGE_CACHE_SIZE - 1);
@@ -1504,7 +1294,7 @@ static int do_verify(struct fsg_dev *fsg)
1504 * And don't try to read past the end of the file. 1294 * And don't try to read past the end of the file.
1505 * If this means reading 0 then we were asked to read 1295 * If this means reading 0 then we were asked to read
1506 * past the end of file. */ 1296 * past the end of file. */
1507 amount = min((unsigned int) amount_left, mod_data.buflen); 1297 amount = min(amount_left, FSG_BUFLEN);
1508 amount = min((loff_t) amount, 1298 amount = min((loff_t) amount,
1509 curlun->file_length - file_offset); 1299 curlun->file_length - file_offset);
1510 if (amount == 0) { 1300 if (amount == 0) {
@@ -1743,7 +1533,7 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1743 } else { // SC_MODE_SENSE_10 1533 } else { // SC_MODE_SENSE_10
1744 buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA 1534 buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
1745 buf += 8; 1535 buf += 8;
1746 limit = 65535; // Should really be mod_data.buflen 1536 limit = 65535; // Should really be FSG_BUFLEN
1747 } 1537 }
1748 1538
1749 /* No block descriptors */ 1539 /* No block descriptors */
@@ -1790,50 +1580,10 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1790 1580
1791static int do_start_stop(struct fsg_dev *fsg) 1581static int do_start_stop(struct fsg_dev *fsg)
1792{ 1582{
1793 struct fsg_lun *curlun = fsg->curlun;
1794 int loej, start;
1795
1796 if (!mod_data.removable) { 1583 if (!mod_data.removable) {
1797 curlun->sense_data = SS_INVALID_COMMAND; 1584 fsg->curlun->sense_data = SS_INVALID_COMMAND;
1798 return -EINVAL;
1799 }
1800
1801 // int immed = fsg->cmnd[1] & 0x01;
1802 loej = fsg->cmnd[4] & 0x02;
1803 start = fsg->cmnd[4] & 0x01;
1804
1805#ifdef CONFIG_USB_FILE_STORAGE_TEST
1806 if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
1807 (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
1808 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1809 return -EINVAL; 1585 return -EINVAL;
1810 } 1586 }
1811
1812 if (!start) {
1813
1814 /* Are we allowed to unload the media? */
1815 if (curlun->prevent_medium_removal) {
1816 LDBG(curlun, "unload attempt prevented\n");
1817 curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
1818 return -EINVAL;
1819 }
1820 if (loej) { // Simulate an unload/eject
1821 up_read(&fsg->filesem);
1822 down_write(&fsg->filesem);
1823 fsg_lun_close(curlun);
1824 up_write(&fsg->filesem);
1825 down_read(&fsg->filesem);
1826 }
1827 } else {
1828
1829 /* Our emulation doesn't support mounting; the medium is
1830 * available for use as soon as it is loaded. */
1831 if (!fsg_lun_is_open(curlun)) {
1832 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
1833 return -EINVAL;
1834 }
1835 }
1836#endif
1837 return 0; 1587 return 0;
1838} 1588}
1839 1589
@@ -1954,7 +1704,7 @@ static int pad_with_zeros(struct fsg_dev *fsg)
1954 return rc; 1704 return rc;
1955 } 1705 }
1956 1706
1957 nsend = min(fsg->usb_amount_left, (u32) mod_data.buflen); 1707 nsend = min(fsg->usb_amount_left, FSG_BUFLEN);
1958 memset(bh->buf + nkeep, 0, nsend - nkeep); 1708 memset(bh->buf + nkeep, 0, nsend - nkeep);
1959 bh->inreq->length = nsend; 1709 bh->inreq->length = nsend;
1960 bh->inreq->zero = 0; 1710 bh->inreq->zero = 0;
@@ -1994,8 +1744,7 @@ static int throw_away_data(struct fsg_dev *fsg)
1994 /* Try to submit another request if we need one */ 1744 /* Try to submit another request if we need one */
1995 bh = fsg->next_buffhd_to_fill; 1745 bh = fsg->next_buffhd_to_fill;
1996 if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) { 1746 if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
1997 amount = min(fsg->usb_amount_left, 1747 amount = min(fsg->usb_amount_left, FSG_BUFLEN);
1998 (u32) mod_data.buflen);
1999 1748
2000 /* amount is always divisible by 512, hence by 1749 /* amount is always divisible by 512, hence by
2001 * the bulk-out maxpacket size */ 1750 * the bulk-out maxpacket size */
@@ -2040,49 +1789,27 @@ static int finish_reply(struct fsg_dev *fsg)
2040 1789
2041 /* All but the last buffer of data must have already been sent */ 1790 /* All but the last buffer of data must have already been sent */
2042 case DATA_DIR_TO_HOST: 1791 case DATA_DIR_TO_HOST:
2043 if (fsg->data_size == 0) 1792 if (fsg->data_size == 0) {
2044 ; // Nothing to send 1793 /* Nothing to send */
2045 1794
2046 /* If there's no residue, simply send the last buffer */ 1795 /* If there's no residue, simply send the last buffer */
2047 else if (fsg->residue == 0) { 1796 } else if (fsg->residue == 0) {
2048 bh->inreq->zero = 0; 1797 bh->inreq->zero = 0;
2049 start_transfer(fsg, fsg->bulk_in, bh->inreq, 1798 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2050 &bh->inreq_busy, &bh->state); 1799 &bh->inreq_busy, &bh->state);
2051 fsg->next_buffhd_to_fill = bh->next; 1800 fsg->next_buffhd_to_fill = bh->next;
2052 }
2053
2054 /* There is a residue. For CB and CBI, simply mark the end
2055 * of the data with a short packet. However, if we are
2056 * allowed to stall, there was no data at all (residue ==
2057 * data_size), and the command failed (invalid LUN or
2058 * sense data is set), then halt the bulk-in endpoint
2059 * instead. */
2060 else if (!transport_is_bbb()) {
2061 if (mod_data.can_stall &&
2062 fsg->residue == fsg->data_size &&
2063 (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
2064 bh->state = BUF_STATE_EMPTY;
2065 rc = halt_bulk_in_endpoint(fsg);
2066 } else {
2067 bh->inreq->zero = 1;
2068 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2069 &bh->inreq_busy, &bh->state);
2070 fsg->next_buffhd_to_fill = bh->next;
2071 }
2072 }
2073 1801
2074 /* For Bulk-only, if we're allowed to stall then send the 1802 /* For Bulk-only, if we're allowed to stall then send the
2075 * short packet and halt the bulk-in endpoint. If we can't 1803 * short packet and halt the bulk-in endpoint. If we can't
2076 * stall, pad out the remaining data with 0's. */ 1804 * stall, pad out the remaining data with 0's. */
2077 else { 1805 } else if (mod_data.can_stall) {
2078 if (mod_data.can_stall) { 1806 bh->inreq->zero = 1;
2079 bh->inreq->zero = 1; 1807 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2080 start_transfer(fsg, fsg->bulk_in, bh->inreq, 1808 &bh->inreq_busy, &bh->state);
2081 &bh->inreq_busy, &bh->state); 1809 fsg->next_buffhd_to_fill = bh->next;
2082 fsg->next_buffhd_to_fill = bh->next; 1810 rc = halt_bulk_in_endpoint(fsg);
2083 rc = halt_bulk_in_endpoint(fsg); 1811 } else {
2084 } else 1812 rc = pad_with_zeros(fsg);
2085 rc = pad_with_zeros(fsg);
2086 } 1813 }
2087 break; 1814 break;
2088 1815
@@ -2126,6 +1853,7 @@ static int send_status(struct fsg_dev *fsg)
2126{ 1853{
2127 struct fsg_lun *curlun = fsg->curlun; 1854 struct fsg_lun *curlun = fsg->curlun;
2128 struct fsg_buffhd *bh; 1855 struct fsg_buffhd *bh;
1856 struct bulk_cs_wrap *csw;
2129 int rc; 1857 int rc;
2130 u8 status = USB_STATUS_PASS; 1858 u8 status = USB_STATUS_PASS;
2131 u32 sd, sdinfo = 0; 1859 u32 sd, sdinfo = 0;
@@ -2158,46 +1886,19 @@ static int send_status(struct fsg_dev *fsg)
2158 SK(sd), ASC(sd), ASCQ(sd), sdinfo); 1886 SK(sd), ASC(sd), ASCQ(sd), sdinfo);
2159 } 1887 }
2160 1888
2161 if (transport_is_bbb()) {
2162 struct bulk_cs_wrap *csw = bh->buf;
2163
2164 /* Store and send the Bulk-only CSW */
2165 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
2166 csw->Tag = fsg->tag;
2167 csw->Residue = cpu_to_le32(fsg->residue);
2168 csw->Status = status;
2169
2170 bh->inreq->length = USB_BULK_CS_WRAP_LEN;
2171 bh->inreq->zero = 0;
2172 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2173 &bh->inreq_busy, &bh->state);
2174
2175 } else if (mod_data.transport_type == USB_PR_CB) {
2176 1889
2177 /* Control-Bulk transport has no status phase! */ 1890 /* Store and send the Bulk-only CSW */
2178 return 0; 1891 csw = bh->buf;
2179 1892
2180 } else { // USB_PR_CBI 1893 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
2181 struct interrupt_data *buf = bh->buf; 1894 csw->Tag = fsg->tag;
1895 csw->Residue = cpu_to_le32(fsg->residue);
1896 csw->Status = status;
2182 1897
2183 /* Store and send the Interrupt data. UFI sends the ASC 1898 bh->inreq->length = USB_BULK_CS_WRAP_LEN;
2184 * and ASCQ bytes. Everything else sends a Type (which 1899 bh->inreq->zero = 0;
2185 * is always 0) and the status Value. */ 1900 start_transfer(fsg, fsg->bulk_in, bh->inreq,
2186 if (mod_data.protocol_type == USB_SC_UFI) { 1901 &bh->inreq_busy, &bh->state);
2187 buf->bType = ASC(sd);
2188 buf->bValue = ASCQ(sd);
2189 } else {
2190 buf->bType = 0;
2191 buf->bValue = status;
2192 }
2193 fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
2194
2195 fsg->intr_buffhd = bh; // Point to the right buffhd
2196 fsg->intreq->buf = bh->inreq->buf;
2197 fsg->intreq->context = bh;
2198 start_transfer(fsg, fsg->intr_in, fsg->intreq,
2199 &fsg->intreq_busy, &bh->state);
2200 }
2201 1902
2202 fsg->next_buffhd_to_fill = bh->next; 1903 fsg->next_buffhd_to_fill = bh->next;
2203 return 0; 1904 return 0;
@@ -2218,21 +1919,6 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2218 char hdlen[20]; 1919 char hdlen[20];
2219 struct fsg_lun *curlun; 1920 struct fsg_lun *curlun;
2220 1921
2221 /* Adjust the expected cmnd_size for protocol encapsulation padding.
2222 * Transparent SCSI doesn't pad. */
2223 if (protocol_is_scsi())
2224 ;
2225
2226 /* There's some disagreement as to whether RBC pads commands or not.
2227 * We'll play it safe and accept either form. */
2228 else if (mod_data.protocol_type == USB_SC_RBC) {
2229 if (fsg->cmnd_size == 12)
2230 cmnd_size = 12;
2231
2232 /* All the other protocols pad to 12 bytes */
2233 } else
2234 cmnd_size = 12;
2235
2236 hdlen[0] = 0; 1922 hdlen[0] = 0;
2237 if (fsg->data_dir != DATA_DIR_UNKNOWN) 1923 if (fsg->data_dir != DATA_DIR_UNKNOWN)
2238 sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir], 1924 sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
@@ -2294,13 +1980,9 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2294 } 1980 }
2295 1981
2296 /* Check that the LUN values are consistent */ 1982 /* Check that the LUN values are consistent */
2297 if (transport_is_bbb()) { 1983 if (fsg->lun != lun)
2298 if (fsg->lun != lun) 1984 DBG(fsg, "using LUN %d from CBW, not LUN %d from CDB\n",
2299 DBG(fsg, "using LUN %d from CBW, " 1985 fsg->lun, lun);
2300 "not LUN %d from CDB\n",
2301 fsg->lun, lun);
2302 } else
2303 fsg->lun = lun; // Use LUN from the command
2304 1986
2305 /* Check the LUN */ 1987 /* Check the LUN */
2306 if (fsg->lun >= 0 && fsg->lun < fsg->nluns) { 1988 if (fsg->lun >= 0 && fsg->lun < fsg->nluns) {
@@ -2666,59 +2348,34 @@ static int get_next_command(struct fsg_dev *fsg)
2666 struct fsg_buffhd *bh; 2348 struct fsg_buffhd *bh;
2667 int rc = 0; 2349 int rc = 0;
2668 2350
2669 if (transport_is_bbb()) { 2351 /* Wait for the next buffer to become available */
2670 2352 bh = fsg->next_buffhd_to_fill;
2671 /* Wait for the next buffer to become available */ 2353 while (bh->state != BUF_STATE_EMPTY) {
2672 bh = fsg->next_buffhd_to_fill; 2354 rc = sleep_thread(fsg);
2673 while (bh->state != BUF_STATE_EMPTY) { 2355 if (rc)
2674 rc = sleep_thread(fsg); 2356 return rc;
2675 if (rc) 2357 }
2676 return rc;
2677 }
2678
2679 /* Queue a request to read a Bulk-only CBW */
2680 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN);
2681 bh->outreq->short_not_ok = 1;
2682 start_transfer(fsg, fsg->bulk_out, bh->outreq,
2683 &bh->outreq_busy, &bh->state);
2684
2685 /* We will drain the buffer in software, which means we
2686 * can reuse it for the next filling. No need to advance
2687 * next_buffhd_to_fill. */
2688
2689 /* Wait for the CBW to arrive */
2690 while (bh->state != BUF_STATE_FULL) {
2691 rc = sleep_thread(fsg);
2692 if (rc)
2693 return rc;
2694 }
2695 smp_rmb();
2696 rc = received_cbw(fsg, bh);
2697 bh->state = BUF_STATE_EMPTY;
2698
2699 } else { // USB_PR_CB or USB_PR_CBI
2700 2358
2701 /* Wait for the next command to arrive */ 2359 /* Queue a request to read a Bulk-only CBW */
2702 while (fsg->cbbuf_cmnd_size == 0) { 2360 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN);
2703 rc = sleep_thread(fsg); 2361 bh->outreq->short_not_ok = 1;
2704 if (rc) 2362 start_transfer(fsg, fsg->bulk_out, bh->outreq,
2705 return rc; 2363 &bh->outreq_busy, &bh->state);
2706 }
2707 2364
2708 /* Is the previous status interrupt request still busy? 2365 /* We will drain the buffer in software, which means we
2709 * The host is allowed to skip reading the status, 2366 * can reuse it for the next filling. No need to advance
2710 * so we must cancel it. */ 2367 * next_buffhd_to_fill. */
2711 if (fsg->intreq_busy)
2712 usb_ep_dequeue(fsg->intr_in, fsg->intreq);
2713 2368
2714 /* Copy the command and mark the buffer empty */ 2369 /* Wait for the CBW to arrive */
2715 fsg->data_dir = DATA_DIR_UNKNOWN; 2370 while (bh->state != BUF_STATE_FULL) {
2716 spin_lock_irq(&fsg->lock); 2371 rc = sleep_thread(fsg);
2717 fsg->cmnd_size = fsg->cbbuf_cmnd_size; 2372 if (rc)
2718 memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size); 2373 return rc;
2719 fsg->cbbuf_cmnd_size = 0;
2720 spin_unlock_irq(&fsg->lock);
2721 } 2374 }
2375 smp_rmb();
2376 rc = received_cbw(fsg, bh);
2377 bh->state = BUF_STATE_EMPTY;
2378
2722 return rc; 2379 return rc;
2723} 2380}
2724 2381
@@ -2775,10 +2432,6 @@ reset:
2775 bh->outreq = NULL; 2432 bh->outreq = NULL;
2776 } 2433 }
2777 } 2434 }
2778 if (fsg->intreq) {
2779 usb_ep_free_request(fsg->intr_in, fsg->intreq);
2780 fsg->intreq = NULL;
2781 }
2782 2435
2783 /* Disable the endpoints */ 2436 /* Disable the endpoints */
2784 if (fsg->bulk_in_enabled) { 2437 if (fsg->bulk_in_enabled) {
@@ -2789,10 +2442,6 @@ reset:
2789 usb_ep_disable(fsg->bulk_out); 2442 usb_ep_disable(fsg->bulk_out);
2790 fsg->bulk_out_enabled = 0; 2443 fsg->bulk_out_enabled = 0;
2791 } 2444 }
2792 if (fsg->intr_in_enabled) {
2793 usb_ep_disable(fsg->intr_in);
2794 fsg->intr_in_enabled = 0;
2795 }
2796 2445
2797 fsg->running = 0; 2446 fsg->running = 0;
2798 if (altsetting < 0 || rc != 0) 2447 if (altsetting < 0 || rc != 0)
@@ -2815,14 +2464,6 @@ reset:
2815 fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); 2464 fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
2816 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2465 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2817 2466
2818 if (transport_is_cbi()) {
2819 d = fsg_ep_desc(fsg->gadget,
2820 &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc);
2821 if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
2822 goto reset;
2823 fsg->intr_in_enabled = 1;
2824 }
2825
2826 /* Allocate the requests */ 2467 /* Allocate the requests */
2827 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2468 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2828 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2469 struct fsg_buffhd *bh = &fsg->buffhds[i];
@@ -2836,11 +2477,6 @@ reset:
2836 bh->inreq->complete = bulk_in_complete; 2477 bh->inreq->complete = bulk_in_complete;
2837 bh->outreq->complete = bulk_out_complete; 2478 bh->outreq->complete = bulk_out_complete;
2838 } 2479 }
2839 if (transport_is_cbi()) {
2840 if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
2841 goto reset;
2842 fsg->intreq->complete = intr_in_complete;
2843 }
2844 2480
2845 fsg->running = 1; 2481 fsg->running = 1;
2846 for (i = 0; i < fsg->nluns; ++i) 2482 for (i = 0; i < fsg->nluns; ++i)
@@ -2918,8 +2554,6 @@ static void handle_exception(struct fsg_dev *fsg)
2918 } 2554 }
2919 2555
2920 /* Cancel all the pending transfers */ 2556 /* Cancel all the pending transfers */
2921 if (fsg->intreq_busy)
2922 usb_ep_dequeue(fsg->intr_in, fsg->intreq);
2923 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2557 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2924 bh = &fsg->buffhds[i]; 2558 bh = &fsg->buffhds[i];
2925 if (bh->inreq_busy) 2559 if (bh->inreq_busy)
@@ -2930,7 +2564,7 @@ static void handle_exception(struct fsg_dev *fsg)
2930 2564
2931 /* Wait until everything is idle */ 2565 /* Wait until everything is idle */
2932 for (;;) { 2566 for (;;) {
2933 num_active = fsg->intreq_busy; 2567 num_active = 0;
2934 for (i = 0; i < FSG_NUM_BUFFERS; ++i) { 2568 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2935 bh = &fsg->buffhds[i]; 2569 bh = &fsg->buffhds[i];
2936 num_active += bh->inreq_busy + bh->outreq_busy; 2570 num_active += bh->inreq_busy + bh->outreq_busy;
@@ -2946,8 +2580,6 @@ static void handle_exception(struct fsg_dev *fsg)
2946 usb_ep_fifo_flush(fsg->bulk_in); 2580 usb_ep_fifo_flush(fsg->bulk_in);
2947 if (fsg->bulk_out_enabled) 2581 if (fsg->bulk_out_enabled)
2948 usb_ep_fifo_flush(fsg->bulk_out); 2582 usb_ep_fifo_flush(fsg->bulk_out);
2949 if (fsg->intr_in_enabled)
2950 usb_ep_fifo_flush(fsg->intr_in);
2951 2583
2952 /* Reset the I/O buffer states and pointers, the SCSI 2584 /* Reset the I/O buffer states and pointers, the SCSI
2953 * state, and the exception. Then invoke the handler. */ 2585 * state, and the exception. Then invoke the handler. */
@@ -2999,12 +2631,8 @@ static void handle_exception(struct fsg_dev *fsg)
2999 if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags)) 2631 if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
3000 usb_ep_clear_halt(fsg->bulk_in); 2632 usb_ep_clear_halt(fsg->bulk_in);
3001 2633
3002 if (transport_is_bbb()) { 2634 if (fsg->ep0_req_tag == exception_req_tag)
3003 if (fsg->ep0_req_tag == exception_req_tag) 2635 ep0_queue(fsg); // Complete the status stage
3004 ep0_queue(fsg); // Complete the status stage
3005
3006 } else if (transport_is_cbi())
3007 send_status(fsg); // Status by interrupt pipe
3008 2636
3009 /* Technically this should go here, but it would only be 2637 /* Technically this should go here, but it would only be
3010 * a waste of time. Ditto for the INTERFACE_CHANGE and 2638 * a waste of time. Ditto for the INTERFACE_CHANGE and
@@ -3196,15 +2824,8 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3196 2824
3197static int __init check_parameters(struct fsg_dev *fsg) 2825static int __init check_parameters(struct fsg_dev *fsg)
3198{ 2826{
3199 int prot;
3200 int gcnum; 2827 int gcnum;
3201 2828
3202 /* Store the default values */
3203 mod_data.transport_type = USB_PR_BULK;
3204 mod_data.transport_name = "Bulk-only";
3205 mod_data.protocol_type = USB_SC_SCSI;
3206 mod_data.protocol_name = "Transparent SCSI";
3207
3208 /* Some peripheral controllers are known not to be able to 2829 /* Some peripheral controllers are known not to be able to
3209 * halt bulk endpoints correctly. If one of them is present, 2830 * halt bulk endpoints correctly. If one of them is present,
3210 * disable stalls. 2831 * disable stalls.
@@ -3227,58 +2848,6 @@ static int __init check_parameters(struct fsg_dev *fsg)
3227 } 2848 }
3228 } 2849 }
3229 2850
3230 prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
3231
3232#ifdef CONFIG_USB_FILE_STORAGE_TEST
3233 if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
3234 ; // Use default setting
3235 } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
3236 mod_data.transport_type = USB_PR_CB;
3237 mod_data.transport_name = "Control-Bulk";
3238 } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
3239 mod_data.transport_type = USB_PR_CBI;
3240 mod_data.transport_name = "Control-Bulk-Interrupt";
3241 } else {
3242 ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
3243 return -EINVAL;
3244 }
3245
3246 if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
3247 prot == USB_SC_SCSI) {
3248 ; // Use default setting
3249 } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
3250 prot == USB_SC_RBC) {
3251 mod_data.protocol_type = USB_SC_RBC;
3252 mod_data.protocol_name = "RBC";
3253 } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
3254 strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
3255 prot == USB_SC_8020) {
3256 mod_data.protocol_type = USB_SC_8020;
3257 mod_data.protocol_name = "8020i (ATAPI)";
3258 } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
3259 prot == USB_SC_QIC) {
3260 mod_data.protocol_type = USB_SC_QIC;
3261 mod_data.protocol_name = "QIC-157";
3262 } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
3263 prot == USB_SC_UFI) {
3264 mod_data.protocol_type = USB_SC_UFI;
3265 mod_data.protocol_name = "UFI";
3266 } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
3267 prot == USB_SC_8070) {
3268 mod_data.protocol_type = USB_SC_8070;
3269 mod_data.protocol_name = "8070i";
3270 } else {
3271 ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
3272 return -EINVAL;
3273 }
3274
3275 mod_data.buflen &= PAGE_CACHE_MASK;
3276 if (mod_data.buflen <= 0) {
3277 ERROR(fsg, "invalid buflen\n");
3278 return -ETOOSMALL;
3279 }
3280#endif /* CONFIG_USB_FILE_STORAGE_TEST */
3281
3282 return 0; 2851 return 0;
3283} 2852}
3284 2853
@@ -3381,29 +2950,11 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3381 ep->driver_data = fsg; // claim the endpoint 2950 ep->driver_data = fsg; // claim the endpoint
3382 fsg->bulk_out = ep; 2951 fsg->bulk_out = ep;
3383 2952
3384 if (transport_is_cbi()) {
3385 ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
3386 if (!ep)
3387 goto autoconf_fail;
3388 ep->driver_data = fsg; // claim the endpoint
3389 fsg->intr_in = ep;
3390 }
3391
3392 /* Fix up the descriptors */ 2953 /* Fix up the descriptors */
3393 device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket; 2954 device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
3394 device_desc.idVendor = cpu_to_le16(mod_data.vendor);
3395 device_desc.idProduct = cpu_to_le16(mod_data.product);
3396 device_desc.bcdDevice = cpu_to_le16(mod_data.release); 2955 device_desc.bcdDevice = cpu_to_le16(mod_data.release);
3397 2956
3398 i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
3399 fsg_intf_desc.bNumEndpoints = i;
3400 fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
3401 fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
3402 fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3403
3404 if (gadget_is_dualspeed(gadget)) { 2957 if (gadget_is_dualspeed(gadget)) {
3405 fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3406
3407 /* Assume ep0 uses the same maxpacket value for both speeds */ 2958 /* Assume ep0 uses the same maxpacket value for both speeds */
3408 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; 2959 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
3409 2960
@@ -3412,8 +2963,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3412 fsg_fs_bulk_in_desc.bEndpointAddress; 2963 fsg_fs_bulk_in_desc.bEndpointAddress;
3413 fsg_hs_bulk_out_desc.bEndpointAddress = 2964 fsg_hs_bulk_out_desc.bEndpointAddress =
3414 fsg_fs_bulk_out_desc.bEndpointAddress; 2965 fsg_fs_bulk_out_desc.bEndpointAddress;
3415 fsg_hs_intr_in_desc.bEndpointAddress =
3416 fsg_fs_intr_in_desc.bEndpointAddress;
3417 } 2966 }
3418 2967
3419 if (gadget_is_otg(gadget)) 2968 if (gadget_is_otg(gadget))
@@ -3437,7 +2986,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3437 /* Allocate for the bulk-in endpoint. We assume that 2986 /* Allocate for the bulk-in endpoint. We assume that
3438 * the buffer will also work with the bulk-out (and 2987 * the buffer will also work with the bulk-out (and
3439 * interrupt-in) endpoint. */ 2988 * interrupt-in) endpoint. */
3440 bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL); 2989 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
3441 if (!bh->buf) 2990 if (!bh->buf)
3442 goto out; 2991 goto out;
3443 bh->next = bh + 1; 2992 bh->next = bh + 1;
@@ -3489,15 +3038,9 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3489 } 3038 }
3490 kfree(pathbuf); 3039 kfree(pathbuf);
3491 3040
3492 DBG(fsg, "transport=%s (x%02x)\n",
3493 mod_data.transport_name, mod_data.transport_type);
3494 DBG(fsg, "protocol=%s (x%02x)\n",
3495 mod_data.protocol_name, mod_data.protocol_type);
3496 DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
3497 mod_data.vendor, mod_data.product, mod_data.release);
3498 DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n", 3041 DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
3499 mod_data.removable, mod_data.can_stall, 3042 mod_data.removable, mod_data.can_stall,
3500 mod_data.cdrom, mod_data.buflen); 3043 mod_data.cdrom, FSG_BUFLEN);
3501 DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task)); 3044 DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
3502 3045
3503 set_bit(REGISTERED, &fsg->atomic_bitflags); 3046 set_bit(REGISTERED, &fsg->atomic_bitflags);
@@ -3520,25 +3063,6 @@ out:
3520 3063
3521/*-------------------------------------------------------------------------*/ 3064/*-------------------------------------------------------------------------*/
3522 3065
3523static void fsg_suspend(struct usb_gadget *gadget)
3524{
3525 struct fsg_dev *fsg = get_gadget_data(gadget);
3526
3527 DBG(fsg, "suspend\n");
3528 set_bit(SUSPENDED, &fsg->atomic_bitflags);
3529}
3530
3531static void fsg_resume(struct usb_gadget *gadget)
3532{
3533 struct fsg_dev *fsg = get_gadget_data(gadget);
3534
3535 DBG(fsg, "resume\n");
3536 clear_bit(SUSPENDED, &fsg->atomic_bitflags);
3537}
3538
3539
3540/*-------------------------------------------------------------------------*/
3541
3542static struct usb_gadget_driver fsg_driver = { 3066static struct usb_gadget_driver fsg_driver = {
3543#ifdef CONFIG_USB_GADGET_DUALSPEED 3067#ifdef CONFIG_USB_GADGET_DUALSPEED
3544 .speed = USB_SPEED_HIGH, 3068 .speed = USB_SPEED_HIGH,
@@ -3550,8 +3074,6 @@ static struct usb_gadget_driver fsg_driver = {
3550 .unbind = fsg_unbind, 3074 .unbind = fsg_unbind,
3551 .disconnect = fsg_disconnect, 3075 .disconnect = fsg_disconnect,
3552 .setup = fsg_setup, 3076 .setup = fsg_setup,
3553 .suspend = fsg_suspend,
3554 .resume = fsg_resume,
3555 3077
3556 .driver = { 3078 .driver = {
3557 .name = DRIVER_NAME, 3079 .name = DRIVER_NAME,
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 6523cb6f4c4d..e76c8ced41e2 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -33,6 +33,20 @@
33 * macro is defined prior to including this file. 33 * macro is defined prior to including this file.
34 */ 34 */
35 35
36/*
37 * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
38 * fsg_hs_intr_in_desc objects as well as
39 * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
40 * macros are not defined.
41 *
42 * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
43 * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not
44 * defined (as well as corresponding entries in string tables are
45 * missing) and FSG_STRING_INTERFACE has value of zero.
46 *
47 * When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
48 */
49
36 50
37#include <asm/unaligned.h> 51#include <asm/unaligned.h>
38 52
@@ -327,14 +341,17 @@ static inline u32 get_unaligned_be24(u8 *buf)
327 341
328 342
329enum { 343enum {
344#ifndef FSG_NO_DEVICE_STRINGS
330 FSG_STRING_MANUFACTURER = 1, 345 FSG_STRING_MANUFACTURER = 1,
331 FSG_STRING_PRODUCT, 346 FSG_STRING_PRODUCT,
332 FSG_STRING_SERIAL, 347 FSG_STRING_SERIAL,
333 FSG_STRING_CONFIG, 348 FSG_STRING_CONFIG,
349#endif
334 FSG_STRING_INTERFACE 350 FSG_STRING_INTERFACE
335}; 351};
336 352
337 353
354#ifndef FSG_NO_OTG
338static struct usb_otg_descriptor 355static struct usb_otg_descriptor
339fsg_otg_desc = { 356fsg_otg_desc = {
340 .bLength = sizeof fsg_otg_desc, 357 .bLength = sizeof fsg_otg_desc,
@@ -342,6 +359,7 @@ fsg_otg_desc = {
342 359
343 .bmAttributes = USB_OTG_SRP, 360 .bmAttributes = USB_OTG_SRP,
344}; 361};
362#endif
345 363
346/* There is only one interface. */ 364/* There is only one interface. */
347 365
@@ -380,6 +398,8 @@ fsg_fs_bulk_out_desc = {
380 /* wMaxPacketSize set by autoconfiguration */ 398 /* wMaxPacketSize set by autoconfiguration */
381}; 399};
382 400
401#ifndef FSG_NO_INTR_EP
402
383static struct usb_endpoint_descriptor 403static struct usb_endpoint_descriptor
384fsg_fs_intr_in_desc = { 404fsg_fs_intr_in_desc = {
385 .bLength = USB_DT_ENDPOINT_SIZE, 405 .bLength = USB_DT_ENDPOINT_SIZE,
@@ -391,15 +411,26 @@ fsg_fs_intr_in_desc = {
391 .bInterval = 32, // frames -> 32 ms 411 .bInterval = 32, // frames -> 32 ms
392}; 412};
393 413
414#ifndef FSG_NO_OTG
415# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2
416#else
417# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 1
418#endif
419
420#endif
421
394static const struct usb_descriptor_header *fsg_fs_function[] = { 422static const struct usb_descriptor_header *fsg_fs_function[] = {
423#ifndef FSG_NO_OTG
395 (struct usb_descriptor_header *) &fsg_otg_desc, 424 (struct usb_descriptor_header *) &fsg_otg_desc,
425#endif
396 (struct usb_descriptor_header *) &fsg_intf_desc, 426 (struct usb_descriptor_header *) &fsg_intf_desc,
397 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, 427 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
398 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, 428 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
429#ifndef FSG_NO_INTR_EP
399 (struct usb_descriptor_header *) &fsg_fs_intr_in_desc, 430 (struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
431#endif
400 NULL, 432 NULL,
401}; 433};
402#define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2
403 434
404 435
405/* 436/*
@@ -431,6 +462,8 @@ fsg_hs_bulk_out_desc = {
431 .bInterval = 1, // NAK every 1 uframe 462 .bInterval = 1, // NAK every 1 uframe
432}; 463};
433 464
465#ifndef FSG_NO_INTR_EP
466
434static struct usb_endpoint_descriptor 467static struct usb_endpoint_descriptor
435fsg_hs_intr_in_desc = { 468fsg_hs_intr_in_desc = {
436 .bLength = USB_DT_ENDPOINT_SIZE, 469 .bLength = USB_DT_ENDPOINT_SIZE,
@@ -442,15 +475,26 @@ fsg_hs_intr_in_desc = {
442 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms 475 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms
443}; 476};
444 477
478#ifndef FSG_NO_OTG
479# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2
480#else
481# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 1
482#endif
483
484#endif
485
445static const struct usb_descriptor_header *fsg_hs_function[] = { 486static const struct usb_descriptor_header *fsg_hs_function[] = {
487#ifndef FSG_NO_OTG
446 (struct usb_descriptor_header *) &fsg_otg_desc, 488 (struct usb_descriptor_header *) &fsg_otg_desc,
489#endif
447 (struct usb_descriptor_header *) &fsg_intf_desc, 490 (struct usb_descriptor_header *) &fsg_intf_desc,
448 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, 491 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
449 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, 492 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
493#ifndef FSG_NO_INTR_EP
450 (struct usb_descriptor_header *) &fsg_hs_intr_in_desc, 494 (struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
495#endif
451 NULL, 496 NULL,
452}; 497};
453#define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2
454 498
455/* Maxpacket and other transfer characteristics vary by speed. */ 499/* Maxpacket and other transfer characteristics vary by speed. */
456static struct usb_endpoint_descriptor * 500static struct usb_endpoint_descriptor *
@@ -465,10 +509,12 @@ fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
465 509
466/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ 510/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
467static struct usb_string fsg_strings[] = { 511static struct usb_string fsg_strings[] = {
512#ifndef FSG_NO_DEVICE_STRINGS
468 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, 513 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
469 {FSG_STRING_PRODUCT, fsg_string_product}, 514 {FSG_STRING_PRODUCT, fsg_string_product},
470 {FSG_STRING_SERIAL, fsg_string_serial}, 515 {FSG_STRING_SERIAL, fsg_string_serial},
471 {FSG_STRING_CONFIG, fsg_string_config}, 516 {FSG_STRING_CONFIG, fsg_string_config},
517#endif
472 {FSG_STRING_INTERFACE, fsg_string_interface}, 518 {FSG_STRING_INTERFACE, fsg_string_interface},
473 {} 519 {}
474}; 520};