Subversion Repositories shark

Rev

Rev 847 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
847 giacomo 1
#ifndef __LINUX_USB_H
2
#define __LINUX_USB_H
3
 
4
#include <linux/mod_devicetable.h>
5
#include <linux/usb_ch9.h>
6
 
7
#define USB_MAJOR                       180
8
 
9
 
10
#ifdef __KERNEL__
11
 
12
#include <linux/config.h>
13
#include <linux/errno.h>        /* for -ENODEV */
14
#include <linux/delay.h>        /* for mdelay() */
15
#include <linux/interrupt.h>    /* for in_interrupt() */
16
#include <linux/list.h>         /* for struct list_head */
17
#include <linux/device.h>       /* for struct device */
18
#include <linux/fs.h>           /* for struct file_operations */
19
#include <linux/completion.h>   /* for struct completion */
20
#include <linux/sched.h>        /* for current && schedule_timeout */
21
 
22
extern int wait_ms26(unsigned long timeout);
23
 
24
static __inline__ void wait_ms(unsigned int ms)
25
{
26
        wait_ms26(ms);
27
//      if(!in_interrupt()) {
28
//              current->state = TASK_UNINTERRUPTIBLE;
29
//                schedule_timeout(1 + ms * HZ / 1000);
30
//      }
31
//      else
32
//              mdelay(ms);
33
}
34
 
35
struct usb_device;
36
 
37
/*-------------------------------------------------------------------------*/
38
 
39
/*
40
 * Host-side wrappers for standard USB descriptors ... these are parsed
41
 * from the data provided by devices.  Parsing turns them from a flat
42
 * sequence of descriptors into a hierarchy:
43
 *
44
 *  - devices have one (usually) or more configs;
45
 *  - configs have one (often) or more interfaces;
46
 *  - interfaces have one (usually) or more settings;
47
 *  - each interface setting has zero or (usually) more endpoints.
48
 *
49
 * And there might be other descriptors mixed in with those.
50
 *
51
 * Devices may also have class-specific or vendor-specific descriptors.
52
 */
53
 
54
/* host-side wrapper for parsed endpoint descriptors */
55
struct usb_host_endpoint {
56
        struct usb_endpoint_descriptor  desc;
57
 
58
        unsigned char *extra;   /* Extra descriptors */
59
        int extralen;
60
};
61
 
62
/* host-side wrapper for one interface setting's parsed descriptors */
63
struct usb_host_interface {
64
        struct usb_interface_descriptor desc;
65
 
66
        /* array of desc.bNumEndpoint endpoints associated with this
67
         * interface setting.  these will be in no particular order.
68
         */
69
        struct usb_host_endpoint *endpoint;
70
 
71
        unsigned char *extra;   /* Extra descriptors */
72
        int extralen;
73
};
74
 
75
/**
76
 * struct usb_interface - what usb device drivers talk to
77
 * @altsetting: array of interface descriptors, one for each alternate
78
 *      setting that may be selected.  Each one includes a set of
79
 *      endpoint configurations and will be in numberic order,
80
 *      0..num_altsetting.
81
 * @num_altsetting: number of altsettings defined.
82
 * @act_altsetting: index of current altsetting.  this number is always
83
 *      less than num_altsetting.  after the device is configured, each
84
 *      interface uses its default setting of zero.
85
 * @driver: the USB driver that is bound to this interface.
86
 * @minor: the minor number assigned to this interface, if this
87
 *      interface is bound to a driver that uses the USB major number.
88
 *      If this interface does not use the USB major, this field should
89
 *      be unused.  The driver should set this value in the probe()
90
 *      function of the driver, after it has been assigned a minor
91
 *      number from the USB core by calling usb_register_dev().
92
 * @dev: driver model's view of this device
93
 * @class_dev: driver model's class view of this device.
94
 *
95
 * USB device drivers attach to interfaces on a physical device.  Each
96
 * interface encapsulates a single high level function, such as feeding
97
 * an audio stream to a speaker or reporting a change in a volume control.
98
 * Many USB devices only have one interface.  The protocol used to talk to
99
 * an interface's endpoints can be defined in a usb "class" specification,
100
 * or by a product's vendor.  The (default) control endpoint is part of
101
 * every interface, but is never listed among the interface's descriptors.
102
 *
103
 * The driver that is bound to the interface can use standard driver model
104
 * calls such as dev_get_drvdata() on the dev member of this structure.
105
 *
106
 * Each interface may have alternate settings.  The initial configuration
107
 * of a device sets the first of these, but the device driver can change
108
 * that setting using usb_set_interface().  Alternate settings are often
109
 * used to control the the use of periodic endpoints, such as by having
110
 * different endpoints use different amounts of reserved USB bandwidth.
111
 * All standards-conformant USB devices that use isochronous endpoints
112
 * will use them in non-default settings.
113
 */
114
struct usb_interface {
115
        /* array of alternate settings for this interface.
116
         * these will be in numeric order, 0..num_altsettting
117
         */
118
        struct usb_host_interface *altsetting;
119
 
120
        unsigned act_altsetting;        /* active alternate setting */
121
        unsigned num_altsetting;        /* number of alternate settings */
122
 
123
        struct usb_driver *driver;      /* driver */
124
        int minor;                      /* minor number this interface is bound to */
125
        struct device dev;              /* interface specific device info */
126
        struct class_device *class_dev;
127
};
128
#define to_usb_interface(d) container_of(d, struct usb_interface, dev)
129
#define interface_to_usbdev(intf) \
130
        container_of(intf->dev.parent, struct usb_device, dev)
131
 
132
static inline void *usb_get_intfdata (struct usb_interface *intf)
133
{
134
        return dev_get_drvdata (&intf->dev);
135
}
136
 
137
static inline void usb_set_intfdata (struct usb_interface *intf, void *data)
138
{
139
        dev_set_drvdata(&intf->dev, data);
140
}
141
 
142
/* this maximum is arbitrary */
143
#define USB_MAXINTERFACES       32
144
 
145
/* USB_DT_CONFIG: Configuration descriptor information.
146
 *
147
 * USB_DT_OTHER_SPEED_CONFIG is the same descriptor, except that the
148
 * descriptor type is different.  Highspeed-capable devices can look
149
 * different depending on what speed they're currently running.  Only
150
 * devices with a USB_DT_DEVICE_QUALIFIER have an OTHER_SPEED_CONFIG.
151
 */
152
struct usb_host_config {
153
        struct usb_config_descriptor    desc;
154
 
155
        /* the interfaces associated with this configuration
156
         * these will be in numeric order, 0..desc.bNumInterfaces
157
         */
158
        struct usb_interface *interface[USB_MAXINTERFACES];
159
 
160
        unsigned char *extra;   /* Extra descriptors */
161
        int extralen;
162
};
163
 
164
// FIXME remove; exported only for drivers/usb/misc/auserwald.c
165
// prefer usb_device->epnum[0..31]
166
extern struct usb_endpoint_descriptor *
167
        usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum);
168
 
169
int __usb_get_extra_descriptor(char *buffer, unsigned size,
170
        unsigned char type, void **ptr);
171
#define usb_get_extra_descriptor(ifpoint,type,ptr)\
172
        __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,\
173
                type,(void**)ptr)
174
 
175
/* -------------------------------------------------------------------------- */
176
 
177
struct usb_operations;
178
 
179
/* USB device number allocation bitmap */
180
struct usb_devmap {
181
        unsigned long devicemap[128 / (8*sizeof(unsigned long))];
182
};
183
 
184
/*
185
 * Allocated per bus (tree of devices) we have:
186
 */
187
struct usb_bus {
188
        struct device *controller;      /* host/master side hardware */
189
        int busnum;                     /* Bus number (in order of reg) */
190
        char *bus_name;                 /* stable id (PCI slot_name etc) */
191
 
192
        int devnum_next;                /* Next open device number in round-robin allocation */
193
 
194
        struct usb_devmap devmap;       /* device address allocation map */
195
        struct usb_operations *op;      /* Operations (specific to the HC) */
196
        struct usb_device *root_hub;    /* Root hub */
197
        struct list_head bus_list;      /* list of busses */
198
        void *hcpriv;                   /* Host Controller private data */
199
 
200
        int bandwidth_allocated;        /* on this bus: how much of the time
201
                                         * reserved for periodic (intr/iso)
202
                                         * requests is used, on average?
203
                                         * Units: microseconds/frame.
204
                                         * Limits: Full/low speed reserve 90%,
205
                                         * while high speed reserves 80%.
206
                                         */
207
        int bandwidth_int_reqs;         /* number of Interrupt requests */
208
        int bandwidth_isoc_reqs;        /* number of Isoc. requests */
209
 
210
        struct dentry *usbfs_dentry;    /* usbfs dentry entry for the bus */
211
        struct dentry *usbdevfs_dentry; /* usbdevfs dentry entry for the bus */
212
 
213
        struct class_device class_dev;  /* class device for this bus */
214
        void (*release)(struct usb_bus *bus);   /* function to destroy this bus's memory */
215
};
216
#define to_usb_bus(d) container_of(d, struct usb_bus, class_dev)
217
 
218
 
219
/* -------------------------------------------------------------------------- */
220
 
221
/* This is arbitrary.
222
 * From USB 2.0 spec Table 11-13, offset 7, a hub can
223
 * have up to 255 ports. The most yet reported is 10.
224
 */
225
#define USB_MAXCHILDREN         (16)
226
 
227
struct usb_tt;
228
 
229
struct usb_device {
230
        int             devnum;         /* Address on USB bus */
231
        char            devpath [16];   /* Use in messages: /port/port/... */
232
        enum usb_device_state   state;  /* configured, not attached, etc */
233
        enum usb_device_speed   speed;  /* high/full/low (or error) */
234
 
235
        struct usb_tt   *tt;            /* low/full speed dev, highspeed hub */
236
        int             ttport;         /* device port on that tt hub */
237
 
238
        struct semaphore serialize;
239
 
240
        unsigned int toggle[2];         /* one bit for each endpoint ([0] = IN, [1] = OUT) */
241
        unsigned int halted[2];         /* endpoint halts; one bit per endpoint # & direction; */
242
                                        /* [0] = IN, [1] = OUT */
243
        int epmaxpacketin[16];          /* INput endpoint specific maximums */
244
        int epmaxpacketout[16];         /* OUTput endpoint specific maximums */
245
 
246
        struct usb_device *parent;      /* our hub, unless we're the root */
247
        struct usb_bus *bus;            /* Bus we're part of */
248
 
249
        struct device dev;              /* Generic device interface */
250
 
251
        struct usb_device_descriptor descriptor;/* Descriptor */
252
        struct usb_host_config *config; /* All of the configs */
253
        struct usb_host_config *actconfig;/* the active configuration */
254
 
255
        char **rawdescriptors;          /* Raw descriptors for each config */
256
 
257
        int have_langid;                /* whether string_langid is valid yet */
258
        int string_langid;              /* language ID for strings */
259
 
260
        void *hcpriv;                   /* Host Controller private data */
261
 
262
        struct list_head filelist;
263
        struct dentry *usbfs_dentry;    /* usbfs dentry entry for the device */
264
        struct dentry *usbdevfs_dentry; /* usbdevfs dentry entry for the device */
265
 
266
        /*
267
         * Child devices - these can be either new devices
268
         * (if this is a hub device), or different instances
269
         * of this same device.
270
         *
271
         * Each instance needs its own set of data structures.
272
         */
273
 
274
        int maxchild;                   /* Number of ports if hub */
275
        struct usb_device *children[USB_MAXCHILDREN];
276
};
277
#define to_usb_device(d) container_of(d, struct usb_device, dev)
278
 
279
extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);
280
extern struct usb_device *usb_get_dev(struct usb_device *dev);
281
extern void usb_put_dev(struct usb_device *dev);
282
 
283
/* mostly for devices emulating SCSI over USB */
284
extern int usb_reset_device(struct usb_device *dev);
285
 
286
extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);
287
 
288
/* for drivers using iso endpoints */
289
extern int usb_get_current_frame_number (struct usb_device *usb_dev);
290
 
291
/* used these for multi-interface device registration */
292
extern int usb_driver_claim_interface(struct usb_driver *driver,
293
                        struct usb_interface *iface, void* priv);
294
extern int usb_interface_claimed(struct usb_interface *iface);
295
extern void usb_driver_release_interface(struct usb_driver *driver,
296
                        struct usb_interface *iface);
297
const struct usb_device_id *usb_match_id(struct usb_interface *interface,
298
                                         const struct usb_device_id *id);
299
 
300
extern struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor);
301
extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum);
302
 
303
 
304
/**
305
 * usb_make_path - returns stable device path in the usb tree
306
 * @dev: the device whose path is being constructed
307
 * @buf: where to put the string
308
 * @size: how big is "buf"?
309
 *
310
 * Returns length of the string (> 0) or negative if size was too small.
311
 *
312
 * This identifier is intended to be "stable", reflecting physical paths in
313
 * hardware such as physical bus addresses for host controllers or ports on
314
 * USB hubs.  That makes it stay the same until systems are physically
315
 * reconfigured, by re-cabling a tree of USB devices or by moving USB host
316
 * controllers.  Adding and removing devices, including virtual root hubs
317
 * in host controller driver modules, does not change these path identifers;
318
 * neither does rebooting or re-enumerating.  These are more useful identifiers
319
 * than changeable ("unstable") ones like bus numbers or device addresses.
320
 *
321
 * With a partial exception for devices connected to USB 2.0 root hubs, these
322
 * identifiers are also predictable.  So long as the device tree isn't changed,
323
 * plugging any USB device into a given hub port always gives it the same path.
324
 * Because of the use of "companion" controllers, devices connected to ports on
325
 * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are
326
 * high speed, and a different one if they are full or low speed.
327
 */
328
static inline int usb_make_path (struct usb_device *dev, char *buf, size_t size)
329
{
330
        int actual;
331
        actual = snprintf26(buf, size, "usb-%s-%s", dev->bus->bus_name, dev->devpath);
332
        return (actual >= (int)size) ? -1 : actual;
333
}
334
 
335
/*-------------------------------------------------------------------------*/
336
 
337
#define USB_DEVICE_ID_MATCH_DEVICE              (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
338
#define USB_DEVICE_ID_MATCH_DEV_RANGE           (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
339
#define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION  (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
340
#define USB_DEVICE_ID_MATCH_DEV_INFO \
341
        (USB_DEVICE_ID_MATCH_DEV_CLASS | USB_DEVICE_ID_MATCH_DEV_SUBCLASS | USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
342
#define USB_DEVICE_ID_MATCH_INT_INFO \
343
        (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS | USB_DEVICE_ID_MATCH_INT_PROTOCOL)
344
 
345
/**
346
 * USB_DEVICE - macro used to describe a specific usb device
347
 * @vend: the 16 bit USB Vendor ID
348
 * @prod: the 16 bit USB Product ID
349
 *
350
 * This macro is used to create a struct usb_device_id that matches a
351
 * specific device.
352
 */
353
#define USB_DEVICE(vend,prod) \
354
        .match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = (vend), .idProduct = (prod)
355
/**
356
 * USB_DEVICE_VER - macro used to describe a specific usb device with a version range
357
 * @vend: the 16 bit USB Vendor ID
358
 * @prod: the 16 bit USB Product ID
359
 * @lo: the bcdDevice_lo value
360
 * @hi: the bcdDevice_hi value
361
 *
362
 * This macro is used to create a struct usb_device_id that matches a
363
 * specific device, with a version range.
364
 */
365
#define USB_DEVICE_VER(vend,prod,lo,hi) \
366
        .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, .idVendor = (vend), .idProduct = (prod), .bcdDevice_lo = (lo), .bcdDevice_hi = (hi)
367
 
368
/**
369
 * USB_DEVICE_INFO - macro used to describe a class of usb devices
370
 * @cl: bDeviceClass value
371
 * @sc: bDeviceSubClass value
372
 * @pr: bDeviceProtocol value
373
 *
374
 * This macro is used to create a struct usb_device_id that matches a
375
 * specific class of devices.
376
 */
377
#define USB_DEVICE_INFO(cl,sc,pr) \
378
        .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, .bDeviceClass = (cl), .bDeviceSubClass = (sc), .bDeviceProtocol = (pr)
379
 
380
/**
381
 * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces
382
 * @cl: bInterfaceClass value
383
 * @sc: bInterfaceSubClass value
384
 * @pr: bInterfaceProtocol value
385
 *
386
 * This macro is used to create a struct usb_device_id that matches a
387
 * specific class of interfaces.
388
 */
389
#define USB_INTERFACE_INFO(cl,sc,pr) \
390
        .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, .bInterfaceClass = (cl), .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr)
391
 
392
/* -------------------------------------------------------------------------- */
393
 
394
/**
395
 * struct usb_driver - identifies USB driver to usbcore
396
 * @owner: Pointer to the module owner of this driver; initialize
397
 *      it using THIS_MODULE.
398
 * @name: The driver name should be unique among USB drivers,
399
 *      and should normally be the same as the module name.
400
 * @probe: Called to see if the driver is willing to manage a particular
401
 *      interface on a device.  If it is, probe returns zero and uses
402
 *      dev_set_drvdata() to associate driver-specific data with the
403
 *      interface.  It may also use usb_set_interface() to specify the
404
 *      appropriate altsetting.  If unwilling to manage the interface,
405
 *      return a negative errno value.
406
 * @disconnect: Called when the interface is no longer accessible, usually
407
 *      because its device has been (or is being) disconnected or the
408
 *      driver module is being unloaded.
409
 * @ioctl: Used for drivers that want to talk to userspace through
410
 *      the "usbfs" filesystem.  This lets devices provide ways to
411
 *      expose information to user space regardless of where they
412
 *      do (or don't) show up otherwise in the filesystem.
413
 * @suspend: Called when the device is going to be suspended by the system.
414
 * @resume: Called when the device is being resumed by the system.
415
 * @id_table: USB drivers use ID table to support hotplugging.
416
 *      Export this with MODULE_DEVICE_TABLE(usb,...).  This must be set
417
 *      or your driver's probe function will never get called.
418
 * @driver: the driver model core driver structure.
419
 * @serialize: a semaphore used to serialize access to this driver.  Used
420
 *      in the probe and disconnect functions.  Only the USB core should use
421
 *      this lock.
422
 *
423
 * USB drivers must provide a name, probe() and disconnect() methods,
424
 * and an id_table.  Other driver fields are optional.
425
 *
426
 * The id_table is used in hotplugging.  It holds a set of descriptors,
427
 * and specialized data may be associated with each entry.  That table
428
 * is used by both user and kernel mode hotplugging support.
429
 *
430
 * The probe() and disconnect() methods are called in a context where
431
 * they can sleep, but they should avoid abusing the privilege.  Most
432
 * work to connect to a device should be done when the device is opened,
433
 * and undone at the last close.  The disconnect code needs to address
434
 * concurrency issues with respect to open() and close() methods, as
435
 * well as forcing all pending I/O requests to complete (by unlinking
436
 * them as necessary, and blocking until the unlinks complete).
437
 */
438
struct usb_driver {
439
        struct module *owner;
440
 
441
        const char *name;
442
 
443
        int (*probe) (struct usb_interface *intf,
444
                      const struct usb_device_id *id);
445
 
446
        void (*disconnect) (struct usb_interface *intf);
447
 
448
        int (*ioctl) (struct usb_interface *intf, unsigned int code, void *buf);
449
 
450
        int (*suspend) (struct usb_interface *intf, u32 state);
451
        int (*resume) (struct usb_interface *intf);
452
 
453
        const struct usb_device_id *id_table;
454
 
455
        struct device_driver driver;
456
 
457
        struct semaphore serialize;
458
};
459
#define to_usb_driver(d) container_of(d, struct usb_driver, driver)
460
 
461
extern struct bus_type usb_bus_type;
462
 
463
/**
464
 * struct usb_class_driver - identifies a USB driver that wants to use the USB major number
465
 * @name: devfs name for this driver.  Will also be used by the driver
466
 *      class code to create a usb class device.
467
 * @fops: pointer to the struct file_operations of this driver.
468
 * @mode: the mode for the devfs file to be created for this driver.
469
 * @minor_base: the start of the minor range for this driver.
470
 *
471
 * This structure is used for the usb_register_dev() and
472
 * usb_unregister_dev() functions, to consolodate a number of the
473
 * paramaters used for them.
474
 */
475
struct usb_class_driver {
476
        char *name;
477
        struct file_operations *fops;
478
        mode_t mode;
479
        int minor_base;
480
};
481
 
482
/*
483
 * use these in module_init()/module_exit()
484
 * and don't forget MODULE_DEVICE_TABLE(usb, ...)
485
 */
486
extern int usb_register(struct usb_driver *);
487
extern void usb_deregister(struct usb_driver *);
488
 
489
extern int usb_register_dev(struct usb_interface *intf,
490
                            struct usb_class_driver *class_driver);
491
extern void usb_deregister_dev(struct usb_interface *intf,
492
                               struct usb_class_driver *class_driver);
493
 
494
extern int usb_disabled(void);
495
 
496
/* -------------------------------------------------------------------------- */
497
 
498
/*
499
 * URB support, for asynchronous request completions
500
 */
501
 
502
/*
503
 * urb->transfer_flags:
504
 */
505
#define URB_SHORT_NOT_OK        0x0001  /* report short reads as errors */
506
#define URB_ISO_ASAP            0x0002  /* iso-only, urb->start_frame ignored */
507
#define URB_NO_TRANSFER_DMA_MAP 0x0004  /* urb->transfer_dma valid on submit */
508
#define URB_NO_SETUP_DMA_MAP    0x0008  /* urb->setup_dma valid on submit */
509
#define URB_ASYNC_UNLINK        0x0010  /* usb_unlink_urb() returns asap */
510
#define URB_NO_FSBR             0x0020  /* UHCI-specific */
511
#define URB_ZERO_PACKET         0x0040  /* Finish bulk OUTs with short packet */
512
#define URB_NO_INTERRUPT        0x0080  /* HINT: no non-error interrupt needed */
513
 
514
struct usb_iso_packet_descriptor {
515
        unsigned int offset;
516
        unsigned int length;            /* expected length */
517
        unsigned int actual_length;
518
        unsigned int status;
519
};
520
 
521
struct urb;
522
struct pt_regs;
523
 
524
typedef void (*usb_complete_t)(struct urb *, struct pt_regs *);
525
 
526
/**
527
 * struct urb - USB Request Block
528
 * @urb_list: For use by current owner of the URB.
529
 * @pipe: Holds endpoint number, direction, type, and more.
530
 *      Create these values with the eight macros available;
531
 *      usb_{snd,rcv}TYPEpipe(dev,endpoint), where the type is "ctrl"
532
 *      (control), "bulk", "int" (interrupt), or "iso" (isochronous).
533
 *      For example usb_sndbulkpipe() or usb_rcvintpipe().  Endpoint
534
 *      numbers range from zero to fifteen.  Note that "in" endpoint two
535
 *      is a different endpoint (and pipe) from "out" endpoint two.
536
 *      The current configuration controls the existence, type, and
537
 *      maximum packet size of any given endpoint.
538
 * @dev: Identifies the USB device to perform the request.
539
 * @status: This is read in non-iso completion functions to get the
540
 *      status of the particular request.  ISO requests only use it
541
 *      to tell whether the URB was unlinked; detailed status for
542
 *      each frame is in the fields of the iso_frame-desc.
543
 * @transfer_flags: A variety of flags may be used to affect how URB
544
 *      submission, unlinking, or operation are handled.  Different
545
 *      kinds of URB can use different flags.
546
 * @transfer_buffer:  This identifies the buffer to (or from) which
547
 *      the I/O request will be performed (unless URB_NO_TRANSFER_DMA_MAP
548
 *      is set).  This buffer must be suitable for DMA; allocate it with
549
 *      kmalloc() or equivalent.  For transfers to "in" endpoints, contents
550
 *      of this buffer will be modified.  This buffer is used for data
551
 *      phases of control transfers.
552
 * @transfer_dma: When transfer_flags includes URB_NO_TRANSFER_DMA_MAP,
553
 *      the device driver is saying that it provided this DMA address,
554
 *      which the host controller driver should use in preference to the
555
 *      transfer_buffer.
556
 * @transfer_buffer_length: How big is transfer_buffer.  The transfer may
557
 *      be broken up into chunks according to the current maximum packet
558
 *      size for the endpoint, which is a function of the configuration
559
 *      and is encoded in the pipe.  When the length is zero, neither
560
 *      transfer_buffer nor transfer_dma is used.
561
 * @actual_length: This is read in non-iso completion functions, and
562
 *      it tells how many bytes (out of transfer_buffer_length) were
563
 *      transferred.  It will normally be the same as requested, unless
564
 *      either an error was reported or a short read was performed.
565
 *      The URB_SHORT_NOT_OK transfer flag may be used to make such
566
 *      short reads be reported as errors.
567
 * @setup_packet: Only used for control transfers, this points to eight bytes
568
 *      of setup data.  Control transfers always start by sending this data
569
 *      to the device.  Then transfer_buffer is read or written, if needed.
570
 * @setup_dma: For control transfers with URB_NO_SETUP_DMA_MAP set, the
571
 *      device driver has provided this DMA address for the setup packet.
572
 *      The host controller driver should use this in preference to
573
 *      setup_packet.
574
 * @start_frame: Returns the initial frame for interrupt or isochronous
575
 *      transfers.
576
 * @number_of_packets: Lists the number of ISO transfer buffers.
577
 * @interval: Specifies the polling interval for interrupt or isochronous
578
 *      transfers.  The units are frames (milliseconds) for for full and low
579
 *      speed devices, and microframes (1/8 millisecond) for highspeed ones.
580
 * @error_count: Returns the number of ISO transfers that reported errors.
581
 * @context: For use in completion functions.  This normally points to
582
 *      request-specific driver context.
583
 * @complete: Completion handler. This URB is passed as the parameter to the
584
 *      completion function.  The completion function may then do what
585
 *      it likes with the URB, including resubmitting or freeing it.
586
 * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to
587
 *      collect the transfer status for each buffer.
588
 * @timeout: If set to zero, the urb will never timeout.  Otherwise this is
589
 *      the time in jiffies that this urb will timeout in.
590
 *
591
 * This structure identifies USB transfer requests.  URBs must be allocated by
592
 * calling usb_alloc_urb() and freed with a call to usb_free_urb().
593
 * Initialization may be done using various usb_fill_*_urb() functions.  URBs
594
 * are submitted using usb_submit_urb(), and pending requests may be canceled
595
 * using usb_unlink_urb().
596
 *
597
 * Data Transfer Buffers:
598
 *
599
 * Normally drivers provide I/O buffers allocated with kmalloc() or otherwise
600
 * taken from the general page pool.  That is provided by transfer_buffer
601
 * (control requests also use setup_packet), and host controller drivers
602
 * perform a dma mapping (and unmapping) for each buffer transferred.  Those
603
 * mapping operations can be expensive on some platforms (perhaps using a dma
604
 * bounce buffer or talking to an IOMMU),
605
 * although they're cheap on commodity x86 and ppc hardware.
606
 *
607
 * Alternatively, drivers may pass the URB_NO_xxx_DMA_MAP transfer flags,
608
 * which tell the host controller driver that no such mapping is needed since
609
 * the device driver is DMA-aware.  For example, a device driver might
610
 * allocate a DMA buffer with usb_buffer_alloc() or call usb_buffer_map().
611
 * When these transfer flags are provided, host controller drivers will
612
 * attempt to use the dma addresses found in the transfer_dma and/or
613
 * setup_dma fields rather than determining a dma address themselves.  (Note
614
 * that transfer_buffer and setup_packet must still be set because not all
615
 * host controllers use DMA, nor do virtual root hubs).
616
 *
617
 * Initialization:
618
 *
619
 * All URBs submitted must initialize dev, pipe,
620
 * transfer_flags (may be zero), complete, timeout (may be zero).
621
 * The URB_ASYNC_UNLINK transfer flag affects later invocations of
622
 * the usb_unlink_urb() routine.
623
 *
624
 * All URBs must also initialize
625
 * transfer_buffer and transfer_buffer_length.  They may provide the
626
 * URB_SHORT_NOT_OK transfer flag, indicating that short reads are
627
 * to be treated as errors; that flag is invalid for write requests.
628
 *
629
 * Bulk URBs may
630
 * use the URB_ZERO_PACKET transfer flag, indicating that bulk OUT transfers
631
 * should always terminate with a short packet, even if it means adding an
632
 * extra zero length packet.
633
 *
634
 * Control URBs must provide a setup_packet.  The setup_packet and
635
 * transfer_buffer may each be mapped for DMA or not, independently of
636
 * the other.  The transfer_flags bits URB_NO_TRANSFER_DMA_MAP and
637
 * URB_NO_SETUP_DMA_MAP indicate which buffers have already been mapped.
638
 * URB_NO_SETUP_DMA_MAP is ignored for non-control URBs.
639
 *
640
 * Interrupt UBS must provide an interval, saying how often (in milliseconds
641
 * or, for highspeed devices, 125 microsecond units)
642
 * to poll for transfers.  After the URB has been submitted, the interval
643
 * and start_frame fields reflect how the transfer was actually scheduled.
644
 * The polling interval may be more frequent than requested.
645
 * For example, some controllers have a maximum interval of 32 microseconds,
646
 * while others support intervals of up to 1024 microseconds.
647
 * Isochronous URBs also have transfer intervals.  (Note that for isochronous
648
 * endpoints, as well as high speed interrupt endpoints, the encoding of
649
 * the transfer interval in the endpoint descriptor is logarithmic.)
650
 *
651
 * Isochronous URBs normally use the URB_ISO_ASAP transfer flag, telling
652
 * the host controller to schedule the transfer as soon as bandwidth
653
 * utilization allows, and then set start_frame to reflect the actual frame
654
 * selected during submission.  Otherwise drivers must specify the start_frame
655
 * and handle the case where the transfer can't begin then.  However, drivers
656
 * won't know how bandwidth is currently allocated, and while they can
657
 * find the current frame using usb_get_current_frame_number () they can't
658
 * know the range for that frame number.  (Ranges for frame counter values
659
 * are HC-specific, and can go from 256 to 65536 frames from "now".)
660
 *
661
 * Isochronous URBs have a different data transfer model, in part because
662
 * the quality of service is only "best effort".  Callers provide specially
663
 * allocated URBs, with number_of_packets worth of iso_frame_desc structures
664
 * at the end.  Each such packet is an individual ISO transfer.  Isochronous
665
 * URBs are normally queued, submitted by drivers to arrange that
666
 * transfers are at least double buffered, and then explicitly resubmitted
667
 * in completion handlers, so
668
 * that data (such as audio or video) streams at as constant a rate as the
669
 * host controller scheduler can support.
670
 *
671
 * Completion Callbacks:
672
 *
673
 * The completion callback is made in_interrupt(), and one of the first
674
 * things that a completion handler should do is check the status field.
675
 * The status field is provided for all URBs.  It is used to report
676
 * unlinked URBs, and status for all non-ISO transfers.  It should not
677
 * be examined before the URB is returned to the completion handler.
678
 *
679
 * The context field is normally used to link URBs back to the relevant
680
 * driver or request state.
681
 *
682
 * When completion callback is invoked for non-isochronous URBs, the
683
 * actual_length field tells how many bytes were transferred.
684
 *
685
 * ISO transfer status is reported in the status and actual_length fields
686
 * of the iso_frame_desc array, and the number of errors is reported in
687
 * error_count.  Completion callbacks for ISO transfers will normally
688
 * (re)submit URBs to ensure a constant transfer rate.
689
 */
690
struct urb
691
{
692
        /* private, usb core and host controller only fields in the urb */
693
        spinlock_t lock;                /* lock for the URB */
694
        atomic_t count;                 /* reference count of the URB */
695
        void *hcpriv;                   /* private data for host controller */
696
        struct list_head urb_list;      /* list pointer to all active urbs */
697
        int bandwidth;                  /* bandwidth for INT/ISO request */
698
 
699
        /* public, documented fields in the urb that can be used by drivers */
700
        struct usb_device *dev;         /* (in) pointer to associated device */
701
        unsigned int pipe;              /* (in) pipe information */
702
        int status;                     /* (return) non-ISO status */
703
        unsigned int transfer_flags;    /* (in) URB_SHORT_NOT_OK | ...*/
704
        void *transfer_buffer;          /* (in) associated data buffer */
705
        dma_addr_t transfer_dma;        /* (in) dma addr for transfer_buffer */
706
        int transfer_buffer_length;     /* (in) data buffer length */
707
        int actual_length;              /* (return) actual transfer length */
708
        unsigned char *setup_packet;    /* (in) setup packet (control only) */
709
        dma_addr_t setup_dma;           /* (in) dma addr for setup_packet */
710
        int start_frame;                /* (modify) start frame (INT/ISO) */
711
        int number_of_packets;          /* (in) number of ISO packets */
712
        int interval;                   /* (in) transfer interval (INT/ISO) */
713
        int error_count;                /* (return) number of ISO errors */
714
        int timeout;                    /* (in) timeout, in jiffies */
715
        void *context;                  /* (in) context for completion */
716
        usb_complete_t complete;        /* (in) completion routine */
717
        struct usb_iso_packet_descriptor iso_frame_desc[0];     /* (in) ISO ONLY */
718
};
719
 
720
/* -------------------------------------------------------------------------- */
721
 
722
/**
723
 * usb_fill_control_urb - initializes a control urb
724
 * @urb: pointer to the urb to initialize.
725
 * @dev: pointer to the struct usb_device for this urb.
726
 * @pipe: the endpoint pipe
727
 * @setup_packet: pointer to the setup_packet buffer
728
 * @transfer_buffer: pointer to the transfer buffer
729
 * @buffer_length: length of the transfer buffer
730
 * @complete: pointer to the usb_complete_t function
731
 * @context: what to set the urb context to.
732
 *
733
 * Initializes a control urb with the proper information needed to submit
734
 * it to a device.
735
 */
736
static inline void usb_fill_control_urb (struct urb *urb,
737
                                         struct usb_device *dev,
738
                                         unsigned int pipe,
739
                                         unsigned char *setup_packet,
740
                                         void *transfer_buffer,
741
                                         int buffer_length,
742
                                         usb_complete_t complete,
743
                                         void *context)
744
{
745
        spin_lock_init(&urb->lock);
746
        urb->dev = dev;
747
        urb->pipe = pipe;
748
        urb->setup_packet = setup_packet;
749
        urb->transfer_buffer = transfer_buffer;
750
        urb->transfer_buffer_length = buffer_length;
751
        urb->complete = complete;
752
        urb->context = context;
753
}
754
 
755
/**
756
 * usb_fill_bulk_urb - macro to help initialize a bulk urb
757
 * @urb: pointer to the urb to initialize.
758
 * @dev: pointer to the struct usb_device for this urb.
759
 * @pipe: the endpoint pipe
760
 * @transfer_buffer: pointer to the transfer buffer
761
 * @buffer_length: length of the transfer buffer
762
 * @complete: pointer to the usb_complete_t function
763
 * @context: what to set the urb context to.
764
 *
765
 * Initializes a bulk urb with the proper information needed to submit it
766
 * to a device.
767
 */
768
static inline void usb_fill_bulk_urb (struct urb *urb,
769
                                      struct usb_device *dev,
770
                                      unsigned int pipe,
771
                                      void *transfer_buffer,
772
                                      int buffer_length,
773
                                      usb_complete_t complete,
774
                                      void *context)
775
{
776
        spin_lock_init(&urb->lock);
777
        urb->dev = dev;
778
        urb->pipe = pipe;
779
        urb->transfer_buffer = transfer_buffer;
780
        urb->transfer_buffer_length = buffer_length;
781
        urb->complete = complete;
782
        urb->context = context;
783
}
784
 
785
/**
786
 * usb_fill_int_urb - macro to help initialize a interrupt urb
787
 * @urb: pointer to the urb to initialize.
788
 * @dev: pointer to the struct usb_device for this urb.
789
 * @pipe: the endpoint pipe
790
 * @transfer_buffer: pointer to the transfer buffer
791
 * @buffer_length: length of the transfer buffer
792
 * @complete: pointer to the usb_complete_t function
793
 * @context: what to set the urb context to.
794
 * @interval: what to set the urb interval to, encoded like
795
 *      the endpoint descriptor's bInterval value.
796
 *
797
 * Initializes a interrupt urb with the proper information needed to submit
798
 * it to a device.
799
 * Note that high speed interrupt endpoints use a logarithmic encoding of
800
 * the endpoint interval, and express polling intervals in microframes
801
 * (eight per millisecond) rather than in frames (one per millisecond).
802
 */
803
static inline void usb_fill_int_urb (struct urb *urb,
804
                                     struct usb_device *dev,
805
                                     unsigned int pipe,
806
                                     void *transfer_buffer,
807
                                     int buffer_length,
808
                                     usb_complete_t complete,
809
                                     void *context,
810
                                     int interval)
811
{
812
        spin_lock_init(&urb->lock);
813
        urb->dev = dev;
814
        urb->pipe = pipe;
815
        urb->transfer_buffer = transfer_buffer;
816
        urb->transfer_buffer_length = buffer_length;
817
        urb->complete = complete;
818
        urb->context = context;
819
        if (dev->speed == USB_SPEED_HIGH)
820
                urb->interval = 1 << (interval - 1);
821
        else
822
                urb->interval = interval;
823
        urb->start_frame = -1;
824
}
825
 
826
extern void usb_init_urb(struct urb *urb);
827
extern struct urb *usb_alloc_urb(int iso_packets, int mem_flags);
828
extern void usb_free_urb(struct urb *urb);
829
#define usb_put_urb usb_free_urb
830
extern struct urb *usb_get_urb(struct urb *urb);
831
extern int usb_submit_urb(struct urb *urb, int mem_flags);
832
extern int usb_unlink_urb(struct urb *urb);
833
 
834
#define HAVE_USB_BUFFERS
835
void *usb_buffer_alloc (struct usb_device *dev, size_t size,
836
        int mem_flags, dma_addr_t *dma);
837
void usb_buffer_free (struct usb_device *dev, size_t size,
838
        void *addr, dma_addr_t dma);
839
 
840
struct urb *usb_buffer_map (struct urb *urb);
841
void usb_buffer_dmasync (struct urb *urb);
842
void usb_buffer_unmap (struct urb *urb);
843
 
844
struct scatterlist;
845
int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe,
846
                struct scatterlist *sg, int nents);
847
void usb_buffer_dmasync_sg (struct usb_device *dev, unsigned pipe,
848
                struct scatterlist *sg, int n_hw_ents);
849
void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe,
850
                struct scatterlist *sg, int n_hw_ents);
851
 
852
/*-------------------------------------------------------------------*
853
 *                         SYNCHRONOUS CALL SUPPORT                  *
854
 *-------------------------------------------------------------------*/
855
 
856
extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
857
        __u8 request, __u8 requesttype, __u16 value, __u16 index,
858
        void *data, __u16 size, int timeout);
859
extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
860
        void *data, int len, int *actual_length,
861
        int timeout);
862
 
863
/* wrappers around usb_control_msg() for the most common standard requests */
864
extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
865
        unsigned char descindex, void *buf, int size);
866
extern int usb_get_device_descriptor(struct usb_device *dev);
867
extern int usb_get_status(struct usb_device *dev,
868
        int type, int target, void *data);
869
extern int usb_get_string(struct usb_device *dev,
870
        unsigned short langid, unsigned char index, void *buf, int size);
871
extern int usb_string(struct usb_device *dev, int index,
872
        char *buf, size_t size);
873
 
874
/* wrappers that also update important state inside usbcore */
875
extern int usb_clear_halt(struct usb_device *dev, int pipe);
876
extern int usb_reset_configuration(struct usb_device *dev);
877
extern int usb_set_configuration(struct usb_device *dev, int configuration);
878
extern int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
879
 
880
/*
881
 * timeouts, in seconds, used for sending/receiving control messages
882
 * they typically complete within a few frames (msec) after they're issued
883
 * USB identifies 5 second timeouts, maybe more in a few cases, and a few
884
 * slow devices (like some MGE Ellipse UPSes) actually push that limit.
885
 */
886
#define USB_CTRL_GET_TIMEOUT    5
887
#define USB_CTRL_SET_TIMEOUT    5
888
 
889
 
890
/**
891
 * struct usb_sg_request - support for scatter/gather I/O
892
 * @status: zero indicates success, else negative errno
893
 * @bytes: counts bytes transferred.
894
 *
895
 * These requests are initialized using usb_sg_init(), and then are used
896
 * as request handles passed to usb_sg_wait() or usb_sg_cancel().  Most
897
 * members of the request object aren't for driver access.
898
 *
899
 * The status and bytecount values are valid only after usb_sg_wait()
900
 * returns.  If the status is zero, then the bytecount matches the total
901
 * from the request.
902
 *
903
 * After an error completion, drivers may need to clear a halt condition
904
 * on the endpoint.
905
 */
906
struct usb_sg_request {
907
        int                     status;
908
        size_t                  bytes;
909
 
910
        /*
911
         * members below are private to usbcore,
912
         * and are not provided for driver access!
913
         */
914
        spinlock_t              lock;
915
 
916
        struct usb_device       *dev;
917
        int                     pipe;
918
        struct scatterlist      *sg;
919
        int                     nents;
920
 
921
        int                     entries;
922
        struct urb              **urbs;
923
 
924
        int                     count;
925
        struct completion       complete;
926
};
927
 
928
int usb_sg_init (
929
        struct usb_sg_request   *io,
930
        struct usb_device       *dev,
931
        unsigned                pipe,
932
        unsigned                period,
933
        struct scatterlist      *sg,
934
        int                     nents,
935
        size_t                  length,
936
        int                     mem_flags
937
);
938
void usb_sg_cancel (struct usb_sg_request *io);
939
void usb_sg_wait (struct usb_sg_request *io);
940
 
941
 
942
/* -------------------------------------------------------------------------- */
943
 
944
/*
945
 * Calling this entity a "pipe" is glorifying it. A USB pipe
946
 * is something embarrassingly simple: it basically consists
947
 * of the following information:
948
 *  - device number (7 bits)
949
 *  - endpoint number (4 bits)
950
 *  - current Data0/1 state (1 bit) [Historical; now gone]
951
 *  - direction (1 bit)
952
 *  - speed (1 bit) [Historical and specific to USB 1.1; now gone.]
953
 *  - max packet size (2 bits: 8, 16, 32 or 64) [Historical; now gone.]
954
 *  - pipe type (2 bits: control, interrupt, bulk, isochronous)
955
 *
956
 * That's 18 bits. Really. Nothing more. And the USB people have
957
 * documented these eighteen bits as some kind of glorious
958
 * virtual data structure.
959
 *
960
 * Let's not fall in that trap. We'll just encode it as a simple
961
 * unsigned int. The encoding is:
962
 *
963
 *  - max size:         bits 0-1        [Historical; now gone.]
964
 *  - direction:        bit 7           (0 = Host-to-Device [Out],
965
 *                                       1 = Device-to-Host [In] ...
966
 *                                      like endpoint bEndpointAddress)
967
 *  - device:           bits 8-14       ... bit positions known to uhci-hcd
968
 *  - endpoint:         bits 15-18      ... bit positions known to uhci-hcd
969
 *  - Data0/1:          bit 19          [Historical; now gone. ]
970
 *  - lowspeed:         bit 26          [Historical; now gone. ]
971
 *  - pipe type:        bits 30-31      (00 = isochronous, 01 = interrupt,
972
 *                                       10 = control, 11 = bulk)
973
 *
974
 * Why? Because it's arbitrary, and whatever encoding we select is really
975
 * up to us. This one happens to share a lot of bit positions with the UHCI
976
 * specification, so that much of the uhci driver can just mask the bits
977
 * appropriately.
978
 */
979
 
980
/* NOTE:  these are not the standard USB_ENDPOINT_XFER_* values!! */
981
#define PIPE_ISOCHRONOUS                0
982
#define PIPE_INTERRUPT                  1
983
#define PIPE_CONTROL                    2
984
#define PIPE_BULK                       3
985
 
986
#define usb_maxpacket(dev, pipe, out)   (out \
987
                                ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
988
                                : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
989
 
990
#define usb_pipein(pipe)        ((pipe) & USB_DIR_IN)
991
#define usb_pipeout(pipe)       (!usb_pipein(pipe))
992
#define usb_pipedevice(pipe)    (((pipe) >> 8) & 0x7f)
993
#define usb_pipeendpoint(pipe)  (((pipe) >> 15) & 0xf)
994
#define usb_pipetype(pipe)      (((pipe) >> 30) & 3)
995
#define usb_pipeisoc(pipe)      (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
996
#define usb_pipeint(pipe)       (usb_pipetype((pipe)) == PIPE_INTERRUPT)
997
#define usb_pipecontrol(pipe)   (usb_pipetype((pipe)) == PIPE_CONTROL)
998
#define usb_pipebulk(pipe)      (usb_pipetype((pipe)) == PIPE_BULK)
999
 
1000
/* The D0/D1 toggle bits ... USE WITH CAUTION (they're almost hcd-internal) */
1001
#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)
1002
#define usb_dotoggle(dev, ep, out)  ((dev)->toggle[out] ^= (1 << (ep)))
1003
#define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | ((bit) << (ep)))
1004
 
1005
/* Endpoint halt control/status ... likewise USE WITH CAUTION */
1006
#define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
1007
#define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
1008
 
1009
 
1010
static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint)
1011
{
1012
        return (dev->devnum << 8) | (endpoint << 15);
1013
}
1014
 
1015
/* Create various pipes... */
1016
#define usb_sndctrlpipe(dev,endpoint)   ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
1017
#define usb_rcvctrlpipe(dev,endpoint)   ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1018
#define usb_sndisocpipe(dev,endpoint)   ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
1019
#define usb_rcvisocpipe(dev,endpoint)   ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1020
#define usb_sndbulkpipe(dev,endpoint)   ((PIPE_BULK << 30) | __create_pipe(dev,endpoint))
1021
#define usb_rcvbulkpipe(dev,endpoint)   ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1022
#define usb_sndintpipe(dev,endpoint)    ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
1023
#define usb_rcvintpipe(dev,endpoint)    ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
1024
 
1025
/* -------------------------------------------------------------------------- */
1026
 
1027
/*
1028
 * Debugging and troubleshooting/diagnostic helpers.
1029
 */
1030
void usb_show_device_descriptor(struct usb_device_descriptor *);
1031
void usb_show_config_descriptor(struct usb_config_descriptor *);
1032
void usb_show_interface_descriptor(struct usb_interface_descriptor *);
1033
void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);
1034
void usb_show_device(struct usb_device *);
1035
void usb_show_string(struct usb_device *dev, char *id, int index);
1036
 
1037
#ifdef DEBUG
1038
#define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , __FILE__ , ## arg)
1039
#else
1040
#define dbg(format, arg...) do {} while (0)
1041
#endif
1042
 
1043
#ifdef DEBUG
1044
#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , __FILE__ , ## arg)
1045
#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , __FILE__ , ## arg)
1046
#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , __FILE__ , ## arg)
1047
#else
1048
#define err(format, arg...)
1049
#define info(format, arg...)
1050
#define warn(format, arg...)
1051
#endif
1052
 
1053
#endif  /* __KERNEL__ */
1054
 
1055
#endif