1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * (C) Copyright 2001 4 * Denis Peter, MPL AG Switzerland 5 * 6 * Note: Part of this code has been derived from linux 7 */ 8#ifndef _USB_DEFS_H_ 9#define _USB_DEFS_H_ 10 11/* USB constants */ 12 13/* Device and/or Interface Class codes */ 14#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ 15#define USB_CLASS_AUDIO 1 16#define USB_CLASS_COMM 2 17#define USB_CLASS_HID 3 18#define USB_CLASS_PRINTER 7 19#define USB_CLASS_MASS_STORAGE 8 20#define USB_CLASS_HUB 9 21#define USB_CLASS_DATA 10 22#define USB_CLASS_VENDOR_SPEC 0xff 23 24/* some HID sub classes */ 25#define USB_SUB_HID_NONE 0 26#define USB_SUB_HID_BOOT 1 27 28/* some UID Protocols */ 29#define USB_PROT_HID_NONE 0 30#define USB_PROT_HID_KEYBOARD 1 31#define USB_PROT_HID_MOUSE 2 32 33 34/* Sub STORAGE Classes */ 35#define US_SC_RBC 1 /* Typically, flash devices */ 36#define US_SC_8020 2 /* CD-ROM */ 37#define US_SC_QIC 3 /* QIC-157 Tapes */ 38#define US_SC_UFI 4 /* Floppy */ 39#define US_SC_8070 5 /* Removable media */ 40#define US_SC_SCSI 6 /* Transparent */ 41#define US_SC_MIN US_SC_RBC 42#define US_SC_MAX US_SC_SCSI 43 44/* STORAGE Protocols */ 45#define US_PR_CB 1 /* Control/Bulk w/o interrupt */ 46#define US_PR_CBI 0 /* Control/Bulk/Interrupt */ 47#define US_PR_BULK 0x50 /* bulk only */ 48 49/* USB types */ 50#define USB_TYPE_STANDARD (0x00 << 5) 51#define USB_TYPE_CLASS (0x01 << 5) 52#define USB_TYPE_VENDOR (0x02 << 5) 53#define USB_TYPE_RESERVED (0x03 << 5) 54 55/* USB recipients */ 56#define USB_RECIP_DEVICE 0x00 57#define USB_RECIP_INTERFACE 0x01 58#define USB_RECIP_ENDPOINT 0x02 59#define USB_RECIP_OTHER 0x03 60 61/* USB directions */ 62#define USB_DIR_OUT 0 63#define USB_DIR_IN 0x80 64 65/* 66 * bmRequestType: USB Device Requests, table 9.2 USB 2.0 spec. 67 * (shifted) direction/type/recipient. 68 */ 69#define DeviceRequest \ 70 ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE) << 8) 71 72#define DeviceOutRequest \ 73 ((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE) << 8) 74 75#define InterfaceRequest \ 76 ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8) 77 78#define EndpointRequest \ 79 ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8) 80 81#define EndpointOutRequest \ 82 ((USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8) 83 84/* class requests from the USB 2.0 hub spec, table 11-15 */ 85#define HUB_CLASS_REQ(dir, type, request) ((((dir) | (type)) << 8) | (request)) 86/* GetBusState and SetHubDescriptor are optional, omitted */ 87#define ClearHubFeature HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_HUB, \ 88 USB_REQ_CLEAR_FEATURE) 89#define ClearPortFeature HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \ 90 USB_REQ_CLEAR_FEATURE) 91#define GetHubDescriptor HUB_CLASS_REQ(USB_DIR_IN, USB_RT_HUB, \ 92 USB_REQ_GET_DESCRIPTOR) 93#define GetHubStatus HUB_CLASS_REQ(USB_DIR_IN, USB_RT_HUB, \ 94 USB_REQ_GET_STATUS) 95#define GetPortStatus HUB_CLASS_REQ(USB_DIR_IN, USB_RT_PORT, \ 96 USB_REQ_GET_STATUS) 97#define SetHubFeature HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_HUB, \ 98 USB_REQ_SET_FEATURE) 99#define SetPortFeature HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \ 100 USB_REQ_SET_FEATURE) 101#define ClearTTBuffer HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \ 102 HUB_CLEAR_TT_BUFFER) 103#define ResetTT HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \ 104 HUB_RESET_TT) 105#define GetTTState HUB_CLASS_REQ(USB_DIR_IN, USB_RT_PORT, \ 106 HUB_GET_TT_STATE) 107#define StopTT HUB_CLASS_REQ(USB_DIR_OUT, USB_RT_PORT, \ 108 HUB_STOP_TT) 109 110/* Descriptor types */ 111#define USB_DT_DEVICE 0x01 112#define USB_DT_CONFIG 0x02 113#define USB_DT_STRING 0x03 114#define USB_DT_INTERFACE 0x04 115#define USB_DT_ENDPOINT 0x05 116 117#define USB_DT_HID (USB_TYPE_CLASS | 0x01) 118#define USB_DT_REPORT (USB_TYPE_CLASS | 0x02) 119#define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03) 120#define USB_DT_HUB (USB_TYPE_CLASS | 0x09) 121#define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a) 122 123/* Descriptor sizes per descriptor type */ 124#define USB_DT_DEVICE_SIZE 18 125#define USB_DT_CONFIG_SIZE 9 126#define USB_DT_INTERFACE_SIZE 9 127#define USB_DT_ENDPOINT_SIZE 7 128#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ 129#define USB_DT_HUB_NONVAR_SIZE 7 130#define USB_DT_HID_SIZE 9 131 132/* Endpoints */ 133#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ 134#define USB_ENDPOINT_DIR_MASK 0x80 135 136#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ 137#define USB_ENDPOINT_XFER_CONTROL 0 138#define USB_ENDPOINT_XFER_ISOC 1 139#define USB_ENDPOINT_XFER_BULK 2 140#define USB_ENDPOINT_XFER_INT 3 141 142/* USB Packet IDs (PIDs) */ 143#define USB_PID_UNDEF_0 0xf0 144#define USB_PID_OUT 0xe1 145#define USB_PID_ACK 0xd2 146#define USB_PID_DATA0 0xc3 147#define USB_PID_UNDEF_4 0xb4 148#define USB_PID_SOF 0xa5 149#define USB_PID_UNDEF_6 0x96 150#define USB_PID_UNDEF_7 0x87 151#define USB_PID_UNDEF_8 0x78 152#define USB_PID_IN 0x69 153#define USB_PID_NAK 0x5a 154#define USB_PID_DATA1 0x4b 155#define USB_PID_PREAMBLE 0x3c 156#define USB_PID_SETUP 0x2d 157#define USB_PID_STALL 0x1e 158#define USB_PID_UNDEF_F 0x0f 159 160/* Standard requests */ 161#define USB_REQ_GET_STATUS 0x00 162#define USB_REQ_CLEAR_FEATURE 0x01 163#define USB_REQ_SET_FEATURE 0x03 164#define USB_REQ_SET_ADDRESS 0x05 165#define USB_REQ_GET_DESCRIPTOR 0x06 166#define USB_REQ_SET_DESCRIPTOR 0x07 167#define USB_REQ_GET_CONFIGURATION 0x08 168#define USB_REQ_SET_CONFIGURATION 0x09 169#define USB_REQ_GET_INTERFACE 0x0A 170#define USB_REQ_SET_INTERFACE 0x0B 171#define USB_REQ_SYNCH_FRAME 0x0C 172 173/* HID requests */ 174#define USB_REQ_GET_REPORT 0x01 175#define USB_REQ_GET_IDLE 0x02 176#define USB_REQ_GET_PROTOCOL 0x03 177#define USB_REQ_SET_REPORT 0x09 178#define USB_REQ_SET_IDLE 0x0A 179#define USB_REQ_SET_PROTOCOL 0x0B 180 181/* Device features */ 182#define USB_FEAT_HALT 0x00 183#define USB_FEAT_WAKEUP 0x01 184#define USB_FEAT_TEST 0x02 185 186/* Test modes */ 187#define USB_TEST_MODE_J 0x01 188#define USB_TEST_MODE_K 0x02 189#define USB_TEST_MODE_SE0_NAK 0x03 190#define USB_TEST_MODE_PACKET 0x04 191#define USB_TEST_MODE_FORCE_ENABLE 0x05 192 193 194/* 195 * "pipe" definitions, use unsigned so we can compare reliably, since this 196 * value is shifted up to bits 30/31. 197 */ 198#define PIPE_ISOCHRONOUS 0U 199#define PIPE_INTERRUPT 1U 200#define PIPE_CONTROL 2U 201#define PIPE_BULK 3U 202#define PIPE_DEVEP_MASK 0x0007ff00 203 204#define USB_ISOCHRONOUS 0 205#define USB_INTERRUPT 1 206#define USB_CONTROL 2 207#define USB_BULK 3 208 209#define USB_PIPE_TYPE_SHIFT 30 210#define USB_PIPE_TYPE_MASK (3 << USB_PIPE_TYPE_SHIFT) 211 212#define USB_PIPE_DEV_SHIFT 8 213#define USB_PIPE_DEV_MASK (0x7f << USB_PIPE_DEV_SHIFT) 214 215#define USB_PIPE_EP_SHIFT 15 216#define USB_PIPE_EP_MASK (0xf << USB_PIPE_EP_SHIFT) 217 218/* USB-status codes: */ 219#define USB_ST_ACTIVE 0x1 /* TD is active */ 220#define USB_ST_STALLED 0x2 /* TD is stalled */ 221#define USB_ST_BUF_ERR 0x4 /* buffer error */ 222#define USB_ST_BABBLE_DET 0x8 /* Babble detected */ 223#define USB_ST_NAK_REC 0x10 /* NAK Received*/ 224#define USB_ST_CRC_ERR 0x20 /* CRC/timeout Error */ 225#define USB_ST_BIT_ERR 0x40 /* Bitstuff error */ 226#define USB_ST_NOT_PROC 0x80000000L /* Not yet processed */ 227 228 229/************************************************************************* 230 * Hub defines 231 */ 232 233/* 234 * Hub request types 235 */ 236 237#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE) 238#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER) 239 240/* 241 * Hub Class feature numbers 242 */ 243#define C_HUB_LOCAL_POWER 0 244#define C_HUB_OVER_CURRENT 1 245 246/* 247 * Port feature numbers 248 */ 249#define USB_PORT_FEAT_CONNECTION 0 250#define USB_PORT_FEAT_ENABLE 1 251#define USB_PORT_FEAT_SUSPEND 2 252#define USB_PORT_FEAT_OVER_CURRENT 3 253#define USB_PORT_FEAT_RESET 4 254#define USB_PORT_FEAT_POWER 8 255#define USB_PORT_FEAT_LOWSPEED 9 256#define USB_PORT_FEAT_HIGHSPEED 10 257#define USB_PORT_FEAT_C_CONNECTION 16 258#define USB_PORT_FEAT_C_ENABLE 17 259#define USB_PORT_FEAT_C_SUSPEND 18 260#define USB_PORT_FEAT_C_OVER_CURRENT 19 261#define USB_PORT_FEAT_C_RESET 20 262#define USB_PORT_FEAT_TEST 21 263 264/* 265 * Changes to Port feature numbers for Super speed, 266 * from USB 3.0 spec Table 10-8 267 */ 268#define USB_SS_PORT_FEAT_U1_TIMEOUT 23 269#define USB_SS_PORT_FEAT_U2_TIMEOUT 24 270#define USB_SS_PORT_FEAT_C_LINK_STATE 25 271#define USB_SS_PORT_FEAT_C_CONFIG_ERROR 26 272#define USB_SS_PORT_FEAT_BH_RESET 28 273#define USB_SS_PORT_FEAT_C_BH_RESET 29 274 275/* wPortStatus bits */ 276#define USB_PORT_STAT_CONNECTION 0x0001 277#define USB_PORT_STAT_ENABLE 0x0002 278#define USB_PORT_STAT_SUSPEND 0x0004 279#define USB_PORT_STAT_OVERCURRENT 0x0008 280#define USB_PORT_STAT_RESET 0x0010 281#define USB_PORT_STAT_POWER 0x0100 282#define USB_PORT_STAT_LOW_SPEED 0x0200 283#define USB_PORT_STAT_HIGH_SPEED 0x0400 /* support for EHCI */ 284#define USB_PORT_STAT_SUPER_SPEED 0x0600 /* faking support to XHCI */ 285#define USB_PORT_STAT_SPEED_MASK \ 286 (USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED) 287 288/* 289 * Changes to wPortStatus bit field in USB 3.0 290 * See USB 3.0 spec Table 10-10 291 */ 292#define USB_SS_PORT_STAT_LINK_STATE 0x01e0 293#define USB_SS_PORT_STAT_POWER 0x0200 294#define USB_SS_PORT_STAT_SPEED 0x1c00 295#define USB_SS_PORT_STAT_SPEED_5GBPS 0x0000 296/* Bits that are the same from USB 2.0 */ 297#define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION | \ 298 USB_PORT_STAT_ENABLE | \ 299 USB_PORT_STAT_OVERCURRENT | \ 300 USB_PORT_STAT_RESET) 301 302/* wPortChange bits */ 303#define USB_PORT_STAT_C_CONNECTION 0x0001 304#define USB_PORT_STAT_C_ENABLE 0x0002 305#define USB_PORT_STAT_C_SUSPEND 0x0004 306#define USB_PORT_STAT_C_OVERCURRENT 0x0008 307#define USB_PORT_STAT_C_RESET 0x0010 308 309/* 310 * Changes to wPortChange bit fields in USB 3.0 311 * See USB 3.0 spec Table 10-12 312 */ 313#define USB_SS_PORT_STAT_C_BH_RESET 0x0020 314#define USB_SS_PORT_STAT_C_LINK_STATE 0x0040 315#define USB_SS_PORT_STAT_C_CONFIG_ERROR 0x0080 316 317/* wHubCharacteristics (masks) */ 318#define HUB_CHAR_COMMON_OCPM 0x0000 /* All ports Over-Current reporting */ 319#define HUB_CHAR_INDV_PORT_LPSM 0x0001 /* per-port power control */ 320#define HUB_CHAR_NO_LPSM 0x0002 /* no power switching */ 321#define HUB_CHAR_LPSM 0x0003 322#define HUB_CHAR_COMPOUND 0x0004 323#define HUB_CHAR_INDV_PORT_OCPM 0x0008 /* per-port Over-current reporting */ 324#define HUB_CHAR_NO_OCPM 0x0010 /* No Over-current Protection support */ 325#define HUB_CHAR_OCPM 0x0018 326#define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */ 327#define HUB_CHAR_PORTIND 0x0080 /* per-port indicators (LEDs) */ 328 329/* 330 * Hub Status & Hub Change bit masks 331 */ 332#define HUB_STATUS_LOCAL_POWER 0x0001 333#define HUB_STATUS_OVERCURRENT 0x0002 334 335#define HUB_CHANGE_LOCAL_POWER 0x0001 336#define HUB_CHANGE_OVERCURRENT 0x0002 337 338/* Mask for wIndex in get/set port feature */ 339#define USB_HUB_PORT_MASK 0xf 340 341/* Hub class request codes */ 342#define USB_REQ_SET_HUB_DEPTH 0x0c 343 344/* 345 * As of USB 2.0, full/low speed devices are segregated into trees. 346 * One type grows from USB 1.1 host controllers (OHCI, UHCI etc). 347 * The other type grows from high speed hubs when they connect to 348 * full/low speed devices using "Transaction Translators" (TTs). 349 */ 350struct usb_tt { 351 bool multi; /* true means one TT per port */ 352 unsigned think_time; /* think time in ns */ 353}; 354 355/* 356 * CBI style 357 */ 358 359#define US_CBI_ADSC 0 360 361/* Command Block Wrapper */ 362struct umass_bbb_cbw { 363 __u32 dCBWSignature; 364# define CBWSIGNATURE 0x43425355 365 __u32 dCBWTag; 366 __u32 dCBWDataTransferLength; 367 __u8 bCBWFlags; 368# define CBWFLAGS_OUT 0x00 369# define CBWFLAGS_IN 0x80 370# define CBWFLAGS_SBZ 0x7f 371 __u8 bCBWLUN; 372 __u8 bCDBLength; 373# define CBWCDBLENGTH 16 374 __u8 CBWCDB[CBWCDBLENGTH]; 375}; 376#define UMASS_BBB_CBW_SIZE 31 377 378/* Command Status Wrapper */ 379struct umass_bbb_csw { 380 __u32 dCSWSignature; 381# define CSWSIGNATURE 0x53425355 382 __u32 dCSWTag; 383 __u32 dCSWDataResidue; 384 __u8 bCSWStatus; 385# define CSWSTATUS_GOOD 0x0 386# define CSWSTATUS_FAILED 0x1 387# define CSWSTATUS_PHASE 0x2 388}; 389#define UMASS_BBB_CSW_SIZE 13 390 391/* 392 * BULK only 393 */ 394#define US_BBB_RESET 0xff 395#define US_BBB_GET_MAX_LUN 0xfe 396 397#endif /*_USB_DEFS_H_ */ 398