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