19 #ifndef __USB_CORE_HCD_H
20 #define __USB_CORE_HCD_H
26 #define MAX_TOPO_LEVEL 6
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
78 const char *product_desc;
86 struct urb *status_urb;
87 #ifdef CONFIG_USB_SUSPEND
94 const struct hc_driver *
driver;
107 #define HCD_FLAG_HW_ACCESSIBLE 0
108 #define HCD_FLAG_POLL_RH 2
109 #define HCD_FLAG_POLL_PENDING 3
110 #define HCD_FLAG_WAKEUP_PENDING 4
111 #define HCD_FLAG_RH_RUNNING 5
112 #define HCD_FLAG_DEAD 6
117 #define HCD_HW_ACCESSIBLE(hcd) ((hcd)->flags & (1U << HCD_FLAG_HW_ACCESSIBLE))
118 #define HCD_POLL_RH(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_RH))
119 #define HCD_POLL_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_PENDING))
120 #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING))
121 #define HCD_RH_RUNNING(hcd) ((hcd)->flags & (1U << HCD_FLAG_RH_RUNNING))
122 #define HCD_DEAD(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEAD))
125 unsigned rh_registered:1;
126 unsigned rh_pollable:1;
131 unsigned uses_new_polling:1;
133 unsigned authorized_default:1;
140 unsigned power_budget;
153 struct mutex *bandwidth_mutex;
154 struct usb_hcd *shared_hcd;
155 struct usb_hcd *primary_hcd;
158 #define HCD_BUFFER_POOLS 4
162 # define __ACTIVE 0x01
163 # define __SUSPEND 0x04
164 # define __TRANSIENT 0x80
166 # define HC_STATE_HALT 0
167 # define HC_STATE_RUNNING (__ACTIVE)
168 # define HC_STATE_QUIESCING (__SUSPEND|__TRANSIENT|__ACTIVE)
169 # define HC_STATE_RESUMING (__SUSPEND|__TRANSIENT)
170 # define HC_STATE_SUSPENDED (__SUSPEND)
172 #define HC_IS_RUNNING(state) ((state) & __ACTIVE)
173 #define HC_IS_SUSPENDED(state) ((state) & __SUSPEND)
184 unsigned long hcd_priv[0]
189 static inline struct usb_bus *hcd_to_bus(
struct usb_hcd *hcd)
194 static inline struct usb_hcd *bus_to_hcd(
struct usb_bus *
bus)
209 const char *product_desc;
210 size_t hcd_priv_size;
216 #define HCD_MEMORY 0x0001
217 #define HCD_LOCAL_MEM 0x0002
218 #define HCD_SHARED 0x0004
219 #define HCD_USB11 0x0010
220 #define HCD_USB2 0x0020
221 #define HCD_USB3 0x0040
222 #define HCD_MASK 0x0070
225 int (*reset) (
struct usb_hcd *hcd);
232 int (*pci_suspend)(
struct usb_hcd *hcd,
bool do_wakeup);
235 int (*pci_resume)(
struct usb_hcd *hcd,
bool hibernated);
241 void (*shutdown) (
struct usb_hcd *hcd);
244 int (*get_frame_number) (
struct usb_hcd *hcd);
247 int (*urb_enqueue)(
struct usb_hcd *hcd,
249 int (*urb_dequeue)(
struct usb_hcd *hcd,
261 int (*map_urb_for_dma)(
struct usb_hcd *hcd,
struct urb *
urb,
263 void (*unmap_urb_for_dma)(
struct usb_hcd *hcd,
struct urb *
urb);
266 void (*endpoint_disable)(
struct usb_hcd *hcd,
267 struct usb_host_endpoint *ep);
271 void (*endpoint_reset)(
struct usb_hcd *hcd,
272 struct usb_host_endpoint *ep);
275 int (*hub_status_data) (
struct usb_hcd *hcd,
char *
buf);
276 int (*hub_control) (
struct usb_hcd *hcd,
279 int (*bus_suspend)(
struct usb_hcd *);
280 int (*bus_resume)(
struct usb_hcd *);
281 int (*start_port_reset)(
struct usb_hcd *,
unsigned port_num);
284 void (*relinquish_port)(
struct usb_hcd *,
int);
286 int (*port_handed_over)(
struct usb_hcd *,
int);
289 void (*clear_tt_buffer_complete)(
struct usb_hcd *,
290 struct usb_host_endpoint *);
294 int (*alloc_dev)(
struct usb_hcd *,
struct usb_device *);
296 void (*free_dev)(
struct usb_hcd *,
struct usb_device *);
298 int (*alloc_streams)(
struct usb_hcd *hcd,
struct usb_device *
udev,
299 struct usb_host_endpoint **eps,
unsigned int num_eps,
300 unsigned int num_streams,
gfp_t mem_flags);
304 int (*free_streams)(
struct usb_hcd *hcd,
struct usb_device *
udev,
305 struct usb_host_endpoint **eps,
unsigned int num_eps,
319 int (*add_endpoint)(
struct usb_hcd *,
struct usb_device *,
320 struct usb_host_endpoint *);
322 int (*drop_endpoint)(
struct usb_hcd *,
struct usb_device *,
323 struct usb_host_endpoint *);
329 int (*check_bandwidth)(
struct usb_hcd *,
struct usb_device *);
337 void (*reset_bandwidth)(
struct usb_hcd *,
struct usb_device *);
339 int (*address_device)(
struct usb_hcd *,
struct usb_device *
udev);
343 int (*update_hub_device)(
struct usb_hcd *,
struct usb_device *hdev,
344 struct usb_tt *
tt,
gfp_t mem_flags);
345 int (*reset_device)(
struct usb_hcd *,
struct usb_device *);
349 int (*update_device)(
struct usb_hcd *,
struct usb_device *);
350 int (*set_usb2_hw_lpm)(
struct usb_hcd *,
struct usb_device *,
int);
353 int (*enable_usb3_lpm_timeout)(
struct usb_hcd *,
358 int (*disable_usb3_lpm_timeout)(
struct usb_hcd *,
376 struct usb_host_endpoint *ep);
378 struct usb_host_endpoint *ep);
380 struct usb_host_endpoint *ep);
383 struct usb_host_config *new_config,
384 struct usb_host_interface *old_alt,
385 struct usb_host_interface *new_alt);
389 struct device *
dev,
const char *bus_name);
391 struct device *
dev,
const char *bus_name,
392 struct usb_hcd *shared_hcd);
393 extern struct usb_hcd *
usb_get_hcd(
struct usb_hcd *hcd);
397 unsigned int irqnum,
unsigned long irqflags);
411 #ifdef CONFIG_PM_SLEEP
412 extern const struct dev_pm_ops usb_hcd_pci_pm_ops;
431 unsigned int portnum);
434 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)
435 #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << (ep)))
436 #define usb_settoggle(dev, ep, out, bit) \
437 ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | \
443 extern struct usb_device *
usb_alloc_dev(
struct usb_device *parent,
444 struct usb_bus *,
unsigned port);
473 struct usb_device *hub;
483 struct usb_tt_clear {
488 struct usb_host_endpoint *ep;
495 #define DeviceRequest \
496 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
497 #define DeviceOutRequest \
498 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
500 #define InterfaceRequest \
501 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
503 #define EndpointRequest \
504 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
505 #define EndpointOutRequest \
506 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
510 #define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE)
511 #define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE)
512 #define GetHubDescriptor (0xa000 | USB_REQ_GET_DESCRIPTOR)
513 #define GetHubStatus (0xa000 | USB_REQ_GET_STATUS)
514 #define GetPortStatus (0xa300 | USB_REQ_GET_STATUS)
515 #define SetHubFeature (0x2000 | USB_REQ_SET_FEATURE)
516 #define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE)
522 #define SetHubDepth (0x3000 | HUB_SET_DEPTH)
523 #define GetPortErrorCount (0x8000 | HUB_GET_PORT_ERR_COUNT)
528 #define FRAME_TIME_USECS 1000L
529 #define BitTime(bytecount) (7 * 8 * bytecount / 6)
534 #define NS_TO_US(ns) ((ns + 500L) / 1000L)
541 #define BW_HOST_DELAY 1000L
542 #define BW_HUB_LS_SETUP 333L
545 #define FRAME_TIME_BITS 12000L
546 #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
547 #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
554 #define USB2_HOST_DELAY 5
555 #define HS_NSECS(bytes) (((55 * 8 * 2083) \
556 + (2083UL * (3 + BitTime(bytes))))/1000 \
558 #define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \
559 + (2083UL * (3 + BitTime(bytes))))/1000 \
561 #define HS_USECS(bytes) NS_TO_US(HS_NSECS(bytes))
562 #define HS_USECS_ISO(bytes) NS_TO_US(HS_NSECS_ISO(bytes))
565 int isoc,
int bytecount);
577 extern struct mutex usb_bus_list_lock;
580 extern int usb_find_interface_driver(
struct usb_device *
dev,
583 #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
586 extern void usb_root_hub_lost_power(
struct usb_device *rhdev);
587 extern int hcd_bus_suspend(
struct usb_device *rhdev,
pm_message_t msg);
591 #ifdef CONFIG_USB_SUSPEND
592 extern void usb_hcd_resume_root_hub(
struct usb_hcd *hcd);
594 static inline void usb_hcd_resume_root_hub(
struct usb_hcd *hcd)
602 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
604 struct usb_mon_operations {
611 extern struct usb_mon_operations *mon_ops;
613 static inline void usbmon_urb_submit(
struct usb_bus *
bus,
struct urb *
urb)
616 (*mon_ops->urb_submit)(bus, urb);
619 static inline void usbmon_urb_submit_error(
struct usb_bus *bus,
struct urb *urb,
623 (*mon_ops->urb_submit_error)(bus, urb, error);
626 static inline void usbmon_urb_complete(
struct usb_bus *bus,
struct urb *urb,
630 (*mon_ops->urb_complete)(bus, urb, status);
633 int usb_mon_register(
struct usb_mon_operations *ops);
634 void usb_mon_deregister(
void);
638 static inline void usbmon_urb_submit(
struct usb_bus *bus,
struct urb *urb) {}
639 static inline void usbmon_urb_submit_error(
struct usb_bus *bus,
struct urb *urb,
641 static inline void usbmon_urb_complete(
struct usb_bus *bus,
struct urb *urb,
650 #define RUN_CONTEXT (in_irq() ? "in_irq" \
651 : (in_interrupt() ? "in_interrupt" : "can sleep"))
660 #define USB_UHCI_LOADED 0
661 #define USB_OHCI_LOADED 1
662 #define USB_EHCI_LOADED 2