1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __USB_CORE_HCD_H
20#define __USB_CORE_HCD_H
21
22#ifdef __KERNEL__
23
24#include <linux/rwsem.h>
25
26#define MAX_TOPO_LEVEL 6
27
28
29
30
31
32
33
34
35#define USB_PID_EXT 0xf0
36#define USB_PID_OUT 0xe1
37#define USB_PID_ACK 0xd2
38#define USB_PID_DATA0 0xc3
39#define USB_PID_PING 0xb4
40#define USB_PID_SOF 0xa5
41#define USB_PID_NYET 0x96
42#define USB_PID_DATA2 0x87
43#define USB_PID_SPLIT 0x78
44#define USB_PID_IN 0x69
45#define USB_PID_NAK 0x5a
46#define USB_PID_DATA1 0x4b
47#define USB_PID_PREAMBLE 0x3c
48#define USB_PID_ERR 0x3c
49#define USB_PID_SETUP 0x2d
50#define USB_PID_STALL 0x1e
51#define USB_PID_MDATA 0x0f
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70struct usb_hcd {
71
72
73
74
75 struct usb_bus self;
76 struct kref kref;
77
78 const char *product_desc;
79 char irq_descr[24];
80
81 struct timer_list rh_timer;
82 struct urb *status_urb;
83#ifdef CONFIG_USB_SUSPEND
84 struct work_struct wakeup_work;
85#endif
86
87
88
89
90 const struct hc_driver *driver;
91
92
93 unsigned long flags;
94#define HCD_FLAG_HW_ACCESSIBLE 0x00000001
95#define HCD_FLAG_SAW_IRQ 0x00000002
96
97 unsigned rh_registered:1;
98
99
100
101 unsigned uses_new_polling:1;
102 unsigned poll_rh:1;
103 unsigned poll_pending:1;
104 unsigned wireless:1;
105 unsigned authorized_default:1;
106 unsigned has_tt:1;
107
108 int irq;
109 void __iomem *regs;
110 u64 rsrc_start;
111 u64 rsrc_len;
112 unsigned power_budget;
113
114
115
116
117
118
119
120
121
122
123
124
125 struct mutex bandwidth_mutex;
126
127
128#define HCD_BUFFER_POOLS 4
129 struct dma_pool *pool [HCD_BUFFER_POOLS];
130
131 int state;
132# define __ACTIVE 0x01
133# define __SUSPEND 0x04
134# define __TRANSIENT 0x80
135
136# define HC_STATE_HALT 0
137# define HC_STATE_RUNNING (__ACTIVE)
138# define HC_STATE_QUIESCING (__SUSPEND|__TRANSIENT|__ACTIVE)
139# define HC_STATE_RESUMING (__SUSPEND|__TRANSIENT)
140# define HC_STATE_SUSPENDED (__SUSPEND)
141
142#define HC_IS_RUNNING(state) ((state) & __ACTIVE)
143#define HC_IS_SUSPENDED(state) ((state) & __SUSPEND)
144
145
146
147
148
149
150
151
152
153
154 unsigned long hcd_priv[0]
155 __attribute__ ((aligned(sizeof(unsigned long))));
156};
157
158
159static inline struct usb_bus *hcd_to_bus(struct usb_hcd *hcd)
160{
161 return &hcd->self;
162}
163
164static inline struct usb_hcd *bus_to_hcd(struct usb_bus *bus)
165{
166 return container_of(bus, struct usb_hcd, self);
167}
168
169struct hcd_timeout {
170 struct list_head timeout_list;
171 struct timer_list timer;
172};
173
174
175
176
177struct hc_driver {
178 const char *description;
179 const char *product_desc;
180 size_t hcd_priv_size;
181
182
183 irqreturn_t (*irq) (struct usb_hcd *hcd);
184
185 int flags;
186#define HCD_MEMORY 0x0001
187#define HCD_LOCAL_MEM 0x0002
188#define HCD_USB11 0x0010
189#define HCD_USB2 0x0020
190#define HCD_USB3 0x0040
191#define HCD_MASK 0x0070
192
193
194 int (*reset) (struct usb_hcd *hcd);
195 int (*start) (struct usb_hcd *hcd);
196
197
198
199
200
201 int (*pci_suspend)(struct usb_hcd *hcd);
202
203
204 int (*pci_resume)(struct usb_hcd *hcd, bool hibernated);
205
206
207 void (*stop) (struct usb_hcd *hcd);
208
209
210 void (*shutdown) (struct usb_hcd *hcd);
211
212
213 int (*get_frame_number) (struct usb_hcd *hcd);
214
215
216 int (*urb_enqueue)(struct usb_hcd *hcd,
217 struct urb *urb, gfp_t mem_flags);
218 int (*urb_dequeue)(struct usb_hcd *hcd,
219 struct urb *urb, int status);
220
221
222 void (*endpoint_disable)(struct usb_hcd *hcd,
223 struct usb_host_endpoint *ep);
224
225
226
227 void (*endpoint_reset)(struct usb_hcd *hcd,
228 struct usb_host_endpoint *ep);
229
230
231 int (*hub_status_data) (struct usb_hcd *hcd, char *buf);
232 int (*hub_control) (struct usb_hcd *hcd,
233 u16 typeReq, u16 wValue, u16 wIndex,
234 char *buf, u16 wLength);
235 int (*bus_suspend)(struct usb_hcd *);
236 int (*bus_resume)(struct usb_hcd *);
237 int (*start_port_reset)(struct usb_hcd *, unsigned port_num);
238
239
240 void (*relinquish_port)(struct usb_hcd *, int);
241
242 int (*port_handed_over)(struct usb_hcd *, int);
243
244
245 void (*clear_tt_buffer_complete)(struct usb_hcd *,
246 struct usb_host_endpoint *);
247
248
249
250 int (*alloc_dev)(struct usb_hcd *, struct usb_device *);
251
252 void (*free_dev)(struct usb_hcd *, struct usb_device *);
253
254
255
256
257
258
259
260
261
262
263
264
265 int (*add_endpoint)(struct usb_hcd *, struct usb_device *, struct usb_host_endpoint *);
266
267 int (*drop_endpoint)(struct usb_hcd *, struct usb_device *, struct usb_host_endpoint *);
268
269
270
271
272
273 int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);
274
275
276
277
278
279
280
281 void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
282
283 int (*address_device)(struct usb_hcd *, struct usb_device *udev);
284
285
286
287 int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev,
288 struct usb_tt *tt, gfp_t mem_flags);
289 int (*reset_device)(struct usb_hcd *, struct usb_device *);
290};
291
292extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
293extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
294 int status);
295extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb);
296
297extern int usb_hcd_submit_urb(struct urb *urb, gfp_t mem_flags);
298extern int usb_hcd_unlink_urb(struct urb *urb, int status);
299extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb,
300 int status);
301extern void usb_hcd_flush_endpoint(struct usb_device *udev,
302 struct usb_host_endpoint *ep);
303extern void usb_hcd_disable_endpoint(struct usb_device *udev,
304 struct usb_host_endpoint *ep);
305extern void usb_hcd_reset_endpoint(struct usb_device *udev,
306 struct usb_host_endpoint *ep);
307extern void usb_hcd_synchronize_unlinks(struct usb_device *udev);
308extern int usb_hcd_alloc_bandwidth(struct usb_device *udev,
309 struct usb_host_config *new_config,
310 struct usb_host_interface *old_alt,
311 struct usb_host_interface *new_alt);
312extern int usb_hcd_get_frame_number(struct usb_device *udev);
313
314extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
315 struct device *dev, const char *bus_name);
316extern struct usb_hcd *usb_get_hcd(struct usb_hcd *hcd);
317extern void usb_put_hcd(struct usb_hcd *hcd);
318extern int usb_add_hcd(struct usb_hcd *hcd,
319 unsigned int irqnum, unsigned long irqflags);
320extern void usb_remove_hcd(struct usb_hcd *hcd);
321
322struct platform_device;
323extern void usb_hcd_platform_shutdown(struct platform_device *dev);
324
325#ifdef CONFIG_PCI
326struct pci_dev;
327struct pci_device_id;
328extern int usb_hcd_pci_probe(struct pci_dev *dev,
329 const struct pci_device_id *id);
330extern void usb_hcd_pci_remove(struct pci_dev *dev);
331extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
332
333#ifdef CONFIG_PM_SLEEP
334extern const struct dev_pm_ops usb_hcd_pci_pm_ops;
335#endif
336#endif
337
338
339int hcd_buffer_create(struct usb_hcd *hcd);
340void hcd_buffer_destroy(struct usb_hcd *hcd);
341
342void *hcd_buffer_alloc(struct usb_bus *bus, size_t size,
343 gfp_t mem_flags, dma_addr_t *dma);
344void hcd_buffer_free(struct usb_bus *bus, size_t size,
345 void *addr, dma_addr_t dma);
346
347
348extern irqreturn_t usb_hcd_irq(int irq, void *__hcd);
349
350extern void usb_hc_died(struct usb_hcd *hcd);
351extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd);
352
353
354#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)
355#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << (ep)))
356#define usb_settoggle(dev, ep, out, bit) \
357 ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | \
358 ((bit) << (ep)))
359
360
361
362
363extern struct usb_device *usb_alloc_dev(struct usb_device *parent,
364 struct usb_bus *, unsigned port);
365extern int usb_new_device(struct usb_device *dev);
366extern void usb_disconnect(struct usb_device **);
367
368extern int usb_get_configuration(struct usb_device *dev);
369extern void usb_destroy_configuration(struct usb_device *dev);
370
371
372
373
374
375
376
377#include "hub.h"
378
379
380#define DeviceRequest \
381 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
382#define DeviceOutRequest \
383 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
384
385#define InterfaceRequest \
386 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
387
388#define EndpointRequest \
389 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
390#define EndpointOutRequest \
391 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
392
393
394
395#define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE)
396#define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE)
397#define GetHubDescriptor (0xa000 | USB_REQ_GET_DESCRIPTOR)
398#define GetHubStatus (0xa000 | USB_REQ_GET_STATUS)
399#define GetPortStatus (0xa300 | USB_REQ_GET_STATUS)
400#define SetHubFeature (0x2000 | USB_REQ_SET_FEATURE)
401#define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE)
402
403
404
405
406
407
408
409#define FRAME_TIME_USECS 1000L
410#define BitTime(bytecount) (7 * 8 * bytecount / 6)
411
412
413
414
415#define NS_TO_US(ns) ((ns + 500L) / 1000L)
416
417
418
419
420
421
422#define BW_HOST_DELAY 1000L
423#define BW_HUB_LS_SETUP 333L
424
425
426#define FRAME_TIME_BITS 12000L
427#define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
428#define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
429
430
431
432
433
434
435#define USB2_HOST_DELAY 5
436#define HS_NSECS(bytes) (((55 * 8 * 2083) \
437 + (2083UL * (3 + BitTime(bytes))))/1000 \
438 + USB2_HOST_DELAY)
439#define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \
440 + (2083UL * (3 + BitTime(bytes))))/1000 \
441 + USB2_HOST_DELAY)
442#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes))
443#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes))
444
445extern long usb_calc_bus_time(int speed, int is_input,
446 int isoc, int bytecount);
447
448
449
450extern void usb_set_device_state(struct usb_device *udev,
451 enum usb_device_state new_state);
452
453
454
455
456
457extern struct list_head usb_bus_list;
458extern struct mutex usb_bus_list_lock;
459extern wait_queue_head_t usb_kill_urb_queue;
460
461extern int usb_find_interface_driver(struct usb_device *dev,
462 struct usb_interface *interface);
463
464#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
465
466#ifdef CONFIG_PM
467extern void usb_root_hub_lost_power(struct usb_device *rhdev);
468extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg);
469extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg);
470#endif
471
472#ifdef CONFIG_USB_SUSPEND
473extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd);
474#else
475static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
476{
477 return;
478}
479#endif
480
481
482
483
484
485
486#ifdef CONFIG_USB_DEVICEFS
487
488
489
490
491
492extern void usbfs_update_special(void);
493extern int usbfs_init(void);
494extern void usbfs_cleanup(void);
495
496#else
497
498static inline void usbfs_update_special(void) {}
499static inline int usbfs_init(void) { return 0; }
500static inline void usbfs_cleanup(void) { }
501
502#endif
503
504
505
506#if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
507
508struct usb_mon_operations {
509 void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
510 void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
511 void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
512
513};
514
515extern struct usb_mon_operations *mon_ops;
516
517static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
518{
519 if (bus->monitored)
520 (*mon_ops->urb_submit)(bus, urb);
521}
522
523static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb,
524 int error)
525{
526 if (bus->monitored)
527 (*mon_ops->urb_submit_error)(bus, urb, error);
528}
529
530static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
531 int status)
532{
533 if (bus->monitored)
534 (*mon_ops->urb_complete)(bus, urb, status);
535}
536
537int usb_mon_register(struct usb_mon_operations *ops);
538void usb_mon_deregister(void);
539
540#else
541
542static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb) {}
543static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb,
544 int error) {}
545static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
546 int status) {}
547
548#endif
549
550
551
552
553
554#define bitmap DeviceRemovable
555
556
557
558
559
560
561#define RUN_CONTEXT (in_irq() ? "in_irq" \
562 : (in_interrupt() ? "in_interrupt" : "can sleep"))
563
564
565
566
567
568extern struct rw_semaphore ehci_cf_port_reset_rwsem;
569
570
571#define USB_UHCI_LOADED 0
572#define USB_OHCI_LOADED 1
573#define USB_EHCI_LOADED 2
574extern unsigned long usb_hcds_loaded;
575
576#endif
577
578#endif
579