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