162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * This file holds Hub protocol constants and data structures that are 462306a36Sopenharmony_ci * defined in chapter 11 (Hub Specification) of the USB 2.0 specification. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * It is used/shared between the USB core, the HCDs and couple of other USB 762306a36Sopenharmony_ci * drivers. 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef __LINUX_CH11_H 1162306a36Sopenharmony_ci#define __LINUX_CH11_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/types.h> /* __u8 etc */ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* This is arbitrary. 1662306a36Sopenharmony_ci * From USB 2.0 spec Table 11-13, offset 7, a hub can 1762306a36Sopenharmony_ci * have up to 255 ports. The most yet reported is 10. 1862306a36Sopenharmony_ci * Upcoming hardware might raise that limit. 1962306a36Sopenharmony_ci * Because the arrays need to add a bit for hub status data, we 2062306a36Sopenharmony_ci * use 31, so plus one evens out to four bytes. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#define USB_MAXCHILDREN 31 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* See USB 3.1 spec Table 10-5 */ 2562306a36Sopenharmony_ci#define USB_SS_MAXPORTS 15 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* 2862306a36Sopenharmony_ci * Hub request types 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE) 3262306a36Sopenharmony_ci#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* 3562306a36Sopenharmony_ci * Port status type for GetPortStatus requests added in USB 3.1 3662306a36Sopenharmony_ci * See USB 3.1 spec Table 10-12 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_ci#define HUB_PORT_STATUS 0 3962306a36Sopenharmony_ci#define HUB_PORT_PD_STATUS 1 4062306a36Sopenharmony_ci#define HUB_EXT_PORT_STATUS 2 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci/* 4362306a36Sopenharmony_ci * Hub class requests 4462306a36Sopenharmony_ci * See USB 2.0 spec Table 11-16 4562306a36Sopenharmony_ci */ 4662306a36Sopenharmony_ci#define HUB_CLEAR_TT_BUFFER 8 4762306a36Sopenharmony_ci#define HUB_RESET_TT 9 4862306a36Sopenharmony_ci#define HUB_GET_TT_STATE 10 4962306a36Sopenharmony_ci#define HUB_STOP_TT 11 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* 5262306a36Sopenharmony_ci * Hub class additional requests defined by USB 3.0 spec 5362306a36Sopenharmony_ci * See USB 3.0 spec Table 10-6 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci#define HUB_SET_DEPTH 12 5662306a36Sopenharmony_ci#define HUB_GET_PORT_ERR_COUNT 13 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci/* 5962306a36Sopenharmony_ci * Hub Class feature numbers 6062306a36Sopenharmony_ci * See USB 2.0 spec Table 11-17 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_ci#define C_HUB_LOCAL_POWER 0 6362306a36Sopenharmony_ci#define C_HUB_OVER_CURRENT 1 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* 6662306a36Sopenharmony_ci * Port feature numbers 6762306a36Sopenharmony_ci * See USB 2.0 spec Table 11-17 6862306a36Sopenharmony_ci */ 6962306a36Sopenharmony_ci#define USB_PORT_FEAT_CONNECTION 0 7062306a36Sopenharmony_ci#define USB_PORT_FEAT_ENABLE 1 7162306a36Sopenharmony_ci#define USB_PORT_FEAT_SUSPEND 2 /* L2 suspend */ 7262306a36Sopenharmony_ci#define USB_PORT_FEAT_OVER_CURRENT 3 7362306a36Sopenharmony_ci#define USB_PORT_FEAT_RESET 4 7462306a36Sopenharmony_ci#define USB_PORT_FEAT_L1 5 /* L1 suspend */ 7562306a36Sopenharmony_ci#define USB_PORT_FEAT_POWER 8 7662306a36Sopenharmony_ci#define USB_PORT_FEAT_LOWSPEED 9 /* Should never be used */ 7762306a36Sopenharmony_ci#define USB_PORT_FEAT_C_CONNECTION 16 7862306a36Sopenharmony_ci#define USB_PORT_FEAT_C_ENABLE 17 7962306a36Sopenharmony_ci#define USB_PORT_FEAT_C_SUSPEND 18 8062306a36Sopenharmony_ci#define USB_PORT_FEAT_C_OVER_CURRENT 19 8162306a36Sopenharmony_ci#define USB_PORT_FEAT_C_RESET 20 8262306a36Sopenharmony_ci#define USB_PORT_FEAT_TEST 21 8362306a36Sopenharmony_ci#define USB_PORT_FEAT_INDICATOR 22 8462306a36Sopenharmony_ci#define USB_PORT_FEAT_C_PORT_L1 23 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/* 8762306a36Sopenharmony_ci * Port feature selectors added by USB 3.0 spec. 8862306a36Sopenharmony_ci * See USB 3.0 spec Table 10-7 8962306a36Sopenharmony_ci */ 9062306a36Sopenharmony_ci#define USB_PORT_FEAT_LINK_STATE 5 9162306a36Sopenharmony_ci#define USB_PORT_FEAT_U1_TIMEOUT 23 9262306a36Sopenharmony_ci#define USB_PORT_FEAT_U2_TIMEOUT 24 9362306a36Sopenharmony_ci#define USB_PORT_FEAT_C_PORT_LINK_STATE 25 9462306a36Sopenharmony_ci#define USB_PORT_FEAT_C_PORT_CONFIG_ERROR 26 9562306a36Sopenharmony_ci#define USB_PORT_FEAT_REMOTE_WAKE_MASK 27 9662306a36Sopenharmony_ci#define USB_PORT_FEAT_BH_PORT_RESET 28 9762306a36Sopenharmony_ci#define USB_PORT_FEAT_C_BH_PORT_RESET 29 9862306a36Sopenharmony_ci#define USB_PORT_FEAT_FORCE_LINKPM_ACCEPT 30 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#define USB_PORT_LPM_TIMEOUT(p) (((p) & 0xff) << 8) 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/* USB 3.0 hub remote wake mask bits, see table 10-14 */ 10362306a36Sopenharmony_ci#define USB_PORT_FEAT_REMOTE_WAKE_CONNECT (1 << 8) 10462306a36Sopenharmony_ci#define USB_PORT_FEAT_REMOTE_WAKE_DISCONNECT (1 << 9) 10562306a36Sopenharmony_ci#define USB_PORT_FEAT_REMOTE_WAKE_OVER_CURRENT (1 << 10) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/* 10862306a36Sopenharmony_ci * Hub Status and Hub Change results 10962306a36Sopenharmony_ci * See USB 2.0 spec Table 11-19 and Table 11-20 11062306a36Sopenharmony_ci * USB 3.1 extends the port status request and may return 4 additional bytes. 11162306a36Sopenharmony_ci * See USB 3.1 spec section 10.16.2.6 Table 10-12 and 10-15 11262306a36Sopenharmony_ci */ 11362306a36Sopenharmony_cistruct usb_port_status { 11462306a36Sopenharmony_ci __le16 wPortStatus; 11562306a36Sopenharmony_ci __le16 wPortChange; 11662306a36Sopenharmony_ci __le32 dwExtPortStatus; 11762306a36Sopenharmony_ci} __attribute__ ((packed)); 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* 12062306a36Sopenharmony_ci * wPortStatus bit field 12162306a36Sopenharmony_ci * See USB 2.0 spec Table 11-21 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_ci#define USB_PORT_STAT_CONNECTION 0x0001 12462306a36Sopenharmony_ci#define USB_PORT_STAT_ENABLE 0x0002 12562306a36Sopenharmony_ci#define USB_PORT_STAT_SUSPEND 0x0004 12662306a36Sopenharmony_ci#define USB_PORT_STAT_OVERCURRENT 0x0008 12762306a36Sopenharmony_ci#define USB_PORT_STAT_RESET 0x0010 12862306a36Sopenharmony_ci#define USB_PORT_STAT_L1 0x0020 12962306a36Sopenharmony_ci/* bits 6 to 7 are reserved */ 13062306a36Sopenharmony_ci#define USB_PORT_STAT_POWER 0x0100 13162306a36Sopenharmony_ci#define USB_PORT_STAT_LOW_SPEED 0x0200 13262306a36Sopenharmony_ci#define USB_PORT_STAT_HIGH_SPEED 0x0400 13362306a36Sopenharmony_ci#define USB_PORT_STAT_TEST 0x0800 13462306a36Sopenharmony_ci#define USB_PORT_STAT_INDICATOR 0x1000 13562306a36Sopenharmony_ci/* bits 13 to 15 are reserved */ 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci/* 13862306a36Sopenharmony_ci * Additions to wPortStatus bit field from USB 3.0 13962306a36Sopenharmony_ci * See USB 3.0 spec Table 10-10 14062306a36Sopenharmony_ci */ 14162306a36Sopenharmony_ci#define USB_PORT_STAT_LINK_STATE 0x01e0 14262306a36Sopenharmony_ci#define USB_SS_PORT_STAT_POWER 0x0200 14362306a36Sopenharmony_ci#define USB_SS_PORT_STAT_SPEED 0x1c00 14462306a36Sopenharmony_ci#define USB_PORT_STAT_SPEED_5GBPS 0x0000 14562306a36Sopenharmony_ci/* Valid only if port is enabled */ 14662306a36Sopenharmony_ci/* Bits that are the same from USB 2.0 */ 14762306a36Sopenharmony_ci#define USB_SS_PORT_STAT_MASK (USB_PORT_STAT_CONNECTION | \ 14862306a36Sopenharmony_ci USB_PORT_STAT_ENABLE | \ 14962306a36Sopenharmony_ci USB_PORT_STAT_OVERCURRENT | \ 15062306a36Sopenharmony_ci USB_PORT_STAT_RESET) 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci/* 15362306a36Sopenharmony_ci * Definitions for PORT_LINK_STATE values 15462306a36Sopenharmony_ci * (bits 5-8) in wPortStatus 15562306a36Sopenharmony_ci */ 15662306a36Sopenharmony_ci#define USB_SS_PORT_LS_U0 0x0000 15762306a36Sopenharmony_ci#define USB_SS_PORT_LS_U1 0x0020 15862306a36Sopenharmony_ci#define USB_SS_PORT_LS_U2 0x0040 15962306a36Sopenharmony_ci#define USB_SS_PORT_LS_U3 0x0060 16062306a36Sopenharmony_ci#define USB_SS_PORT_LS_SS_DISABLED 0x0080 16162306a36Sopenharmony_ci#define USB_SS_PORT_LS_RX_DETECT 0x00a0 16262306a36Sopenharmony_ci#define USB_SS_PORT_LS_SS_INACTIVE 0x00c0 16362306a36Sopenharmony_ci#define USB_SS_PORT_LS_POLLING 0x00e0 16462306a36Sopenharmony_ci#define USB_SS_PORT_LS_RECOVERY 0x0100 16562306a36Sopenharmony_ci#define USB_SS_PORT_LS_HOT_RESET 0x0120 16662306a36Sopenharmony_ci#define USB_SS_PORT_LS_COMP_MOD 0x0140 16762306a36Sopenharmony_ci#define USB_SS_PORT_LS_LOOPBACK 0x0160 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/* 17062306a36Sopenharmony_ci * wPortChange bit field 17162306a36Sopenharmony_ci * See USB 2.0 spec Table 11-22 and USB 2.0 LPM ECN Table-4.10 17262306a36Sopenharmony_ci * Bits 0 to 5 shown, bits 6 to 15 are reserved 17362306a36Sopenharmony_ci */ 17462306a36Sopenharmony_ci#define USB_PORT_STAT_C_CONNECTION 0x0001 17562306a36Sopenharmony_ci#define USB_PORT_STAT_C_ENABLE 0x0002 17662306a36Sopenharmony_ci#define USB_PORT_STAT_C_SUSPEND 0x0004 17762306a36Sopenharmony_ci#define USB_PORT_STAT_C_OVERCURRENT 0x0008 17862306a36Sopenharmony_ci#define USB_PORT_STAT_C_RESET 0x0010 17962306a36Sopenharmony_ci#define USB_PORT_STAT_C_L1 0x0020 18062306a36Sopenharmony_ci/* 18162306a36Sopenharmony_ci * USB 3.0 wPortChange bit fields 18262306a36Sopenharmony_ci * See USB 3.0 spec Table 10-11 18362306a36Sopenharmony_ci */ 18462306a36Sopenharmony_ci#define USB_PORT_STAT_C_BH_RESET 0x0020 18562306a36Sopenharmony_ci#define USB_PORT_STAT_C_LINK_STATE 0x0040 18662306a36Sopenharmony_ci#define USB_PORT_STAT_C_CONFIG_ERROR 0x0080 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/* 18962306a36Sopenharmony_ci * USB 3.1 dwExtPortStatus field masks 19062306a36Sopenharmony_ci * See USB 3.1 spec 10.16.2.6.3 Table 10-15 19162306a36Sopenharmony_ci */ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define USB_EXT_PORT_STAT_RX_SPEED_ID 0x0000000f 19462306a36Sopenharmony_ci#define USB_EXT_PORT_STAT_TX_SPEED_ID 0x000000f0 19562306a36Sopenharmony_ci#define USB_EXT_PORT_STAT_RX_LANES 0x00000f00 19662306a36Sopenharmony_ci#define USB_EXT_PORT_STAT_TX_LANES 0x0000f000 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci#define USB_EXT_PORT_RX_LANES(p) \ 19962306a36Sopenharmony_ci (((p) & USB_EXT_PORT_STAT_RX_LANES) >> 8) 20062306a36Sopenharmony_ci#define USB_EXT_PORT_TX_LANES(p) \ 20162306a36Sopenharmony_ci (((p) & USB_EXT_PORT_STAT_TX_LANES) >> 12) 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci/* 20462306a36Sopenharmony_ci * wHubCharacteristics (masks) 20562306a36Sopenharmony_ci * See USB 2.0 spec Table 11-13, offset 3 20662306a36Sopenharmony_ci */ 20762306a36Sopenharmony_ci#define HUB_CHAR_LPSM 0x0003 /* Logical Power Switching Mode mask */ 20862306a36Sopenharmony_ci#define HUB_CHAR_COMMON_LPSM 0x0000 /* All ports power control at once */ 20962306a36Sopenharmony_ci#define HUB_CHAR_INDV_PORT_LPSM 0x0001 /* per-port power control */ 21062306a36Sopenharmony_ci#define HUB_CHAR_NO_LPSM 0x0002 /* no power switching */ 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci#define HUB_CHAR_COMPOUND 0x0004 /* hub is part of a compound device */ 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci#define HUB_CHAR_OCPM 0x0018 /* Over-Current Protection Mode mask */ 21562306a36Sopenharmony_ci#define HUB_CHAR_COMMON_OCPM 0x0000 /* All ports Over-Current reporting */ 21662306a36Sopenharmony_ci#define HUB_CHAR_INDV_PORT_OCPM 0x0008 /* per-port Over-current reporting */ 21762306a36Sopenharmony_ci#define HUB_CHAR_NO_OCPM 0x0010 /* No Over-current Protection support */ 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci#define HUB_CHAR_TTTT 0x0060 /* TT Think Time mask */ 22062306a36Sopenharmony_ci#define HUB_CHAR_PORTIND 0x0080 /* per-port indicators (LEDs) */ 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_cistruct usb_hub_status { 22362306a36Sopenharmony_ci __le16 wHubStatus; 22462306a36Sopenharmony_ci __le16 wHubChange; 22562306a36Sopenharmony_ci} __attribute__ ((packed)); 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ci/* 22862306a36Sopenharmony_ci * Hub Status & Hub Change bit masks 22962306a36Sopenharmony_ci * See USB 2.0 spec Table 11-19 and Table 11-20 23062306a36Sopenharmony_ci * Bits 0 and 1 for wHubStatus and wHubChange 23162306a36Sopenharmony_ci * Bits 2 to 15 are reserved for both 23262306a36Sopenharmony_ci */ 23362306a36Sopenharmony_ci#define HUB_STATUS_LOCAL_POWER 0x0001 23462306a36Sopenharmony_ci#define HUB_STATUS_OVERCURRENT 0x0002 23562306a36Sopenharmony_ci#define HUB_CHANGE_LOCAL_POWER 0x0001 23662306a36Sopenharmony_ci#define HUB_CHANGE_OVERCURRENT 0x0002 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci/* 24062306a36Sopenharmony_ci * Hub descriptor 24162306a36Sopenharmony_ci * See USB 2.0 spec Table 11-13 24262306a36Sopenharmony_ci */ 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci#define USB_DT_HUB (USB_TYPE_CLASS | 0x09) 24562306a36Sopenharmony_ci#define USB_DT_SS_HUB (USB_TYPE_CLASS | 0x0a) 24662306a36Sopenharmony_ci#define USB_DT_HUB_NONVAR_SIZE 7 24762306a36Sopenharmony_ci#define USB_DT_SS_HUB_SIZE 12 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ci/* 25062306a36Sopenharmony_ci * Hub Device descriptor 25162306a36Sopenharmony_ci * USB Hub class device protocols 25262306a36Sopenharmony_ci */ 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci#define USB_HUB_PR_FS 0 /* Full speed hub */ 25562306a36Sopenharmony_ci#define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */ 25662306a36Sopenharmony_ci#define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */ 25762306a36Sopenharmony_ci#define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */ 25862306a36Sopenharmony_ci#define USB_HUB_PR_SS 3 /* Super speed hub */ 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_cistruct usb_hub_descriptor { 26162306a36Sopenharmony_ci __u8 bDescLength; 26262306a36Sopenharmony_ci __u8 bDescriptorType; 26362306a36Sopenharmony_ci __u8 bNbrPorts; 26462306a36Sopenharmony_ci __le16 wHubCharacteristics; 26562306a36Sopenharmony_ci __u8 bPwrOn2PwrGood; 26662306a36Sopenharmony_ci __u8 bHubContrCurrent; 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci /* 2.0 and 3.0 hubs differ here */ 26962306a36Sopenharmony_ci union { 27062306a36Sopenharmony_ci struct { 27162306a36Sopenharmony_ci /* add 1 bit for hub status change; round to bytes */ 27262306a36Sopenharmony_ci __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8]; 27362306a36Sopenharmony_ci __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8]; 27462306a36Sopenharmony_ci } __attribute__ ((packed)) hs; 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci struct { 27762306a36Sopenharmony_ci __u8 bHubHdrDecLat; 27862306a36Sopenharmony_ci __le16 wHubDelay; 27962306a36Sopenharmony_ci __le16 DeviceRemovable; 28062306a36Sopenharmony_ci } __attribute__ ((packed)) ss; 28162306a36Sopenharmony_ci } u; 28262306a36Sopenharmony_ci} __attribute__ ((packed)); 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_ci/* port indicator status selectors, tables 11-7 and 11-25 */ 28562306a36Sopenharmony_ci#define HUB_LED_AUTO 0 28662306a36Sopenharmony_ci#define HUB_LED_AMBER 1 28762306a36Sopenharmony_ci#define HUB_LED_GREEN 2 28862306a36Sopenharmony_ci#define HUB_LED_OFF 3 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_cienum hub_led_mode { 29162306a36Sopenharmony_ci INDICATOR_AUTO = 0, 29262306a36Sopenharmony_ci INDICATOR_CYCLE, 29362306a36Sopenharmony_ci /* software blinks for attention: software, hardware, reserved */ 29462306a36Sopenharmony_ci INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF, 29562306a36Sopenharmony_ci INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF, 29662306a36Sopenharmony_ci INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF 29762306a36Sopenharmony_ci} __attribute__ ((packed)); 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci/* Transaction Translator Think Times, in bits */ 30062306a36Sopenharmony_ci#define HUB_TTTT_8_BITS 0x00 30162306a36Sopenharmony_ci#define HUB_TTTT_16_BITS 0x20 30262306a36Sopenharmony_ci#define HUB_TTTT_24_BITS 0x40 30362306a36Sopenharmony_ci#define HUB_TTTT_32_BITS 0x60 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ci#endif /* __LINUX_CH11_H */ 306