Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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