iPXE
usb.h
Go to the documentation of this file.
1 #ifndef _IPXE_USB_H
2 #define _IPXE_USB_H
3 
4 /** @file
5  *
6  * Universal Serial Bus (USB)
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <byteswap.h>
13 #include <ipxe/list.h>
14 #include <ipxe/device.h>
15 #include <ipxe/process.h>
16 #include <ipxe/iobuf.h>
17 #include <ipxe/tables.h>
18 
19 /** USB protocols */
21  /** USB 2.0 */
22  USB_PROTO_2_0 = 0x0200,
23  /** USB 3.0 */
24  USB_PROTO_3_0 = 0x0300,
25  /** USB 3.1 */
26  USB_PROTO_3_1 = 0x0301,
27 };
28 
29 /** Define a USB speed
30  *
31  * @v mantissa Mantissa
32  * @v exponent Exponent (in engineering terms: 1=k, 2=M, 3=G)
33  * @ret speed USB speed
34  */
35 #define USB_SPEED( mantissa, exponent ) ( (exponent << 16) | (mantissa) )
36 
37 /** Extract USB speed mantissa */
38 #define USB_SPEED_MANTISSA(speed) ( (speed) & 0xffff )
39 
40 /** Extract USB speed exponent */
41 #define USB_SPEED_EXPONENT(speed) ( ( (speed) >> 16 ) & 0x3 )
42 
43 /** USB device speeds */
44 enum usb_speed {
45  /** Not connected */
47  /** Low speed (1.5Mbps) */
48  USB_SPEED_LOW = USB_SPEED ( 1500, 1 ),
49  /** Full speed (12Mbps) */
51  /** High speed (480Mbps) */
52  USB_SPEED_HIGH = USB_SPEED ( 480, 2 ),
53  /** Super speed (5Gbps) */
55 };
56 
57 /** Define a USB bus:device address
58  *
59  * @v bus Bus address
60  * @v dev Device address
61  * @ret busdev Bus:device address
62  */
63 #define USB_BUSDEV( bus, dev ) ( ( (bus) << 8 ) | (dev) )
64 
65 /** Extract USB bus address */
66 #define USB_BUS( busdev ) ( (busdev) >> 8 )
67 
68 /** Extract USB device address */
69 #define USB_DEV( busdev ) ( (busdev) & 0xff )
70 
71 /** USB packet IDs */
72 enum usb_pid {
73  /** IN PID */
74  USB_PID_IN = 0x69,
75  /** OUT PID */
76  USB_PID_OUT = 0xe1,
77  /** SETUP PID */
78  USB_PID_SETUP = 0x2d,
79 };
80 
81 /** A USB setup data packet */
83  /** Request */
85  /** Value parameter */
87  /** Index parameter */
89  /** Length of data stage */
91 } __attribute__ (( packed ));
92 
93 /** Data transfer is from host to device */
94 #define USB_DIR_OUT ( 0 << 7 )
95 
96 /** Data transfer is from device to host */
97 #define USB_DIR_IN ( 1 << 7 )
98 
99 /** Standard request type */
100 #define USB_TYPE_STANDARD ( 0 << 5 )
101 
102 /** Class-specific request type */
103 #define USB_TYPE_CLASS ( 1 << 5 )
104 
105 /** Vendor-specific request type */
106 #define USB_TYPE_VENDOR ( 2 << 5 )
107 
108 /** Request recipient mask */
109 #define USB_RECIP_MASK ( 0x1f << 0 )
110 
111 /** Request recipient is the device */
112 #define USB_RECIP_DEVICE ( 0 << 0 )
113 
114 /** Request recipient is an interface */
115 #define USB_RECIP_INTERFACE ( 1 << 0 )
116 
117 /** Request recipient is an endpoint */
118 #define USB_RECIP_ENDPOINT ( 2 << 0 )
119 
120 /** Construct USB request type */
121 #define USB_REQUEST_TYPE(type) ( (type) << 8 )
122 
123 /** Get status */
124 #define USB_GET_STATUS ( USB_DIR_IN | USB_REQUEST_TYPE ( 0 ) )
125 
126 /** Clear feature */
127 #define USB_CLEAR_FEATURE ( USB_DIR_OUT | USB_REQUEST_TYPE ( 1 ) )
128 
129 /** Set feature */
130 #define USB_SET_FEATURE ( USB_DIR_OUT | USB_REQUEST_TYPE ( 3 ) )
131 
132 /** Set address */
133 #define USB_SET_ADDRESS ( USB_DIR_OUT | USB_REQUEST_TYPE ( 5 ) )
134 
135 /** Get descriptor */
136 #define USB_GET_DESCRIPTOR ( USB_DIR_IN | USB_REQUEST_TYPE ( 6 ) )
137 
138 /** Set descriptor */
139 #define USB_SET_DESCRIPTOR ( USB_DIR_OUT | USB_REQUEST_TYPE ( 7 ) )
140 
141 /** Get configuration */
142 #define USB_GET_CONFIGURATION ( USB_DIR_IN | USB_REQUEST_TYPE ( 8 ) )
143 
144 /** Set configuration */
145 #define USB_SET_CONFIGURATION ( USB_DIR_OUT | USB_REQUEST_TYPE ( 9 ) )
146 
147 /** Get interface */
148 #define USB_GET_INTERFACE \
149  ( USB_DIR_IN | USB_RECIP_INTERFACE | USB_REQUEST_TYPE ( 10 ) )
150 
151 /** Set interface */
152 #define USB_SET_INTERFACE \
153  ( USB_DIR_OUT | USB_RECIP_INTERFACE | USB_REQUEST_TYPE ( 11 ) )
154 
155 /** Endpoint halt feature */
156 #define USB_ENDPOINT_HALT 0
157 
158 /** A USB class code tuple */
159 struct usb_class {
160  /** Class code */
161  uint8_t class;
162  /** Subclass code */
164  /** Protocol code */
166 } __attribute__ (( packed ));
167 
168 /** Class code for USB hubs */
169 #define USB_CLASS_HUB 9
170 
171 /** A USB descriptor header */
173  /** Length of descriptor */
175  /** Descriptor type */
177 } __attribute__ (( packed ));
178 
179 /** A USB device descriptor */
181  /** Descriptor header */
183  /** USB specification release number in BCD */
185  /** Device class */
186  struct usb_class class;
187  /** Maximum packet size for endpoint zero */
189  /** Vendor ID */
191  /** Product ID */
193  /** Device release number in BCD */
195  /** Manufacturer string */
197  /** Product string */
199  /** Serial number string */
201  /** Number of possible configurations */
203 } __attribute__ (( packed ));
204 
205 /** A USB device descriptor */
206 #define USB_DEVICE_DESCRIPTOR 1
207 
208 /** A USB configuration descriptor */
210  /** Descriptor header */
212  /** Total length */
214  /** Number of interfaces */
216  /** Configuration value */
218  /** Configuration string */
220  /** Attributes */
222  /** Maximum power consumption */
224 } __attribute__ (( packed ));
225 
226 /** A USB configuration descriptor */
227 #define USB_CONFIGURATION_DESCRIPTOR 2
228 
229 /** A USB string descriptor */
231  /** Descriptor header */
233  /** String */
234  char string[0];
235 } __attribute__ (( packed ));
236 
237 /** A USB string descriptor */
238 #define USB_STRING_DESCRIPTOR 3
239 
240 /** Language ID for English */
241 #define USB_LANG_ENGLISH 0x0409
242 
243 /** A USB interface descriptor */
245  /** Descriptor header */
247  /** Interface number */
249  /** Alternate setting */
251  /** Number of endpoints */
253  /** Interface class */
254  struct usb_class class;
255  /** Interface name */
257 } __attribute__ (( packed ));
258 
259 /** A USB interface descriptor */
260 #define USB_INTERFACE_DESCRIPTOR 4
261 
262 /** A USB endpoint descriptor */
264  /** Descriptor header */
266  /** Endpoint address */
268  /** Attributes */
270  /** Maximum packet size and burst size */
272  /** Polling interval */
274 } __attribute__ (( packed ));
275 
276 /** A USB endpoint descriptor */
277 #define USB_ENDPOINT_DESCRIPTOR 5
278 
279 /** Endpoint attribute transfer type mask */
280 #define USB_ENDPOINT_ATTR_TYPE_MASK 0x03
281 
282 /** Endpoint periodic type */
283 #define USB_ENDPOINT_ATTR_PERIODIC 0x01
284 
285 /** Control endpoint transfer type */
286 #define USB_ENDPOINT_ATTR_CONTROL 0x00
287 
288 /** Bulk endpoint transfer type */
289 #define USB_ENDPOINT_ATTR_BULK 0x02
290 
291 /** Interrupt endpoint transfer type */
292 #define USB_ENDPOINT_ATTR_INTERRUPT 0x03
293 
294 /** Bulk OUT endpoint (internal) type */
295 #define USB_BULK_OUT ( USB_ENDPOINT_ATTR_BULK | USB_DIR_OUT )
296 
297 /** Bulk IN endpoint (internal) type */
298 #define USB_BULK_IN ( USB_ENDPOINT_ATTR_BULK | USB_DIR_IN )
299 
300 /** Interrupt IN endpoint (internal) type */
301 #define USB_INTERRUPT_IN ( USB_ENDPOINT_ATTR_INTERRUPT | USB_DIR_IN )
302 
303 /** Interrupt OUT endpoint (internal) type */
304 #define USB_INTERRUPT_OUT ( USB_ENDPOINT_ATTR_INTERRUPT | USB_DIR_OUT )
305 
306 /** USB endpoint MTU */
307 #define USB_ENDPOINT_MTU(sizes) ( ( (sizes) >> 0 ) & 0x07ff )
308 
309 /** USB endpoint maximum burst size */
310 #define USB_ENDPOINT_BURST(sizes) ( ( (sizes) >> 11 ) & 0x0003 )
311 
312 /** A USB endpoint companion descriptor */
314  /** Descriptor header */
316  /** Maximum burst size */
318  /** Extended attributes */
320  /** Number of bytes per service interval */
322 } __attribute__ (( packed ));
323 
324 /** A USB endpoint companion descriptor */
325 #define USB_ENDPOINT_COMPANION_DESCRIPTOR 48
326 
327 /** A USB interface association descriptor */
329  /** Descriptor header */
331  /** First interface number */
333  /** Interface count */
335  /** Association class */
336  struct usb_class class;
337  /** Association name */
339 } __attribute__ (( packed ));
340 
341 /** A USB interface association descriptor */
342 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR 11
343 
344 /** A class-specific interface descriptor */
345 #define USB_CS_INTERFACE_DESCRIPTOR 36
346 
347 /** A class-specific endpoint descriptor */
348 #define USB_CS_ENDPOINT_DESCRIPTOR 37
349 
350 /**
351  * Get next USB descriptor
352  *
353  * @v desc USB descriptor header
354  * @ret next Next USB descriptor header
355  */
356 static inline __attribute__ (( always_inline )) struct usb_descriptor_header *
358 
359  return ( ( ( void * ) desc ) + desc->len );
360 }
361 
362 /**
363  * Check that descriptor lies within a configuration descriptor
364  *
365  * @v config Configuration descriptor
366  * @v desc Descriptor header
367  * @v is_within Descriptor is within the configuration descriptor
368  */
369 static inline __attribute__ (( always_inline )) int
371  struct usb_descriptor_header *desc ) {
372  struct usb_descriptor_header *end =
373  ( ( ( void * ) config ) + le16_to_cpu ( config->len ) );
374 
375  /* Check that descriptor starts within the configuration
376  * descriptor, and that the length does not exceed the
377  * configuration descriptor. This relies on the fact that
378  * usb_next_descriptor() needs to access only the first byte
379  * of the descriptor in order to determine the length.
380  */
381  return ( ( desc < end ) && ( usb_next_descriptor ( desc ) <= end ) );
382 }
383 
384 /** Iterate over all configuration descriptors */
385 #define for_each_config_descriptor( desc, config ) \
386  for ( desc = container_of ( &(config)->header, \
387  typeof ( *desc ), header ) ; \
388  usb_is_within_config ( (config), &desc->header ) ; \
389  desc = container_of ( usb_next_descriptor ( &desc->header ), \
390  typeof ( *desc ), header ) )
391 
392 /** Iterate over all configuration descriptors within an interface descriptor */
393 #define for_each_interface_descriptor( desc, config, interface ) \
394  for ( desc = container_of ( usb_next_descriptor ( &(interface)-> \
395  header ), \
396  typeof ( *desc ), header ) ; \
397  ( usb_is_within_config ( (config), &desc->header ) && \
398  ( desc->header.type != USB_INTERFACE_DESCRIPTOR ) ) ; \
399  desc = container_of ( usb_next_descriptor ( &desc->header ), \
400  typeof ( *desc ), header ) )
401 
402 /** A USB endpoint */
403 struct usb_endpoint {
404  /** USB device */
405  struct usb_device *usb;
406  /** Endpoint address */
407  unsigned int address;
408  /** Attributes */
409  unsigned int attributes;
410  /** Maximum transfer size */
411  size_t mtu;
412  /** Maximum burst size */
413  unsigned int burst;
414  /** Interval (in microframes) */
415  unsigned int interval;
416 
417  /** Endpoint is open */
418  int open;
419  /** Buffer fill level */
420  unsigned int fill;
421 
422  /** List of halted endpoints */
424 
425  /** Host controller operations */
427  /** Host controller private data */
428  void *priv;
429  /** Driver operations */
431 
432  /** Recycled I/O buffer list */
434  /** Refill buffer reserved header length */
435  size_t reserve;
436  /** Refill buffer payload length */
437  size_t len;
438  /** Maximum fill level */
439  unsigned int max;
440 };
441 
442 /** USB endpoint host controller operations */
444  /** Open endpoint
445  *
446  * @v ep USB endpoint
447  * @ret rc Return status code
448  */
449  int ( * open ) ( struct usb_endpoint *ep );
450  /** Close endpoint
451  *
452  * @v ep USB endpoint
453  */
454  void ( * close ) ( struct usb_endpoint *ep );
455  /**
456  * Reset endpoint
457  *
458  * @v ep USB endpoint
459  * @ret rc Return status code
460  */
461  int ( * reset ) ( struct usb_endpoint *ep );
462  /** Update MTU
463  *
464  * @v ep USB endpoint
465  * @ret rc Return status code
466  */
467  int ( * mtu ) ( struct usb_endpoint *ep );
468  /** Enqueue message transfer
469  *
470  * @v ep USB endpoint
471  * @v iobuf I/O buffer
472  * @ret rc Return status code
473  */
474  int ( * message ) ( struct usb_endpoint *ep,
475  struct io_buffer *iobuf );
476  /** Enqueue stream transfer
477  *
478  * @v ep USB endpoint
479  * @v iobuf I/O buffer
480  * @v zlp Append a zero-length packet
481  * @ret rc Return status code
482  */
483  int ( * stream ) ( struct usb_endpoint *ep, struct io_buffer *iobuf,
484  int zlp );
485 };
486 
487 /** USB endpoint driver operations */
489  /** Complete transfer
490  *
491  * @v ep USB endpoint
492  * @v iobuf I/O buffer
493  * @v rc Completion status code
494  */
495  void ( * complete ) ( struct usb_endpoint *ep,
496  struct io_buffer *iobuf, int rc );
497 };
498 
499 /** Control endpoint address */
500 #define USB_EP0_ADDRESS 0x00
501 
502 /** Control endpoint attributes */
503 #define USB_EP0_ATTRIBUTES 0x00
504 
505 /** Calculate default MTU based on device speed
506  *
507  * @v speed Device speed
508  * @ret mtu Default MTU
509  */
510 #define USB_EP0_DEFAULT_MTU(speed) \
511  ( ( (speed) >= USB_SPEED_SUPER ) ? 512 : \
512  ( ( (speed) >= USB_SPEED_FULL ) ? 64 : 8 ) )
513 
514 /** Control endpoint maximum burst size */
515 #define USB_EP0_BURST 0
516 
517 /** Control endpoint interval */
518 #define USB_EP0_INTERVAL 0
519 
520 /** Maximum endpoint number */
521 #define USB_ENDPOINT_MAX 0x0f
522 
523 /** Endpoint direction is in */
524 #define USB_ENDPOINT_IN 0x80
525 
526 /** Construct endpoint index from endpoint address */
527 #define USB_ENDPOINT_IDX(address) \
528  ( ( (address) & USB_ENDPOINT_MAX ) | \
529  ( ( (address) & USB_ENDPOINT_IN ) >> 3 ) )
530 
531 /**
532  * Initialise USB endpoint
533  *
534  * @v ep USB endpoint
535  * @v usb USB device
536  * @v driver Driver operations
537  */
538 static inline __attribute__ (( always_inline )) void
539 usb_endpoint_init ( struct usb_endpoint *ep, struct usb_device *usb,
540  struct usb_endpoint_driver_operations *driver ) {
541 
542  ep->usb = usb;
543  ep->driver = driver;
544 }
545 
546 /**
547  * Describe USB endpoint
548  *
549  * @v ep USB endpoint
550  * @v address Endpoint address
551  * @v attributes Attributes
552  * @v mtu Maximum packet size
553  * @v burst Maximum burst size
554  * @v interval Interval (in microframes)
555  */
556 static inline __attribute__ (( always_inline )) void
557 usb_endpoint_describe ( struct usb_endpoint *ep, unsigned int address,
558  unsigned int attributes, size_t mtu,
559  unsigned int burst, unsigned int interval ) {
560 
561  ep->address = address;
562  ep->attributes = attributes;
563  ep->mtu = mtu;
564  ep->burst = burst;
565  ep->interval = interval;
566 }
567 
568 /**
569  * Set USB endpoint host controller private data
570  *
571  * @v ep USB endpoint
572  * @v priv Host controller private data
573  */
574 static inline __attribute__ (( always_inline )) void
576  ep->priv = priv;
577 }
578 
579 /**
580  * Get USB endpoint host controller private data
581  *
582  * @v ep USB endpoint
583  * @ret priv Host controller private data
584  */
585 static inline __attribute__ (( always_inline )) void *
587  return ep->priv;
588 }
589 
590 extern const char * usb_endpoint_name ( struct usb_endpoint *ep );
591 extern int
593  struct usb_configuration_descriptor *config,
595  unsigned int type, unsigned int index );
596 extern int usb_endpoint_open ( struct usb_endpoint *ep );
597 extern int usb_endpoint_clear_halt ( struct usb_endpoint *ep );
598 extern void usb_endpoint_close ( struct usb_endpoint *ep );
599 extern int usb_message ( struct usb_endpoint *ep, unsigned int request,
600  unsigned int value, unsigned int index,
601  struct io_buffer *iobuf );
602 extern int usb_stream ( struct usb_endpoint *ep, struct io_buffer *iobuf,
603  int terminate );
604 extern void usb_complete_err ( struct usb_endpoint *ep,
605  struct io_buffer *iobuf, int rc );
606 
607 /**
608  * Initialise USB endpoint refill
609  *
610  * @v ep USB endpoint
611  * @v reserve Refill buffer reserved header length
612  * @v len Refill buffer payload length (zero for endpoint's MTU)
613  * @v max Maximum fill level
614  */
615 static inline __attribute__ (( always_inline )) void
616 usb_refill_init ( struct usb_endpoint *ep, size_t reserve, size_t len,
617  unsigned int max ) {
618 
619  INIT_LIST_HEAD ( &ep->recycled );
620  ep->reserve = reserve;
621  ep->len = len;
622  ep->max = max;
623 }
624 
625 /**
626  * Recycle I/O buffer
627  *
628  * @v ep USB endpoint
629  * @v iobuf I/O buffer
630  */
631 static inline __attribute__ (( always_inline )) void
632 usb_recycle ( struct usb_endpoint *ep, struct io_buffer *iobuf ) {
633 
634  list_add_tail ( &iobuf->list, &ep->recycled );
635 }
636 
637 extern int usb_prefill ( struct usb_endpoint *ep );
638 extern int usb_refill_limit ( struct usb_endpoint *ep, unsigned int max );
639 extern int usb_refill ( struct usb_endpoint *ep );
640 extern void usb_flush ( struct usb_endpoint *ep );
641 
642 /** A USB class descriptor */
644  /** Class */
645  struct usb_class class;
646  /** Scalar value */
648 };
649 
650 /**
651  * A USB function descriptor
652  *
653  * This is an internal descriptor used to represent an association of
654  * interfaces within a USB device.
655  */
657  /** Vendor ID */
659  /** Product ID */
661  /** Class */
663  /** Number of interfaces */
664  unsigned int count;
665 };
666 
667 /**
668  * A USB function
669  *
670  * A USB function represents an association of interfaces within a USB
671  * device.
672  */
673 struct usb_function {
674  /** Name */
675  const char *name;
676  /** USB device */
677  struct usb_device *usb;
678  /** Function descriptor */
680  /** Generic device */
681  struct device dev;
682  /** List of functions within this USB device */
683  struct list_head list;
684 
685  /** Driver */
687  /** Driver private data */
688  void *priv;
689  /** Driver device ID */
690  struct usb_device_id *id;
691 
692  /** List of interface numbers
693  *
694  * This must be the last field within the structure.
695  */
697 };
698 
699 /**
700  * Set USB function driver private data
701  *
702  * @v func USB function
703  * @v priv Driver private data
704  */
705 static inline __attribute__ (( always_inline )) void
706 usb_func_set_drvdata ( struct usb_function *func, void *priv ) {
707  func->priv = priv;
708 }
709 
710 /**
711  * Get USB function driver private data
712  *
713  * @v function USB function
714  * @ret priv Driver private data
715  */
716 static inline __attribute__ (( always_inline )) void *
718  return func->priv;
719 }
720 
721 /** A USB device */
722 struct usb_device {
723  /** Name */
724  char name[32];
725  /** USB port */
726  struct usb_port *port;
727  /** Device speed */
728  unsigned int speed;
729  /** List of devices on this bus */
730  struct list_head list;
731  /** Device address, if assigned */
732  unsigned int address;
733  /** Device descriptor */
735  /** List of functions */
737 
738  /** Host controller operations */
740  /** Host controller private data */
741  void *priv;
742 
743  /** Endpoint list */
744  struct usb_endpoint *ep[32];
745 
746  /** Control endpoint */
748  /** Completed control transfers */
750 
751  /** Default language ID (if known) */
752  unsigned int language;
753 };
754 
755 /** USB device host controller operations */
757  /** Open device
758  *
759  * @v usb USB device
760  * @ret rc Return status code
761  */
762  int ( * open ) ( struct usb_device *usb );
763  /** Close device
764  *
765  * @v usb USB device
766  */
767  void ( * close ) ( struct usb_device *usb );
768  /** Assign device address
769  *
770  * @v usb USB device
771  * @ret rc Return status code
772  */
773  int ( * address ) ( struct usb_device *usb );
774 };
775 
776 /**
777  * Set USB device host controller private data
778  *
779  * @v usb USB device
780  * @v priv Host controller private data
781  */
782 static inline __attribute__ (( always_inline )) void
783 usb_set_hostdata ( struct usb_device *usb, void *priv ) {
784  usb->priv = priv;
785 }
786 
787 /**
788  * Get USB device host controller private data
789  *
790  * @v usb USB device
791  * @ret priv Host controller private data
792  */
793 static inline __attribute__ (( always_inline )) void *
794 usb_get_hostdata ( struct usb_device *usb ) {
795  return usb->priv;
796 }
797 
798 /**
799  * Get USB endpoint
800  *
801  * @v usb USB device
802  * @v address Endpoint address
803  * @ret ep USB endpoint, or NULL if not opened
804  */
805 static inline struct usb_endpoint * usb_endpoint ( struct usb_device *usb,
806  unsigned int address ) {
807 
808  return usb->ep[ USB_ENDPOINT_IDX ( address ) ];
809 }
810 
811 /** A USB port */
812 struct usb_port {
813  /** USB hub */
814  struct usb_hub *hub;
815  /** Port address */
816  unsigned int address;
817  /** Port protocol */
818  unsigned int protocol;
819  /** Port speed */
820  unsigned int speed;
821  /** Port disconnection has been detected
822  *
823  * This should be set whenever the underlying hardware reports
824  * a connection status change.
825  */
827  /** Port has an attached device */
828  int attached;
829  /** Currently attached device (if in use)
830  *
831  * Note that this field will be NULL if the attached device
832  * has been freed (e.g. because there were no drivers found).
833  */
834  struct usb_device *usb;
835  /** List of changed ports */
837 };
838 
839 /** A USB hub */
840 struct usb_hub {
841  /** Name */
842  const char *name;
843  /** USB bus */
844  struct usb_bus *bus;
845  /** Underlying USB device, if any */
846  struct usb_device *usb;
847  /** Hub protocol */
848  unsigned int protocol;
849  /** Number of ports */
850  unsigned int ports;
851 
852  /** List of hubs */
853  struct list_head list;
854 
855  /** Host controller operations */
857  /** Driver operations */
859  /** Driver private data */
860  void *priv;
861 
862  /** Port list
863  *
864  * This must be the last field within the structure.
865  */
866  struct usb_port port[0];
867 };
868 
869 /** USB hub host controller operations */
871  /** Open hub
872  *
873  * @v hub USB hub
874  * @ret rc Return status code
875  */
876  int ( * open ) ( struct usb_hub *hub );
877  /** Close hub
878  *
879  * @v hub USB hub
880  */
881  void ( * close ) ( struct usb_hub *hub );
882 };
883 
884 /** USB hub driver operations */
886  /** Open hub
887  *
888  * @v hub USB hub
889  * @ret rc Return status code
890  */
891  int ( * open ) ( struct usb_hub *hub );
892  /** Close hub
893  *
894  * @v hub USB hub
895  */
896  void ( * close ) ( struct usb_hub *hub );
897  /** Enable port
898  *
899  * @v hub USB hub
900  * @v port USB port
901  * @ret rc Return status code
902  */
903  int ( * enable ) ( struct usb_hub *hub, struct usb_port *port );
904  /** Disable port
905  *
906  * @v hub USB hub
907  * @v port USB port
908  * @ret rc Return status code
909  */
910  int ( * disable ) ( struct usb_hub *hub, struct usb_port *port );
911  /** Update port speed
912  *
913  * @v hub USB hub
914  * @v port USB port
915  * @ret rc Return status code
916  */
917  int ( * speed ) ( struct usb_hub *hub, struct usb_port *port );
918  /** Clear transaction translator buffer
919  *
920  * @v hub USB hub
921  * @v port USB port
922  * @v ep USB endpoint
923  * @ret rc Return status code
924  */
925  int ( * clear_tt ) ( struct usb_hub *hub, struct usb_port *port,
926  struct usb_endpoint *ep );
927 };
928 
929 /**
930  * Set USB hub driver private data
931  *
932  * @v hub USB hub
933  * @v priv Driver private data
934  */
935 static inline __attribute__ (( always_inline )) void
936 usb_hub_set_drvdata ( struct usb_hub *hub, void *priv ) {
937  hub->priv = priv;
938 }
939 
940 /**
941  * Get USB hub driver private data
942  *
943  * @v hub USB hub
944  * @ret priv Driver private data
945  */
946 static inline __attribute__ (( always_inline )) void *
947 usb_hub_get_drvdata ( struct usb_hub *hub ) {
948  return hub->priv;
949 }
950 
951 /**
952  * Get USB port
953  *
954  * @v hub USB hub
955  * @v address Port address
956  * @ret port USB port
957  */
958 static inline __attribute__ (( always_inline )) struct usb_port *
959 usb_port ( struct usb_hub *hub, unsigned int address ) {
960 
961  return &hub->port[ address - 1 ];
962 }
963 
964 /** A USB bus */
965 struct usb_bus {
966  /** Name */
967  const char *name;
968  /** Underlying hardware device */
969  struct device *dev;
970  /** Host controller operations set */
972 
973  /** Bus address
974  *
975  * This is an internal index used only to allow a USB device
976  * to be identified via a nominal bus:device address.
977  */
978  unsigned int address;
979  /** Largest transfer allowed on the bus */
980  size_t mtu;
981  /** Address in-use mask
982  *
983  * This is used only by buses which perform manual address
984  * assignment. USB allows for addresses in the range [1,127].
985  * We use a simple bitmask which restricts us to the range
986  * [1,64]; this is unlikely to be a problem in practice. For
987  * comparison: controllers which perform autonomous address
988  * assignment (such as xHCI) typically allow for only 32
989  * devices per bus anyway.
990  */
991  unsigned long long addresses;
992 
993  /** Root hub */
994  struct usb_hub *hub;
995 
996  /** List of USB buses */
997  struct list_head list;
998  /** List of devices */
1000  /** List of hubs */
1001  struct list_head hubs;
1002 
1003  /** Host controller operations */
1005  /** Host controller private data */
1006  void *priv;
1007 };
1008 
1009 /** USB bus host controller operations */
1011  /** Open bus
1012  *
1013  * @v bus USB bus
1014  * @ret rc Return status code
1015  */
1016  int ( * open ) ( struct usb_bus *bus );
1017  /** Close bus
1018  *
1019  * @v bus USB bus
1020  */
1021  void ( * close ) ( struct usb_bus *bus );
1022  /** Poll bus
1023  *
1024  * @v bus USB bus
1025  */
1026  void ( * poll ) ( struct usb_bus *bus );
1027 };
1028 
1029 /** USB host controller operations */
1031  /** Endpoint operations */
1033  /** Device operations */
1035  /** Bus operations */
1037  /** Hub operations */
1039  /** Root hub operations */
1041 };
1042 
1043 /**
1044  * Set USB bus host controller private data
1045  *
1046  * @v bus USB bus
1047  * @v priv Host controller private data
1048  */
1049 static inline __attribute__ (( always_inline )) void
1050 usb_bus_set_hostdata ( struct usb_bus *bus, void *priv ) {
1051  bus->priv = priv;
1052 }
1053 
1054 /**
1055  * Get USB bus host controller private data
1056  *
1057  * @v bus USB bus
1058  * @ret priv Host controller private data
1059  */
1060 static inline __attribute__ (( always_inline )) void *
1062  return bus->priv;
1063 }
1064 
1065 /**
1066  * Poll USB bus
1067  *
1068  * @v bus USB bus
1069  */
1070 static inline __attribute__ (( always_inline )) void
1071 usb_poll ( struct usb_bus *bus ) {
1072  bus->host->poll ( bus );
1073 }
1074 
1075 /** Iterate over all USB buses */
1076 #define for_each_usb_bus( bus ) \
1077  list_for_each_entry ( (bus), &usb_buses, list )
1078 
1079 /**
1080  * Complete transfer (without error)
1081  *
1082  * @v ep USB endpoint
1083  * @v iobuf I/O buffer
1084  */
1085 static inline __attribute__ (( always_inline )) void
1086 usb_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf ) {
1087  usb_complete_err ( ep, iobuf, 0 );
1088 }
1089 
1090 extern int usb_control ( struct usb_device *usb, unsigned int request,
1091  unsigned int value, unsigned int index, void *data,
1092  size_t len );
1093 extern int usb_get_string_descriptor ( struct usb_device *usb,
1094  unsigned int index,
1095  unsigned int language,
1096  char *buf, size_t len );
1097 
1098 /**
1099  * Get status
1100  *
1101  * @v usb USB device
1102  * @v type Request type
1103  * @v index Target index
1104  * @v data Status to fill in
1105  * @v len Length of status descriptor
1106  * @ret rc Return status code
1107  */
1108 static inline __attribute__ (( always_inline )) int
1109 usb_get_status ( struct usb_device *usb, unsigned int type, unsigned int index,
1110  void *data, size_t len ) {
1111 
1112  return usb_control ( usb, ( USB_GET_STATUS | type ), 0, index,
1113  data, len );
1114 }
1115 
1116 /**
1117  * Clear feature
1118  *
1119  * @v usb USB device
1120  * @v type Request type
1121  * @v feature Feature selector
1122  * @v index Target index
1123  * @ret rc Return status code
1124  */
1125 static inline __attribute__ (( always_inline )) int
1126 usb_clear_feature ( struct usb_device *usb, unsigned int type,
1127  unsigned int feature, unsigned int index ) {
1128 
1129  return usb_control ( usb, ( USB_CLEAR_FEATURE | type ),
1130  feature, index, NULL, 0 );
1131 }
1132 
1133 /**
1134  * Set feature
1135  *
1136  * @v usb USB device
1137  * @v type Request type
1138  * @v feature Feature selector
1139  * @v index Target index
1140  * @ret rc Return status code
1141  */
1142 static inline __attribute__ (( always_inline )) int
1143 usb_set_feature ( struct usb_device *usb, unsigned int type,
1144  unsigned int feature, unsigned int index ) {
1145 
1146  return usb_control ( usb, ( USB_SET_FEATURE | type ),
1147  feature, index, NULL, 0 );
1148 }
1149 
1150 /**
1151  * Set address
1152  *
1153  * @v usb USB device
1154  * @v address Device address
1155  * @ret rc Return status code
1156  */
1157 static inline __attribute__ (( always_inline )) int
1158 usb_set_address ( struct usb_device *usb, unsigned int address ) {
1159 
1160  return usb_control ( usb, USB_SET_ADDRESS, address, 0, NULL, 0 );
1161 }
1162 
1163 /**
1164  * Get USB descriptor
1165  *
1166  * @v usb USB device
1167  * @v type Request type
1168  * @v desc Descriptor type
1169  * @v index Descriptor index
1170  * @v language Language ID (for string descriptors)
1171  * @v data Descriptor to fill in
1172  * @v len Maximum length of descriptor
1173  * @ret rc Return status code
1174  */
1175 static inline __attribute__ (( always_inline )) int
1176 usb_get_descriptor ( struct usb_device *usb, unsigned int type,
1177  unsigned int desc, unsigned int index,
1178  unsigned int language, struct usb_descriptor_header *data,
1179  size_t len ) {
1180 
1181  return usb_control ( usb, ( USB_GET_DESCRIPTOR | type ),
1182  ( ( desc << 8 ) | index ), language, data, len );
1183 }
1184 
1185 /**
1186  * Get first part of USB device descriptor (up to and including MTU)
1187  *
1188  * @v usb USB device
1189  * @v data Device descriptor to (partially) fill in
1190  * @ret rc Return status code
1191  */
1192 static inline __attribute__ (( always_inline )) int
1194 
1195  return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
1196  &data->header,
1197  ( offsetof ( typeof ( *data ), mtu ) +
1198  sizeof ( data->mtu ) ) );
1199 }
1200 
1201 /**
1202  * Get USB device descriptor
1203  *
1204  * @v usb USB device
1205  * @v data Device descriptor to fill in
1206  * @ret rc Return status code
1207  */
1208 static inline __attribute__ (( always_inline )) int
1210  struct usb_device_descriptor *data ) {
1211 
1212  return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
1213  &data->header, sizeof ( *data ) );
1214 }
1215 
1216 /**
1217  * Get USB configuration descriptor
1218  *
1219  * @v usb USB device
1220  * @v index Configuration index
1221  * @v data Configuration descriptor to fill in
1222  * @ret rc Return status code
1223  */
1224 static inline __attribute__ (( always_inline )) int
1225 usb_get_config_descriptor ( struct usb_device *usb, unsigned int index,
1227  size_t len ) {
1228 
1230  0, &data->header, len );
1231 }
1232 
1233 /**
1234  * Set USB configuration
1235  *
1236  * @v usb USB device
1237  * @v index Configuration index
1238  * @ret rc Return status code
1239  */
1240 static inline __attribute__ (( always_inline )) int
1241 usb_set_configuration ( struct usb_device *usb, unsigned int index ) {
1242 
1243  return usb_control ( usb, USB_SET_CONFIGURATION, index, 0, NULL, 0 );
1244 }
1245 
1246 /**
1247  * Set USB interface alternate setting
1248  *
1249  * @v usb USB device
1250  * @v interface Interface number
1251  * @v alternate Alternate setting
1252  * @ret rc Return status code
1253  */
1254 static inline __attribute__ (( always_inline )) int
1255 usb_set_interface ( struct usb_device *usb, unsigned int interface,
1256  unsigned int alternate ) {
1257 
1259  NULL, 0 );
1260 }
1261 
1262 /**
1263  * Get USB depth
1264  *
1265  * @v usb USB device
1266  * @ret depth Hub depth
1267  */
1268 static inline unsigned int usb_depth ( struct usb_device *usb ) {
1269  struct usb_device *parent;
1270  unsigned int depth;
1271 
1272  /* Navigate up to root hub, constructing depth as we go */
1273  for ( depth = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent )
1274  depth++;
1275 
1276  return depth;
1277 }
1278 
1279 extern struct list_head usb_buses;
1280 
1281 extern struct usb_interface_descriptor *
1283  unsigned int interface, unsigned int alternate );
1284 extern struct usb_endpoint_descriptor *
1287  unsigned int type, unsigned int index );
1288 extern struct usb_endpoint_companion_descriptor *
1290  struct usb_endpoint_descriptor *desc );
1291 
1292 extern struct usb_device * find_usb ( struct usb_bus *bus,
1293  unsigned int address );
1294 
1295 extern struct usb_hub * alloc_usb_hub ( struct usb_bus *bus,
1296  struct usb_device *usb,
1297  unsigned int ports,
1298  struct usb_hub_driver_operations *op );
1299 extern int register_usb_hub ( struct usb_hub *hub );
1300 extern void unregister_usb_hub ( struct usb_hub *hub );
1301 extern void free_usb_hub ( struct usb_hub *hub );
1302 
1303 extern void usb_port_changed ( struct usb_port *port );
1304 
1305 extern struct usb_bus * alloc_usb_bus ( struct device *dev,
1306  unsigned int ports, size_t mtu,
1307  struct usb_host_operations *op );
1308 extern int register_usb_bus ( struct usb_bus *bus );
1309 extern void unregister_usb_bus ( struct usb_bus *bus );
1310 extern void free_usb_bus ( struct usb_bus *bus );
1311 extern struct usb_bus * find_usb_bus ( unsigned int address );
1312 extern struct usb_bus * find_usb_bus_by_location ( unsigned int bus_type,
1313  unsigned int location );
1314 
1315 extern int usb_alloc_address ( struct usb_bus *bus );
1316 extern void usb_free_address ( struct usb_bus *bus, unsigned int address );
1317 extern int usb_find_next ( struct usb_device **usb, uint16_t *busdev );
1318 extern unsigned int usb_route_string ( struct usb_device *usb );
1319 extern struct usb_port * usb_root_hub_port ( struct usb_device *usb );
1320 extern struct usb_port * usb_transaction_translator ( struct usb_device *usb );
1321 
1322 /** Minimum reset time
1323  *
1324  * Section 7.1.7.5 of the USB2 specification states that root hub
1325  * ports should assert reset signalling for at least 50ms.
1326  */
1327 #define USB_RESET_DELAY_MS 50
1328 
1329 /** Reset recovery time
1330  *
1331  * Section 9.2.6.2 of the USB2 specification states that the
1332  * "recovery" interval after a port reset is 10ms.
1333  */
1334 #define USB_RESET_RECOVER_DELAY_MS 10
1335 
1336 /** Maximum time to wait for a control transaction to complete
1337  *
1338  * Section 9.2.6.1 of the USB2 specification states that the upper
1339  * limit for commands to be processed is 5 seconds.
1340  */
1341 #define USB_CONTROL_MAX_WAIT_MS 5000
1342 
1343 /** Set address recovery time
1344  *
1345  * Section 9.2.6.3 of the USB2 specification states that devices are
1346  * allowed a 2ms recovery interval after receiving a new address.
1347  */
1348 #define USB_SET_ADDRESS_RECOVER_DELAY_MS 2
1349 
1350 /** Time to wait for ports to stabilise
1351  *
1352  * Section 7.1.7.3 of the USB specification states that we must allow
1353  * 100ms for devices to signal attachment, and an additional 100ms for
1354  * connection debouncing. (This delay is parallelised across all
1355  * ports on a hub; we do not delay separately for each port.)
1356  */
1357 #define USB_PORT_DELAY_MS 200
1358 
1359 /** A USB device ID */
1361  /** Name */
1362  const char *name;
1363  /** Vendor ID */
1365  /** Product ID */
1367  /** Arbitrary driver data */
1368  unsigned long driver_data;
1369 };
1370 
1371 /** Match-anything ID */
1372 #define USB_ANY_ID 0xffff
1373 
1374 /** A USB class ID */
1376  /** Class */
1378  /** Class mask */
1380 };
1381 
1382 /** Construct USB class ID
1383  *
1384  * @v base Base class code (or USB_ANY_ID)
1385  * @v subclass Subclass code (or USB_ANY_ID)
1386  * @v protocol Protocol code (or USB_ANY_ID)
1387  */
1388 #define USB_CLASS_ID( base, subclass, protocol ) { \
1389  .class = { \
1390  .class = { \
1391  ( (base) & 0xff ), \
1392  ( (subclass) & 0xff ), \
1393  ( (protocol) & 0xff ), \
1394  }, \
1395  }, \
1396  .mask = { \
1397  .class = { \
1398  ( ( (base) == USB_ANY_ID ) ? 0x00 : 0xff ), \
1399  ( ( (subclass) == USB_ANY_ID ) ? 0x00 : 0xff ), \
1400  ( ( (protocol) == USB_ANY_ID ) ? 0x00 : 0xff ), \
1401  }, \
1402  }, \
1403  }
1404 
1405 /** A USB driver */
1406 struct usb_driver {
1407  /** USB ID table */
1409  /** Number of entries in ID table */
1410  unsigned int id_count;
1411  /** Class ID */
1413  /** Driver score
1414  *
1415  * This is used to determine the preferred configuration for a
1416  * USB device.
1417  */
1418  unsigned int score;
1419  /**
1420  * Probe device
1421  *
1422  * @v func USB function
1423  * @v config Configuration descriptor
1424  * @ret rc Return status code
1425  */
1426  int ( * probe ) ( struct usb_function *func,
1428  /**
1429  * Remove device
1430  *
1431  * @v func USB function
1432  */
1433  void ( * remove ) ( struct usb_function *func );
1434 };
1435 
1436 /** USB driver table */
1437 #define USB_DRIVERS __table ( struct usb_driver, "usb_drivers" )
1438 
1439 /** Declare a USB driver */
1440 #define __usb_driver __table_entry ( USB_DRIVERS, 01 )
1441 
1442 /** Declare a USB fallback driver */
1443 #define __usb_fallback_driver __table_entry ( USB_DRIVERS, 02 )
1444 
1445 /** USB driver scores */
1447  /** Fallback driver (has no effect on overall score) */
1449  /** Deprecated driver */
1451  /** Normal driver */
1453 };
1454 
1455 extern struct usb_driver *
1457  struct usb_device_id **id );
1458 
1459 #endif /* _IPXE_USB_H */
int(* open)(struct usb_bus *bus)
Open bus.
Definition: usb.h:1016
void unregister_usb_hub(struct usb_hub *hub)
Unregister USB hub.
Definition: usb.c:2029
A USB driver.
Definition: usb.h:1406
#define __attribute__(x)
Definition: compiler.h:10
void(* poll)(struct usb_bus *bus)
Poll bus.
Definition: usb.h:1026
size_t mtu
Largest transfer allowed on the bus.
Definition: usb.h:980
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition: usb.h:575
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * priv
Host controller private data.
Definition: usb.h:1006
unsigned short uint16_t
Definition: stdint.h:11
void(* close)(struct usb_endpoint *ep)
Close endpoint.
Definition: usb.h:454
A USB device ID.
Definition: usb.h:1360
struct usb_bus * find_usb_bus(unsigned int address)
Find USB bus by address.
Definition: usb.c:2219
void(* complete)(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer.
Definition: usb.h:495
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:717
static int usb_set_configuration(struct usb_device *usb, unsigned int index)
Set USB configuration.
Definition: usb.h:1241
static void usb_endpoint_describe(struct usb_endpoint *ep, unsigned int address, unsigned int attributes, size_t mtu, unsigned int burst, unsigned int interval)
Describe USB endpoint.
Definition: usb.h:557
const char * name
Name.
Definition: usb.h:967
uint8_t len
Length of descriptor.
Definition: usb.h:174
#define max(x, y)
Definition: ath.h:39
uint8_t interval
Polling interval.
Definition: usb.h:273
int disconnected
Port disconnection has been detected.
Definition: usb.h:826
const char * name
Name.
Definition: usb.h:675
A USB hub.
Definition: usb.h:840
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition: usb.c:293
const char * name
Name.
Definition: usb.h:1362
int(* mtu)(struct usb_endpoint *ep)
Update MTU.
Definition: usb.h:467
usb_protocol
USB protocols.
Definition: usb.h:20
unsigned int count
Number of interfaces.
Definition: usb.h:664
uint16_t vendor
Vendor ID.
Definition: usb.h:190
A USB interface association descriptor.
Definition: usb.h:328
A USB class code tuple.
Definition: usb.h:159
struct usb_hub_host_operations * host
Host controller operations.
Definition: usb.h:856
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2170
Low speed (1.5Mbps)
Definition: usb.h:48
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:433
#define USB_GET_DESCRIPTOR
Get descriptor.
Definition: usb.h:136
Deprecated driver.
Definition: usb.h:1450
USB 2.0.
Definition: usb.h:22
struct usb_endpoint_companion_descriptor * usb_endpoint_companion_descriptor(struct usb_configuration_descriptor *config, struct usb_endpoint_descriptor *desc)
Locate USB endpoint companion descriptor.
Definition: usb.c:194
uint8_t extended
Extended attributes.
Definition: usb.h:319
OUT PID.
Definition: usb.h:76
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition: usb.c:719
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:315
I/O buffers.
uint64_t address
Base address.
Definition: ena.h:24
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:783
uint32_t type
Operating system type.
Definition: ena.h:12
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:246
union usb_class_descriptor mask
Class mask.
Definition: usb.h:1379
static struct usb_descriptor_header * usb_next_descriptor(struct usb_descriptor_header *desc)
Get next USB descriptor.
Definition: usb.h:357
struct usb_hub_host_operations hub
Hub operations.
Definition: usb.h:1038
size_t len
Refill buffer payload length.
Definition: usb.h:437
struct usb_device * find_usb(struct usb_bus *bus, unsigned int address)
Find USB device by address.
Definition: usb.c:1734
uint16_t periodic
Number of bytes per service interval.
Definition: usb.h:321
struct usb_bus_host_operations bus
Bus operations.
Definition: usb.h:1036
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
struct usb_class class
Interface class.
Definition: usb.h:254
static int usb_get_config_descriptor(struct usb_device *usb, unsigned int index, struct usb_configuration_descriptor *data, size_t len)
Get USB configuration descriptor.
Definition: usb.h:1225
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2283
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:783
uint16_t vendor
Vendor ID.
Definition: usb.h:658
struct usb_driver * driver
Driver.
Definition: usb.h:686
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2194
long index
Definition: bigint.h:62
int attached
Port has an attached device.
Definition: usb.h:828
int usb_message(struct usb_endpoint *ep, unsigned int request, unsigned int value, unsigned int index, struct io_buffer *iobuf)
Enqueue USB message transfer.
Definition: usb.c:491
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:834
uint8_t name
Association name.
Definition: usb.h:338
uint8_t interfaces
Number of interfaces.
Definition: usb.h:215
unsigned int protocol
Port protocol.
Definition: usb.h:818
struct usb_bus * find_usb_bus_by_location(unsigned int bus_type, unsigned int location)
Find USB bus by device location.
Definition: usb.c:2237
int(* reset)(struct usb_endpoint *ep)
Reset endpoint.
Definition: usb.h:461
uint8_t endpoint
Endpoint address.
Definition: usb.h:267
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:232
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1857
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
struct list_head changed
List of changed ports.
Definition: usb.h:836
A USB class ID.
Definition: usb.h:1375
int(* clear_tt)(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
Definition: usb.h:925
struct usb_driver * usb_find_driver(struct usb_function_descriptor *desc, struct usb_device_id **id)
Find USB device driver.
Definition: usb.c:1166
Super speed (5Gbps)
Definition: usb.h:54
int open
Endpoint is open.
Definition: usb.h:418
int usb_endpoint_described(struct usb_endpoint *ep, struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index)
Describe USB endpoint from device configuration.
Definition: usb.c:241
unsigned long long addresses
Address in-use mask.
Definition: usb.h:991
struct usb_interface_descriptor * usb_interface_descriptor(struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
Locate USB interface descriptor.
Definition: usb.c:143
union usb_class_descriptor class
Class.
Definition: usb.h:662
uint8_t attributes
Attributes.
Definition: usb.h:221
USB hub driver operations.
Definition: usb.h:885
struct list_head hubs
List of hubs.
Definition: usb.h:1001
unsigned int address
Device address, if assigned.
Definition: usb.h:732
#define USB_GET_STATUS
Get status.
Definition: usb.h:124
unsigned int speed
Device speed.
Definition: usb.h:728
int(* probe)(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: usb.h:1426
A doubly-linked list entry (or list head)
Definition: list.h:18
int(* open)(struct usb_hub *hub)
Open hub.
Definition: usb.h:876
static int usb_set_interface(struct usb_device *usb, unsigned int interface, unsigned int alternate)
Set USB interface alternate setting.
Definition: usb.h:1255
void * priv
Host controller private data.
Definition: usb.h:428
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1050
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
Definition: usb.h:1158
union usb_class_descriptor class
Class.
Definition: usb.h:1377
struct usb_device_id * id
Driver device ID.
Definition: usb.h:690
A USB string descriptor.
Definition: usb.h:230
uint16_t product
Product ID.
Definition: usb.h:660
int register_usb_hub(struct usb_hub *hub)
Register USB hub.
Definition: usb.c:1975
A USB port.
Definition: usb.h:812
uint16_t product
Product ID.
Definition: usb.h:192
A hardware device.
Definition: device.h:73
A USB endpoint.
Definition: usb.h:403
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:846
uint8_t manufacturer
Manufacturer string.
Definition: usb.h:196
void * priv
Driver private data.
Definition: usb.h:688
u8 port
Port number.
Definition: CIB_PRM.h:31
A USB interface descriptor.
Definition: usb.h:244
struct list_head usb_buses
List of USB buses.
Definition: usb.c:44
A USB function descriptor.
Definition: usb.h:656
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:182
struct usb_port * port
USB port.
Definition: usb.h:726
struct usb_hub_driver_operations root
Root hub operations.
Definition: usb.h:1040
static void usb_recycle(struct usb_endpoint *ep, struct io_buffer *iobuf)
Recycle I/O buffer.
Definition: usb.h:632
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:858
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:881
USB 3.0.
Definition: usb.h:24
struct device * dev
Underlying hardware device.
Definition: usb.h:969
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:330
An object interface.
Definition: interface.h:124
static int usb_clear_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Clear feature.
Definition: usb.h:1126
struct usb_class_id class
Class ID.
Definition: usb.h:1412
Not connected.
Definition: usb.h:46
uint16_t index
Index parameter.
Definition: usb.h:88
struct ib_cm_path alternate
Alternate path.
Definition: ib_mad.h:42
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
usb_driver_score
USB driver scores.
Definition: usb.h:1446
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
uint8_t configurations
Number of possible configurations.
Definition: usb.h:202
uint8_t serial
Serial number string.
Definition: usb.h:200
struct list_head halted
List of halted endpoints.
Definition: usb.h:423
struct usb_class class
Device class.
Definition: usb.h:186
uint8_t power
Maximum power consumption.
Definition: usb.h:223
unsigned int burst
Maximum burst size.
Definition: usb.h:413
unsigned int usb_route_string(struct usb_device *usb)
Get USB route string.
Definition: usb.c:2335
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition: usb.h:616
unsigned int address
Bus address.
Definition: usb.h:978
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:545
struct list_head list
List of USB buses.
Definition: usb.h:997
int(* enable)(struct usb_hub *hub, struct usb_port *port)
Enable port.
Definition: usb.h:903
int usb_alloc_address(struct usb_bus *bus)
Allocate device address.
Definition: usb.c:2263
USB bus host controller operations.
Definition: usb.h:1010
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:706
char name[32]
Name.
Definition: usb.h:724
unsigned int ports
Number of ports.
Definition: usb.h:850
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:35
const char * name
Name.
Definition: usb.h:842
size_t reserve
Refill buffer reserved header length.
Definition: usb.h:435
#define USB_CONFIGURATION_DESCRIPTOR
A USB configuration descriptor.
Definition: usb.h:227
void(* close)(struct usb_device *usb)
Close device.
Definition: usb.h:767
A USB device.
Definition: usb.h:722
static unsigned int usb_depth(struct usb_device *usb)
Get USB depth.
Definition: usb.h:1268
uint8_t type
Descriptor type.
Definition: usb.h:176
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:710
struct usb_endpoint control
Control endpoint.
Definition: usb.h:747
void(* close)(struct usb_bus *bus)
Close bus.
Definition: usb.h:1021
Linked lists.
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1071
static int usb_set_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Set feature.
Definition: usb.h:1143
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
Definition: usb.h:805
#define USB_SET_INTERFACE
Set interface.
Definition: usb.h:152
SETUP PID.
Definition: usb.h:78
uint16_t product
Product ID.
Definition: usb.h:1366
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct list_head list
List of devices on this bus.
Definition: usb.h:730
void * priv
Driver private data.
Definition: usb.h:860
unsigned int score
Driver score.
Definition: usb.h:1418
int usb_get_string_descriptor(struct usb_device *usb, unsigned int index, unsigned int language, char *buf, size_t len)
Get USB string descriptor.
Definition: usb.c:915
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:399
uint8_t name
Configuration string.
Definition: usb.h:219
#define USB_CLEAR_FEATURE
Clear feature.
Definition: usb.h:127
USB device host controller operations.
Definition: usb.h:756
uint8_t endpoints
Number of endpoints.
Definition: usb.h:252
static int usb_get_mtu(struct usb_device *usb, struct usb_device_descriptor *data)
Get first part of USB device descriptor (up to and including MTU)
Definition: usb.h:1193
Normal driver.
Definition: usb.h:1452
Processes.
struct usb_hub * alloc_usb_hub(struct usb_bus *bus, struct usb_device *usb, unsigned int ports, struct usb_hub_driver_operations *op)
Allocate USB hub.
Definition: usb.c:1936
uint8_t attributes
Attributes.
Definition: usb.h:269
unsigned char uint8_t
Definition: stdint.h:10
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:896
void * priv
Host controller private data.
Definition: usb.h:741
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:794
uint8_t name
Interface name.
Definition: usb.h:256
unsigned int fill
Buffer fill level.
Definition: usb.h:420
struct usb_device * usb
USB device.
Definition: usb.h:677
static void usb_endpoint_init(struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
Initialise USB endpoint.
Definition: usb.h:539
#define le16_to_cpu(value)
Definition: byteswap.h:112
uint32_t scalar
Scalar value.
Definition: usb.h:647
unsigned int uint32_t
Definition: stdint.h:12
void free_usb_hub(struct usb_hub *hub)
Free USB hub.
Definition: usb.c:2062
A USB setup data packet.
Definition: usb.h:82
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:527
uint16_t release
Device release number in BCD.
Definition: usb.h:194
uint8_t protocol
Protocol code.
Definition: usb.h:165
USB 3.1.
Definition: usb.h:26
int usb_refill_limit(struct usb_endpoint *ep, unsigned int max)
Refill endpoint up to specified limit.
Definition: usb.c:660
unsigned long driver_data
Arbitrary driver data.
Definition: usb.h:1368
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:211
USB endpoint host controller operations.
Definition: usb.h:443
size_t mtu
Maximum transfer size.
Definition: usb.h:411
uint8_t count
Interface count.
Definition: usb.h:334
uint16_t request
Request.
Definition: usb.h:84
A USB descriptor header.
Definition: usb.h:172
int(* disable)(struct usb_hub *hub, struct usb_port *port)
Disable port.
Definition: usb.h:910
A named feature.
Definition: features.h:78
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
Definition: usb.c:2355
struct usb_host_operations * op
Host controller operations set.
Definition: usb.h:971
static int usb_get_device_descriptor(struct usb_device *usb, struct usb_device_descriptor *data)
Get USB device descriptor.
Definition: usb.h:1209
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
usb_pid
USB packet IDs.
Definition: usb.h:72
USB hub host controller operations.
Definition: usb.h:870
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
unsigned int max
Maximum fill level.
Definition: usb.h:439
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
A USB configuration descriptor.
Definition: usb.h:209
uint16_t vendor
Vendor ID.
Definition: usb.h:1364
unsigned int language
Default language ID (if known)
Definition: usb.h:752
uint8_t subclass
Subclass code.
Definition: usb.h:163
A USB endpoint descriptor.
Definition: usb.h:263
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1061
uint8_t first
First interface number.
Definition: usb.h:332
uint8_t alternate
Alternate setting.
Definition: usb.h:250
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
uint8_t config
Configuration value.
Definition: usb.h:217
struct list_head complete
Completed control transfers.
Definition: usb.h:749
static struct tlan_private * priv
Definition: tlan.c:224
uint16_t protocol
USB specification release number in BCD.
Definition: usb.h:184
struct list_head list
List of hubs.
Definition: usb.h:853
static int usb_get_status(struct usb_device *usb, unsigned int type, unsigned int index, void *data, size_t len)
Get status.
Definition: usb.h:1109
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
uint8_t mtu
Maximum packet size for endpoint zero.
Definition: usb.h:188
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
Definition: usb.c:2094
uint8_t name
Product string.
Definition: usb.h:198
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1086
A USB endpoint companion descriptor.
Definition: usb.h:313
unsigned int address
Port address.
Definition: usb.h:816
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2130
struct usb_hub * hub
USB hub.
Definition: usb.h:814
unsigned int id_count
Number of entries in ID table.
Definition: usb.h:1410
int usb_endpoint_clear_halt(struct usb_endpoint *ep)
Clear endpoint halt (if applicable)
Definition: usb.c:371
#define USB_SET_ADDRESS
Set address.
Definition: usb.h:133
High speed (480Mbps)
Definition: usb.h:52
void(* remove)(struct usb_function *func)
Remove device.
Definition: usb.h:1433
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
unsigned int interval
Interval (in microframes)
Definition: usb.h:415
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
struct usb_endpoint_host_operations endpoint
Endpoint operations.
Definition: usb.h:1032
uint32_t end
Ending offset.
Definition: netvsc.h:18
int(* address)(struct usb_device *usb)
Assign device address.
Definition: usb.h:773
uint8_t data[48]
Additional event data.
Definition: ena.h:22
USB host controller operations.
Definition: usb.h:1030
Linker tables.
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586
struct usb_class class
Association class.
Definition: usb.h:336
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition: usb.c:2371
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:265
struct usb_hub * hub
Root hub.
Definition: usb.h:994
Device model.
uint16_t len
Total length.
Definition: usb.h:213
uint16_t len
Length of data stage.
Definition: usb.h:90
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:679
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:936
struct usb_device * usb
USB device.
Definition: usb.h:405
usb_speed
USB device speeds.
Definition: usb.h:44
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
static int usb_is_within_config(struct usb_configuration_descriptor *config, struct usb_descriptor_header *desc)
Check that descriptor lies within a configuration descriptor.
Definition: usb.h:370
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:430
int(* message)(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
Definition: usb.h:474
int(* open)(struct usb_endpoint *ep)
Open endpoint.
Definition: usb.h:449
unsigned int protocol
Hub protocol.
Definition: usb.h:848
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:426
static int usb_get_descriptor(struct usb_device *usb, unsigned int type, unsigned int desc, unsigned int index, unsigned int language, struct usb_descriptor_header *data, size_t len)
Get USB descriptor.
Definition: usb.h:1176
struct usb_device_host_operations * host
Host controller operations.
Definition: usb.h:739
struct usb_bus_host_operations * host
Host controller operations.
Definition: usb.h:1004
A USB device descriptor.
Definition: usb.h:180
#define USB_SET_FEATURE
Set feature.
Definition: usb.h:130
USB endpoint driver operations.
Definition: usb.h:488
struct device dev
Generic device.
Definition: usb.h:681
A USB function.
Definition: usb.h:673
uint16_t value
Value parameter.
Definition: usb.h:86
A USB class descriptor.
Definition: usb.h:643
uint16_t sizes
Maximum packet size and burst size.
Definition: usb.h:271
struct usb_bus * bus
USB bus.
Definition: usb.h:844
struct list_head functions
List of functions.
Definition: usb.h:736
Fallback driver (has no effect on overall score)
Definition: usb.h:1448
unsigned int speed
Port speed.
Definition: usb.h:820
struct usb_endpoint_descriptor * usb_endpoint_descriptor(struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index)
Locate USB endpoint descriptor.
Definition: usb.c:167
int(* speed)(struct usb_hub *hub, struct usb_port *port)
Update port speed.
Definition: usb.h:917
uint32_t len
Length.
Definition: ena.h:14
#define USB_SET_CONFIGURATION
Set configuration.
Definition: usb.h:145
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Standard Device Descriptor USB 2.0 spec, Section 9.6.1.
Definition: Usb.h:106
struct list_head list
List of functions within this USB device.
Definition: usb.h:683
A USB bus.
Definition: usb.h:965
unsigned int attributes
Attributes.
Definition: usb.h:409
struct list_head devices
List of devices.
Definition: usb.h:999
uint8_t interface
Interface number.
Definition: usb.h:248
uint8_t bus
Bus.
Definition: edd.h:14
Full speed (12Mbps)
Definition: usb.h:50
unsigned int address
Endpoint address.
Definition: usb.h:407
uint8_t burst
Maximum burst size.
Definition: usb.h:317
struct usb_class class
Class.
Definition: usb.h:645
IN PID.
Definition: usb.h:74
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:947
int usb_find_next(struct usb_device **usb, uint16_t *busdev)
Find next USB device.
Definition: usb.c:2301
int usb_prefill(struct usb_endpoint *ep)
Prefill endpoint recycled buffer list.
Definition: usb.c:619
int(* open)(struct usb_hub *hub)
Open hub.
Definition: usb.h:891
struct usb_device_id * ids
USB ID table.
Definition: usb.h:1408
int(* open)(struct usb_device *usb)
Open device.
Definition: usb.h:762
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:586
A persistent I/O buffer.
Definition: iobuf.h:33
int(* stream)(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
Definition: usb.h:483
struct usb_port port[0]
Port list.
Definition: usb.h:866