306 lines · c
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */2/*3 * This file holds Hub protocol constants and data structures that are4 * defined in chapter 11 (Hub Specification) of the USB 2.0 specification.5 *6 * It is used/shared between the USB core, the HCDs and couple of other USB7 * drivers.8 */9 10#ifndef __LINUX_CH11_H11#define __LINUX_CH11_H12 13#include <linux/types.h> /* __u8 etc */14 15/* This is arbitrary.16 * From USB 2.0 spec Table 11-13, offset 7, a hub can17 * have up to 255 ports. The most yet reported is 10.18 * Upcoming hardware might raise that limit.19 * Because the arrays need to add a bit for hub status data, we20 * use 31, so plus one evens out to four bytes.21 */22#define USB_MAXCHILDREN 3123 24/* See USB 3.1 spec Table 10-5 */25#define USB_SS_MAXPORTS 1526 27/*28 * Hub request types29 */30 31#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)32#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)33 34/*35 * Port status type for GetPortStatus requests added in USB 3.136 * See USB 3.1 spec Table 10-1237 */38#define HUB_PORT_STATUS 039#define HUB_PORT_PD_STATUS 140#define HUB_EXT_PORT_STATUS 241 42/*43 * Hub class requests44 * See USB 2.0 spec Table 11-1645 */46#define HUB_CLEAR_TT_BUFFER 847#define HUB_RESET_TT 948#define HUB_GET_TT_STATE 1049#define HUB_STOP_TT 1150 51/*52 * Hub class additional requests defined by USB 3.0 spec53 * See USB 3.0 spec Table 10-654 */55#define HUB_SET_DEPTH 1256#define HUB_GET_PORT_ERR_COUNT 1357 58/*59 * Hub Class feature numbers60 * See USB 2.0 spec Table 11-1761 */62#define C_HUB_LOCAL_POWER 063#define C_HUB_OVER_CURRENT 164 65/*66 * Port feature numbers67 * See USB 2.0 spec Table 11-1768 */69#define USB_PORT_FEAT_CONNECTION 070#define USB_PORT_FEAT_ENABLE 171#define USB_PORT_FEAT_SUSPEND 2 /* L2 suspend */72#define USB_PORT_FEAT_OVER_CURRENT 373#define USB_PORT_FEAT_RESET 474#define USB_PORT_FEAT_L1 5 /* L1 suspend */75#define USB_PORT_FEAT_POWER 876#define USB_PORT_FEAT_LOWSPEED 9 /* Should never be used */77#define USB_PORT_FEAT_C_CONNECTION 1678#define USB_PORT_FEAT_C_ENABLE 1779#define USB_PORT_FEAT_C_SUSPEND 1880#define USB_PORT_FEAT_C_OVER_CURRENT 1981#define USB_PORT_FEAT_C_RESET 2082#define USB_PORT_FEAT_TEST 2183#define USB_PORT_FEAT_INDICATOR 2284#define USB_PORT_FEAT_C_PORT_L1 2385 86/*87 * Port feature selectors added by USB 3.0 spec.88 * See USB 3.0 spec Table 10-789 */90#define USB_PORT_FEAT_LINK_STATE 591#define USB_PORT_FEAT_U1_TIMEOUT 2392#define USB_PORT_FEAT_U2_TIMEOUT 2493#define USB_PORT_FEAT_C_PORT_LINK_STATE 2594#define USB_PORT_FEAT_C_PORT_CONFIG_ERROR 2695#define USB_PORT_FEAT_REMOTE_WAKE_MASK 2796#define USB_PORT_FEAT_BH_PORT_RESET 2897#define USB_PORT_FEAT_C_BH_PORT_RESET 2998#define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 3099 100#define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8)101 102/* USB 3.0 hub remote wake mask bits, see table 10-14 */103#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8)104#define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9)105#define USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT (1 << 10)106 107/*108 * Hub Status and Hub Change results109 * See USB 2.0 spec Table 11-19 and Table 11-20110 * USB 3.1 extends the port status request and may return 4 additional bytes.111 * See USB 3.1 spec section 10.16.2.6 Table 10-12 and 10-15112 */113struct usb_port_status {114 __le16 wPortStatus;115 __le16 wPortChange;116 __le32 dwExtPortStatus;117} __attribute__ ((packed));118 119/*120 * wPortStatus bit field121 * See USB 2.0 spec Table 11-21122 */123#define USB_PORT_STAT_CONNECTION 0x0001124#define USB_PORT_STAT_ENABLE 0x0002125#define USB_PORT_STAT_SUSPEND 0x0004126#define USB_PORT_STAT_OVERCURRENT 0x0008127#define USB_PORT_STAT_RESET 0x0010128#define USB_PORT_STAT_L1 0x0020129/* bits 6 to 7 are reserved */130#define USB_PORT_STAT_POWER 0x0100131#define USB_PORT_STAT_LOW_SPEED 0x0200132#define USB_PORT_STAT_HIGH_SPEED 0x0400133#define USB_PORT_STAT_TEST 0x0800134#define USB_PORT_STAT_INDICATOR 0x1000135/* bits 13 to 15 are reserved */136 137/*138 * Additions to wPortStatus bit field from USB 3.0139 * See USB 3.0 spec Table 10-10140 */141#define USB_PORT_STAT_LINK_STATE 0x01e0142#define USB_SS_PORT_STAT_POWER 0x0200143#define USB_SS_PORT_STAT_SPEED 0x1c00144#define USB_PORT_STAT_SPEED_5GBPS 0x0000145/* Valid only if port is enabled */146/* Bits that are the same from USB 2.0 */147#define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION | \148 USB_PORT_STAT_ENABLE | \149 USB_PORT_STAT_OVERCURRENT | \150 USB_PORT_STAT_RESET)151 152/*153 * Definitions for PORT_LINK_STATE values154 * (bits 5-8) in wPortStatus155 */156#define USB_SS_PORT_LS_U0 0x0000157#define USB_SS_PORT_LS_U1 0x0020158#define USB_SS_PORT_LS_U2 0x0040159#define USB_SS_PORT_LS_U3 0x0060160#define USB_SS_PORT_LS_SS_DISABLED 0x0080161#define USB_SS_PORT_LS_RX_DETECT 0x00a0162#define USB_SS_PORT_LS_SS_INACTIVE 0x00c0163#define USB_SS_PORT_LS_POLLING 0x00e0164#define USB_SS_PORT_LS_RECOVERY 0x0100165#define USB_SS_PORT_LS_HOT_RESET 0x0120166#define USB_SS_PORT_LS_COMP_MOD 0x0140167#define USB_SS_PORT_LS_LOOPBACK 0x0160168 169/*170 * wPortChange bit field171 * See USB 2.0 spec Table 11-22 and USB 2.0 LPM ECN Table-4.10172 * Bits 0 to 5 shown, bits 6 to 15 are reserved173 */174#define USB_PORT_STAT_C_CONNECTION 0x0001175#define USB_PORT_STAT_C_ENABLE 0x0002176#define USB_PORT_STAT_C_SUSPEND 0x0004177#define USB_PORT_STAT_C_OVERCURRENT 0x0008178#define USB_PORT_STAT_C_RESET 0x0010179#define USB_PORT_STAT_C_L1 0x0020180/*181 * USB 3.0 wPortChange bit fields182 * See USB 3.0 spec Table 10-11183 */184#define USB_PORT_STAT_C_BH_RESET 0x0020185#define USB_PORT_STAT_C_LINK_STATE 0x0040186#define USB_PORT_STAT_C_CONFIG_ERROR 0x0080187 188/*189 * USB 3.1 dwExtPortStatus field masks190 * See USB 3.1 spec 10.16.2.6.3 Table 10-15191 */192 193#define USB_EXT_PORT_STAT_RX_SPEED_ID 0x0000000f194#define USB_EXT_PORT_STAT_TX_SPEED_ID 0x000000f0195#define USB_EXT_PORT_STAT_RX_LANES 0x00000f00196#define USB_EXT_PORT_STAT_TX_LANES 0x0000f000197 198#define USB_EXT_PORT_RX_LANES(p) \199 (((p) & USB_EXT_PORT_STAT_RX_LANES) >> 8)200#define USB_EXT_PORT_TX_LANES(p) \201 (((p) & USB_EXT_PORT_STAT_TX_LANES) >> 12)202 203/*204 * wHubCharacteristics (masks)205 * See USB 2.0 spec Table 11-13, offset 3206 */207#define HUB_CHAR_LPSM 0x0003 /* Logical Power Switching Mode mask */208#define HUB_CHAR_COMMON_LPSM 0x0000 /* All ports power control at once */209#define HUB_CHAR_INDV_PORT_LPSM 0x0001 /* per-port power control */210#define HUB_CHAR_NO_LPSM 0x0002 /* no power switching */211 212#define HUB_CHAR_COMPOUND 0x0004 /* hub is part of a compound device */213 214#define HUB_CHAR_OCPM 0x0018 /* Over-Current Protection Mode mask */215#define HUB_CHAR_COMMON_OCPM 0x0000 /* All ports Over-Current reporting */216#define HUB_CHAR_INDV_PORT_OCPM 0x0008 /* per-port Over-current reporting */217#define HUB_CHAR_NO_OCPM 0x0010 /* No Over-current Protection support */218 219#define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */220#define HUB_CHAR_PORTIND 0x0080 /* per-port indicators (LEDs) */221 222struct usb_hub_status {223 __le16 wHubStatus;224 __le16 wHubChange;225} __attribute__ ((packed));226 227/*228 * Hub Status & Hub Change bit masks229 * See USB 2.0 spec Table 11-19 and Table 11-20230 * Bits 0 and 1 for wHubStatus and wHubChange231 * Bits 2 to 15 are reserved for both232 */233#define HUB_STATUS_LOCAL_POWER 0x0001234#define HUB_STATUS_OVERCURRENT 0x0002235#define HUB_CHANGE_LOCAL_POWER 0x0001236#define HUB_CHANGE_OVERCURRENT 0x0002237 238 239/*240 * Hub descriptor241 * See USB 2.0 spec Table 11-13242 */243 244#define USB_DT_HUB (USB_TYPE_CLASS | 0x09)245#define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a)246#define USB_DT_HUB_NONVAR_SIZE 7247#define USB_DT_SS_HUB_SIZE 12248 249/*250 * Hub Device descriptor251 * USB Hub class device protocols252 */253 254#define USB_HUB_PR_FS 0 /* Full speed hub */255#define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */256#define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */257#define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */258#define USB_HUB_PR_SS 3 /* Super speed hub */259 260struct usb_hub_descriptor {261 __u8 bDescLength;262 __u8 bDescriptorType;263 __u8 bNbrPorts;264 __le16 wHubCharacteristics;265 __u8 bPwrOn2PwrGood;266 __u8 bHubContrCurrent;267 268 /* 2.0 and 3.0 hubs differ here */269 union {270 struct {271 /* add 1 bit for hub status change; round to bytes */272 __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];273 __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];274 } __attribute__ ((packed)) hs;275 276 struct {277 __u8 bHubHdrDecLat;278 __le16 wHubDelay;279 __le16 DeviceRemovable;280 } __attribute__ ((packed)) ss;281 } u;282} __attribute__ ((packed));283 284/* port indicator status selectors, tables 11-7 and 11-25 */285#define HUB_LED_AUTO 0286#define HUB_LED_AMBER 1287#define HUB_LED_GREEN 2288#define HUB_LED_OFF 3289 290enum hub_led_mode {291 INDICATOR_AUTO = 0,292 INDICATOR_CYCLE,293 /* software blinks for attention: software, hardware, reserved */294 INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF,295 INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF,296 INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF297} __attribute__ ((packed));298 299/* Transaction Translator Think Times, in bits */300#define HUB_TTTT_8_BITS 0x00301#define HUB_TTTT_16_BITS 0x20302#define HUB_TTTT_24_BITS 0x40303#define HUB_TTTT_32_BITS 0x60304 305#endif /* __LINUX_CH11_H */306