aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/storage_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/storage_common.c')
-rw-r--r--drivers/usb/gadget/storage_common.c108
1 files changed, 55 insertions, 53 deletions
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 7e81a2d898f0..868d8ee86756 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -61,8 +61,8 @@
61 * 61 *
62 * DO NOT REUSE THESE IDs with any other driver!! Ever!! 62 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
63 * Instead: allocate your own, using normal USB-IF procedures. */ 63 * Instead: allocate your own, using normal USB-IF procedures. */
64#define FSG_VENDOR_ID 0x0525 // NetChip 64#define FSG_VENDOR_ID 0x0525 /* NetChip */
65#define FSG_PRODUCT_ID 0xa4a5 // Linux-USB File-backed Storage Gadget 65#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
66 66
67 67
68/*-------------------------------------------------------------------------*/ 68/*-------------------------------------------------------------------------*/
@@ -103,7 +103,7 @@
103#ifdef DUMP_MSGS 103#ifdef DUMP_MSGS
104 104
105# define dump_msg(fsg, /* const char * */ label, \ 105# define dump_msg(fsg, /* const char * */ label, \
106 /* const u8 * */ buf, /* unsigned */ length) do { \ 106 /* const u8 * */ buf, /* unsigned */ length) do { \
107 if (length < 512) { \ 107 if (length < 512) { \
108 DBG(fsg, "%s, length %u:\n", label, length); \ 108 DBG(fsg, "%s, length %u:\n", label, length); \
109 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ 109 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
@@ -116,11 +116,11 @@
116#else 116#else
117 117
118# define dump_msg(fsg, /* const char * */ label, \ 118# define dump_msg(fsg, /* const char * */ label, \
119 /* const u8 * */ buf, /* unsigned */ length) do { } while (0) 119 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
120 120
121# ifdef VERBOSE_DEBUG 121# ifdef VERBOSE_DEBUG
122 122
123#define dump_cdb(fsg) \ 123# define dump_cdb(fsg) \
124 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ 124 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
125 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ 125 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
126 126
@@ -143,45 +143,45 @@
143#define TYPE_CDROM 0x05 143#define TYPE_CDROM 0x05
144 144
145/* USB protocol value = the transport method */ 145/* USB protocol value = the transport method */
146#define USB_PR_CBI 0x00 // Control/Bulk/Interrupt 146#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
147#define USB_PR_CB 0x01 // Control/Bulk w/o interrupt 147#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
148#define USB_PR_BULK 0x50 // Bulk-only 148#define USB_PR_BULK 0x50 /* Bulk-only */
149 149
150/* USB subclass value = the protocol encapsulation */ 150/* USB subclass value = the protocol encapsulation */
151#define USB_SC_RBC 0x01 // Reduced Block Commands (flash) 151#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */
152#define USB_SC_8020 0x02 // SFF-8020i, MMC-2, ATAPI (CD-ROM) 152#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
153#define USB_SC_QIC 0x03 // QIC-157 (tape) 153#define USB_SC_QIC 0x03 /* QIC-157 (tape) */
154#define USB_SC_UFI 0x04 // UFI (floppy) 154#define USB_SC_UFI 0x04 /* UFI (floppy) */
155#define USB_SC_8070 0x05 // SFF-8070i (removable) 155#define USB_SC_8070 0x05 /* SFF-8070i (removable) */
156#define USB_SC_SCSI 0x06 // Transparent SCSI 156#define USB_SC_SCSI 0x06 /* Transparent SCSI */
157 157
158/* Bulk-only data structures */ 158/* Bulk-only data structures */
159 159
160/* Command Block Wrapper */ 160/* Command Block Wrapper */
161struct fsg_bulk_cb_wrap { 161struct fsg_bulk_cb_wrap {
162 __le32 Signature; // Contains 'USBC' 162 __le32 Signature; /* Contains 'USBC' */
163 u32 Tag; // Unique per command id 163 u32 Tag; /* Unique per command id */
164 __le32 DataTransferLength; // Size of the data 164 __le32 DataTransferLength; /* Size of the data */
165 u8 Flags; // Direction in bit 7 165 u8 Flags; /* Direction in bit 7 */
166 u8 Lun; // LUN (normally 0) 166 u8 Lun; /* LUN (normally 0) */
167 u8 Length; // Of the CDB, <= MAX_COMMAND_SIZE 167 u8 Length; /* Of the CDB, <= MAX_COMMAND_SIZE */
168 u8 CDB[16]; // Command Data Block 168 u8 CDB[16]; /* Command Data Block */
169}; 169};
170 170
171#define USB_BULK_CB_WRAP_LEN 31 171#define USB_BULK_CB_WRAP_LEN 31
172#define USB_BULK_CB_SIG 0x43425355 // Spells out USBC 172#define USB_BULK_CB_SIG 0x43425355 /* Spells out USBC */
173#define USB_BULK_IN_FLAG 0x80 173#define USB_BULK_IN_FLAG 0x80
174 174
175/* Command Status Wrapper */ 175/* Command Status Wrapper */
176struct bulk_cs_wrap { 176struct bulk_cs_wrap {
177 __le32 Signature; // Should = 'USBS' 177 __le32 Signature; /* Should = 'USBS' */
178 u32 Tag; // Same as original command 178 u32 Tag; /* Same as original command */
179 __le32 Residue; // Amount not transferred 179 __le32 Residue; /* Amount not transferred */
180 u8 Status; // See below 180 u8 Status; /* See below */
181}; 181};
182 182
183#define USB_BULK_CS_WRAP_LEN 13 183#define USB_BULK_CS_WRAP_LEN 13
184#define USB_BULK_CS_SIG 0x53425355 // Spells out 'USBS' 184#define USB_BULK_CS_SIG 0x53425355 /* Spells out 'USBS' */
185#define USB_STATUS_PASS 0 185#define USB_STATUS_PASS 0
186#define USB_STATUS_FAIL 1 186#define USB_STATUS_FAIL 1
187#define USB_STATUS_PHASE_ERROR 2 187#define USB_STATUS_PHASE_ERROR 2
@@ -203,7 +203,8 @@ struct interrupt_data {
203#define USB_CBI_ADSC_REQUEST 0x00 203#define USB_CBI_ADSC_REQUEST 0x00
204 204
205 205
206#define MAX_COMMAND_SIZE 16 // Length of a SCSI Command Data Block 206/* Length of a SCSI Command Data Block */
207#define MAX_COMMAND_SIZE 16
207 208
208/* SCSI commands that we recognize */ 209/* SCSI commands that we recognize */
209#define SC_FORMAT_UNIT 0x04 210#define SC_FORMAT_UNIT 0x04
@@ -248,7 +249,7 @@ struct interrupt_data {
248#define SS_WRITE_ERROR 0x030c02 249#define SS_WRITE_ERROR 0x030c02
249#define SS_WRITE_PROTECTED 0x072700 250#define SS_WRITE_PROTECTED 0x072700
250 251
251#define SK(x) ((u8) ((x) >> 16)) // Sense Key byte, etc. 252#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
252#define ASC(x) ((u8) ((x) >> 8)) 253#define ASC(x) ((u8) ((x) >> 8))
253#define ASCQ(x) ((u8) (x)) 254#define ASCQ(x) ((u8) (x))
254 255
@@ -261,13 +262,13 @@ struct fsg_lun {
261 loff_t file_length; 262 loff_t file_length;
262 loff_t num_sectors; 263 loff_t num_sectors;
263 264
264 unsigned int initially_ro : 1; 265 unsigned int initially_ro:1;
265 unsigned int ro : 1; 266 unsigned int ro:1;
266 unsigned int removable : 1; 267 unsigned int removable:1;
267 unsigned int cdrom : 1; 268 unsigned int cdrom:1;
268 unsigned int prevent_medium_removal : 1; 269 unsigned int prevent_medium_removal:1;
269 unsigned int registered : 1; 270 unsigned int registered:1;
270 unsigned int info_valid : 1; 271 unsigned int info_valid:1;
271 272
272 u32 sense_data; 273 u32 sense_data;
273 u32 sense_data_info; 274 u32 sense_data_info;
@@ -286,7 +287,7 @@ static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
286 287
287/* Big enough to hold our biggest descriptor */ 288/* Big enough to hold our biggest descriptor */
288#define EP0_BUFSIZE 256 289#define EP0_BUFSIZE 256
289#define DELAYED_STATUS (EP0_BUFSIZE + 999) // An impossibly large value 290#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
290 291
291/* Number of buffers we will use. 2 is enough for double-buffering */ 292/* Number of buffers we will use. 2 is enough for double-buffering */
292#define FSG_NUM_BUFFERS 2 293#define FSG_NUM_BUFFERS 2
@@ -324,7 +325,8 @@ struct fsg_buffhd {
324}; 325};
325 326
326enum fsg_state { 327enum fsg_state {
327 FSG_STATE_COMMAND_PHASE = -10, // This one isn't used anywhere 328 /* This one isn't used anywhere */
329 FSG_STATE_COMMAND_PHASE = -10,
328 FSG_STATE_DATA_PHASE, 330 FSG_STATE_DATA_PHASE,
329 FSG_STATE_STATUS_PHASE, 331 FSG_STATE_STATUS_PHASE,
330 332
@@ -386,10 +388,10 @@ fsg_intf_desc = {
386 .bLength = sizeof fsg_intf_desc, 388 .bLength = sizeof fsg_intf_desc,
387 .bDescriptorType = USB_DT_INTERFACE, 389 .bDescriptorType = USB_DT_INTERFACE,
388 390
389 .bNumEndpoints = 2, // Adjusted during fsg_bind() 391 .bNumEndpoints = 2, /* Adjusted during fsg_bind() */
390 .bInterfaceClass = USB_CLASS_MASS_STORAGE, 392 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
391 .bInterfaceSubClass = USB_SC_SCSI, // Adjusted during fsg_bind() 393 .bInterfaceSubClass = USB_SC_SCSI, /* Adjusted during fsg_bind() */
392 .bInterfaceProtocol = USB_PR_BULK, // Adjusted during fsg_bind() 394 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */
393 .iInterface = FSG_STRING_INTERFACE, 395 .iInterface = FSG_STRING_INTERFACE,
394}; 396};
395 397
@@ -426,7 +428,7 @@ fsg_fs_intr_in_desc = {
426 .bEndpointAddress = USB_DIR_IN, 428 .bEndpointAddress = USB_DIR_IN,
427 .bmAttributes = USB_ENDPOINT_XFER_INT, 429 .bmAttributes = USB_ENDPOINT_XFER_INT,
428 .wMaxPacketSize = cpu_to_le16(2), 430 .wMaxPacketSize = cpu_to_le16(2),
429 .bInterval = 32, // frames -> 32 ms 431 .bInterval = 32, /* frames -> 32 ms */
430}; 432};
431 433
432#ifndef FSG_NO_OTG 434#ifndef FSG_NO_OTG
@@ -477,7 +479,7 @@ fsg_hs_bulk_out_desc = {
477 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */ 479 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
478 .bmAttributes = USB_ENDPOINT_XFER_BULK, 480 .bmAttributes = USB_ENDPOINT_XFER_BULK,
479 .wMaxPacketSize = cpu_to_le16(512), 481 .wMaxPacketSize = cpu_to_le16(512),
480 .bInterval = 1, // NAK every 1 uframe 482 .bInterval = 1, /* NAK every 1 uframe */
481}; 483};
482 484
483#ifndef FSG_NO_INTR_EP 485#ifndef FSG_NO_INTR_EP
@@ -490,7 +492,7 @@ fsg_hs_intr_in_desc = {
490 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ 492 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
491 .bmAttributes = USB_ENDPOINT_XFER_INT, 493 .bmAttributes = USB_ENDPOINT_XFER_INT,
492 .wMaxPacketSize = cpu_to_le16(2), 494 .wMaxPacketSize = cpu_to_le16(2),
493 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms 495 .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */
494}; 496};
495 497
496#ifndef FSG_NO_OTG 498#ifndef FSG_NO_OTG
@@ -538,7 +540,7 @@ static struct usb_string fsg_strings[] = {
538}; 540};
539 541
540static struct usb_gadget_strings fsg_stringtab = { 542static struct usb_gadget_strings fsg_stringtab = {
541 .language = 0x0409, // en-us 543 .language = 0x0409, /* en-us */
542 .strings = fsg_strings, 544 .strings = fsg_strings,
543}; 545};
544 546
@@ -600,11 +602,11 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
600 rc = (int) size; 602 rc = (int) size;
601 goto out; 603 goto out;
602 } 604 }
603 num_sectors = size >> 9; // File size in 512-byte blocks 605 num_sectors = size >> 9; /* File size in 512-byte blocks */
604 min_sectors = 1; 606 min_sectors = 1;
605 if (curlun->cdrom) { 607 if (curlun->cdrom) {
606 num_sectors &= ~3; // Reduce to a multiple of 2048 608 num_sectors &= ~3; /* Reduce to a multiple of 2048 */
607 min_sectors = 300*4; // Smallest track is 300 frames 609 min_sectors = 300*4; /* Smallest track is 300 frames */
608 if (num_sectors >= 256*60*75*4) { 610 if (num_sectors >= 256*60*75*4) {
609 num_sectors = (256*60*75 - 1) * 4; 611 num_sectors = (256*60*75 - 1) * 4;
610 LINFO(curlun, "file too big: %s\n", filename); 612 LINFO(curlun, "file too big: %s\n", filename);
@@ -696,17 +698,17 @@ static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
696 ssize_t rc; 698 ssize_t rc;
697 699
698 down_read(filesem); 700 down_read(filesem);
699 if (fsg_lun_is_open(curlun)) { // Get the complete pathname 701 if (fsg_lun_is_open(curlun)) { /* Get the complete pathname */
700 p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1); 702 p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1);
701 if (IS_ERR(p)) 703 if (IS_ERR(p))
702 rc = PTR_ERR(p); 704 rc = PTR_ERR(p);
703 else { 705 else {
704 rc = strlen(p); 706 rc = strlen(p);
705 memmove(buf, p, rc); 707 memmove(buf, p, rc);
706 buf[rc] = '\n'; // Add a newline 708 buf[rc] = '\n'; /* Add a newline */
707 buf[++rc] = 0; 709 buf[++rc] = 0;
708 } 710 }
709 } else { // No file, return 0 bytes 711 } else { /* No file, return 0 bytes */
710 *buf = 0; 712 *buf = 0;
711 rc = 0; 713 rc = 0;
712 } 714 }
@@ -750,12 +752,12 @@ static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
750 752
751 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) { 753 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) {
752 LDBG(curlun, "eject attempt prevented\n"); 754 LDBG(curlun, "eject attempt prevented\n");
753 return -EBUSY; // "Door is locked" 755 return -EBUSY; /* "Door is locked" */
754 } 756 }
755 757
756 /* Remove a trailing newline */ 758 /* Remove a trailing newline */
757 if (count > 0 && buf[count-1] == '\n') 759 if (count > 0 && buf[count-1] == '\n')
758 ((char *) buf)[count-1] = 0; // Ugh! 760 ((char *) buf)[count-1] = 0; /* Ugh! */
759 761
760 /* Eject current medium */ 762 /* Eject current medium */
761 down_write(filesem); 763 down_write(filesem);