| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806 |
- #ifndef _USB_H_
- #define _USB_H_
- #include "typedef.h"
- #define cpu_to_le16(x) (x)
- #define le16_to_cpu(x) (x)
- #define le32_to_cpu(x) (x)
- #define cpu_to_le32(x) (x)
- #define be32_to_cpu(x) ((((x) >> 24) & 0xff) | ((((x) >> 16) & 0xff) << 8) | \
- ((((x) >> 8) & 0xff) << 16) | (((x) & 0xff) << 24))
- #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
- ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
- ((x & 0xffff0000) ? 16 : 0))
- /* Everything is aribtrary */
- #define USB_ALTSETTINGALLOC 4
- #define USB_MAXALTSETTING 128 /* Hard limit */
- #define USB_MAX_DEVICE 2
- #define USB_MAXINTERFACES 2
- #define USB_MAXENDPOINTS 4
- #define USB_MAXCHILDREN 4 /* This is arbitrary */
- #define USB_MAX_HUB 1
- #define USB_MAX_STOR_DEV 1
- #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
- /* Sub STORAGE Classes */
- #define US_SC_RBC 1 /* Typically, flash devices */
- #define US_SC_8020 2 /* CD-ROM */
- #define US_SC_QIC 3 /* QIC-157 Tapes */
- #define US_SC_UFI 4 /* Floppy */
- #define US_SC_8070 5 /* Removable media */
- #define US_SC_SCSI 6 /* Transparent */
- #define US_SC_MIN US_SC_RBC
- #define US_SC_MAX US_SC_SCSI
- /* STORAGE Protocols */
- #define US_PR_CB 1 /* Control/Bulk w/o interrupt */
- #define US_PR_CBI 0 /* Control/Bulk/Interrupt */
- #define US_PR_BULK 0x50 /* bulk only */
- /* USB types */
- #define USB_TYPE_STANDARD (0x00 << 5)
- #define USB_TYPE_CLASS (0x01 << 5)
- #define USB_TYPE_VENDOR (0x02 << 5)
- #define USB_TYPE_RESERVED (0x03 << 5)
- /* USB recipients */
- #define USB_RECIP_DEVICE 0x00
- #define USB_RECIP_INTERFACE 0x01
- #define USB_RECIP_ENDPOINT 0x02
- #define USB_RECIP_OTHER 0x03
- /* Endpoints */
- #define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
- #define USB_ENDPOINT_DIR_MASK 0x80
- #define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
- #define USB_ENDPOINT_XFER_CONTROL 0
- #define USB_ENDPOINT_XFER_ISOC 1
- #define USB_ENDPOINT_XFER_BULK 2
- #define USB_ENDPOINT_XFER_INT 3
- /* USB Packet IDs (PIDs) */
- #define USB_PID_UNDEF_0 0xf0
- #define USB_PID_OUT 0xe1
- #define USB_PID_ACK 0xd2
- #define USB_PID_DATA0 0xc3
- #define USB_PID_UNDEF_4 0xb4
- #define USB_PID_SOF 0xa5
- #define USB_PID_UNDEF_6 0x96
- #define USB_PID_UNDEF_7 0x87
- #define USB_PID_UNDEF_8 0x78
- #define USB_PID_IN 0x69
- #define USB_PID_NAK 0x5a
- #define USB_PID_DATA1 0x4b
- #define USB_PID_PREAMBLE 0x3c
- #define USB_PID_SETUP 0x2d
- #define USB_PID_STALL 0x1e
- #define USB_PID_UNDEF_F 0x0f
- /*
- * "pipe" definitions, use unsigned so we can compare reliably, since this
- * value is shifted up to bits 30/31.
- */
- #define PIPE_ISOCHRONOUS 0U
- #define PIPE_INTERRUPT 1U
- #define PIPE_CONTROL 2U
- #define PIPE_BULK 3U
- #define PIPE_DEVEP_MASK 0x0007ff00
- #define USB_ISOCHRONOUS 0
- #define USB_INTERRUPT 1
- #define USB_CONTROL 2
- #define USB_BULK 3
- #define USB_PIPE_TYPE_SHIFT 30
- #define USB_PIPE_TYPE_MASK (3 << USB_PIPE_TYPE_SHIFT)
- #define USB_PIPE_DEV_SHIFT 8
- #define USB_PIPE_DEV_MASK (0x7f << USB_PIPE_DEV_SHIFT)
- #define USB_PIPE_EP_SHIFT 15
- #define USB_PIPE_EP_MASK (0xf << USB_PIPE_EP_SHIFT)
- /* USB-status codes: */
- #define USB_ST_ACTIVE 0x1 /* TD is active */
- #define USB_ST_STALLED 0x2 /* TD is stalled */
- #define USB_ST_BUF_ERR 0x4 /* buffer error */
- #define USB_ST_BABBLE_DET 0x8 /* Babble detected */
- #define USB_ST_NAK_REC 0x10 /* NAK Received*/
- #define USB_ST_CRC_ERR 0x20 /* CRC/timeout Error */
- #define USB_ST_BIT_ERR 0x40 /* Bitstuff error */
- #define USB_ST_NOT_PROC 0x80000000L /* Not yet processed */
- /*
- * Hub request types
- */
- #define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
- #define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
- /*
- * Port feature numbers
- */
- #define USB_PORT_FEAT_CONNECTION 0
- #define USB_PORT_FEAT_ENABLE 1
- #define USB_PORT_FEAT_SUSPEND 2
- #define USB_PORT_FEAT_OVER_CURRENT 3
- #define USB_PORT_FEAT_RESET 4
- #define USB_PORT_FEAT_POWER 8
- #define USB_PORT_FEAT_LOWSPEED 9
- #define USB_PORT_FEAT_HIGHSPEED 10
- #define USB_PORT_FEAT_C_CONNECTION 16
- #define USB_PORT_FEAT_C_ENABLE 17
- #define USB_PORT_FEAT_C_SUSPEND 18
- #define USB_PORT_FEAT_C_OVER_CURRENT 19
- #define USB_PORT_FEAT_C_RESET 20
- #define USB_PORT_FEAT_TEST 21
- /*
- * Changes to Port feature numbers for Super speed,
- * from USB 3.0 spec Table 10-8
- */
- #define USB_SS_PORT_FEAT_U1_TIMEOUT 23
- #define USB_SS_PORT_FEAT_U2_TIMEOUT 24
- #define USB_SS_PORT_FEAT_C_LINK_STATE 25
- #define USB_SS_PORT_FEAT_C_CONFIG_ERROR 26
- #define USB_SS_PORT_FEAT_BH_RESET 28
- #define USB_SS_PORT_FEAT_C_BH_RESET 29
- /* wPortStatus bits */
- #define USB_PORT_STAT_CONNECTION 0x0001
- #define USB_PORT_STAT_ENABLE 0x0002
- #define USB_PORT_STAT_SUSPEND 0x0004
- #define USB_PORT_STAT_OVERCURRENT 0x0008
- #define USB_PORT_STAT_RESET 0x0010
- #define USB_PORT_STAT_POWER 0x0100
- #define USB_PORT_STAT_LOW_SPEED 0x0200
- #define USB_PORT_STAT_HIGH_SPEED 0x0400 /* support for EHCI */
- #define USB_PORT_STAT_SUPER_SPEED 0x0600 /* faking support to XHCI */
- #define USB_PORT_STAT_SPEED_MASK \
- (USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED)
- /* wPortChange bits */
- #define USB_PORT_STAT_C_CONNECTION 0x0001
- #define USB_PORT_STAT_C_ENABLE 0x0002
- #define USB_PORT_STAT_C_SUSPEND 0x0004
- #define USB_PORT_STAT_C_OVERCURRENT 0x0008
- #define USB_PORT_STAT_C_RESET 0x0010
- /*
- * Changes to wPortChange bit fields in USB 3.0
- * See USB 3.0 spec Table 10-12
- */
- #define USB_SS_PORT_STAT_C_BH_RESET 0x0020
- #define USB_SS_PORT_STAT_C_LINK_STATE 0x0040
- #define USB_SS_PORT_STAT_C_CONFIG_ERROR 0x0080
- /* wHubCharacteristics (masks) */
- #define HUB_CHAR_LPSM 0x0003
- #define HUB_CHAR_COMPOUND 0x0004
- #define HUB_CHAR_OCPM 0x0018
- #define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */
- #define USB_DIR_OUT 0 /* to device */
- #define USB_DIR_IN 0x80 /* to host */
- /*
- * Standard requests, for the bRequest field of a SETUP packet.
- *
- * These are qualified by the bRequestType field, so that for example
- * TYPE_CLASS or TYPE_VENDOR specific feature flags could be retrieved
- * by a GET_STATUS request.
- */
- #define USB_REQ_GET_STATUS 0x00
- #define USB_REQ_CLEAR_FEATURE 0x01
- #define USB_REQ_SET_FEATURE 0x03
- #define USB_REQ_SET_ADDRESS 0x05
- #define USB_REQ_GET_DESCRIPTOR 0x06
- #define USB_REQ_SET_DESCRIPTOR 0x07
- #define USB_REQ_GET_CONFIGURATION 0x08
- #define USB_REQ_SET_CONFIGURATION 0x09
- #define USB_REQ_GET_INTERFACE 0x0A
- #define USB_REQ_SET_INTERFACE 0x0B
- #define USB_REQ_SYNCH_FRAME 0x0C
- #define USB_REQ_SET_SEL 0x30
- #define USB_REQ_SET_ISOCH_DELAY 0x31
- #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */
- #define USB_REQ_GET_ENCRYPTION 0x0E
- #define USB_REQ_RPIPE_ABORT 0x0E
- #define USB_REQ_SET_HANDSHAKE 0x0F
- #define USB_REQ_RPIPE_RESET 0x0F
- #define USB_REQ_GET_HANDSHAKE 0x10
- #define USB_REQ_SET_CONNECTION 0x11
- #define USB_REQ_SET_SECURITY_DATA 0x12
- #define USB_REQ_GET_SECURITY_DATA 0x13
- #define USB_REQ_SET_WUSB_DATA 0x14
- #define USB_REQ_LOOPBACK_DATA_WRITE 0x15
- #define USB_REQ_LOOPBACK_DATA_READ 0x16
- #define USB_REQ_SET_INTERFACE_DS 0x17
- /*
- * Descriptor types ... USB 2.0 spec table 9.5
- */
- #define USB_DT_DEVICE 0x01
- #define USB_DT_CONFIG 0x02
- #define USB_DT_STRING 0x03
- #define USB_DT_INTERFACE 0x04
- #define USB_DT_ENDPOINT 0x05
- #define USB_DT_DEVICE_QUALIFIER 0x06
- #define USB_DT_OTHER_SPEED_CONFIG 0x07
- #define USB_DT_INTERFACE_POWER 0x08
- #define USB_DT_HID (USB_TYPE_CLASS | 0x01)
- #define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
- #define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
- #define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
- #define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)
- /* these are from a minor usb 2.0 revision (ECN) */
- #define USB_DT_OTG 0x09
- #define USB_DT_DEBUG 0x0a
- #define USB_DT_INTERFACE_ASSOCIATION 0x0b
- /* these are from the Wireless USB spec */
- #define USB_DT_SECURITY 0x0c
- #define USB_DT_KEY 0x0d
- #define USB_DT_ENCRYPTION_TYPE 0x0e
- #define USB_DT_BOS 0x0f
- #define USB_DT_DEVICE_CAPABILITY 0x10
- #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
- #define USB_DT_WIRE_ADAPTER 0x21
- #define USB_DT_RPIPE 0x22
- #define USB_DT_CS_RADIO_CONTROL 0x23
- /* From the T10 UAS specification */
- #define USB_DT_PIPE_USAGE 0x24
- /* From the USB 3.0 spec */
- #define USB_DT_SS_ENDPOINT_COMP 0x30
- /* From HID 1.11 spec */
- #define USB_DT_HID_REPORT 0x22
- /*-------------------------------------------------------------------------*/
- /* USB 2.0 defines three speeds, here's how Linux identifies them */
- enum usb_device_speed {
- USB_SPEED_UNKNOWN = 0, /* enumerating */
- USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
- USB_SPEED_HIGH, /* usb 2.0 */
- USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
- USB_SPEED_SUPER, /* usb 3.0 */
- };
- /* Create various pipes... */
- #define create_pipe(dev,endpoint) \
- (((dev)->devnum << 8) | ((endpoint) << 15) | \
- (dev)->maxpacketsize)
- #define default_pipe(dev) ((dev)->speed << 26)
- #define usb_sndctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
- create_pipe(dev, endpoint))
- #define usb_rcvctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
- create_pipe(dev, endpoint) | \
- USB_DIR_IN)
- #define usb_sndisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
- create_pipe(dev, endpoint))
- #define usb_rcvisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
- create_pipe(dev, endpoint) | \
- USB_DIR_IN)
- #define usb_sndbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
- create_pipe(dev, endpoint))
- #define usb_rcvbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
- create_pipe(dev, endpoint) | \
- USB_DIR_IN)
- #define usb_sndintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
- create_pipe(dev, endpoint))
- #define usb_rcvintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
- create_pipe(dev, endpoint) | \
- USB_DIR_IN)
- #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | \
- default_pipe(dev))
- #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | \
- default_pipe(dev) | \
- USB_DIR_IN)
- /* The D0/D1 toggle bits */
- #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
- #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
- #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
- ((dev)->toggle[out] & \
- ~(1 << ep)) | ((bit) << ep))
- /* Endpoint halt control/status */
- #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
- #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
- #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
- #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
- #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \
- USB_PID_OUT)
- #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
- #define usb_pipein(pipe) (((pipe) >> 7) & 1)
- #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
- #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
- #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
- #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
- #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
- #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
- #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
- #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
- #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
- #define usb_pipe_ep_index(pipe) \
- usb_pipecontrol(pipe) ? (usb_pipeendpoint(pipe) * 2) : \
- ((usb_pipeendpoint(pipe) * 2) - \
- (usb_pipein(pipe) ? 0 : 1))
- #define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
- /* All standard descriptors have these 2 fields at the beginning */
- __packed struct usb_descriptor_header {
- u8 bLength;
- u8 bDescriptorType;
- };
- __packed struct usb_device_descriptor {
- u8 bLength;
- u8 bDescriptorType; /* 0x01 */
- u16 bcdUSB;
- u8 bDeviceClass;
- u8 bDeviceSubClass;
- u8 bDeviceProtocol;
- u8 bMaxPacketSize0;
- u16 idVendor;
- u16 idProduct;
- u16 bcdDevice;
- u8 iManufacturer;
- u8 iProduct;
- u8 iSerialNumber;
- u8 bNumConfigurations;
- };
- #define USB_DT_DEVICE_SIZE 18
- /*
- * Device and/or Interface Class codes
- * as found in bDeviceClass or bInterfaceClass
- * and defined by www.usb.org documents
- */
- #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
- #define USB_CLASS_AUDIO 1
- #define USB_CLASS_COMM 2
- #define USB_CLASS_HID 3
- #define USB_CLASS_PHYSICAL 5
- #define USB_CLASS_STILL_IMAGE 6
- #define USB_CLASS_PRINTER 7
- #define USB_CLASS_MASS_STORAGE 8
- #define USB_CLASS_HUB 9
- #define USB_CLASS_CDC_DATA 0x0a
- #define USB_CLASS_CSCID 0x0b /* chip+ smart card */
- #define USB_CLASS_CONTENT_SEC 0x0d /* content security */
- #define USB_CLASS_VIDEO 0x0e
- #define USB_CLASS_WIRELESS_CONTROLLER 0xe0
- #define USB_CLASS_MISC 0xef
- #define USB_CLASS_APP_SPEC 0xfe
- #define USB_CLASS_VENDOR_SPEC 0xff
- #define USB_SUBCLASS_VENDOR_SPEC 0xff
- __packed struct usb_config_descriptor {
- u8 bLength;
- u8 bDescriptorType;
- u16 wTotalLength;
- u8 bNumInterfaces;
- u8 bConfigurationValue;
- u8 iConfiguration;
- u8 bmAttributes;
- u8 bMaxPower;
- };
- #define USB_DT_CONFIG_SIZE 9
- /* USB_DT_INTERFACE: Interface descriptor */
- __packed struct usb_interface_descriptor {
- u8 bLength;
- u8 bDescriptorType;
- u8 bInterfaceNumber;
- u8 bAlternateSetting;
- u8 bNumEndpoints;
- u8 bInterfaceClass;
- u8 bInterfaceSubClass;
- u8 bInterfaceProtocol;
- u8 iInterface;
- };
- #define USB_DT_INTERFACE_SIZE 9
- /*-------------------------------------------------------------------------*/
- /* USB_DT_ENDPOINT: Endpoint descriptor */
- __packed struct usb_endpoint_descriptor {
- u8 bLength;
- u8 bDescriptorType;
- u8 bEndpointAddress;
- u8 bmAttributes;
- u16 wMaxPacketSize;
- u8 bInterval;
- /* NOTE: these two are _only_ in audio endpoints. */
- /* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
- u8 bRefresh;
- u8 bSynchAddress;
- };
- #define USB_DT_ENDPOINT_SIZE 7
- #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
- /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
- __packed struct usb_ss_ep_comp_descriptor {
- u8 bLength;
- u8 bDescriptorType;
- u8 bMaxBurst;
- u8 bmAttributes;
- u16 wBytesPerInterval;
- };
- #define USB_DT_SS_EP_COMP_SIZE 6
- /*
- * This is the timeout to allow for submitting an urb in ms. We allow more
- * time for a BULK device to react - some are slow.
- */
- //#define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000)
- /* device request (setup) */
- __packed struct devrequest {
- u8 requesttype;
- u8 request;
- u16 value;
- u16 index;
- u16 length;
- };
- /* Interface */
- __packed struct usb_interface {
- struct usb_interface_descriptor desc;
- u8 no_of_ep;
- u8 num_altsetting;
- u8 act_altsetting;
- struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
- /*
- * Super Speed Device will have Super Speed Endpoint
- * Companion Descriptor (section 9.6.7 of usb 3.0 spec)
- * Revision 1.0 June 6th 2011
- */
- struct usb_ss_ep_comp_descriptor ss_ep_comp_desc[USB_MAXENDPOINTS];
- };
- /* Configuration information.. */
- __packed struct usb_config {
- struct usb_config_descriptor desc;
- u8 no_of_if; /* number of interfaces */
- struct usb_interface if_desc[USB_MAXINTERFACES];
- };
- enum {
- /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
- PACKET_SIZE_8 = 0,
- PACKET_SIZE_16 = 1,
- PACKET_SIZE_32 = 2,
- PACKET_SIZE_64 = 3,
- };
- /**
- * struct usb_device - information about a USB device
- */
- struct usb_device {
- int devnum; /* Device number on USB bus */
- int speed; /* full/low/high */
- char mf[32]; /* manufacturer */
- char prod[32]; /* product */
- char serial[32]; /* serial number */
- /* Maximum packet size; one of: PACKET_SIZE_* */
- int maxpacketsize;
- /* one bit for each endpoint ([0] = IN, [1] = OUT) */
- unsigned int toggle[2];
- /* endpoint halts; one bit per endpoint # & direction;
- * [0] = IN, [1] = OUT
- */
- unsigned int halted[2];
- int epmaxpacketin[16]; /* INput endpoint specific maximums */
- int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
- int configno; /* selected config number */
- /* Device Descriptor */
- #pragma pack(ARCH_DMA_MINALIGN)
- struct usb_device_descriptor descriptor;
- struct usb_config config; /* config descriptor */
- int have_langid; /* whether string_langid is valid yet */
- int string_langid; /* language ID for strings */
- int (*irq_handle)(struct usb_device *dev);
- unsigned long irq_status;
- int irq_act_len; /* transferred bytes */
- void *privptr;
- /*
- * Child devices - if this is a hub device
- * Each instance needs its own set of data structures.
- */
- unsigned long status;
- unsigned long int_pending; /* 1 bit per ep, used by int_queue */
- int act_len; /* transferred bytes */
- int maxchild; /* Number of ports if hub */
- int portnr; /* Port number, 1=first */
- /* parent hub, or NULL if this is the root hub */
- struct usb_device *parent;
- struct usb_device *children[USB_MAXCHILDREN];
- void *controller; /* hardware controller private data */
-
- /* slot_id - for xHCI enabled devices */
- unsigned int slot_id;
- };
- enum usb_init_type {
- USB_INIT_HOST,
- USB_INIT_DEVICE
- };
- /*************************************************************************
- * Hub Stuff
- */
- __packed struct usb_port_status {
- unsigned short wPortStatus;
- unsigned short wPortChange;
- };
- __packed struct usb_hub_status {
- unsigned short wHubStatus;
- unsigned short wHubChange;
- };
- /*
- * Hub Device descriptor
- * USB Hub class device protocols
- */
- #define USB_HUB_PR_FS 0 /* Full speed hub */
- #define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */
- #define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */
- #define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */
- #define USB_HUB_PR_SS 3 /* Super speed hub */
- /* Transaction Translator Think Times, in bits */
- #define HUB_TTTT_8_BITS 0x00
- #define HUB_TTTT_16_BITS 0x20
- #define HUB_TTTT_24_BITS 0x40
- #define HUB_TTTT_32_BITS 0x60
- /* Hub descriptor */
- __packed struct usb_hub_descriptor {
- unsigned char bLength;
- unsigned char bDescriptorType;
- unsigned char bNbrPorts;
- unsigned short wHubCharacteristics;
- unsigned char bPwrOn2PwrGood;
- unsigned char bHubContrCurrent;
- /* 2.0 and 3.0 hubs differ here */
- union {
- __packed struct {
- /* add 1 bit for hub status change; round to bytes */
- unsigned char DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
- unsigned char PortPowerCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
- } hs;
- __packed struct {
- unsigned char bHubHdrDecLat;
- unsigned short wHubDelay;
- unsigned short DeviceRemovable;
- }ss;
- } u;
- };
- struct usb_tt {
- bool multi; /* true means one TT per port */
- unsigned think_time; /* think time in ns */
- };
- void usb_find_usb2_hub_address_port(struct usb_device *udev,
- uint8_t *hub_address, uint8_t *hub_port);
- /*
- * CBI style
- */
- #define US_CBI_ADSC 0
- /* Command Block Wrapper */
- #define CBWSIGNATURE 0x43425355
- #define CBWFLAGS_OUT 0x00
- #define CBWFLAGS_IN 0x80
- #define CBWFLAGS_SBZ 0x7f
- #define CBWCDBLENGTH 16
- struct umass_bbb_cbw {
- u32 dCBWSignature;
- u32 dCBWTag;
- u32 dCBWDataTransferLength;
- u8 bCBWFlags;
- u8 bCBWLUN;
- u8 bCDBLength;
- u8 CBWCDB[CBWCDBLENGTH];
- };
- #define UMASS_BBB_CBW_SIZE 31
- #define CSWSIGNATURE 0x53425355
- #define CSWSTATUS_GOOD 0x0
- #define CSWSTATUS_FAILED 0x1
- #define CSWSTATUS_PHASE 0x2
- /* Command Status Wrapper */
- struct umass_bbb_csw {
- u32 dCSWSignature;
- u32 dCSWTag;
- u32 dCSWDataResidue;
- u8 bCSWStatus;
- };
- #define UMASS_BBB_CSW_SIZE 13
- /*
- * BULK only
- */
- #define US_BBB_RESET 0xff
- #define US_BBB_GET_MAX_LUN 0xfe
- struct usb_hub_device {
- struct usb_device *pusb_dev;
- struct usb_hub_descriptor desc;
- unsigned long connect_timeout; /* Device connection timeout in ms */
- unsigned long query_delay; /* Device query delay in ms */
- int overcurrent_count[USB_MAXCHILDREN]; /* Over-current counter */
- int hub_depth; /* USB 3.0 hub depth */
- struct usb_tt tt; /* Transaction Translator */
- };
- /* Device descriptor */
- static unsigned char root_hub_dev_des[] = {
- 0x12, /* __u8 bLength; */
- 0x01, /* __u8 bDescriptorType; Device */
- 0x10, /* __u16 bcdUSB; v1.1 */
- 0x01,
- 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
- 0x00, /* __u8 bDeviceSubClass; */
- 0x00, /* __u8 bDeviceProtocol; */
- 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
- 0x00, /* __u16 idVendor; */
- 0x00,
- 0x00, /* __u16 idProduct; */
- 0x00,
- 0x00, /* __u16 bcdDevice; */
- 0x00,
- 0x00, /* __u8 iManufacturer; */
- 0x01, /* __u8 iProduct; */
- 0x00, /* __u8 iSerialNumber; */
- 0x01, /* __u8 bNumConfigurations; */
- };
- /* Configuration descriptor */
- static unsigned char root_hub_config_des[] = {
- 0x09, /* __u8 bLength; */
- 0x02, /* __u8 bDescriptorType; Configuration */
- 0x19, /* __u16 wTotalLength; */
- 0x00,
- 0x01, /* __u8 bNumInterfaces; */
- 0x01, /* __u8 bConfigurationValue; */
- 0x00, /* __u8 iConfiguration; */
- 0x40, /* __u8 bmAttributes;
- * Bit 7: Bus-powered
- * 6: Self-powered,
- * 5 Remote-wakwup,
- * 4..0: resvd
- */
- 0x00, /* __u8 MaxPower; */
- /* interface */
- 0x09, /* __u8 if_bLength; */
- 0x04, /* __u8 if_bDescriptorType; Interface */
- 0x00, /* __u8 if_bInterfaceNumber; */
- 0x00, /* __u8 if_bAlternateSetting; */
- 0x01, /* __u8 if_bNumEndpoints; */
- 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
- 0x00, /* __u8 if_bInterfaceSubClass; */
- 0x00, /* __u8 if_bInterfaceProtocol; */
- 0x00, /* __u8 if_iInterface; */
- /* endpoint */
- 0x07, /* __u8 ep_bLength; */
- 0x05, /* __u8 ep_bDescriptorType; Endpoint */
- 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
- 0x03, /* __u8 ep_bmAttributes; Interrupt */
- 0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
- 0x00,
- 0xff, /* __u8 ep_bInterval; 255 ms */
- };
- #if 0
- #ifdef WANT_USB_ROOT_HUB_HUB_DES
- static unsigned char root_hub_hub_des[] = {
- 0x09, /* __u8 bLength; */
- 0x29, /* __u8 bDescriptorType; Hub-descriptor */
- 0x02, /* __u8 bNbrPorts; */
- 0x00, /* __u16 wHubCharacteristics; */
- 0x00,
- 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
- 0x00, /* __u8 bHubContrCurrent; 0 mA */
- 0x00, /* __u8 DeviceRemovable; *** 7 Ports max *** */
- 0xff, /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
- };
- #endif
- #endif
- static unsigned char root_hub_str_index0[] = {
- 0x04, /* __u8 bLength; */
- 0x03, /* __u8 bDescriptorType; String-descriptor */
- 0x09, /* __u8 lang ID */
- 0x04, /* __u8 lang ID */
- };
- static unsigned char root_hub_str_index1[] = {
- 32, /* __u8 bLength; */
- 0x03, /* __u8 bDescriptorType; String-descriptor */
- 'U', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- '-', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'B', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'o', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'o', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 't', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- ' ', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'R', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'o', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'o', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 't', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- ' ', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'H', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'u', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- 'b', /* __u8 Unicode */
- 0, /* __u8 Unicode */
- };
- //sdp
- #define EP0_CON 0
- #define EP_MASK 0xF
- int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
- #endif
|