aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMichal Nazarewicz <m.nazarewicz@samsung.com>2009-10-28 11:57:15 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 14:55:18 -0500
commitd6181702f510302dce5666a50344b5acb196ab4e (patch)
tree82b28ab17bcc357cd290d79c0590a4d9b514ff8e /drivers
parentb6058d0fefc0b5ff777dfbff990a0a50a4ac144b (diff)
USB: g_file_storage: "fsg_" prefix added to some identifiers
Prefixed some identifiers that were defined in storage_common.c file with "fsg_". Not all identifiers were prefixed but the ones that are most likely to produce conflicts when used with other USB functions. 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')
-rw-r--r--drivers/usb/gadget/file_storage.c203
-rw-r--r--drivers/usb/gadget/storage_common.c132
2 files changed, 183 insertions, 152 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 332599c11987..90233f4f3601 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -248,8 +248,6 @@
248#include <linux/freezer.h> 248#include <linux/freezer.h>
249#include <linux/utsname.h> 249#include <linux/utsname.h>
250 250
251#include <asm/unaligned.h>
252
253#include <linux/usb/ch9.h> 251#include <linux/usb/ch9.h>
254#include <linux/usb/gadget.h> 252#include <linux/usb/gadget.h>
255 253
@@ -274,8 +272,11 @@
274#define DRIVER_NAME "g_file_storage" 272#define DRIVER_NAME "g_file_storage"
275#define DRIVER_VERSION "20 November 2008" 273#define DRIVER_VERSION "20 November 2008"
276 274
277static const char longname[] = DRIVER_DESC; 275static char fsg_string_manufacturer[64];
278static const char shortname[] = DRIVER_NAME; 276static const char fsg_string_product[] = DRIVER_DESC;
277static char fsg_string_serial[13];
278static const char fsg_string_config[] = "Self-powered";
279static const char fsg_string_interface[] = "Mass Storage";
279 280
280MODULE_DESCRIPTION(DRIVER_DESC); 281MODULE_DESCRIPTION(DRIVER_DESC);
281MODULE_AUTHOR("Alan Stern"); 282MODULE_AUTHOR("Alan Stern");
@@ -285,8 +286,8 @@ MODULE_LICENSE("Dual BSD/GPL");
285 * 286 *
286 * DO NOT REUSE THESE IDs with any other driver!! Ever!! 287 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
287 * Instead: allocate your own, using normal USB-IF procedures. */ 288 * Instead: allocate your own, using normal USB-IF procedures. */
288#define DRIVER_VENDOR_ID 0x0525 // NetChip 289#define FSG_VENDOR_ID 0x0525 // NetChip
289#define DRIVER_PRODUCT_ID 0xa4a5 // Linux-USB File-backed Storage Gadget 290#define FSG_PRODUCT_ID 0xa4a5 // Linux-USB File-backed Storage Gadget
290 291
291 292
292/* 293/*
@@ -301,11 +302,11 @@ MODULE_LICENSE("Dual BSD/GPL");
301 302
302/* Encapsulate the module parameter settings */ 303/* Encapsulate the module parameter settings */
303 304
304#define MAX_LUNS 8 305#define FSG_MAX_LUNS 8
305 306
306static struct { 307static struct {
307 char *file[MAX_LUNS]; 308 char *file[FSG_MAX_LUNS];
308 int ro[MAX_LUNS]; 309 int ro[FSG_MAX_LUNS];
309 unsigned int num_filenames; 310 unsigned int num_filenames;
310 unsigned int num_ros; 311 unsigned int num_ros;
311 unsigned int nluns; 312 unsigned int nluns;
@@ -332,8 +333,8 @@ static struct {
332 .removable = 0, 333 .removable = 0,
333 .can_stall = 1, 334 .can_stall = 1,
334 .cdrom = 0, 335 .cdrom = 0,
335 .vendor = DRIVER_VENDOR_ID, 336 .vendor = FSG_VENDOR_ID,
336 .product = DRIVER_PRODUCT_ID, 337 .product = FSG_PRODUCT_ID,
337 .release = 0xffff, // Use controller chip type 338 .release = 0xffff, // Use controller chip type
338 .buflen = 16384, 339 .buflen = 16384,
339 }; 340 };
@@ -434,7 +435,7 @@ struct fsg_dev {
434 int intreq_busy; 435 int intreq_busy;
435 struct fsg_buffhd *intr_buffhd; 436 struct fsg_buffhd *intr_buffhd;
436 437
437 unsigned int bulk_out_maxpacket; 438 unsigned int bulk_out_maxpacket;
438 enum fsg_state state; // For exception handling 439 enum fsg_state state; // For exception handling
439 unsigned int exception_req_tag; 440 unsigned int exception_req_tag;
440 441
@@ -459,7 +460,7 @@ struct fsg_dev {
459 460
460 struct fsg_buffhd *next_buffhd_to_fill; 461 struct fsg_buffhd *next_buffhd_to_fill;
461 struct fsg_buffhd *next_buffhd_to_drain; 462 struct fsg_buffhd *next_buffhd_to_drain;
462 struct fsg_buffhd buffhds[NUM_BUFFERS]; 463 struct fsg_buffhd buffhds[FSG_NUM_BUFFERS];
463 464
464 int thread_wakeup_needed; 465 int thread_wakeup_needed;
465 struct completion thread_notifier; 466 struct completion thread_notifier;
@@ -484,8 +485,8 @@ struct fsg_dev {
484 u8 cbbuf_cmnd[MAX_COMMAND_SIZE]; 485 u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
485 486
486 unsigned int nluns; 487 unsigned int nluns;
487 struct lun *luns; 488 struct fsg_lun *luns;
488 struct lun *curlun; 489 struct fsg_lun *curlun;
489}; 490};
490 491
491typedef void (*fsg_routine_t)(struct fsg_dev *); 492typedef void (*fsg_routine_t)(struct fsg_dev *);
@@ -549,13 +550,13 @@ device_desc = {
549 .bDeviceClass = USB_CLASS_PER_INTERFACE, 550 .bDeviceClass = USB_CLASS_PER_INTERFACE,
550 551
551 /* The next three values can be overridden by module parameters */ 552 /* The next three values can be overridden by module parameters */
552 .idVendor = cpu_to_le16(DRIVER_VENDOR_ID), 553 .idVendor = cpu_to_le16(FSG_VENDOR_ID),
553 .idProduct = cpu_to_le16(DRIVER_PRODUCT_ID), 554 .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
554 .bcdDevice = cpu_to_le16(0xffff), 555 .bcdDevice = cpu_to_le16(0xffff),
555 556
556 .iManufacturer = STRING_MANUFACTURER, 557 .iManufacturer = FSG_STRING_MANUFACTURER,
557 .iProduct = STRING_PRODUCT, 558 .iProduct = FSG_STRING_PRODUCT,
558 .iSerialNumber = STRING_SERIAL, 559 .iSerialNumber = FSG_STRING_SERIAL,
559 .bNumConfigurations = 1, 560 .bNumConfigurations = 1,
560}; 561};
561 562
@@ -567,7 +568,7 @@ config_desc = {
567 /* wTotalLength computed by usb_gadget_config_buf() */ 568 /* wTotalLength computed by usb_gadget_config_buf() */
568 .bNumInterfaces = 1, 569 .bNumInterfaces = 1,
569 .bConfigurationValue = CONFIG_VALUE, 570 .bConfigurationValue = CONFIG_VALUE,
570 .iConfiguration = STRING_CONFIG, 571 .iConfiguration = FSG_STRING_CONFIG,
571 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 572 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
572 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, 573 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
573}; 574};
@@ -604,9 +605,9 @@ static int populate_config_buf(struct usb_gadget *gadget,
604 if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG) 605 if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
605 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed; 606 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
606 if (gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH) 607 if (gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH)
607 function = hs_function; 608 function = fsg_hs_function;
608 else 609 else
609 function = fs_function; 610 function = fsg_fs_function;
610 611
611 /* for now, don't advertise srp-only devices */ 612 /* for now, don't advertise srp-only devices */
612 if (!gadget_is_otg(gadget)) 613 if (!gadget_is_otg(gadget))
@@ -957,7 +958,7 @@ get_config:
957 VDBG(fsg, "get string descriptor\n"); 958 VDBG(fsg, "get string descriptor\n");
958 959
959 /* wIndex == language code */ 960 /* wIndex == language code */
960 value = usb_gadget_get_string(&stringtab, 961 value = usb_gadget_get_string(&fsg_stringtab,
961 w_value & 0xff, req->buf); 962 w_value & 0xff, req->buf);
962 break; 963 break;
963 } 964 }
@@ -1122,7 +1123,7 @@ static int sleep_thread(struct fsg_dev *fsg)
1122 1123
1123static int do_read(struct fsg_dev *fsg) 1124static int do_read(struct fsg_dev *fsg)
1124{ 1125{
1125 struct lun *curlun = fsg->curlun; 1126 struct fsg_lun *curlun = fsg->curlun;
1126 u32 lba; 1127 u32 lba;
1127 struct fsg_buffhd *bh; 1128 struct fsg_buffhd *bh;
1128 int rc; 1129 int rc;
@@ -1248,7 +1249,7 @@ static int do_read(struct fsg_dev *fsg)
1248 1249
1249static int do_write(struct fsg_dev *fsg) 1250static int do_write(struct fsg_dev *fsg)
1250{ 1251{
1251 struct lun *curlun = fsg->curlun; 1252 struct fsg_lun *curlun = fsg->curlun;
1252 u32 lba; 1253 u32 lba;
1253 struct fsg_buffhd *bh; 1254 struct fsg_buffhd *bh;
1254 int get_some_more; 1255 int get_some_more;
@@ -1437,12 +1438,12 @@ static int do_write(struct fsg_dev *fsg)
1437 1438
1438static int do_synchronize_cache(struct fsg_dev *fsg) 1439static int do_synchronize_cache(struct fsg_dev *fsg)
1439{ 1440{
1440 struct lun *curlun = fsg->curlun; 1441 struct fsg_lun *curlun = fsg->curlun;
1441 int rc; 1442 int rc;
1442 1443
1443 /* We ignore the requested LBA and write out all file's 1444 /* We ignore the requested LBA and write out all file's
1444 * dirty data buffers. */ 1445 * dirty data buffers. */
1445 rc = fsync_sub(curlun); 1446 rc = fsg_lun_fsync_sub(curlun);
1446 if (rc) 1447 if (rc)
1447 curlun->sense_data = SS_WRITE_ERROR; 1448 curlun->sense_data = SS_WRITE_ERROR;
1448 return 0; 1449 return 0;
@@ -1451,7 +1452,7 @@ static int do_synchronize_cache(struct fsg_dev *fsg)
1451 1452
1452/*-------------------------------------------------------------------------*/ 1453/*-------------------------------------------------------------------------*/
1453 1454
1454static void invalidate_sub(struct lun *curlun) 1455static void invalidate_sub(struct fsg_lun *curlun)
1455{ 1456{
1456 struct file *filp = curlun->filp; 1457 struct file *filp = curlun->filp;
1457 struct inode *inode = filp->f_path.dentry->d_inode; 1458 struct inode *inode = filp->f_path.dentry->d_inode;
@@ -1463,7 +1464,7 @@ static void invalidate_sub(struct lun *curlun)
1463 1464
1464static int do_verify(struct fsg_dev *fsg) 1465static int do_verify(struct fsg_dev *fsg)
1465{ 1466{
1466 struct lun *curlun = fsg->curlun; 1467 struct fsg_lun *curlun = fsg->curlun;
1467 u32 lba; 1468 u32 lba;
1468 u32 verification_length; 1469 u32 verification_length;
1469 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill; 1470 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
@@ -1496,7 +1497,7 @@ static int do_verify(struct fsg_dev *fsg)
1496 file_offset = ((loff_t) lba) << 9; 1497 file_offset = ((loff_t) lba) << 9;
1497 1498
1498 /* Write out all the dirty buffers before invalidating them */ 1499 /* Write out all the dirty buffers before invalidating them */
1499 fsync_sub(curlun); 1500 fsg_lun_fsync_sub(curlun);
1500 if (signal_pending(current)) 1501 if (signal_pending(current))
1501 return -EINTR; 1502 return -EINTR;
1502 1503
@@ -1593,7 +1594,7 @@ static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1593 1594
1594static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1595static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1595{ 1596{
1596 struct lun *curlun = fsg->curlun; 1597 struct fsg_lun *curlun = fsg->curlun;
1597 u8 *buf = (u8 *) bh->buf; 1598 u8 *buf = (u8 *) bh->buf;
1598 u32 sd, sdinfo; 1599 u32 sd, sdinfo;
1599 int valid; 1600 int valid;
@@ -1647,7 +1648,7 @@ static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1647 1648
1648static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1649static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1649{ 1650{
1650 struct lun *curlun = fsg->curlun; 1651 struct fsg_lun *curlun = fsg->curlun;
1651 u32 lba = get_unaligned_be32(&fsg->cmnd[2]); 1652 u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
1652 int pmi = fsg->cmnd[8]; 1653 int pmi = fsg->cmnd[8];
1653 u8 *buf = (u8 *) bh->buf; 1654 u8 *buf = (u8 *) bh->buf;
@@ -1667,7 +1668,7 @@ static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1667 1668
1668static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1669static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1669{ 1670{
1670 struct lun *curlun = fsg->curlun; 1671 struct fsg_lun *curlun = fsg->curlun;
1671 int msf = fsg->cmnd[1] & 0x02; 1672 int msf = fsg->cmnd[1] & 0x02;
1672 u32 lba = get_unaligned_be32(&fsg->cmnd[2]); 1673 u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
1673 u8 *buf = (u8 *) bh->buf; 1674 u8 *buf = (u8 *) bh->buf;
@@ -1690,7 +1691,7 @@ static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1690 1691
1691static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1692static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1692{ 1693{
1693 struct lun *curlun = fsg->curlun; 1694 struct fsg_lun *curlun = fsg->curlun;
1694 int msf = fsg->cmnd[1] & 0x02; 1695 int msf = fsg->cmnd[1] & 0x02;
1695 int start_track = fsg->cmnd[6]; 1696 int start_track = fsg->cmnd[6];
1696 u8 *buf = (u8 *) bh->buf; 1697 u8 *buf = (u8 *) bh->buf;
@@ -1718,7 +1719,7 @@ static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1718 1719
1719static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1720static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1720{ 1721{
1721 struct lun *curlun = fsg->curlun; 1722 struct fsg_lun *curlun = fsg->curlun;
1722 int mscmnd = fsg->cmnd[0]; 1723 int mscmnd = fsg->cmnd[0];
1723 u8 *buf = (u8 *) bh->buf; 1724 u8 *buf = (u8 *) bh->buf;
1724 u8 *buf0 = buf; 1725 u8 *buf0 = buf;
@@ -1799,7 +1800,7 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1799 1800
1800static int do_start_stop(struct fsg_dev *fsg) 1801static int do_start_stop(struct fsg_dev *fsg)
1801{ 1802{
1802 struct lun *curlun = fsg->curlun; 1803 struct fsg_lun *curlun = fsg->curlun;
1803 int loej, start; 1804 int loej, start;
1804 1805
1805 if (!mod_data.removable) { 1806 if (!mod_data.removable) {
@@ -1829,7 +1830,7 @@ static int do_start_stop(struct fsg_dev *fsg)
1829 if (loej) { // Simulate an unload/eject 1830 if (loej) { // Simulate an unload/eject
1830 up_read(&fsg->filesem); 1831 up_read(&fsg->filesem);
1831 down_write(&fsg->filesem); 1832 down_write(&fsg->filesem);
1832 close_backing_file(curlun); 1833 fsg_lun_close(curlun);
1833 up_write(&fsg->filesem); 1834 up_write(&fsg->filesem);
1834 down_read(&fsg->filesem); 1835 down_read(&fsg->filesem);
1835 } 1836 }
@@ -1837,7 +1838,7 @@ static int do_start_stop(struct fsg_dev *fsg)
1837 1838
1838 /* Our emulation doesn't support mounting; the medium is 1839 /* Our emulation doesn't support mounting; the medium is
1839 * available for use as soon as it is loaded. */ 1840 * available for use as soon as it is loaded. */
1840 if (!backing_file_is_open(curlun)) { 1841 if (!fsg_lun_is_open(curlun)) {
1841 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 1842 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
1842 return -EINVAL; 1843 return -EINVAL;
1843 } 1844 }
@@ -1849,7 +1850,7 @@ static int do_start_stop(struct fsg_dev *fsg)
1849 1850
1850static int do_prevent_allow(struct fsg_dev *fsg) 1851static int do_prevent_allow(struct fsg_dev *fsg)
1851{ 1852{
1852 struct lun *curlun = fsg->curlun; 1853 struct fsg_lun *curlun = fsg->curlun;
1853 int prevent; 1854 int prevent;
1854 1855
1855 if (!mod_data.removable) { 1856 if (!mod_data.removable) {
@@ -1864,7 +1865,7 @@ static int do_prevent_allow(struct fsg_dev *fsg)
1864 } 1865 }
1865 1866
1866 if (curlun->prevent_medium_removal && !prevent) 1867 if (curlun->prevent_medium_removal && !prevent)
1867 fsync_sub(curlun); 1868 fsg_lun_fsync_sub(curlun);
1868 curlun->prevent_medium_removal = prevent; 1869 curlun->prevent_medium_removal = prevent;
1869 return 0; 1870 return 0;
1870} 1871}
@@ -1873,7 +1874,7 @@ static int do_prevent_allow(struct fsg_dev *fsg)
1873static int do_read_format_capacities(struct fsg_dev *fsg, 1874static int do_read_format_capacities(struct fsg_dev *fsg,
1874 struct fsg_buffhd *bh) 1875 struct fsg_buffhd *bh)
1875{ 1876{
1876 struct lun *curlun = fsg->curlun; 1877 struct fsg_lun *curlun = fsg->curlun;
1877 u8 *buf = (u8 *) bh->buf; 1878 u8 *buf = (u8 *) bh->buf;
1878 1879
1879 buf[0] = buf[1] = buf[2] = 0; 1880 buf[0] = buf[1] = buf[2] = 0;
@@ -1890,7 +1891,7 @@ static int do_read_format_capacities(struct fsg_dev *fsg,
1890 1891
1891static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1892static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
1892{ 1893{
1893 struct lun *curlun = fsg->curlun; 1894 struct fsg_lun *curlun = fsg->curlun;
1894 1895
1895 /* We don't support MODE SELECT */ 1896 /* We don't support MODE SELECT */
1896 curlun->sense_data = SS_INVALID_COMMAND; 1897 curlun->sense_data = SS_INVALID_COMMAND;
@@ -2133,7 +2134,7 @@ static int finish_reply(struct fsg_dev *fsg)
2133 2134
2134static int send_status(struct fsg_dev *fsg) 2135static int send_status(struct fsg_dev *fsg)
2135{ 2136{
2136 struct lun *curlun = fsg->curlun; 2137 struct fsg_lun *curlun = fsg->curlun;
2137 struct fsg_buffhd *bh; 2138 struct fsg_buffhd *bh;
2138 int rc; 2139 int rc;
2139 u8 status = USB_STATUS_PASS; 2140 u8 status = USB_STATUS_PASS;
@@ -2225,7 +2226,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2225 int lun = fsg->cmnd[1] >> 5; 2226 int lun = fsg->cmnd[1] >> 5;
2226 static const char dirletter[4] = {'u', 'o', 'i', 'n'}; 2227 static const char dirletter[4] = {'u', 'o', 'i', 'n'};
2227 char hdlen[20]; 2228 char hdlen[20];
2228 struct lun *curlun; 2229 struct fsg_lun *curlun;
2229 2230
2230 /* Adjust the expected cmnd_size for protocol encapsulation padding. 2231 /* Adjust the expected cmnd_size for protocol encapsulation padding.
2231 * Transparent SCSI doesn't pad. */ 2232 * Transparent SCSI doesn't pad. */
@@ -2354,7 +2355,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2354 2355
2355 /* If the medium isn't mounted and the command needs to access 2356 /* If the medium isn't mounted and the command needs to access
2356 * it, return an error. */ 2357 * it, return an error. */
2357 if (curlun && !backing_file_is_open(curlun) && needs_medium) { 2358 if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
2358 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 2359 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
2359 return -EINVAL; 2360 return -EINVAL;
2360 } 2361 }
@@ -2609,8 +2610,8 @@ static int do_scsi_command(struct fsg_dev *fsg)
2609 2610
2610static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) 2611static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2611{ 2612{
2612 struct usb_request *req = bh->outreq; 2613 struct usb_request *req = bh->outreq;
2613 struct bulk_cb_wrap *cbw = req->buf; 2614 struct fsg_bulk_cb_wrap *cbw = req->buf;
2614 2615
2615 /* Was this a real packet? Should it be ignored? */ 2616 /* Was this a real packet? Should it be ignored? */
2616 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags)) 2617 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
@@ -2639,7 +2640,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2639 } 2640 }
2640 2641
2641 /* Is the CBW meaningful? */ 2642 /* Is the CBW meaningful? */
2642 if (cbw->Lun >= MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG || 2643 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG ||
2643 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) { 2644 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
2644 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, " 2645 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
2645 "cmdlen %u\n", 2646 "cmdlen %u\n",
@@ -2772,7 +2773,7 @@ static int do_set_interface(struct fsg_dev *fsg, int altsetting)
2772 2773
2773reset: 2774reset:
2774 /* Deallocate the requests */ 2775 /* Deallocate the requests */
2775 for (i = 0; i < NUM_BUFFERS; ++i) { 2776 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2776 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2777 struct fsg_buffhd *bh = &fsg->buffhds[i];
2777 2778
2778 if (bh->inreq) { 2779 if (bh->inreq) {
@@ -2810,12 +2811,14 @@ reset:
2810 DBG(fsg, "set interface %d\n", altsetting); 2811 DBG(fsg, "set interface %d\n", altsetting);
2811 2812
2812 /* Enable the endpoints */ 2813 /* Enable the endpoints */
2813 d = ep_desc(fsg->gadget, &fs_bulk_in_desc, &hs_bulk_in_desc); 2814 d = fsg_ep_desc(fsg->gadget,
2815 &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
2814 if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0) 2816 if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
2815 goto reset; 2817 goto reset;
2816 fsg->bulk_in_enabled = 1; 2818 fsg->bulk_in_enabled = 1;
2817 2819
2818 d = ep_desc(fsg->gadget, &fs_bulk_out_desc, &hs_bulk_out_desc); 2820 d = fsg_ep_desc(fsg->gadget,
2821 &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc);
2819 if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0) 2822 if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
2820 goto reset; 2823 goto reset;
2821 fsg->bulk_out_enabled = 1; 2824 fsg->bulk_out_enabled = 1;
@@ -2823,14 +2826,15 @@ reset:
2823 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2826 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2824 2827
2825 if (transport_is_cbi()) { 2828 if (transport_is_cbi()) {
2826 d = ep_desc(fsg->gadget, &fs_intr_in_desc, &hs_intr_in_desc); 2829 d = fsg_ep_desc(fsg->gadget,
2830 &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc);
2827 if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0) 2831 if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
2828 goto reset; 2832 goto reset;
2829 fsg->intr_in_enabled = 1; 2833 fsg->intr_in_enabled = 1;
2830 } 2834 }
2831 2835
2832 /* Allocate the requests */ 2836 /* Allocate the requests */
2833 for (i = 0; i < NUM_BUFFERS; ++i) { 2837 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2834 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2838 struct fsg_buffhd *bh = &fsg->buffhds[i];
2835 2839
2836 if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0) 2840 if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
@@ -2906,7 +2910,7 @@ static void handle_exception(struct fsg_dev *fsg)
2906 struct fsg_buffhd *bh; 2910 struct fsg_buffhd *bh;
2907 enum fsg_state old_state; 2911 enum fsg_state old_state;
2908 u8 new_config; 2912 u8 new_config;
2909 struct lun *curlun; 2913 struct fsg_lun *curlun;
2910 unsigned int exception_req_tag; 2914 unsigned int exception_req_tag;
2911 int rc; 2915 int rc;
2912 2916
@@ -2926,7 +2930,7 @@ static void handle_exception(struct fsg_dev *fsg)
2926 /* Cancel all the pending transfers */ 2930 /* Cancel all the pending transfers */
2927 if (fsg->intreq_busy) 2931 if (fsg->intreq_busy)
2928 usb_ep_dequeue(fsg->intr_in, fsg->intreq); 2932 usb_ep_dequeue(fsg->intr_in, fsg->intreq);
2929 for (i = 0; i < NUM_BUFFERS; ++i) { 2933 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2930 bh = &fsg->buffhds[i]; 2934 bh = &fsg->buffhds[i];
2931 if (bh->inreq_busy) 2935 if (bh->inreq_busy)
2932 usb_ep_dequeue(fsg->bulk_in, bh->inreq); 2936 usb_ep_dequeue(fsg->bulk_in, bh->inreq);
@@ -2937,7 +2941,7 @@ static void handle_exception(struct fsg_dev *fsg)
2937 /* Wait until everything is idle */ 2941 /* Wait until everything is idle */
2938 for (;;) { 2942 for (;;) {
2939 num_active = fsg->intreq_busy; 2943 num_active = fsg->intreq_busy;
2940 for (i = 0; i < NUM_BUFFERS; ++i) { 2944 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2941 bh = &fsg->buffhds[i]; 2945 bh = &fsg->buffhds[i];
2942 num_active += bh->inreq_busy + bh->outreq_busy; 2946 num_active += bh->inreq_busy + bh->outreq_busy;
2943 } 2947 }
@@ -2959,7 +2963,7 @@ static void handle_exception(struct fsg_dev *fsg)
2959 * state, and the exception. Then invoke the handler. */ 2963 * state, and the exception. Then invoke the handler. */
2960 spin_lock_irq(&fsg->lock); 2964 spin_lock_irq(&fsg->lock);
2961 2965
2962 for (i = 0; i < NUM_BUFFERS; ++i) { 2966 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2963 bh = &fsg->buffhds[i]; 2967 bh = &fsg->buffhds[i];
2964 bh->state = BUF_STATE_EMPTY; 2968 bh->state = BUF_STATE_EMPTY;
2965 } 2969 }
@@ -3041,7 +3045,7 @@ static void handle_exception(struct fsg_dev *fsg)
3041 3045
3042 case FSG_STATE_DISCONNECT: 3046 case FSG_STATE_DISCONNECT:
3043 for (i = 0; i < fsg->nluns; ++i) 3047 for (i = 0; i < fsg->nluns; ++i)
3044 fsync_sub(fsg->luns + i); 3048 fsg_lun_fsync_sub(fsg->luns + i);
3045 do_set_config(fsg, 0); // Unconfigured state 3049 do_set_config(fsg, 0); // Unconfigured state
3046 break; 3050 break;
3047 3051
@@ -3132,7 +3136,7 @@ static int fsg_main_thread(void *fsg_)
3132 3136
3133static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *buf) 3137static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *buf)
3134{ 3138{
3135 struct lun *curlun = dev_to_lun(dev); 3139 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
3136 3140
3137 return sprintf(buf, "%d\n", curlun->ro); 3141 return sprintf(buf, "%d\n", curlun->ro);
3138} 3142}
@@ -3140,13 +3144,13 @@ static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *
3140static ssize_t show_file(struct device *dev, struct device_attribute *attr, 3144static ssize_t show_file(struct device *dev, struct device_attribute *attr,
3141 char *buf) 3145 char *buf)
3142{ 3146{
3143 struct lun *curlun = dev_to_lun(dev); 3147 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
3144 struct fsg_dev *fsg = dev_get_drvdata(dev); 3148 struct fsg_dev *fsg = dev_get_drvdata(dev);
3145 char *p; 3149 char *p;
3146 ssize_t rc; 3150 ssize_t rc;
3147 3151
3148 down_read(&fsg->filesem); 3152 down_read(&fsg->filesem);
3149 if (backing_file_is_open(curlun)) { // Get the complete pathname 3153 if (fsg_lun_is_open(curlun)) { // Get the complete pathname
3150 p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1); 3154 p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1);
3151 if (IS_ERR(p)) 3155 if (IS_ERR(p))
3152 rc = PTR_ERR(p); 3156 rc = PTR_ERR(p);
@@ -3169,7 +3173,7 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr,
3169 const char *buf, size_t count) 3173 const char *buf, size_t count)
3170{ 3174{
3171 ssize_t rc = count; 3175 ssize_t rc = count;
3172 struct lun *curlun = dev_to_lun(dev); 3176 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
3173 struct fsg_dev *fsg = dev_get_drvdata(dev); 3177 struct fsg_dev *fsg = dev_get_drvdata(dev);
3174 int i; 3178 int i;
3175 3179
@@ -3179,7 +3183,7 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr,
3179 /* Allow the write-enable status to change only while the backing file 3183 /* Allow the write-enable status to change only while the backing file
3180 * is closed. */ 3184 * is closed. */
3181 down_read(&fsg->filesem); 3185 down_read(&fsg->filesem);
3182 if (backing_file_is_open(curlun)) { 3186 if (fsg_lun_is_open(curlun)) {
3183 LDBG(curlun, "read-only status change prevented\n"); 3187 LDBG(curlun, "read-only status change prevented\n");
3184 rc = -EBUSY; 3188 rc = -EBUSY;
3185 } else { 3189 } else {
@@ -3193,11 +3197,11 @@ static ssize_t store_ro(struct device *dev, struct device_attribute *attr,
3193static ssize_t store_file(struct device *dev, struct device_attribute *attr, 3197static ssize_t store_file(struct device *dev, struct device_attribute *attr,
3194 const char *buf, size_t count) 3198 const char *buf, size_t count)
3195{ 3199{
3196 struct lun *curlun = dev_to_lun(dev); 3200 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
3197 struct fsg_dev *fsg = dev_get_drvdata(dev); 3201 struct fsg_dev *fsg = dev_get_drvdata(dev);
3198 int rc = 0; 3202 int rc = 0;
3199 3203
3200 if (curlun->prevent_medium_removal && backing_file_is_open(curlun)) { 3204 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) {
3201 LDBG(curlun, "eject attempt prevented\n"); 3205 LDBG(curlun, "eject attempt prevented\n");
3202 return -EBUSY; // "Door is locked" 3206 return -EBUSY; // "Door is locked"
3203 } 3207 }
@@ -3208,14 +3212,14 @@ static ssize_t store_file(struct device *dev, struct device_attribute *attr,
3208 3212
3209 /* Eject current medium */ 3213 /* Eject current medium */
3210 down_write(&fsg->filesem); 3214 down_write(&fsg->filesem);
3211 if (backing_file_is_open(curlun)) { 3215 if (fsg_lun_is_open(curlun)) {
3212 close_backing_file(curlun); 3216 fsg_lun_close(curlun);
3213 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT; 3217 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
3214 } 3218 }
3215 3219
3216 /* Load new medium */ 3220 /* Load new medium */
3217 if (count > 0 && buf[0]) { 3221 if (count > 0 && buf[0]) {
3218 rc = open_backing_file(curlun, buf); 3222 rc = fsg_lun_open(curlun, buf);
3219 if (rc == 0) 3223 if (rc == 0)
3220 curlun->unit_attention_data = 3224 curlun->unit_attention_data =
3221 SS_NOT_READY_TO_READY_TRANSITION; 3225 SS_NOT_READY_TO_READY_TRANSITION;
@@ -3251,7 +3255,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3251{ 3255{
3252 struct fsg_dev *fsg = get_gadget_data(gadget); 3256 struct fsg_dev *fsg = get_gadget_data(gadget);
3253 int i; 3257 int i;
3254 struct lun *curlun; 3258 struct fsg_lun *curlun;
3255 struct usb_request *req = fsg->ep0req; 3259 struct usb_request *req = fsg->ep0req;
3256 3260
3257 DBG(fsg, "unbind\n"); 3261 DBG(fsg, "unbind\n");
@@ -3263,7 +3267,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3263 if (curlun->registered) { 3267 if (curlun->registered) {
3264 device_remove_file(&curlun->dev, &dev_attr_ro); 3268 device_remove_file(&curlun->dev, &dev_attr_ro);
3265 device_remove_file(&curlun->dev, &dev_attr_file); 3269 device_remove_file(&curlun->dev, &dev_attr_file);
3266 close_backing_file(curlun); 3270 fsg_lun_close(curlun);
3267 device_unregister(&curlun->dev); 3271 device_unregister(&curlun->dev);
3268 curlun->registered = 0; 3272 curlun->registered = 0;
3269 } 3273 }
@@ -3279,7 +3283,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3279 } 3283 }
3280 3284
3281 /* Free the data buffers */ 3285 /* Free the data buffers */
3282 for (i = 0; i < NUM_BUFFERS; ++i) 3286 for (i = 0; i < FSG_NUM_BUFFERS; ++i)
3283 kfree(fsg->buffhds[i].buf); 3287 kfree(fsg->buffhds[i].buf);
3284 3288
3285 /* Free the request and buffer for endpoint 0 */ 3289 /* Free the request and buffer for endpoint 0 */
@@ -3386,7 +3390,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3386 struct fsg_dev *fsg = the_fsg; 3390 struct fsg_dev *fsg = the_fsg;
3387 int rc; 3391 int rc;
3388 int i; 3392 int i;
3389 struct lun *curlun; 3393 struct fsg_lun *curlun;
3390 struct usb_ep *ep; 3394 struct usb_ep *ep;
3391 struct usb_request *req; 3395 struct usb_request *req;
3392 char *pathbuf, *p; 3396 char *pathbuf, *p;
@@ -3412,7 +3416,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3412 i = mod_data.nluns; 3416 i = mod_data.nluns;
3413 if (i == 0) 3417 if (i == 0)
3414 i = max(mod_data.num_filenames, 1u); 3418 i = max(mod_data.num_filenames, 1u);
3415 if (i > MAX_LUNS) { 3419 if (i > FSG_MAX_LUNS) {
3416 ERROR(fsg, "invalid number of LUNs: %d\n", i); 3420 ERROR(fsg, "invalid number of LUNs: %d\n", i);
3417 rc = -EINVAL; 3421 rc = -EINVAL;
3418 goto out; 3422 goto out;
@@ -3420,7 +3424,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3420 3424
3421 /* Create the LUNs, open their backing files, and register the 3425 /* Create the LUNs, open their backing files, and register the
3422 * LUN devices in sysfs. */ 3426 * LUN devices in sysfs. */
3423 fsg->luns = kzalloc(i * sizeof(struct lun), GFP_KERNEL); 3427 fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
3424 if (!fsg->luns) { 3428 if (!fsg->luns) {
3425 rc = -ENOMEM; 3429 rc = -ENOMEM;
3426 goto out; 3430 goto out;
@@ -3454,7 +3458,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3454 kref_get(&fsg->ref); 3458 kref_get(&fsg->ref);
3455 3459
3456 if (mod_data.file[i] && *mod_data.file[i]) { 3460 if (mod_data.file[i] && *mod_data.file[i]) {
3457 if ((rc = open_backing_file(curlun, 3461 if ((rc = fsg_lun_open(curlun,
3458 mod_data.file[i])) != 0) 3462 mod_data.file[i])) != 0)
3459 goto out; 3463 goto out;
3460 } else if (!mod_data.removable) { 3464 } else if (!mod_data.removable) {
@@ -3466,20 +3470,20 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3466 3470
3467 /* Find all the endpoints we will use */ 3471 /* Find all the endpoints we will use */
3468 usb_ep_autoconfig_reset(gadget); 3472 usb_ep_autoconfig_reset(gadget);
3469 ep = usb_ep_autoconfig(gadget, &fs_bulk_in_desc); 3473 ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
3470 if (!ep) 3474 if (!ep)
3471 goto autoconf_fail; 3475 goto autoconf_fail;
3472 ep->driver_data = fsg; // claim the endpoint 3476 ep->driver_data = fsg; // claim the endpoint
3473 fsg->bulk_in = ep; 3477 fsg->bulk_in = ep;
3474 3478
3475 ep = usb_ep_autoconfig(gadget, &fs_bulk_out_desc); 3479 ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
3476 if (!ep) 3480 if (!ep)
3477 goto autoconf_fail; 3481 goto autoconf_fail;
3478 ep->driver_data = fsg; // claim the endpoint 3482 ep->driver_data = fsg; // claim the endpoint
3479 fsg->bulk_out = ep; 3483 fsg->bulk_out = ep;
3480 3484
3481 if (transport_is_cbi()) { 3485 if (transport_is_cbi()) {
3482 ep = usb_ep_autoconfig(gadget, &fs_intr_in_desc); 3486 ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
3483 if (!ep) 3487 if (!ep)
3484 goto autoconf_fail; 3488 goto autoconf_fail;
3485 ep->driver_data = fsg; // claim the endpoint 3489 ep->driver_data = fsg; // claim the endpoint
@@ -3493,28 +3497,28 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3493 device_desc.bcdDevice = cpu_to_le16(mod_data.release); 3497 device_desc.bcdDevice = cpu_to_le16(mod_data.release);
3494 3498
3495 i = (transport_is_cbi() ? 3 : 2); // Number of endpoints 3499 i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
3496 intf_desc.bNumEndpoints = i; 3500 fsg_intf_desc.bNumEndpoints = i;
3497 intf_desc.bInterfaceSubClass = mod_data.protocol_type; 3501 fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
3498 intf_desc.bInterfaceProtocol = mod_data.transport_type; 3502 fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
3499 fs_function[i + FS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3503 fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3500 3504
3501 if (gadget_is_dualspeed(gadget)) { 3505 if (gadget_is_dualspeed(gadget)) {
3502 hs_function[i + HS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3506 fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3503 3507
3504 /* Assume ep0 uses the same maxpacket value for both speeds */ 3508 /* Assume ep0 uses the same maxpacket value for both speeds */
3505 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; 3509 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
3506 3510
3507 /* Assume endpoint addresses are the same for both speeds */ 3511 /* Assume endpoint addresses are the same for both speeds */
3508 hs_bulk_in_desc.bEndpointAddress = 3512 fsg_hs_bulk_in_desc.bEndpointAddress =
3509 fs_bulk_in_desc.bEndpointAddress; 3513 fsg_fs_bulk_in_desc.bEndpointAddress;
3510 hs_bulk_out_desc.bEndpointAddress = 3514 fsg_hs_bulk_out_desc.bEndpointAddress =
3511 fs_bulk_out_desc.bEndpointAddress; 3515 fsg_fs_bulk_out_desc.bEndpointAddress;
3512 hs_intr_in_desc.bEndpointAddress = 3516 fsg_hs_intr_in_desc.bEndpointAddress =
3513 fs_intr_in_desc.bEndpointAddress; 3517 fsg_fs_intr_in_desc.bEndpointAddress;
3514 } 3518 }
3515 3519
3516 if (gadget_is_otg(gadget)) 3520 if (gadget_is_otg(gadget))
3517 otg_desc.bmAttributes |= USB_OTG_HNP; 3521 fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
3518 3522
3519 rc = -ENOMEM; 3523 rc = -ENOMEM;
3520 3524
@@ -3528,7 +3532,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3528 req->complete = ep0_complete; 3532 req->complete = ep0_complete;
3529 3533
3530 /* Allocate the data buffers */ 3534 /* Allocate the data buffers */
3531 for (i = 0; i < NUM_BUFFERS; ++i) { 3535 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
3532 struct fsg_buffhd *bh = &fsg->buffhds[i]; 3536 struct fsg_buffhd *bh = &fsg->buffhds[i];
3533 3537
3534 /* Allocate for the bulk-in endpoint. We assume that 3538 /* Allocate for the bulk-in endpoint. We assume that
@@ -3539,23 +3543,24 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3539 goto out; 3543 goto out;
3540 bh->next = bh + 1; 3544 bh->next = bh + 1;
3541 } 3545 }
3542 fsg->buffhds[NUM_BUFFERS - 1].next = &fsg->buffhds[0]; 3546 fsg->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->buffhds[0];
3543 3547
3544 /* This should reflect the actual gadget power source */ 3548 /* This should reflect the actual gadget power source */
3545 usb_gadget_set_selfpowered(gadget); 3549 usb_gadget_set_selfpowered(gadget);
3546 3550
3547 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 3551 snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
3552 "%s %s with %s",
3548 init_utsname()->sysname, init_utsname()->release, 3553 init_utsname()->sysname, init_utsname()->release,
3549 gadget->name); 3554 gadget->name);
3550 3555
3551 /* On a real device, serial[] would be loaded from permanent 3556 /* On a real device, serial[] would be loaded from permanent
3552 * storage. We just encode it from the driver version string. */ 3557 * storage. We just encode it from the driver version string. */
3553 for (i = 0; i < sizeof(serial) - 2; i += 2) { 3558 for (i = 0; i < sizeof fsg_string_serial - 2; i += 2) {
3554 unsigned char c = DRIVER_VERSION[i / 2]; 3559 unsigned char c = DRIVER_VERSION[i / 2];
3555 3560
3556 if (!c) 3561 if (!c)
3557 break; 3562 break;
3558 sprintf(&serial[i], "%02X", c); 3563 sprintf(&fsg_string_serial[i], "%02X", c);
3559 } 3564 }
3560 3565
3561 fsg->thread_task = kthread_create(fsg_main_thread, fsg, 3566 fsg->thread_task = kthread_create(fsg_main_thread, fsg,
@@ -3571,7 +3576,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3571 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 3576 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
3572 for (i = 0; i < fsg->nluns; ++i) { 3577 for (i = 0; i < fsg->nluns; ++i) {
3573 curlun = &fsg->luns[i]; 3578 curlun = &fsg->luns[i];
3574 if (backing_file_is_open(curlun)) { 3579 if (fsg_lun_is_open(curlun)) {
3575 p = NULL; 3580 p = NULL;
3576 if (pathbuf) { 3581 if (pathbuf) {
3577 p = d_path(&curlun->filp->f_path, 3582 p = d_path(&curlun->filp->f_path,
@@ -3641,7 +3646,7 @@ static struct usb_gadget_driver fsg_driver = {
3641#else 3646#else
3642 .speed = USB_SPEED_FULL, 3647 .speed = USB_SPEED_FULL,
3643#endif 3648#endif
3644 .function = (char *) longname, 3649 .function = (char *) fsg_string_product,
3645 .bind = fsg_bind, 3650 .bind = fsg_bind,
3646 .unbind = fsg_unbind, 3651 .unbind = fsg_unbind,
3647 .disconnect = fsg_disconnect, 3652 .disconnect = fsg_disconnect,
@@ -3650,7 +3655,7 @@ static struct usb_gadget_driver fsg_driver = {
3650 .resume = fsg_resume, 3655 .resume = fsg_resume,
3651 3656
3652 .driver = { 3657 .driver = {
3653 .name = (char *) shortname, 3658 .name = DRIVER_NAME,
3654 .owner = THIS_MODULE, 3659 .owner = THIS_MODULE,
3655 // .release = ... 3660 // .release = ...
3656 // .suspend = ... 3661 // .suspend = ...
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index fa86fdaafc1d..19bf1e330dd0 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -4,9 +4,38 @@
4 * Copyright (C) 2003-2008 Alan Stern 4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyeight (C) 2009 Samsung Electronics 5 * Copyeight (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) 6 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24/*
25 * This file requires the following identifiers used in USB strings to
26 * be defined (each of type pointer to char):
27 * - fsg_string_manufacturer -- name of the manufacturer
28 * - fsg_string_product -- name of the product
29 * - fsg_string_serial -- product's serial
30 * - fsg_string_config -- name of the configuration
31 * - fsg_string_interface -- name of the interface
32 * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
33 * macro is defined prior to including this file.
7 */ 34 */
8 35
9 36
37#include <asm/unaligned.h>
38
10 39
11/*-------------------------------------------------------------------------*/ 40/*-------------------------------------------------------------------------*/
12 41
@@ -93,7 +122,7 @@
93/* Bulk-only data structures */ 122/* Bulk-only data structures */
94 123
95/* Command Block Wrapper */ 124/* Command Block Wrapper */
96struct bulk_cb_wrap { 125struct fsg_bulk_cb_wrap {
97 __le32 Signature; // Contains 'USBC' 126 __le32 Signature; // Contains 'USBC'
98 u32 Tag; // Unique per command id 127 u32 Tag; // Unique per command id
99 __le32 DataTransferLength; // Size of the data 128 __le32 DataTransferLength; // Size of the data
@@ -191,7 +220,7 @@ struct interrupt_data {
191/*-------------------------------------------------------------------------*/ 220/*-------------------------------------------------------------------------*/
192 221
193 222
194struct lun { 223struct fsg_lun {
195 struct file *filp; 224 struct file *filp;
196 loff_t file_length; 225 loff_t file_length;
197 loff_t num_sectors; 226 loff_t num_sectors;
@@ -208,11 +237,11 @@ struct lun {
208 struct device dev; 237 struct device dev;
209}; 238};
210 239
211#define backing_file_is_open(curlun) ((curlun)->filp != NULL) 240#define fsg_lun_is_open(curlun) ((curlun)->filp != NULL)
212 241
213static struct lun *dev_to_lun(struct device *dev) 242static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
214{ 243{
215 return container_of(dev, struct lun, dev); 244 return container_of(dev, struct fsg_lun, dev);
216} 245}
217 246
218 247
@@ -221,7 +250,7 @@ static struct lun *dev_to_lun(struct device *dev)
221#define DELAYED_STATUS (EP0_BUFSIZE + 999) // An impossibly large value 250#define DELAYED_STATUS (EP0_BUFSIZE + 999) // An impossibly large value
222 251
223/* Number of buffers we will use. 2 is enough for double-buffering */ 252/* Number of buffers we will use. 2 is enough for double-buffering */
224#define NUM_BUFFERS 2 253#define FSG_NUM_BUFFERS 2
225 254
226enum fsg_buffer_state { 255enum fsg_buffer_state {
227 BUF_STATE_EMPTY = 0, 256 BUF_STATE_EMPTY = 0,
@@ -280,16 +309,18 @@ static inline u32 get_unaligned_be24(u8 *buf)
280/*-------------------------------------------------------------------------*/ 309/*-------------------------------------------------------------------------*/
281 310
282 311
283#define STRING_MANUFACTURER 1 312enum {
284#define STRING_PRODUCT 2 313 FSG_STRING_MANUFACTURER = 1,
285#define STRING_SERIAL 3 314 FSG_STRING_PRODUCT,
286#define STRING_CONFIG 4 315 FSG_STRING_SERIAL,
287#define STRING_INTERFACE 5 316 FSG_STRING_CONFIG,
317 FSG_STRING_INTERFACE
318};
288 319
289 320
290static struct usb_otg_descriptor 321static struct usb_otg_descriptor
291otg_desc = { 322fsg_otg_desc = {
292 .bLength = sizeof(otg_desc), 323 .bLength = sizeof fsg_otg_desc,
293 .bDescriptorType = USB_DT_OTG, 324 .bDescriptorType = USB_DT_OTG,
294 325
295 .bmAttributes = USB_OTG_SRP, 326 .bmAttributes = USB_OTG_SRP,
@@ -298,22 +329,22 @@ otg_desc = {
298/* There is only one interface. */ 329/* There is only one interface. */
299 330
300static struct usb_interface_descriptor 331static struct usb_interface_descriptor
301intf_desc = { 332fsg_intf_desc = {
302 .bLength = sizeof intf_desc, 333 .bLength = sizeof fsg_intf_desc,
303 .bDescriptorType = USB_DT_INTERFACE, 334 .bDescriptorType = USB_DT_INTERFACE,
304 335
305 .bNumEndpoints = 2, // Adjusted during fsg_bind() 336 .bNumEndpoints = 2, // Adjusted during fsg_bind()
306 .bInterfaceClass = USB_CLASS_MASS_STORAGE, 337 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
307 .bInterfaceSubClass = USB_SC_SCSI, // Adjusted during fsg_bind() 338 .bInterfaceSubClass = USB_SC_SCSI, // Adjusted during fsg_bind()
308 .bInterfaceProtocol = USB_PR_BULK, // Adjusted during fsg_bind() 339 .bInterfaceProtocol = USB_PR_BULK, // Adjusted during fsg_bind()
309 .iInterface = STRING_INTERFACE, 340 .iInterface = FSG_STRING_INTERFACE,
310}; 341};
311 342
312/* Three full-speed endpoint descriptors: bulk-in, bulk-out, 343/* Three full-speed endpoint descriptors: bulk-in, bulk-out,
313 * and interrupt-in. */ 344 * and interrupt-in. */
314 345
315static struct usb_endpoint_descriptor 346static struct usb_endpoint_descriptor
316fs_bulk_in_desc = { 347fsg_fs_bulk_in_desc = {
317 .bLength = USB_DT_ENDPOINT_SIZE, 348 .bLength = USB_DT_ENDPOINT_SIZE,
318 .bDescriptorType = USB_DT_ENDPOINT, 349 .bDescriptorType = USB_DT_ENDPOINT,
319 350
@@ -323,7 +354,7 @@ fs_bulk_in_desc = {
323}; 354};
324 355
325static struct usb_endpoint_descriptor 356static struct usb_endpoint_descriptor
326fs_bulk_out_desc = { 357fsg_fs_bulk_out_desc = {
327 .bLength = USB_DT_ENDPOINT_SIZE, 358 .bLength = USB_DT_ENDPOINT_SIZE,
328 .bDescriptorType = USB_DT_ENDPOINT, 359 .bDescriptorType = USB_DT_ENDPOINT,
329 360
@@ -333,7 +364,7 @@ fs_bulk_out_desc = {
333}; 364};
334 365
335static struct usb_endpoint_descriptor 366static struct usb_endpoint_descriptor
336fs_intr_in_desc = { 367fsg_fs_intr_in_desc = {
337 .bLength = USB_DT_ENDPOINT_SIZE, 368 .bLength = USB_DT_ENDPOINT_SIZE,
338 .bDescriptorType = USB_DT_ENDPOINT, 369 .bDescriptorType = USB_DT_ENDPOINT,
339 370
@@ -343,15 +374,15 @@ fs_intr_in_desc = {
343 .bInterval = 32, // frames -> 32 ms 374 .bInterval = 32, // frames -> 32 ms
344}; 375};
345 376
346static const struct usb_descriptor_header *fs_function[] = { 377static const struct usb_descriptor_header *fsg_fs_function[] = {
347 (struct usb_descriptor_header *) &otg_desc, 378 (struct usb_descriptor_header *) &fsg_otg_desc,
348 (struct usb_descriptor_header *) &intf_desc, 379 (struct usb_descriptor_header *) &fsg_intf_desc,
349 (struct usb_descriptor_header *) &fs_bulk_in_desc, 380 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
350 (struct usb_descriptor_header *) &fs_bulk_out_desc, 381 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
351 (struct usb_descriptor_header *) &fs_intr_in_desc, 382 (struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
352 NULL, 383 NULL,
353}; 384};
354#define FS_FUNCTION_PRE_EP_ENTRIES 2 385#define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2
355 386
356 387
357/* 388/*
@@ -363,7 +394,7 @@ static const struct usb_descriptor_header *fs_function[] = {
363 * for the config descriptor. 394 * for the config descriptor.
364 */ 395 */
365static struct usb_endpoint_descriptor 396static struct usb_endpoint_descriptor
366hs_bulk_in_desc = { 397fsg_hs_bulk_in_desc = {
367 .bLength = USB_DT_ENDPOINT_SIZE, 398 .bLength = USB_DT_ENDPOINT_SIZE,
368 .bDescriptorType = USB_DT_ENDPOINT, 399 .bDescriptorType = USB_DT_ENDPOINT,
369 400
@@ -373,7 +404,7 @@ hs_bulk_in_desc = {
373}; 404};
374 405
375static struct usb_endpoint_descriptor 406static struct usb_endpoint_descriptor
376hs_bulk_out_desc = { 407fsg_hs_bulk_out_desc = {
377 .bLength = USB_DT_ENDPOINT_SIZE, 408 .bLength = USB_DT_ENDPOINT_SIZE,
378 .bDescriptorType = USB_DT_ENDPOINT, 409 .bDescriptorType = USB_DT_ENDPOINT,
379 410
@@ -384,7 +415,7 @@ hs_bulk_out_desc = {
384}; 415};
385 416
386static struct usb_endpoint_descriptor 417static struct usb_endpoint_descriptor
387hs_intr_in_desc = { 418fsg_hs_intr_in_desc = {
388 .bLength = USB_DT_ENDPOINT_SIZE, 419 .bLength = USB_DT_ENDPOINT_SIZE,
389 .bDescriptorType = USB_DT_ENDPOINT, 420 .bDescriptorType = USB_DT_ENDPOINT,
390 421
@@ -394,19 +425,19 @@ hs_intr_in_desc = {
394 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms 425 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms
395}; 426};
396 427
397static const struct usb_descriptor_header *hs_function[] = { 428static const struct usb_descriptor_header *fsg_hs_function[] = {
398 (struct usb_descriptor_header *) &otg_desc, 429 (struct usb_descriptor_header *) &fsg_otg_desc,
399 (struct usb_descriptor_header *) &intf_desc, 430 (struct usb_descriptor_header *) &fsg_intf_desc,
400 (struct usb_descriptor_header *) &hs_bulk_in_desc, 431 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
401 (struct usb_descriptor_header *) &hs_bulk_out_desc, 432 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
402 (struct usb_descriptor_header *) &hs_intr_in_desc, 433 (struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
403 NULL, 434 NULL,
404}; 435};
405#define HS_FUNCTION_PRE_EP_ENTRIES 2 436#define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2
406 437
407/* Maxpacket and other transfer characteristics vary by speed. */ 438/* Maxpacket and other transfer characteristics vary by speed. */
408static struct usb_endpoint_descriptor * 439static struct usb_endpoint_descriptor *
409ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, 440fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
410 struct usb_endpoint_descriptor *hs) 441 struct usb_endpoint_descriptor *hs)
411{ 442{
412 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 443 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
@@ -415,24 +446,19 @@ ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
415} 446}
416 447
417 448
418/* The CBI specification limits the serial string to 12 uppercase hexadecimal
419 * characters. */
420static char manufacturer[64];
421static char serial[13];
422
423/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ 449/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
424static struct usb_string strings[] = { 450static struct usb_string fsg_strings[] = {
425 {STRING_MANUFACTURER, manufacturer}, 451 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
426 {STRING_PRODUCT, longname}, 452 {FSG_STRING_PRODUCT, fsg_string_product},
427 {STRING_SERIAL, serial}, 453 {FSG_STRING_SERIAL, fsg_string_serial},
428 {STRING_CONFIG, "Self-powered"}, 454 {FSG_STRING_CONFIG, fsg_string_config},
429 {STRING_INTERFACE, "Mass Storage"}, 455 {FSG_STRING_INTERFACE, fsg_string_interface},
430 {} 456 {}
431}; 457};
432 458
433static struct usb_gadget_strings stringtab = { 459static struct usb_gadget_strings fsg_stringtab = {
434 .language = 0x0409, // en-us 460 .language = 0x0409, // en-us
435 .strings = strings, 461 .strings = fsg_strings,
436}; 462};
437 463
438 464
@@ -441,7 +467,7 @@ static struct usb_gadget_strings stringtab = {
441/* If the next two routines are called while the gadget is registered, 467/* If the next two routines are called while the gadget is registered,
442 * the caller must own fsg->filesem for writing. */ 468 * the caller must own fsg->filesem for writing. */
443 469
444static int open_backing_file(struct lun *curlun, const char *filename) 470static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
445{ 471{
446 int ro; 472 int ro;
447 struct file *filp = NULL; 473 struct file *filp = NULL;
@@ -525,7 +551,7 @@ out:
525} 551}
526 552
527 553
528static void close_backing_file(struct lun *curlun) 554static void fsg_lun_close(struct fsg_lun *curlun)
529{ 555{
530 if (curlun->filp) { 556 if (curlun->filp) {
531 LDBG(curlun, "close backing file\n"); 557 LDBG(curlun, "close backing file\n");
@@ -539,7 +565,7 @@ static void close_backing_file(struct lun *curlun)
539 565
540/* Sync the file data, don't bother with the metadata. 566/* Sync the file data, don't bother with the metadata.
541 * This code was copied from fs/buffer.c:sys_fdatasync(). */ 567 * This code was copied from fs/buffer.c:sys_fdatasync(). */
542static int fsync_sub(struct lun *curlun) 568static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
543{ 569{
544 struct file *filp = curlun->filp; 570 struct file *filp = curlun->filp;
545 571