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