diff options
Diffstat (limited to 'drivers/usb/gadget/storage_common.c')
-rw-r--r-- | drivers/usb/gadget/storage_common.c | 165 |
1 files changed, 5 insertions, 160 deletions
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 8d9bcd8207c8..0e3ae43454a2 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c | |||
@@ -11,30 +11,10 @@ | |||
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | |||
15 | /* | 14 | /* |
16 | * This file requires the following identifiers used in USB strings to | 15 | * This file requires the following identifiers used in USB strings to |
17 | * be defined (each of type pointer to char): | 16 | * be defined (each of type pointer to char): |
18 | * - fsg_string_manufacturer -- name of the manufacturer | ||
19 | * - fsg_string_product -- name of the product | ||
20 | * - fsg_string_config -- name of the configuration | ||
21 | * - fsg_string_interface -- name of the interface | 17 | * - fsg_string_interface -- name of the interface |
22 | * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS | ||
23 | * macro is defined prior to including this file. | ||
24 | */ | ||
25 | |||
26 | /* | ||
27 | * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and | ||
28 | * fsg_hs_intr_in_desc objects as well as | ||
29 | * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES | ||
30 | * macros are not defined. | ||
31 | * | ||
32 | * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER, | ||
33 | * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not | ||
34 | * defined (as well as corresponding entries in string tables are | ||
35 | * missing) and FSG_STRING_INTERFACE has value of zero. | ||
36 | * | ||
37 | * When FSG_NO_OTG is defined fsg_otg_desc won't be defined. | ||
38 | */ | 18 | */ |
39 | 19 | ||
40 | /* | 20 | /* |
@@ -78,34 +58,6 @@ | |||
78 | #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) | 58 | #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) |
79 | #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) | 59 | #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) |
80 | 60 | ||
81 | /* | ||
82 | * Keep those macros in sync with those in | ||
83 | * include/linux/usb/composite.h or else GCC will complain. If they | ||
84 | * are identical (the same names of arguments, white spaces in the | ||
85 | * same places) GCC will allow redefinition otherwise (even if some | ||
86 | * white space is removed or added) warning will be issued. | ||
87 | * | ||
88 | * Those macros are needed here because File Storage Gadget does not | ||
89 | * include the composite.h header. For composite gadgets those macros | ||
90 | * are redundant since composite.h is included any way. | ||
91 | * | ||
92 | * One could check whether those macros are already defined (which | ||
93 | * would indicate composite.h had been included) or not (which would | ||
94 | * indicate we were in FSG) but this is not done because a warning is | ||
95 | * desired if definitions here differ from the ones in composite.h. | ||
96 | * | ||
97 | * We want the definitions to match and be the same in File Storage | ||
98 | * Gadget as well as Mass Storage Function (and so composite gadgets | ||
99 | * using MSF). If someone changes them in composite.h it will produce | ||
100 | * a warning in this file when building MSF. | ||
101 | */ | ||
102 | #define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args) | ||
103 | #define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args) | ||
104 | #define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args) | ||
105 | #define WARNING(d, fmt, args...) dev_warn(&(d)->gadget->dev , fmt , ## args) | ||
106 | #define INFO(d, fmt, args...) dev_info(&(d)->gadget->dev , fmt , ## args) | ||
107 | |||
108 | |||
109 | 61 | ||
110 | #ifdef DUMP_MSGS | 62 | #ifdef DUMP_MSGS |
111 | 63 | ||
@@ -203,9 +155,12 @@ struct fsg_lun { | |||
203 | struct device dev; | 155 | struct device dev; |
204 | }; | 156 | }; |
205 | 157 | ||
206 | #define fsg_lun_is_open(curlun) ((curlun)->filp != NULL) | 158 | static inline bool fsg_lun_is_open(struct fsg_lun *curlun) |
159 | { | ||
160 | return curlun->filp != NULL; | ||
161 | } | ||
207 | 162 | ||
208 | static struct fsg_lun *fsg_lun_from_dev(struct device *dev) | 163 | static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev) |
209 | { | 164 | { |
210 | return container_of(dev, struct fsg_lun, dev); | 165 | return container_of(dev, struct fsg_lun, dev); |
211 | } | 166 | } |
@@ -308,26 +263,10 @@ static inline u32 get_unaligned_be24(u8 *buf) | |||
308 | 263 | ||
309 | 264 | ||
310 | enum { | 265 | enum { |
311 | #ifndef FSG_NO_DEVICE_STRINGS | ||
312 | FSG_STRING_MANUFACTURER = 1, | ||
313 | FSG_STRING_PRODUCT, | ||
314 | FSG_STRING_SERIAL, | ||
315 | FSG_STRING_CONFIG, | ||
316 | #endif | ||
317 | FSG_STRING_INTERFACE | 266 | FSG_STRING_INTERFACE |
318 | }; | 267 | }; |
319 | 268 | ||
320 | 269 | ||
321 | #ifndef FSG_NO_OTG | ||
322 | static struct usb_otg_descriptor | ||
323 | fsg_otg_desc = { | ||
324 | .bLength = sizeof fsg_otg_desc, | ||
325 | .bDescriptorType = USB_DT_OTG, | ||
326 | |||
327 | .bmAttributes = USB_OTG_SRP, | ||
328 | }; | ||
329 | #endif | ||
330 | |||
331 | /* There is only one interface. */ | 270 | /* There is only one interface. */ |
332 | 271 | ||
333 | static struct usb_interface_descriptor | 272 | static struct usb_interface_descriptor |
@@ -367,37 +306,10 @@ fsg_fs_bulk_out_desc = { | |||
367 | /* wMaxPacketSize set by autoconfiguration */ | 306 | /* wMaxPacketSize set by autoconfiguration */ |
368 | }; | 307 | }; |
369 | 308 | ||
370 | #ifndef FSG_NO_INTR_EP | ||
371 | |||
372 | static struct usb_endpoint_descriptor | ||
373 | fsg_fs_intr_in_desc = { | ||
374 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
375 | .bDescriptorType = USB_DT_ENDPOINT, | ||
376 | |||
377 | .bEndpointAddress = USB_DIR_IN, | ||
378 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
379 | .wMaxPacketSize = cpu_to_le16(2), | ||
380 | .bInterval = 32, /* frames -> 32 ms */ | ||
381 | }; | ||
382 | |||
383 | #ifndef FSG_NO_OTG | ||
384 | # define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2 | ||
385 | #else | ||
386 | # define FSG_FS_FUNCTION_PRE_EP_ENTRIES 1 | ||
387 | #endif | ||
388 | |||
389 | #endif | ||
390 | |||
391 | static struct usb_descriptor_header *fsg_fs_function[] = { | 309 | static struct usb_descriptor_header *fsg_fs_function[] = { |
392 | #ifndef FSG_NO_OTG | ||
393 | (struct usb_descriptor_header *) &fsg_otg_desc, | ||
394 | #endif | ||
395 | (struct usb_descriptor_header *) &fsg_intf_desc, | 310 | (struct usb_descriptor_header *) &fsg_intf_desc, |
396 | (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, | 311 | (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, |
397 | (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, | 312 | (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, |
398 | #ifndef FSG_NO_INTR_EP | ||
399 | (struct usb_descriptor_header *) &fsg_fs_intr_in_desc, | ||
400 | #endif | ||
401 | NULL, | 313 | NULL, |
402 | }; | 314 | }; |
403 | 315 | ||
@@ -431,37 +343,11 @@ fsg_hs_bulk_out_desc = { | |||
431 | .bInterval = 1, /* NAK every 1 uframe */ | 343 | .bInterval = 1, /* NAK every 1 uframe */ |
432 | }; | 344 | }; |
433 | 345 | ||
434 | #ifndef FSG_NO_INTR_EP | ||
435 | |||
436 | static struct usb_endpoint_descriptor | ||
437 | fsg_hs_intr_in_desc = { | ||
438 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
439 | .bDescriptorType = USB_DT_ENDPOINT, | ||
440 | |||
441 | /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ | ||
442 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
443 | .wMaxPacketSize = cpu_to_le16(2), | ||
444 | .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */ | ||
445 | }; | ||
446 | |||
447 | #ifndef FSG_NO_OTG | ||
448 | # define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2 | ||
449 | #else | ||
450 | # define FSG_HS_FUNCTION_PRE_EP_ENTRIES 1 | ||
451 | #endif | ||
452 | |||
453 | #endif | ||
454 | 346 | ||
455 | static struct usb_descriptor_header *fsg_hs_function[] = { | 347 | static struct usb_descriptor_header *fsg_hs_function[] = { |
456 | #ifndef FSG_NO_OTG | ||
457 | (struct usb_descriptor_header *) &fsg_otg_desc, | ||
458 | #endif | ||
459 | (struct usb_descriptor_header *) &fsg_intf_desc, | 348 | (struct usb_descriptor_header *) &fsg_intf_desc, |
460 | (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, | 349 | (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, |
461 | (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, | 350 | (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, |
462 | #ifndef FSG_NO_INTR_EP | ||
463 | (struct usb_descriptor_header *) &fsg_hs_intr_in_desc, | ||
464 | #endif | ||
465 | NULL, | 351 | NULL, |
466 | }; | 352 | }; |
467 | 353 | ||
@@ -499,34 +385,6 @@ static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = { | |||
499 | /*.bMaxBurst = DYNAMIC, */ | 385 | /*.bMaxBurst = DYNAMIC, */ |
500 | }; | 386 | }; |
501 | 387 | ||
502 | #ifndef FSG_NO_INTR_EP | ||
503 | |||
504 | static struct usb_endpoint_descriptor | ||
505 | fsg_ss_intr_in_desc = { | ||
506 | .bLength = USB_DT_ENDPOINT_SIZE, | ||
507 | .bDescriptorType = USB_DT_ENDPOINT, | ||
508 | |||
509 | /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ | ||
510 | .bmAttributes = USB_ENDPOINT_XFER_INT, | ||
511 | .wMaxPacketSize = cpu_to_le16(2), | ||
512 | .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */ | ||
513 | }; | ||
514 | |||
515 | static struct usb_ss_ep_comp_descriptor fsg_ss_intr_in_comp_desc = { | ||
516 | .bLength = sizeof(fsg_ss_bulk_in_comp_desc), | ||
517 | .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, | ||
518 | |||
519 | .wBytesPerInterval = cpu_to_le16(2), | ||
520 | }; | ||
521 | |||
522 | #ifndef FSG_NO_OTG | ||
523 | # define FSG_SS_FUNCTION_PRE_EP_ENTRIES 2 | ||
524 | #else | ||
525 | # define FSG_SS_FUNCTION_PRE_EP_ENTRIES 1 | ||
526 | #endif | ||
527 | |||
528 | #endif | ||
529 | |||
530 | static __maybe_unused struct usb_ext_cap_descriptor fsg_ext_cap_desc = { | 388 | static __maybe_unused struct usb_ext_cap_descriptor fsg_ext_cap_desc = { |
531 | .bLength = USB_DT_USB_EXT_CAP_SIZE, | 389 | .bLength = USB_DT_USB_EXT_CAP_SIZE, |
532 | .bDescriptorType = USB_DT_DEVICE_CAPABILITY, | 390 | .bDescriptorType = USB_DT_DEVICE_CAPABILITY, |
@@ -563,18 +421,11 @@ static __maybe_unused struct usb_bos_descriptor fsg_bos_desc = { | |||
563 | }; | 421 | }; |
564 | 422 | ||
565 | static struct usb_descriptor_header *fsg_ss_function[] = { | 423 | static struct usb_descriptor_header *fsg_ss_function[] = { |
566 | #ifndef FSG_NO_OTG | ||
567 | (struct usb_descriptor_header *) &fsg_otg_desc, | ||
568 | #endif | ||
569 | (struct usb_descriptor_header *) &fsg_intf_desc, | 424 | (struct usb_descriptor_header *) &fsg_intf_desc, |
570 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, | 425 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc, |
571 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, | 426 | (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc, |
572 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_desc, | 427 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_desc, |
573 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, | 428 | (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc, |
574 | #ifndef FSG_NO_INTR_EP | ||
575 | (struct usb_descriptor_header *) &fsg_ss_intr_in_desc, | ||
576 | (struct usb_descriptor_header *) &fsg_ss_intr_in_comp_desc, | ||
577 | #endif | ||
578 | NULL, | 429 | NULL, |
579 | }; | 430 | }; |
580 | 431 | ||
@@ -594,12 +445,6 @@ fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, | |||
594 | 445 | ||
595 | /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ | 446 | /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ |
596 | static struct usb_string fsg_strings[] = { | 447 | static struct usb_string fsg_strings[] = { |
597 | #ifndef FSG_NO_DEVICE_STRINGS | ||
598 | {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, | ||
599 | {FSG_STRING_PRODUCT, fsg_string_product}, | ||
600 | {FSG_STRING_SERIAL, ""}, | ||
601 | {FSG_STRING_CONFIG, fsg_string_config}, | ||
602 | #endif | ||
603 | {FSG_STRING_INTERFACE, fsg_string_interface}, | 448 | {FSG_STRING_INTERFACE, fsg_string_interface}, |
604 | {} | 449 | {} |
605 | }; | 450 | }; |