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 void usb_endpoint_close ( struct usb_endpoint *ep );
584 extern int usb_message ( struct usb_endpoint *ep, unsigned int request,
585  unsigned int value, unsigned int index,
586  struct io_buffer *iobuf );
587 extern int usb_stream ( struct usb_endpoint *ep, struct io_buffer *iobuf,
588  int terminate );
589 extern void usb_complete_err ( struct usb_endpoint *ep,
590  struct io_buffer *iobuf, int rc );
591 
592 /**
593  * Initialise USB endpoint refill
594  *
595  * @v ep USB endpoint
596  * @v reserve Refill buffer reserved header length
597  * @v len Refill buffer payload length (zero for endpoint's MTU)
598  * @v max Maximum fill level
599  */
600 static inline __attribute__ (( always_inline )) void
601 usb_refill_init ( struct usb_endpoint *ep, size_t reserve, size_t len,
602  unsigned int max ) {
603 
604  INIT_LIST_HEAD ( &ep->recycled );
605  ep->reserve = reserve;
606  ep->len = len;
607  ep->max = max;
608 }
609 
610 /**
611  * Recycle I/O buffer
612  *
613  * @v ep USB endpoint
614  * @v iobuf I/O buffer
615  */
616 static inline __attribute__ (( always_inline )) void
617 usb_recycle ( struct usb_endpoint *ep, struct io_buffer *iobuf ) {
618 
619  list_add_tail ( &iobuf->list, &ep->recycled );
620 }
621 
622 extern int usb_prefill ( struct usb_endpoint *ep );
623 extern int usb_refill ( struct usb_endpoint *ep );
624 extern void usb_flush ( struct usb_endpoint *ep );
625 
626 /** A USB class descriptor */
628  /** Class */
629  struct usb_class class;
630  /** Scalar value */
632 };
633 
634 /**
635  * A USB function descriptor
636  *
637  * This is an internal descriptor used to represent an association of
638  * interfaces within a USB device.
639  */
641  /** Vendor ID */
643  /** Product ID */
645  /** Class */
647  /** Number of interfaces */
648  unsigned int count;
649 };
650 
651 /**
652  * A USB function
653  *
654  * A USB function represents an association of interfaces within a USB
655  * device.
656  */
657 struct usb_function {
658  /** Name */
659  const char *name;
660  /** USB device */
661  struct usb_device *usb;
662  /** Function descriptor */
664  /** Generic device */
665  struct device dev;
666  /** List of functions within this USB device */
667  struct list_head list;
668 
669  /** Driver */
671  /** Driver private data */
672  void *priv;
673  /** Driver device ID */
674  struct usb_device_id *id;
675 
676  /** List of interface numbers
677  *
678  * This must be the last field within the structure.
679  */
681 };
682 
683 /**
684  * Set USB function driver private data
685  *
686  * @v func USB function
687  * @v priv Driver private data
688  */
689 static inline __attribute__ (( always_inline )) void
690 usb_func_set_drvdata ( struct usb_function *func, void *priv ) {
691  func->priv = priv;
692 }
693 
694 /**
695  * Get USB function driver private data
696  *
697  * @v function USB function
698  * @ret priv Driver private data
699  */
700 static inline __attribute__ (( always_inline )) void *
702  return func->priv;
703 }
704 
705 /** A USB device */
706 struct usb_device {
707  /** Name */
708  char name[32];
709  /** USB port */
710  struct usb_port *port;
711  /** Device speed */
712  unsigned int speed;
713  /** List of devices on this bus */
714  struct list_head list;
715  /** Device address, if assigned */
716  unsigned int address;
717  /** Device descriptor */
719  /** List of functions */
721 
722  /** Host controller operations */
724  /** Host controller private data */
725  void *priv;
726 
727  /** Endpoint list */
728  struct usb_endpoint *ep[32];
729 
730  /** Control endpoint */
732  /** Completed control transfers */
734 
735  /** Default language ID (if known) */
736  unsigned int language;
737 };
738 
739 /** USB device host controller operations */
741  /** Open device
742  *
743  * @v usb USB device
744  * @ret rc Return status code
745  */
746  int ( * open ) ( struct usb_device *usb );
747  /** Close device
748  *
749  * @v usb USB device
750  */
751  void ( * close ) ( struct usb_device *usb );
752  /** Assign device address
753  *
754  * @v usb USB device
755  * @ret rc Return status code
756  */
757  int ( * address ) ( struct usb_device *usb );
758 };
759 
760 /**
761  * Set USB device host controller private data
762  *
763  * @v usb USB device
764  * @v priv Host controller private data
765  */
766 static inline __attribute__ (( always_inline )) void
767 usb_set_hostdata ( struct usb_device *usb, void *priv ) {
768  usb->priv = priv;
769 }
770 
771 /**
772  * Get USB device host controller private data
773  *
774  * @v usb USB device
775  * @ret priv Host controller private data
776  */
777 static inline __attribute__ (( always_inline )) void *
778 usb_get_hostdata ( struct usb_device *usb ) {
779  return usb->priv;
780 }
781 
782 /**
783  * Get USB endpoint
784  *
785  * @v usb USB device
786  * @v address Endpoint address
787  * @ret ep USB endpoint, or NULL if not opened
788  */
789 static inline struct usb_endpoint * usb_endpoint ( struct usb_device *usb,
790  unsigned int address ) {
791 
792  return usb->ep[ USB_ENDPOINT_IDX ( address ) ];
793 }
794 
795 /** A USB port */
796 struct usb_port {
797  /** USB hub */
798  struct usb_hub *hub;
799  /** Port address */
800  unsigned int address;
801  /** Port protocol */
802  unsigned int protocol;
803  /** Port speed */
804  unsigned int speed;
805  /** Port disconnection has been detected
806  *
807  * This should be set whenever the underlying hardware reports
808  * a connection status change.
809  */
811  /** Port has an attached device */
812  int attached;
813  /** Currently attached device (if in use)
814  *
815  * Note that this field will be NULL if the attached device
816  * has been freed (e.g. because there were no drivers found).
817  */
818  struct usb_device *usb;
819  /** List of changed ports */
821 };
822 
823 /** A USB hub */
824 struct usb_hub {
825  /** Name */
826  const char *name;
827  /** USB bus */
828  struct usb_bus *bus;
829  /** Underlying USB device, if any */
830  struct usb_device *usb;
831  /** Hub protocol */
832  unsigned int protocol;
833  /** Number of ports */
834  unsigned int ports;
835 
836  /** List of hubs */
837  struct list_head list;
838 
839  /** Host controller operations */
841  /** Driver operations */
843  /** Driver private data */
844  void *priv;
845 
846  /** Port list
847  *
848  * This must be the last field within the structure.
849  */
850  struct usb_port port[0];
851 };
852 
853 /** USB hub host controller operations */
855  /** Open hub
856  *
857  * @v hub USB hub
858  * @ret rc Return status code
859  */
860  int ( * open ) ( struct usb_hub *hub );
861  /** Close hub
862  *
863  * @v hub USB hub
864  */
865  void ( * close ) ( struct usb_hub *hub );
866 };
867 
868 /** USB hub driver operations */
870  /** Open hub
871  *
872  * @v hub USB hub
873  * @ret rc Return status code
874  */
875  int ( * open ) ( struct usb_hub *hub );
876  /** Close hub
877  *
878  * @v hub USB hub
879  */
880  void ( * close ) ( struct usb_hub *hub );
881  /** Enable port
882  *
883  * @v hub USB hub
884  * @v port USB port
885  * @ret rc Return status code
886  */
887  int ( * enable ) ( struct usb_hub *hub, struct usb_port *port );
888  /** Disable port
889  *
890  * @v hub USB hub
891  * @v port USB port
892  * @ret rc Return status code
893  */
894  int ( * disable ) ( struct usb_hub *hub, struct usb_port *port );
895  /** Update port speed
896  *
897  * @v hub USB hub
898  * @v port USB port
899  * @ret rc Return status code
900  */
901  int ( * speed ) ( struct usb_hub *hub, struct usb_port *port );
902  /** Clear transaction translator buffer
903  *
904  * @v hub USB hub
905  * @v port USB port
906  * @v ep USB endpoint
907  * @ret rc Return status code
908  */
909  int ( * clear_tt ) ( struct usb_hub *hub, struct usb_port *port,
910  struct usb_endpoint *ep );
911 };
912 
913 /**
914  * Set USB hub driver private data
915  *
916  * @v hub USB hub
917  * @v priv Driver private data
918  */
919 static inline __attribute__ (( always_inline )) void
920 usb_hub_set_drvdata ( struct usb_hub *hub, void *priv ) {
921  hub->priv = priv;
922 }
923 
924 /**
925  * Get USB hub driver private data
926  *
927  * @v hub USB hub
928  * @ret priv Driver private data
929  */
930 static inline __attribute__ (( always_inline )) void *
931 usb_hub_get_drvdata ( struct usb_hub *hub ) {
932  return hub->priv;
933 }
934 
935 /**
936  * Get USB port
937  *
938  * @v hub USB hub
939  * @v address Port address
940  * @ret port USB port
941  */
942 static inline __attribute__ (( always_inline )) struct usb_port *
943 usb_port ( struct usb_hub *hub, unsigned int address ) {
944 
945  return &hub->port[ address - 1 ];
946 }
947 
948 /** A USB bus */
949 struct usb_bus {
950  /** Name */
951  const char *name;
952  /** Underlying hardware device */
953  struct device *dev;
954  /** Host controller operations set */
956 
957  /** Largest transfer allowed on the bus */
958  size_t mtu;
959  /** Address in-use mask
960  *
961  * This is used only by buses which perform manual address
962  * assignment. USB allows for addresses in the range [1,127].
963  * We use a simple bitmask which restricts us to the range
964  * [1,64]; this is unlikely to be a problem in practice. For
965  * comparison: controllers which perform autonomous address
966  * assignment (such as xHCI) typically allow for only 32
967  * devices per bus anyway.
968  */
969  unsigned long long addresses;
970 
971  /** Root hub */
972  struct usb_hub *hub;
973 
974  /** List of USB buses */
975  struct list_head list;
976  /** List of devices */
978  /** List of hubs */
979  struct list_head hubs;
980 
981  /** Host controller operations */
983  /** Host controller private data */
984  void *priv;
985 };
986 
987 /** USB bus host controller operations */
989  /** Open bus
990  *
991  * @v bus USB bus
992  * @ret rc Return status code
993  */
994  int ( * open ) ( struct usb_bus *bus );
995  /** Close bus
996  *
997  * @v bus USB bus
998  */
999  void ( * close ) ( struct usb_bus *bus );
1000  /** Poll bus
1001  *
1002  * @v bus USB bus
1003  */
1004  void ( * poll ) ( struct usb_bus *bus );
1005 };
1006 
1007 /** USB host controller operations */
1009  /** Endpoint operations */
1011  /** Device operations */
1013  /** Bus operations */
1015  /** Hub operations */
1017  /** Root hub operations */
1019 };
1020 
1021 /**
1022  * Set USB bus host controller private data
1023  *
1024  * @v bus USB bus
1025  * @v priv Host controller private data
1026  */
1027 static inline __attribute__ (( always_inline )) void
1028 usb_bus_set_hostdata ( struct usb_bus *bus, void *priv ) {
1029  bus->priv = priv;
1030 }
1031 
1032 /**
1033  * Get USB bus host controller private data
1034  *
1035  * @v bus USB bus
1036  * @ret priv Host controller private data
1037  */
1038 static inline __attribute__ (( always_inline )) void *
1040  return bus->priv;
1041 }
1042 
1043 /**
1044  * Poll USB bus
1045  *
1046  * @v bus USB bus
1047  */
1048 static inline __attribute__ (( always_inline )) void
1049 usb_poll ( struct usb_bus *bus ) {
1050  bus->host->poll ( bus );
1051 }
1052 
1053 /** Iterate over all USB buses */
1054 #define for_each_usb_bus( bus ) \
1055  list_for_each_entry ( (bus), &usb_buses, list )
1056 
1057 /**
1058  * Complete transfer (without error)
1059  *
1060  * @v ep USB endpoint
1061  * @v iobuf I/O buffer
1062  */
1063 static inline __attribute__ (( always_inline )) void
1064 usb_complete ( struct usb_endpoint *ep, struct io_buffer *iobuf ) {
1065  usb_complete_err ( ep, iobuf, 0 );
1066 }
1067 
1068 extern int usb_control ( struct usb_device *usb, unsigned int request,
1069  unsigned int value, unsigned int index, void *data,
1070  size_t len );
1071 extern int usb_get_string_descriptor ( struct usb_device *usb,
1072  unsigned int index,
1073  unsigned int language,
1074  char *buf, size_t len );
1075 
1076 /**
1077  * Get status
1078  *
1079  * @v usb USB device
1080  * @v type Request type
1081  * @v index Target index
1082  * @v data Status to fill in
1083  * @v len Length of status descriptor
1084  * @ret rc Return status code
1085  */
1086 static inline __attribute__ (( always_inline )) int
1087 usb_get_status ( struct usb_device *usb, unsigned int type, unsigned int index,
1088  void *data, size_t len ) {
1089 
1090  return usb_control ( usb, ( USB_GET_STATUS | type ), 0, index,
1091  data, len );
1092 }
1093 
1094 /**
1095  * Clear feature
1096  *
1097  * @v usb USB device
1098  * @v type Request type
1099  * @v feature Feature selector
1100  * @v index Target index
1101  * @ret rc Return status code
1102  */
1103 static inline __attribute__ (( always_inline )) int
1104 usb_clear_feature ( struct usb_device *usb, unsigned int type,
1105  unsigned int feature, unsigned int index ) {
1106 
1107  return usb_control ( usb, ( USB_CLEAR_FEATURE | type ),
1108  feature, index, NULL, 0 );
1109 }
1110 
1111 /**
1112  * Set feature
1113  *
1114  * @v usb USB device
1115  * @v type Request type
1116  * @v feature Feature selector
1117  * @v index Target index
1118  * @ret rc Return status code
1119  */
1120 static inline __attribute__ (( always_inline )) int
1121 usb_set_feature ( struct usb_device *usb, unsigned int type,
1122  unsigned int feature, unsigned int index ) {
1123 
1124  return usb_control ( usb, ( USB_SET_FEATURE | type ),
1125  feature, index, NULL, 0 );
1126 }
1127 
1128 /**
1129  * Set address
1130  *
1131  * @v usb USB device
1132  * @v address Device address
1133  * @ret rc Return status code
1134  */
1135 static inline __attribute__ (( always_inline )) int
1136 usb_set_address ( struct usb_device *usb, unsigned int address ) {
1137 
1138  return usb_control ( usb, USB_SET_ADDRESS, address, 0, NULL, 0 );
1139 }
1140 
1141 /**
1142  * Get USB descriptor
1143  *
1144  * @v usb USB device
1145  * @v type Request type
1146  * @v desc Descriptor type
1147  * @v index Descriptor index
1148  * @v language Language ID (for string descriptors)
1149  * @v data Descriptor to fill in
1150  * @v len Maximum length of descriptor
1151  * @ret rc Return status code
1152  */
1153 static inline __attribute__ (( always_inline )) int
1154 usb_get_descriptor ( struct usb_device *usb, unsigned int type,
1155  unsigned int desc, unsigned int index,
1156  unsigned int language, struct usb_descriptor_header *data,
1157  size_t len ) {
1158 
1159  return usb_control ( usb, ( USB_GET_DESCRIPTOR | type ),
1160  ( ( desc << 8 ) | index ), language, data, len );
1161 }
1162 
1163 /**
1164  * Get first part of USB device descriptor (up to and including MTU)
1165  *
1166  * @v usb USB device
1167  * @v data Device descriptor to (partially) fill in
1168  * @ret rc Return status code
1169  */
1170 static inline __attribute__ (( always_inline )) int
1172 
1173  return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
1174  &data->header,
1175  ( offsetof ( typeof ( *data ), mtu ) +
1176  sizeof ( data->mtu ) ) );
1177 }
1178 
1179 /**
1180  * Get USB device descriptor
1181  *
1182  * @v usb USB device
1183  * @v data Device descriptor to fill in
1184  * @ret rc Return status code
1185  */
1186 static inline __attribute__ (( always_inline )) int
1188  struct usb_device_descriptor *data ) {
1189 
1190  return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
1191  &data->header, sizeof ( *data ) );
1192 }
1193 
1194 /**
1195  * Get USB configuration descriptor
1196  *
1197  * @v usb USB device
1198  * @v index Configuration index
1199  * @v data Configuration descriptor to fill in
1200  * @ret rc Return status code
1201  */
1202 static inline __attribute__ (( always_inline )) int
1203 usb_get_config_descriptor ( struct usb_device *usb, unsigned int index,
1205  size_t len ) {
1206 
1208  0, &data->header, len );
1209 }
1210 
1211 /**
1212  * Set USB configuration
1213  *
1214  * @v usb USB device
1215  * @v index Configuration index
1216  * @ret rc Return status code
1217  */
1218 static inline __attribute__ (( always_inline )) int
1219 usb_set_configuration ( struct usb_device *usb, unsigned int index ) {
1220 
1221  return usb_control ( usb, USB_SET_CONFIGURATION, index, 0, NULL, 0 );
1222 }
1223 
1224 /**
1225  * Set USB interface alternate setting
1226  *
1227  * @v usb USB device
1228  * @v interface Interface number
1229  * @v alternate Alternate setting
1230  * @ret rc Return status code
1231  */
1232 static inline __attribute__ (( always_inline )) int
1233 usb_set_interface ( struct usb_device *usb, unsigned int interface,
1234  unsigned int alternate ) {
1235 
1237  NULL, 0 );
1238 }
1239 
1240 extern struct list_head usb_buses;
1241 
1242 extern struct usb_interface_descriptor *
1244  unsigned int interface, unsigned int alternate );
1245 extern struct usb_endpoint_descriptor *
1248  unsigned int type, unsigned int index );
1249 extern struct usb_endpoint_companion_descriptor *
1251  struct usb_endpoint_descriptor *desc );
1252 
1253 extern struct usb_hub * alloc_usb_hub ( struct usb_bus *bus,
1254  struct usb_device *usb,
1255  unsigned int ports,
1256  struct usb_hub_driver_operations *op );
1257 extern int register_usb_hub ( struct usb_hub *hub );
1258 extern void unregister_usb_hub ( struct usb_hub *hub );
1259 extern void free_usb_hub ( struct usb_hub *hub );
1260 
1261 extern void usb_port_changed ( struct usb_port *port );
1262 
1263 extern struct usb_bus * alloc_usb_bus ( struct device *dev,
1264  unsigned int ports, size_t mtu,
1265  struct usb_host_operations *op );
1266 extern int register_usb_bus ( struct usb_bus *bus );
1267 extern void unregister_usb_bus ( struct usb_bus *bus );
1268 extern void free_usb_bus ( struct usb_bus *bus );
1269 extern struct usb_bus * find_usb_bus_by_location ( unsigned int bus_type,
1270  unsigned int location );
1271 
1272 extern int usb_alloc_address ( struct usb_bus *bus );
1273 extern void usb_free_address ( struct usb_bus *bus, unsigned int address );
1274 extern unsigned int usb_route_string ( struct usb_device *usb );
1275 extern unsigned int usb_depth ( struct usb_device *usb );
1276 extern struct usb_port * usb_root_hub_port ( struct usb_device *usb );
1277 extern struct usb_port * usb_transaction_translator ( struct usb_device *usb );
1278 
1279 /** Minimum reset time
1280  *
1281  * Section 7.1.7.5 of the USB2 specification states that root hub
1282  * ports should assert reset signalling for at least 50ms.
1283  */
1284 #define USB_RESET_DELAY_MS 50
1285 
1286 /** Reset recovery time
1287  *
1288  * Section 9.2.6.2 of the USB2 specification states that the
1289  * "recovery" interval after a port reset is 10ms.
1290  */
1291 #define USB_RESET_RECOVER_DELAY_MS 10
1292 
1293 /** Maximum time to wait for a control transaction to complete
1294  *
1295  * Section 9.2.6.1 of the USB2 specification states that the upper
1296  * limit for commands to be processed is 5 seconds.
1297  */
1298 #define USB_CONTROL_MAX_WAIT_MS 5000
1299 
1300 /** Set address recovery time
1301  *
1302  * Section 9.2.6.3 of the USB2 specification states that devices are
1303  * allowed a 2ms recovery interval after receiving a new address.
1304  */
1305 #define USB_SET_ADDRESS_RECOVER_DELAY_MS 2
1306 
1307 /** Time to wait for ports to stabilise
1308  *
1309  * Section 7.1.7.3 of the USB specification states that we must allow
1310  * 100ms for devices to signal attachment, and an additional 100ms for
1311  * connection debouncing. (This delay is parallelised across all
1312  * ports on a hub; we do not delay separately for each port.)
1313  */
1314 #define USB_PORT_DELAY_MS 200
1315 
1316 /** A USB device ID */
1318  /** Name */
1319  const char *name;
1320  /** Vendor ID */
1322  /** Product ID */
1324  /** Arbitrary driver data */
1325  unsigned long driver_data;
1326 };
1327 
1328 /** Match-anything ID */
1329 #define USB_ANY_ID 0xffff
1330 
1331 /** A USB class ID */
1333  /** Class */
1335  /** Class mask */
1337 };
1338 
1339 /** Construct USB class ID
1340  *
1341  * @v base Base class code (or USB_ANY_ID)
1342  * @v subclass Subclass code (or USB_ANY_ID)
1343  * @v protocol Protocol code (or USB_ANY_ID)
1344  */
1345 #define USB_CLASS_ID( base, subclass, protocol ) { \
1346  .class = { \
1347  .class = { \
1348  ( (base) & 0xff ), \
1349  ( (subclass) & 0xff ), \
1350  ( (protocol) & 0xff ), \
1351  }, \
1352  }, \
1353  .mask = { \
1354  .class = { \
1355  ( ( (base) == USB_ANY_ID ) ? 0x00 : 0xff ), \
1356  ( ( (subclass) == USB_ANY_ID ) ? 0x00 : 0xff ), \
1357  ( ( (protocol) == USB_ANY_ID ) ? 0x00 : 0xff ), \
1358  }, \
1359  }, \
1360  }
1361 
1362 /** A USB driver */
1363 struct usb_driver {
1364  /** USB ID table */
1366  /** Number of entries in ID table */
1367  unsigned int id_count;
1368  /** Class ID */
1370  /** Driver score
1371  *
1372  * This is used to determine the preferred configuration for a
1373  * USB device.
1374  */
1375  unsigned int score;
1376  /**
1377  * Probe device
1378  *
1379  * @v func USB function
1380  * @v config Configuration descriptor
1381  * @ret rc Return status code
1382  */
1383  int ( * probe ) ( struct usb_function *func,
1385  /**
1386  * Remove device
1387  *
1388  * @v func USB function
1389  */
1390  void ( * remove ) ( struct usb_function *func );
1391 };
1392 
1393 /** USB driver table */
1394 #define USB_DRIVERS __table ( struct usb_driver, "usb_drivers" )
1395 
1396 /** Declare a USB driver */
1397 #define __usb_driver __table_entry ( USB_DRIVERS, 01 )
1398 
1399 /** USB driver scores */
1401  /** Fallback driver (has no effect on overall score) */
1403  /** Deprecated driver */
1405  /** Normal driver */
1407 };
1408 
1409 extern struct usb_driver *
1411  struct usb_device_id **id );
1412 
1413 #endif /* _IPXE_USB_H */
int(* open)(struct usb_bus *bus)
Open bus.
Definition: usb.h:994
void unregister_usb_hub(struct usb_hub *hub)
Unregister USB hub.
Definition: usb.c:1966
A USB driver.
Definition: usb.h:1363
#define __attribute__(x)
Definition: compiler.h:10
void(* poll)(struct usb_bus *bus)
Poll bus.
Definition: usb.h:1004
size_t mtu
Largest transfer allowed on the bus.
Definition: usb.h:958
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:984
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:1317
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:701
static int usb_set_configuration(struct usb_device *usb, unsigned int index)
Set USB configuration.
Definition: usb.h:1219
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:951
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:810
const char * name
Name.
Definition: usb.h:659
A USB hub.
Definition: usb.h:824
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition: usb.c:293
const char * name
Name.
Definition: usb.h:1319
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:648
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:840
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2102
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:1404
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:689
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:767
uint8_t type
Type.
Definition: ena.h:16
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:232
union usb_class_descriptor mask
Class mask.
Definition: usb.h:1336
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:1016
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:1014
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:1203
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2198
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:753
uint16_t vendor
Vendor ID.
Definition: usb.h:642
struct usb_driver * driver
Driver.
Definition: usb.h:670
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2126
int attached
Port has an attached device.
Definition: usb.h:812
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:474
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:818
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:802
struct usb_bus * find_usb_bus_by_location(unsigned int bus_type, unsigned int location)
Find USB bus by device location.
Definition: usb.c:2152
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:1794
#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:820
A USB class ID.
Definition: usb.h:1332
int(* clear_tt)(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
Definition: usb.h:909
struct usb_driver * usb_find_driver(struct usb_function_descriptor *desc, struct usb_device_id **id)
Find USB device driver.
Definition: usb.c:1130
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:969
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:646
uint8_t attributes
Attributes.
Definition: usb.h:207
USB hub driver operations.
Definition: usb.h:869
struct list_head hubs
List of hubs.
Definition: usb.h:979
unsigned int address
Device address, if assigned.
Definition: usb.h:716
#define USB_GET_STATUS
Get status.
Definition: usb.h:110
unsigned int speed
Device speed.
Definition: usb.h:712
int(* probe)(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: usb.h:1383
A doubly-linked list entry (or list head)
Definition: list.h:18
int(* open)(struct usb_hub *hub)
Open hub.
Definition: usb.h:860
static int usb_set_interface(struct usb_device *usb, unsigned int interface, unsigned int alternate)
Set USB interface alternate setting.
Definition: usb.h:1233
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:1028
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
Definition: usb.h:1136
union usb_class_descriptor class
Class.
Definition: usb.h:1334
struct usb_device_id * id
Driver device ID.
Definition: usb.h:674
A USB string descriptor.
Definition: usb.h:216
uint16_t product
Product ID.
Definition: usb.h:644
int register_usb_hub(struct usb_hub *hub)
Register USB hub.
Definition: usb.c:1912
A USB port.
Definition: usb.h:796
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:830
uint8_t manufacturer
Manufacturer string.
Definition: usb.h:182
void * priv
Driver private data.
Definition: usb.h:672
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:640
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:168
struct usb_port * port
USB port.
Definition: usb.h:710
struct usb_hub_driver_operations root
Root hub operations.
Definition: usb.h:1018
static void usb_recycle(struct usb_endpoint *ep, struct io_buffer *iobuf)
Recycle I/O buffer.
Definition: usb.h:617
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:842
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:865
USB 3.0.
Definition: usb.h:24
struct device * dev
Underlying hardware device.
Definition: usb.h:953
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:316
An object interface.
Definition: interface.h:109
static int usb_clear_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Clear feature.
Definition: usb.h:1104
struct usb_class_id class
Class ID.
Definition: usb.h:1369
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:1400
#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:2221
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:601
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:528
struct list_head list
List of USB buses.
Definition: usb.h:975
int(* enable)(struct usb_hub *hub, struct usb_port *port)
Enable port.
Definition: usb.h:887
int usb_alloc_address(struct usb_bus *bus)
Allocate device address.
Definition: usb.c:2178
USB bus host controller operations.
Definition: usb.h:988
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:690
char name[32]
Name.
Definition: usb.h:708
unsigned int ports
Number of ports.
Definition: usb.h:834
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:35
const char * name
Name.
Definition: usb.h:826
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:751
A USB device.
Definition: usb.h:706
uint8_t type
Descriptor type.
Definition: usb.h:162
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:642
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct usb_endpoint control
Control endpoint.
Definition: usb.h:731
void(* close)(struct usb_bus *bus)
Close bus.
Definition: usb.h:999
Linked lists.
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1049
static int usb_set_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Set feature.
Definition: usb.h:1121
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
Definition: usb.h:789
#define USB_SET_INTERFACE
Set interface.
Definition: usb.h:138
SETUP PID.
Definition: usb.h:64
uint16_t product
Product ID.
Definition: usb.h:1323
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct list_head list
List of devices on this bus.
Definition: usb.h:714
void * priv
Driver private data.
Definition: usb.h:844
unsigned int score
Driver score.
Definition: usb.h:1375
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:884
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:370
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:740
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:1171
Normal driver.
Definition: usb.h:1406
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:1873
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:880
void * priv
Host controller private data.
Definition: usb.h:725
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:778
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:661
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:631
unsigned int uint32_t
Definition: stdint.h:12
void free_usb_hub(struct usb_hub *hub)
Free USB hub.
Definition: usb.c:1999
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
unsigned long driver_data
Arbitrary driver data.
Definition: usb.h:1325
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:894
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:2258
struct usb_host_operations * op
Host controller operations set.
Definition: usb.h:955
static int usb_get_device_descriptor(struct usb_device *usb, struct usb_device_descriptor *data)
Get USB device descriptor.
Definition: usb.h:1187
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:854
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:1321
unsigned int language
Default language ID (if known)
Definition: usb.h:736
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:1039
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:39
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:733
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:837
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:1087
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:2031
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:1064
A USB endpoint companion descriptor.
Definition: usb.h:299
unsigned int address
Port address.
Definition: usb.h:800
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2067
struct usb_hub * hub
USB hub.
Definition: usb.h:798
unsigned int id_count
Number of entries in ID table.
Definition: usb.h:1367
#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:1390
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
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:1010
uint32_t end
Ending offset.
Definition: netvsc.h:18
int(* address)(struct usb_device *usb)
Assign device address.
Definition: usb.h:757
USB host controller operations.
Definition: usb.h:1008
Linker tables.
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:569
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:2274
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:251
struct usb_hub * hub
Root hub.
Definition: usb.h:972
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:663
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:920
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:943
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
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:832
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:1154
struct usb_device_host_operations * host
Host controller operations.
Definition: usb.h:723
struct usb_bus_host_operations * host
Host controller operations.
Definition: usb.h:982
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:665
A USB function.
Definition: usb.h:657
uint16_t value
Value parameter.
Definition: usb.h:72
A USB class descriptor.
Definition: usb.h:627
uint16_t sizes
Maximum packet size and burst size.
Definition: usb.h:257
struct usb_bus * bus
USB bus.
Definition: usb.h:828
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct list_head functions
List of functions.
Definition: usb.h:720
Fallback driver (has no effect on overall score)
Definition: usb.h:1402
unsigned int speed
Port speed.
Definition: usb.h:804
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:901
#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:667
unsigned int usb_depth(struct usb_device *usb)
Get USB depth.
Definition: usb.c:2241
A USB bus.
Definition: usb.h:949
unsigned int attributes
Attributes.
Definition: usb.h:395
struct list_head devices
List of devices.
Definition: usb.h:977
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:629
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:931
int usb_prefill(struct usb_endpoint *ep)
Prefill endpoint recycled buffer list.
Definition: usb.c:602
int(* open)(struct usb_hub *hub)
Open hub.
Definition: usb.h:875
struct usb_device_id * ids
USB ID table.
Definition: usb.h:1365
int(* open)(struct usb_device *usb)
Open device.
Definition: usb.h:746
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:32
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:850