/* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ /* bos720 src/bos/kernext/usb/common/usb.h 1.2.2.1 */ /* */ /* Licensed Materials - Property of IBM */ /* */ /* Restricted Materials of IBM */ /* */ /* COPYRIGHT International Business Machines Corp. 2003,2013 */ /* All Rights Reserved */ /* */ /* US Government Users Restricted Rights - Use, duplication or */ /* disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /* */ /* IBM_PROLOG_END_TAG */ /* @(#)04 1.2.2.1 src/bos/kernext/usb/common/usb.h, sysxusb, bos720 7/26/13 07:52:25 */ #ifndef _H_USB #define _H_USB #include /* * Refer to Universal Serial Bus Specification Revision 2.0, chapter 9 * for information concerning the items in this header file * * NOTE: bit masks for 16 bit fields are big endian */ /*--------------------------------------------------------------------------* * endian conversion * *--------------------------------------------------------------------------*/ typedef uint8_t fld8_t; typedef struct _fld16_t { uint8_t low; uint8_t high; } fld16_t; /* Extend endian conversion to 32 bit quantities. */ typedef struct _fld32_t { uint8_t byte0; /* LSB */ uint8_t byte1; uint8_t byte2; uint8_t byte3; /* MSB */ } fld32_t; /* _a is field name, _b is data (constant or variable) */ #define LOAD16(_a) (((_a).high<<8) | ((_a).low)) #define STORE16(_a,_b) (_a).low = (0xff & (_b)); \ (_a).high = ((0xff00 & (_b)) >> 8) /*--------------------------------------------------------------------------* * Standard Device Request * *--------------------------------------------------------------------------*/ /* device request structure */ typedef struct _USBDevReq { fld8_t bmRequestType; fld8_t bRequest; fld16_t wValue; fld16_t wIndex; fld16_t wLength; } USBDevReq, *PUSBDevReq; /* USBDevReq initialization macro */ #define USBD_DEVREQ_INIT(_a,_b,_c,_d,_e,_f) \ { \ (_a)->bmRequestType = _b; \ (_a)->bRequest = _c; \ STORE16((_a)->wValue, _d); \ STORE16((_a)->wIndex, _e); \ STORE16((_a)->wLength, _f); \ } /* bmRequestType field */ /* Data transfer direction */ #define USB_RT_DIRECTION_MASK (1<<7) /* Direction mask */ #define USB_RT_TODEVICE (0<<7) /* Host to Device */ #define USB_RT_TOHOST (1<<7) /* Device to Host */ /* Type */ #define USB_RT_TYPE_MASK (3<<5) /* Type mask */ #define USB_RT_STAND (0<<5) /* Standard */ #define USB_RT_CLASS (1<<5) /* Slass */ #define USB_RT_VENDOR (2<<5) /* Vendor */ /* Recipient */ #define USB_RT_RECIPIENT_MASK 0x1f /* Recipient mask */ #define USB_RT_DEVICE 0 /* Device */ #define USB_RT_IF 1 /* Interface */ #define USB_RT_EP 2 /* Endpoint */ #define USB_RT_OTHER 3 /* Other */ /* bRequest field */ #define USB_GET_STATUS 0 #define USB_CLEAR_FEATURE 1 #define USB_GET_STATE 2 #define USB_SET_FEATURE 3 #define USB_SET_ADDR 5 #define USB_GET_DESCRIPTOR 6 #define USB_SET_DESCRIPTOR 7 #define USB_GET_CONFIG 8 #define USB_SET_CONFIG 9 #define USB_GET_IF 10 #define USB_SET_IF 11 #define USB_SYNCH_FRAME 12 /* Descriptor type shift for wValue field */ #define USB_DT_SHIFT 8 /* Endpoint IN/OUT specification for wIndex field */ #define USB_EP_OUT (0<<7) #define USB_EP_IN (1<<7) /*--------------------------------------------------------------------------* * Standard Descriptors * *--------------------------------------------------------------------------*/ /* Descriptor Types */ #define USB_DT_DEVICE 1 #define USB_DT_CONFIG 2 #define USB_DT_STRING 3 #define USB_DT_IF 4 #define USB_DT_EP 5 #define USB_DT_DEV_QUAL 6 #define USB_DT_OTHER_SPEED 7 /* Super Speed Device Specific Descriptor Types */ #define USB_DT_SS_DEBUG 10 #define USB_DT_SS_IF_ASSOC 11 #define USB_DT_SS_BOS 15 #define USB_DT_SS_DEVCAP 16 #define USB_DT_SS_EP_COMP 48 /* Descriptor Lengths */ #define USB_DL_DEVICE 18 #define USB_DL_CONFIG 9 #define USB_DL_IF 9 #define USB_DL_EP 7 #define USB_DL_DEV_QUAL 10 #define USB_DL_OTHER_SPEED 9 /* Super Speed Specific Descriptor Lengths */ #define USB_DL_SS_IF_ASSOC 8 #define USB_DL_SS_EP_COMP 6 #define USB_DL_SS_BOS 5 #define USB_DL_SS_DEVCAP_20EXT 7 #define USB_DL_SS_DEVCAP_SS 10 #define USB_DL_SS_DEVCAP_CONTID 20 /* Super Speed Specific Device Capability Types */ #define USB_SS_DEVCAP_20EXT 0x2 #define USB_SS_DEVCAP_SS 0x3 #define USB_SS_DEVCAP_CONTID 0x4 /* Device Descriptor */ typedef struct _USBDevDesc { fld8_t blength; fld8_t bDescriptorType; fld16_t bcdUSB; fld8_t bDeviceClass; fld8_t bDeviceSubClass; fld8_t bDeviceProtocol; fld8_t bMaxPacketSize0; fld16_t idVendor; fld16_t idProduct; fld16_t bcdDevice; fld8_t iManufacturer; fld8_t iProduct; fld8_t iSerialNumber; fld8_t bNumConfigurations; } USBDevDesc, *PUSBDevDesc; /******************************************************************************* * Binary Device Object Store (BOS) Descriptor * * USB 3.0 Specification: Table 9-9. BOS Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + BOS Descriptor type +* * +----------+---------------------+------+------------+---------------------+* * + 2 + wTotalLength + 2 + Number + Length of this +* * + + + + + desc. and all of +* * + + + + + its subdescriptors +* * +----------+---------------------+------+------------+---------------------+* * + 4 + bNumDeviceCaps + 1 + Number + The number of +* * + + + + + separate devicecap +* * + + + + + desc's inthe BOS +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USBBOSDesc { fld8_t blength; fld8_t bDescriptorType; fld16_t wTotalLength; fld8_t bNumDeviceCaps; } USBBOSDesc, *PUSBBOSDesc; /******************************************************************************* * USB 2.0 Extension Device Capability Descriptor * * USB 3.0 Specification: Table 9-12. USB 2.0 Extension Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + DEVCAP Desc. type +* * +----------+---------------------+------+------------+---------------------+* * + 2 + bDevCapabilityType + 1 + Constant + Capability Type : +* * + + + + + USB 2.0 EXTENSION +* * +----------+---------------------+------+------------+---------------------+* * + 3 + bmAttributes + 4 + Bitmap + Bitmap encoding of +* * + + + + + supported device lvl+* * + + + + + features. +* * + + + + + Bit 0: Rsvd. Zero +* * + + + + + Bit 1: LPM Support +* * + + + + + Bit 2-31: Rsvd.Zero +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USB20ExtDevCapDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bDevCapabilityType; fld32_t bmAttributes; #define USB_SS_LPM_CAPABLE (1<<1) } USB20ExtDevCapDesc, *PUSB20ExtDevCapDesc; /******************************************************************************* * SuperSpeed Device Capability Descriptor * * USB 3.0 Specification: Table 9-12. SuperSpeed Device Capabilies Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + DEVCAP Desc. type +* * +----------+---------------------+------+------------+---------------------+* * + 2 + bDevCapabilityType + 1 + Constant + Capability Type : +* * + + + + + SUPERSPEED_USB +* * +----------+---------------------+------+------------+---------------------+* * + 3 + bmAttributes + 1 + Bitmap + Bitmap encoding of +* * + + + + + supported device lvl+* * + + + + + features. +* * + + + + + Bit 0: Rsvd. Zero +* * + + + + + Bit 1: LTM Capable +* * + + + + + Bit 2-7: Rsvd.Zero +* * +----------+---------------------+------+------------+---------------------+* * + 4 + wSpeedsSupported + 2 + Bitmap + Bitmap encoding of +* * + + + + + speed supported by +* * + + + + + device in SS Mode +* * + + + + + Bit0: Lowspeed USB +* * + + + + + Bit1: Fullspeed USB +* * + + + + + Bit2: Highspeed USB +* * + + + + + Bit3: Superspeed USB+* * + + + + + Bit4-15: Rsvd.Zero +* * +----------+---------------------+------+------------+---------------------+* * + 6 + bFunctionality + 1 + Number + The lowest speed at +* * + + Support + + + which all function- +* * + + + + + -ality supported is +* * + + + + + available to user +* * +----------+---------------------+------+------------+---------------------+* * + 7 + bU1DevExitLat + 1 + Number + U1 Device Exit Lat. +* * + + + + + 00: Zero +* * + + + + + 01: Less than 1us +* * + + + + + 02: Less than 2us ..+* * + + + + + 0A: Less than 10us +* * + + + + + 0B-FF: Rsvd. +* * +----------+---------------------+------+------------+---------------------+* * + 8 + bU2DevExitLat + 2 + Number + U2 Device Exit Lat. +* * + + + + + 000: Zero +* * + + + + + 001: Less than 1us +* * + + + + + 002: Less than 2us..+* * + + + + + 7FF:Less than 2047us+* * + + + + + 800-FFFF: Rsvd. +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USBSSDevCapDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bDevCapabilityType; fld8_t bmAttributes; #define USB_SS_LTM_CAPABLE (1<<1) fld16_t wSpeedsSupported; #define USB_SS_LowSpeed (1<<0) #define USB_SS_FullSpeed (1<<1) #define USB_SS_HighSpeed (1<<2) #define USB_SS_SuperSpeed (1<<3) fld8_t bFunctionalitySupport; fld8_t bU1DevExitLat; fld16_t wU2DevExitLat; } USBSSDevCapDesc, *PUSBSSDevCapDesc; /******************************************************************************* * ContainerID Device Capability Descriptor * * USB 3.0 Specification: Table 9-14. ContainerID Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + DEVCAP Desc. type +* * +----------+---------------------+------+------------+---------------------+* * + 2 + bDevCapabilityType + 1 + Constant + Capability Type : +* * + + + + + CONTAINER_ID +* * +----------+---------------------+------+------------+---------------------+* * + 3 + bReserved + 1 + Number + Rsvd. Zero +* * +----------+---------------------+------+------------+---------------------+* * + 4 + ContainerID + 16 + UUID + This is a 128-bit No+* * + + + + + unique to device +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USBContIDDevCapDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bDevCapabilityType; fld8_t bReserved; fld8_t ContainerID[16]; } USBContIDDevCapDesc, *PUSBContIDDevCapDesc; /* Device Qualifier Descriptor */ typedef struct _USBDevQualDesc { fld8_t blength; fld8_t bDescriptorType; fld16_t bcdUSB; fld8_t bDeviceClass; fld8_t bDeviceSubClass; fld8_t bDeviceProtocol; fld8_t bMaxPacketSize0; fld8_t bNumConfigurations; fld8_t bReserved; } USBDevQualDesc, *PUSBDevQualDesc; /* Configuration Descriptor */ typedef struct _USBConfigDesc { fld8_t blength; fld8_t bDescriptorType; fld16_t wTotalLength; fld8_t bNumInterfaces; fld8_t bConfigurationValue; fld8_t iConfiguration; fld8_t bmAttributes; #define USB_DC_SELFPOWERED (1<<6) #define USB_DC_REMOTEWAKEUP (1<<5) fld8_t bMaxPower; } USBConfigDesc, *PUSBConfigDesc; /* Other Speed Configuration Descriptor */ typedef struct _USBOthSpeedDesc { fld8_t blength; fld8_t bDescriptorType; fld16_t wTotalLength; fld8_t bNumInterfaces; fld8_t bConfigurationValue; fld8_t iConfiguration; fld8_t bmAttributes; fld8_t bMaxPower; } USBOthSpeedDesc, *PUSBOthSpeedDesc; /******************************************************************************* * Interface Association Descriptor * * USB 3.0 Specification: Table 9-16. Interface Association Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + INTERFACE ASSOC. +* * + + + + + Desc. type +* * +----------+---------------------+------+------------+---------------------+* * + 2 + bFirstInterface + 1 + Number + Interface No of Ist +* * + + + + + interface of func. +* * +----------+---------------------+------+------------+---------------------+* * + 3 + bInterfaceCount + 1 + Number + No of contiguous +* * + + + + + interfaces * * +----------+---------------------+------+------------+---------------------+* * + 4 + wFunctionClass + 1 + Class + Class Code +* * +----------+---------------------+------+------------+---------------------+* * + 5 + bFunctionSubClass + 1 + SubClass + SubClass Code +* * +----------+---------------------+------+------------+---------------------+* * + 6 + bFunctionProtocol + 1 + Protocol + Protocol Code +* * +----------+---------------------+------+------------+---------------------+* * + 7 + iFunction + 1 + Index + Index of String +* * + + + + + Desc. describing +* * + + + + + this function +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USBIFAssocDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bFirstInterface; fld8_t bInterfaceCount; fld8_t bFunctionClass; fld8_t bFunctionSubClass; fld8_t bFunctionProtocol; fld8_t iFunction; } USBIFAssocDesc, *PUSBIFAssocDesc; /******************************************************************************* * Interface Descriptor * * USB 2.0 Specification: Table 9-12. Interface Descriptor * * USB 3.0 Specification: Table 9-16. Interface Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + INTERFACE Desc. type+* * +----------+---------------------+------+------------+---------------------+* * + 2 + bInterfaceNumber + 1 + Number + Number of this +* * + + + + + interface +* * +----------+---------------------+------+------------+---------------------+* * + 3 + bAlternateSetting + 1 + Number + Value for used for +* * + + + + + alternate setting +* * +----------+---------------------+------+------------+---------------------+* * + 4 + wNumEndpoints + 1 + Number + No of Endpoints +* * +----------+---------------------+------+------------+---------------------+* * + 5 + bInterfaceClass + 1 + Class + Class Code +* * +----------+---------------------+------+------------+---------------------+* * + 6 + bInterfaceSubClass + 1 + SubClass + SubClass Code +* * +----------+---------------------+------+------------+---------------------+* * + 7 + bInterfaceProtocol + 1 + Protocol + Protocol Code +* * +----------+---------------------+------+------------+---------------------+* * + 8 + iInterface + 1 + Index + Index of String +* * + + + + + Desc. describing +* * + + + + + this Interface +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USBIFDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bInterfaceNumber; fld8_t bAlternateSetting; fld8_t bNumEndPoints; fld8_t bInterfaceClass; fld8_t bInterfaceSubClass; fld8_t bInterfaceProtocol; fld8_t iInterface; } USBIFDesc, *PUSBIFDesc; /* Endpoint Descriptor */ typedef struct _USBEPDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bEndpointAddress; #define USB_DE_ADDR_MASK (15<<0) #define USB_DE_OUT (0<<7) #define USB_DE_IN (1<<7) fld8_t bmAttributes; #define USB_DE_TYPE_MASK (3<<0) #define USB_DE_CTRL (0<<0) #define USB_DE_ISOCH (1<<0) #define USB_DE_BULK (2<<0) #define USB_DE_INTR (3<<0) #define USB_DE_SYNC_MASK (3<<2) #define USB_DE_NOSYNC (0<<2) #define USB_DE_ASYNC (1<<2) #define USB_DE_ADAPT (2<<2) #define USB_DE_SYNC (3<<2) #define USB_DE_USAGE_MASK (3<<4) #define USB_DE_DATA (0<<4) #define USB_DE_FEEDBACK (1<<4) #define USB_DE_IMPLICT (2<<4) /* Super Speed Interrupt EndPt Specific */ #define USB_DE_INTR_USAGE_MASK (3<<4) #define USB_DE_INTR_PERIODIC (1<<4) #define USB_DE_INTR_NOTIF (1<<5) fld16_t wMaxPacketSize; #define USB_DE_SIZE_MASK (0x3ff<<0) #define USB_DE_ATPMShift 11 #define USB_DE_ATPMMask (3<<11) fld8_t bInterval; } USBEPDesc, *PUSBEPDesc; /******************************************************************************* * SuperSpeed Endpoint Companion Descriptor * * USB 3.0 Specification: Table 9-20. SuperSpeed Endpoint Companion Descriptor * * +----------+---------------------+------+------------+---------------------+* * + Offset + Field + Size + Value + Description +* * +----------+---------------------+------+------------+---------------------+* * + 0 + bLength + 1 + Number + Size of descriptor +* * +----------+---------------------+------+------------+---------------------+* * + 1 + bDescriptorType + 1 + Constant + SS_USB_EP_Companion +* * + + + + + Descriptor type +* * +----------+---------------------+------+------------+---------------------+* * + 2 + wMaxBurst + 1 + Number + No of Packets EP can+* * + + + + + send or recv as part+* * + + + + + of a burst. (0-15) +* * +----------+---------------------+------+------------+---------------------+* * + 3 + bmAttributes + 1 + Bitmap + Bulk EP +* * + + + + + Bit0-4: MaxStreams +* * + + + + + Bit5-7: Rsvd +* * + + + + + Ctrl/Intr EP +* * + + + + + Bit0-7: Rsvd +* * + + + + + Iso EP +* * + + + + + Bit0-1: Mult +* * + + + + + Bit 2-7: Rsvd.Zero +* * +----------+---------------------+------+------------+---------------------+* * + 4 + wBytesPerInterval + 2 + Number + No of Bytes this EP +* * + + + + + wiil transfer every +* * + + + + + service interval. +* * + + + + + (Periodic EPs only) +* * +----------+---------------------+------+------------+---------------------+* *******************************************************************************/ typedef struct _USBSSEPCompDesc { fld8_t blength; fld8_t bDescriptorType; fld8_t bMaxBurst; fld8_t bmAttributes; #define USB_SS_BULK_MAXSTREAMS_MASK (31<<0) #define USB_SS_ISOCH_MULT_MASK (3<<0) fld16_t wBytesPerInterval; } USBSSEPCompDesc, *PUSBSSEPCompDesc; /*--------------------------------------------------------------------------* * Miscellaneous * *--------------------------------------------------------------------------*/ #define USB_MINPACKET_SS 512 /* Min packet size for Super Speed */ #define USB_MINPACKET_HS 64 /* Min packet size for High Speed */ #define USB_MINPACKET_FS 8 /* Min packet size for Full Speed */ #define USB_MINPACKET_LS 8 /* Min packet size for Low Speed */ #define MAX_DEV_ADDR 127 /* maximum device address */ /* device classes */ #define USB_INFDCLASS 0 #define USB_HUBDCLASS 9 /* interface classes */ #define USB_AUDIOCLASS 1 #define USB_HIDCLASS 3 #define USB_PRINTERCLASS 7 #define USB_MASSSTORAGECLASS 8 #define USB_HUBCLASS 9 #define USB_SMARTCARDCLASS 11 /* feature selectors, USB standard */ #define USB_STD_FS_ENDPOINT_HALT 0 #define USB_STD_FS_DEVICE_REMOTE_WAKEUP 1 #define USB_STD_FS_TEST_MODE 2 #endif /* _H_USB */