aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-08-02 03:03:39 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:55:04 -0400
commit2e806f67cc570d25395469a0ded0df8ffbd4d82f (patch)
tree7d1e64859244520348cd562558094ce9d82da4e5 /drivers/usb/gadget
parent51a0e85cd9b47e2e6332b40ea486cc1659d8a3ec (diff)
USB: gadget: file storage gadget cleanups
Clean up the file storage gadget, using newer APIs and conventions: - gadget_is_dualspeed() and gadget_is_otg() ... #ifdef removal - Remove many now-needless #includes - Use the DEBUG (from Kconfig+Makefile) and VERBOSE_DEBUG conventions. - Remove some "sparse" warnings (it still dislikes the __user annotations) This gave only a minor object code shrinkage. Signed-off-by: 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/gadget')
-rw-r--r--drivers/usb/gadget/file_storage.c118
1 files changed, 45 insertions, 73 deletions
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 965ad7bec7b7..0019116ee411 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -217,17 +217,11 @@
217 */ 217 */
218 218
219 219
220#undef DEBUG 220/* #define VERBOSE_DEBUG */
221#undef VERBOSE
222#undef DUMP_MSGS 221#undef DUMP_MSGS
223 222
224 223
225#include <asm/system.h>
226#include <asm/uaccess.h>
227
228#include <linux/bitops.h>
229#include <linux/blkdev.h> 224#include <linux/blkdev.h>
230#include <linux/compiler.h>
231#include <linux/completion.h> 225#include <linux/completion.h>
232#include <linux/dcache.h> 226#include <linux/dcache.h>
233#include <linux/delay.h> 227#include <linux/delay.h>
@@ -235,18 +229,10 @@
235#include <linux/fcntl.h> 229#include <linux/fcntl.h>
236#include <linux/file.h> 230#include <linux/file.h>
237#include <linux/fs.h> 231#include <linux/fs.h>
238#include <linux/init.h>
239#include <linux/kernel.h>
240#include <linux/kref.h> 232#include <linux/kref.h>
241#include <linux/kthread.h> 233#include <linux/kthread.h>
242#include <linux/limits.h> 234#include <linux/limits.h>
243#include <linux/list.h>
244#include <linux/module.h>
245#include <linux/moduleparam.h>
246#include <linux/pagemap.h>
247#include <linux/rwsem.h> 235#include <linux/rwsem.h>
248#include <linux/sched.h>
249#include <linux/signal.h>
250#include <linux/slab.h> 236#include <linux/slab.h>
251#include <linux/spinlock.h> 237#include <linux/spinlock.h>
252#include <linux/string.h> 238#include <linux/string.h>
@@ -289,57 +275,51 @@ MODULE_LICENSE("Dual BSD/GPL");
289 275
290/*-------------------------------------------------------------------------*/ 276/*-------------------------------------------------------------------------*/
291 277
292#define xprintk(f,level,fmt,args...) \
293 dev_printk(level , &(f)->gadget->dev , fmt , ## args)
294#define yprintk(l,level,fmt,args...) \ 278#define yprintk(l,level,fmt,args...) \
295 dev_printk(level , &(l)->dev , fmt , ## args) 279 dev_printk(level , &(l)->dev , fmt , ## args)
296 280
297#ifdef DEBUG 281#ifdef DEBUG
298#define DBG(fsg,fmt,args...) \
299 xprintk(fsg , KERN_DEBUG , fmt , ## args)
300#define LDBG(lun,fmt,args...) \ 282#define LDBG(lun,fmt,args...) \
301 yprintk(lun , KERN_DEBUG , fmt , ## args) 283 yprintk(lun , KERN_DEBUG , fmt , ## args)
302#define MDBG(fmt,args...) \ 284#define MDBG(fmt,args...) \
303 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args) 285 printk(KERN_DEBUG DRIVER_NAME ": " fmt , ## args)
304#else 286#else
305#define DBG(fsg,fmt,args...) \
306 do { } while (0)
307#define LDBG(lun,fmt,args...) \ 287#define LDBG(lun,fmt,args...) \
308 do { } while (0) 288 do { } while (0)
309#define MDBG(fmt,args...) \ 289#define MDBG(fmt,args...) \
310 do { } while (0) 290 do { } while (0)
311#undef VERBOSE 291#undef VERBOSE_DEBUG
312#undef DUMP_MSGS 292#undef DUMP_MSGS
313#endif /* DEBUG */ 293#endif /* DEBUG */
314 294
315#ifdef VERBOSE 295#ifdef VERBOSE_DEBUG
316#define VDBG DBG
317#define VLDBG LDBG 296#define VLDBG LDBG
318#else 297#else
319#define VDBG(fsg,fmt,args...) \
320 do { } while (0)
321#define VLDBG(lun,fmt,args...) \ 298#define VLDBG(lun,fmt,args...) \
322 do { } while (0) 299 do { } while (0)
323#endif /* VERBOSE */ 300#endif /* VERBOSE_DEBUG */
324 301
325#define ERROR(fsg,fmt,args...) \
326 xprintk(fsg , KERN_ERR , fmt , ## args)
327#define LERROR(lun,fmt,args...) \ 302#define LERROR(lun,fmt,args...) \
328 yprintk(lun , KERN_ERR , fmt , ## args) 303 yprintk(lun , KERN_ERR , fmt , ## args)
329
330#define WARN(fsg,fmt,args...) \
331 xprintk(fsg , KERN_WARNING , fmt , ## args)
332#define LWARN(lun,fmt,args...) \ 304#define LWARN(lun,fmt,args...) \
333 yprintk(lun , KERN_WARNING , fmt , ## args) 305 yprintk(lun , KERN_WARNING , fmt , ## args)
334
335#define INFO(fsg,fmt,args...) \
336 xprintk(fsg , KERN_INFO , fmt , ## args)
337#define LINFO(lun,fmt,args...) \ 306#define LINFO(lun,fmt,args...) \
338 yprintk(lun , KERN_INFO , fmt , ## args) 307 yprintk(lun , KERN_INFO , fmt , ## args)
339 308
340#define MINFO(fmt,args...) \ 309#define MINFO(fmt,args...) \
341 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args) 310 printk(KERN_INFO DRIVER_NAME ": " fmt , ## args)
342 311
312#define DBG(d, fmt, args...) \
313 dev_dbg(&(d)->gadget->dev , fmt , ## args)
314#define VDBG(d, fmt, args...) \
315 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
316#define ERROR(d, fmt, args...) \
317 dev_err(&(d)->gadget->dev , fmt , ## args)
318#define WARN(d, fmt, args...) \
319 dev_warn(&(d)->gadget->dev , fmt , ## args)
320#define INFO(d, fmt, args...) \
321 dev_info(&(d)->gadget->dev , fmt , ## args)
322
343 323
344/*-------------------------------------------------------------------------*/ 324/*-------------------------------------------------------------------------*/
345 325
@@ -350,8 +330,8 @@ MODULE_LICENSE("Dual BSD/GPL");
350static struct { 330static struct {
351 char *file[MAX_LUNS]; 331 char *file[MAX_LUNS];
352 int ro[MAX_LUNS]; 332 int ro[MAX_LUNS];
353 int num_filenames; 333 unsigned int num_filenames;
354 int num_ros; 334 unsigned int num_ros;
355 unsigned int nluns; 335 unsigned int nluns;
356 336
357 int removable; 337 int removable;
@@ -950,8 +930,6 @@ static const struct usb_descriptor_header *fs_function[] = {
950#define FS_FUNCTION_PRE_EP_ENTRIES 2 930#define FS_FUNCTION_PRE_EP_ENTRIES 2
951 931
952 932
953#ifdef CONFIG_USB_GADGET_DUALSPEED
954
955/* 933/*
956 * USB 2.0 devices need to expose both high speed and full speed 934 * USB 2.0 devices need to expose both high speed and full speed
957 * descriptors, unless they only run at full speed. 935 * descriptors, unless they only run at full speed.
@@ -1014,14 +992,14 @@ static const struct usb_descriptor_header *hs_function[] = {
1014#define HS_FUNCTION_PRE_EP_ENTRIES 2 992#define HS_FUNCTION_PRE_EP_ENTRIES 2
1015 993
1016/* Maxpacket and other transfer characteristics vary by speed. */ 994/* Maxpacket and other transfer characteristics vary by speed. */
1017#define ep_desc(g,fs,hs) (((g)->speed==USB_SPEED_HIGH) ? (hs) : (fs)) 995static inline struct usb_endpoint_descriptor *
1018 996ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
1019#else 997 struct usb_endpoint_descriptor *hs)
1020 998{
1021/* If there's no high speed support, always use the full-speed descriptor. */ 999 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
1022#define ep_desc(g,fs,hs) fs 1000 return hs;
1023 1001 return fs;
1024#endif /* !CONFIG_USB_GADGET_DUALSPEED */ 1002}
1025 1003
1026 1004
1027/* The CBI specification limits the serial string to 12 uppercase hexadecimal 1005/* The CBI specification limits the serial string to 12 uppercase hexadecimal
@@ -1053,26 +1031,22 @@ static struct usb_gadget_strings stringtab = {
1053static int populate_config_buf(struct usb_gadget *gadget, 1031static int populate_config_buf(struct usb_gadget *gadget,
1054 u8 *buf, u8 type, unsigned index) 1032 u8 *buf, u8 type, unsigned index)
1055{ 1033{
1056#ifdef CONFIG_USB_GADGET_DUALSPEED
1057 enum usb_device_speed speed = gadget->speed; 1034 enum usb_device_speed speed = gadget->speed;
1058#endif
1059 int len; 1035 int len;
1060 const struct usb_descriptor_header **function; 1036 const struct usb_descriptor_header **function;
1061 1037
1062 if (index > 0) 1038 if (index > 0)
1063 return -EINVAL; 1039 return -EINVAL;
1064 1040
1065#ifdef CONFIG_USB_GADGET_DUALSPEED 1041 if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
1066 if (type == USB_DT_OTHER_SPEED_CONFIG)
1067 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed; 1042 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
1068 if (speed == USB_SPEED_HIGH) 1043 if (gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH)
1069 function = hs_function; 1044 function = hs_function;
1070 else 1045 else
1071#endif
1072 function = fs_function; 1046 function = fs_function;
1073 1047
1074 /* for now, don't advertise srp-only devices */ 1048 /* for now, don't advertise srp-only devices */
1075 if (!gadget->is_otg) 1049 if (!gadget_is_otg(gadget))
1076 function++; 1050 function++;
1077 1051
1078 len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function); 1052 len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
@@ -1394,10 +1368,9 @@ static int standard_setup_req(struct fsg_dev *fsg,
1394 value = sizeof device_desc; 1368 value = sizeof device_desc;
1395 memcpy(req->buf, &device_desc, value); 1369 memcpy(req->buf, &device_desc, value);
1396 break; 1370 break;
1397#ifdef CONFIG_USB_GADGET_DUALSPEED
1398 case USB_DT_DEVICE_QUALIFIER: 1371 case USB_DT_DEVICE_QUALIFIER:
1399 VDBG(fsg, "get device qualifier\n"); 1372 VDBG(fsg, "get device qualifier\n");
1400 if (!fsg->gadget->is_dualspeed) 1373 if (!gadget_is_dualspeed(fsg->gadget))
1401 break; 1374 break;
1402 value = sizeof dev_qualifier; 1375 value = sizeof dev_qualifier;
1403 memcpy(req->buf, &dev_qualifier, value); 1376 memcpy(req->buf, &dev_qualifier, value);
@@ -1405,15 +1378,12 @@ static int standard_setup_req(struct fsg_dev *fsg,
1405 1378
1406 case USB_DT_OTHER_SPEED_CONFIG: 1379 case USB_DT_OTHER_SPEED_CONFIG:
1407 VDBG(fsg, "get other-speed config descriptor\n"); 1380 VDBG(fsg, "get other-speed config descriptor\n");
1408 if (!fsg->gadget->is_dualspeed) 1381 if (!gadget_is_dualspeed(fsg->gadget))
1409 break; 1382 break;
1410 goto get_config; 1383 goto get_config;
1411#endif
1412 case USB_DT_CONFIG: 1384 case USB_DT_CONFIG:
1413 VDBG(fsg, "get configuration descriptor\n"); 1385 VDBG(fsg, "get configuration descriptor\n");
1414#ifdef CONFIG_USB_GADGET_DUALSPEED 1386get_config:
1415 get_config:
1416#endif
1417 value = populate_config_buf(fsg->gadget, 1387 value = populate_config_buf(fsg->gadget,
1418 req->buf, 1388 req->buf,
1419 w_value >> 8, 1389 w_value >> 8,
@@ -3859,7 +3829,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3859 /* Find out how many LUNs there should be */ 3829 /* Find out how many LUNs there should be */
3860 i = mod_data.nluns; 3830 i = mod_data.nluns;
3861 if (i == 0) 3831 if (i == 0)
3862 i = max(mod_data.num_filenames, 1); 3832 i = max(mod_data.num_filenames, 1u);
3863 if (i > MAX_LUNS) { 3833 if (i > MAX_LUNS) {
3864 ERROR(fsg, "invalid number of LUNs: %d\n", i); 3834 ERROR(fsg, "invalid number of LUNs: %d\n", i);
3865 rc = -EINVAL; 3835 rc = -EINVAL;
@@ -3944,21 +3914,23 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3944 intf_desc.bInterfaceProtocol = mod_data.transport_type; 3914 intf_desc.bInterfaceProtocol = mod_data.transport_type;
3945 fs_function[i + FS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3915 fs_function[i + FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3946 3916
3947#ifdef CONFIG_USB_GADGET_DUALSPEED 3917 if (gadget_is_dualspeed(gadget)) {
3948 hs_function[i + HS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3918 hs_function[i + HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
3949 3919
3950 /* Assume ep0 uses the same maxpacket value for both speeds */ 3920 /* Assume ep0 uses the same maxpacket value for both speeds */
3951 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; 3921 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
3952 3922
3953 /* Assume that all endpoint addresses are the same for both speeds */ 3923 /* Assume endpoint addresses are the same for both speeds */
3954 hs_bulk_in_desc.bEndpointAddress = fs_bulk_in_desc.bEndpointAddress; 3924 hs_bulk_in_desc.bEndpointAddress =
3955 hs_bulk_out_desc.bEndpointAddress = fs_bulk_out_desc.bEndpointAddress; 3925 fs_bulk_in_desc.bEndpointAddress;
3956 hs_intr_in_desc.bEndpointAddress = fs_intr_in_desc.bEndpointAddress; 3926 hs_bulk_out_desc.bEndpointAddress =
3957#endif 3927 fs_bulk_out_desc.bEndpointAddress;
3928 hs_intr_in_desc.bEndpointAddress =
3929 fs_intr_in_desc.bEndpointAddress;
3930 }
3958 3931
3959 if (gadget->is_otg) { 3932 if (gadget_is_otg(gadget))
3960 otg_desc.bmAttributes |= USB_OTG_HNP; 3933 otg_desc.bmAttributes |= USB_OTG_HNP;
3961 }
3962 3934
3963 rc = -ENOMEM; 3935 rc = -ENOMEM;
3964 3936