Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 2 | /* |
Mika Westerberg | 15c6784 | 2018-10-01 12:31:22 +0300 | [diff] [blame] | 3 | * Thunderbolt driver - Port/Switch config area registers |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 4 | * |
| 5 | * Every thunderbolt device consists (logically) of a switch with multiple |
| 6 | * ports. Every port contains up to four config regions (HOPS, PORT, SWITCH, |
| 7 | * COUNTERS) which are used to configure the device. |
| 8 | * |
| 9 | * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com> |
Mika Westerberg | 15c6784 | 2018-10-01 12:31:22 +0300 | [diff] [blame] | 10 | * Copyright (C) 2018, Intel Corporation |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef _TB_REGS |
| 14 | #define _TB_REGS |
| 15 | |
| 16 | #include <linux/types.h> |
| 17 | |
| 18 | |
| 19 | #define TB_ROUTE_SHIFT 8 /* number of bits in a port entry of a route */ |
| 20 | |
| 21 | |
| 22 | /* |
| 23 | * TODO: should be 63? But we do not know how to receive frames larger than 256 |
| 24 | * bytes at the frame level. (header + checksum = 16, 60*4 = 240) |
| 25 | */ |
| 26 | #define TB_MAX_CONFIG_RW_LENGTH 60 |
| 27 | |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 28 | enum tb_switch_cap { |
Rajmohan Mani | cf29b9af | 2019-12-17 15:33:43 +0300 | [diff] [blame] | 29 | TB_SWITCH_CAP_TMU = 0x03, |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 30 | TB_SWITCH_CAP_VSE = 0x05, |
| 31 | }; |
| 32 | |
| 33 | enum tb_switch_vse_cap { |
| 34 | TB_VSE_CAP_PLUG_EVENTS = 0x01, /* also EEPROM */ |
| 35 | TB_VSE_CAP_TIME2 = 0x03, |
Gil Fine | 483c9d8 | 2021-12-17 03:16:42 +0200 | [diff] [blame] | 36 | TB_VSE_CAP_CP_LP = 0x04, |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 37 | TB_VSE_CAP_LINK_CONTROLLER = 0x06, /* also IECS */ |
| 38 | }; |
| 39 | |
| 40 | enum tb_port_cap { |
| 41 | TB_PORT_CAP_PHY = 0x01, |
Gil Fine | 54e4181 | 2020-06-29 20:30:52 +0300 | [diff] [blame] | 42 | TB_PORT_CAP_POWER = 0x02, |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 43 | TB_PORT_CAP_TIME1 = 0x03, |
| 44 | TB_PORT_CAP_ADAP = 0x04, |
| 45 | TB_PORT_CAP_VSE = 0x05, |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 46 | TB_PORT_CAP_USB4 = 0x06, |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | enum tb_port_state { |
| 50 | TB_PORT_DISABLED = 0, /* tb_cap_phy.disable == 1 */ |
| 51 | TB_PORT_CONNECTING = 1, /* retry */ |
| 52 | TB_PORT_UP = 2, |
| 53 | TB_PORT_UNPLUGGED = 7, |
| 54 | }; |
| 55 | |
| 56 | /* capability headers */ |
| 57 | |
| 58 | struct tb_cap_basic { |
| 59 | u8 next; |
| 60 | /* enum tb_cap cap:8; prevent "narrower than values of its type" */ |
| 61 | u8 cap; /* if cap == 0x05 then we have a extended capability */ |
| 62 | } __packed; |
| 63 | |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 64 | /** |
| 65 | * struct tb_cap_extended_short - Switch extended short capability |
| 66 | * @next: Pointer to the next capability. If @next and @length are zero |
| 67 | * then we have a long cap. |
| 68 | * @cap: Base capability ID (see &enum tb_switch_cap) |
| 69 | * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap) |
| 70 | * @length: Length of this capability |
| 71 | */ |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 72 | struct tb_cap_extended_short { |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 73 | u8 next; |
| 74 | u8 cap; |
| 75 | u8 vsec_id; |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 76 | u8 length; |
| 77 | } __packed; |
| 78 | |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 79 | /** |
| 80 | * struct tb_cap_extended_long - Switch extended long capability |
| 81 | * @zero1: This field should be zero |
| 82 | * @cap: Base capability ID (see &enum tb_switch_cap) |
| 83 | * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap) |
| 84 | * @zero2: This field should be zero |
| 85 | * @next: Pointer to the next capability |
| 86 | * @length: Length of this capability |
| 87 | */ |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 88 | struct tb_cap_extended_long { |
| 89 | u8 zero1; |
Mika Westerberg | da2da04 | 2017-06-06 15:24:58 +0300 | [diff] [blame] | 90 | u8 cap; |
| 91 | u8 vsec_id; |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 92 | u8 zero2; |
| 93 | u16 next; |
| 94 | u16 length; |
| 95 | } __packed; |
| 96 | |
Mika Westerberg | 8f83101 | 2020-06-29 20:11:38 +0300 | [diff] [blame] | 97 | /** |
| 98 | * struct tb_cap_any - Structure capable of hold every capability |
| 99 | * @basic: Basic capability |
| 100 | * @extended_short: Vendor specific capability |
| 101 | * @extended_long: Vendor specific extended capability |
| 102 | */ |
| 103 | struct tb_cap_any { |
| 104 | union { |
| 105 | struct tb_cap_basic basic; |
| 106 | struct tb_cap_extended_short extended_short; |
| 107 | struct tb_cap_extended_long extended_long; |
| 108 | }; |
| 109 | } __packed; |
| 110 | |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 111 | /* capabilities */ |
| 112 | |
| 113 | struct tb_cap_link_controller { |
| 114 | struct tb_cap_extended_long cap_header; |
| 115 | u32 count:4; /* number of link controllers */ |
| 116 | u32 unknown1:4; |
| 117 | u32 base_offset:8; /* |
| 118 | * offset (into this capability) of the configuration |
| 119 | * area of the first link controller |
| 120 | */ |
| 121 | u32 length:12; /* link controller configuration area length */ |
| 122 | u32 unknown2:4; /* TODO check that length is correct */ |
| 123 | } __packed; |
| 124 | |
| 125 | struct tb_cap_phy { |
| 126 | struct tb_cap_basic cap_header; |
| 127 | u32 unknown1:16; |
| 128 | u32 unknown2:14; |
| 129 | bool disable:1; |
| 130 | u32 unknown3:11; |
| 131 | enum tb_port_state state:4; |
| 132 | u32 unknown4:2; |
| 133 | } __packed; |
| 134 | |
| 135 | struct tb_eeprom_ctl { |
| 136 | bool clock:1; /* send pulse to transfer one bit */ |
| 137 | bool access_low:1; /* set to 0 before access */ |
| 138 | bool data_out:1; /* to eeprom */ |
| 139 | bool data_in:1; /* from eeprom */ |
| 140 | bool access_high:1; /* set to 1 before access */ |
| 141 | bool not_present:1; /* should be 0 */ |
| 142 | bool unknown1:1; |
| 143 | bool present:1; /* should be 1 */ |
| 144 | u32 unknown2:24; |
| 145 | } __packed; |
| 146 | |
| 147 | struct tb_cap_plug_events { |
| 148 | struct tb_cap_extended_short cap_header; |
| 149 | u32 __unknown1:2; |
| 150 | u32 plug_events:5; |
| 151 | u32 __unknown2:25; |
| 152 | u32 __unknown3; |
| 153 | u32 __unknown4; |
| 154 | struct tb_eeprom_ctl eeprom_ctl; |
| 155 | u32 __unknown5[7]; |
| 156 | u32 drom_offset; /* 32 bit register, but eeprom addresses are 16 bit */ |
| 157 | } __packed; |
| 158 | |
| 159 | /* device headers */ |
| 160 | |
| 161 | /* Present on port 0 in TB_CFG_SWITCH at address zero. */ |
| 162 | struct tb_regs_switch_header { |
| 163 | /* DWORD 0 */ |
| 164 | u16 vendor_id; |
| 165 | u16 device_id; |
| 166 | /* DWORD 1 */ |
| 167 | u32 first_cap_offset:8; |
| 168 | u32 upstream_port_number:6; |
| 169 | u32 max_port_number:6; |
| 170 | u32 depth:3; |
| 171 | u32 __unknown1:1; |
| 172 | u32 revision:8; |
| 173 | /* DWORD 2 */ |
| 174 | u32 route_lo; |
| 175 | /* DWORD 3 */ |
| 176 | u32 route_hi:31; |
| 177 | bool enabled:1; |
| 178 | /* DWORD 4 */ |
| 179 | u32 plug_events_delay:8; /* |
| 180 | * RW, pause between plug events in |
| 181 | * milliseconds. Writing 0x00 is interpreted |
| 182 | * as 255ms. |
| 183 | */ |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 184 | u32 cmuv:8; |
| 185 | u32 __unknown4:8; |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 186 | u32 thunderbolt_version:8; |
| 187 | } __packed; |
| 188 | |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 189 | /* USB4 version 1.0 */ |
| 190 | #define USB4_VERSION_1_0 0x20 |
| 191 | |
| 192 | #define ROUTER_CS_1 0x01 |
| 193 | #define ROUTER_CS_4 0x04 |
| 194 | #define ROUTER_CS_5 0x05 |
| 195 | #define ROUTER_CS_5_SLP BIT(0) |
Mika Westerberg | b2911a5 | 2019-12-06 18:36:07 +0200 | [diff] [blame] | 196 | #define ROUTER_CS_5_WOP BIT(1) |
| 197 | #define ROUTER_CS_5_WOU BIT(2) |
Mika Westerberg | 6026b70 | 2021-01-14 16:44:17 +0200 | [diff] [blame] | 198 | #define ROUTER_CS_5_WOD BIT(3) |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 199 | #define ROUTER_CS_5_C3S BIT(23) |
| 200 | #define ROUTER_CS_5_PTO BIT(24) |
Rajmohan Mani | e6f8185 | 2019-12-17 15:33:44 +0300 | [diff] [blame] | 201 | #define ROUTER_CS_5_UTO BIT(25) |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 202 | #define ROUTER_CS_5_HCO BIT(26) |
| 203 | #define ROUTER_CS_5_CV BIT(31) |
| 204 | #define ROUTER_CS_6 0x06 |
| 205 | #define ROUTER_CS_6_SLPR BIT(0) |
| 206 | #define ROUTER_CS_6_TNS BIT(1) |
Mika Westerberg | b2911a5 | 2019-12-06 18:36:07 +0200 | [diff] [blame] | 207 | #define ROUTER_CS_6_WOPS BIT(2) |
| 208 | #define ROUTER_CS_6_WOUS BIT(3) |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 209 | #define ROUTER_CS_6_HCI BIT(18) |
| 210 | #define ROUTER_CS_6_CR BIT(25) |
| 211 | #define ROUTER_CS_7 0x07 |
| 212 | #define ROUTER_CS_9 0x09 |
| 213 | #define ROUTER_CS_25 0x19 |
| 214 | #define ROUTER_CS_26 0x1a |
Mika Westerberg | 661b194 | 2020-11-10 11:34:07 +0300 | [diff] [blame] | 215 | #define ROUTER_CS_26_OPCODE_MASK GENMASK(15, 0) |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 216 | #define ROUTER_CS_26_STATUS_MASK GENMASK(29, 24) |
| 217 | #define ROUTER_CS_26_STATUS_SHIFT 24 |
| 218 | #define ROUTER_CS_26_ONS BIT(30) |
| 219 | #define ROUTER_CS_26_OV BIT(31) |
| 220 | |
Mika Westerberg | 579f142 | 2020-11-12 15:45:18 +0200 | [diff] [blame] | 221 | /* USB4 router operations opcodes */ |
| 222 | enum usb4_switch_op { |
| 223 | USB4_SWITCH_OP_QUERY_DP_RESOURCE = 0x10, |
| 224 | USB4_SWITCH_OP_ALLOC_DP_RESOURCE = 0x11, |
| 225 | USB4_SWITCH_OP_DEALLOC_DP_RESOURCE = 0x12, |
| 226 | USB4_SWITCH_OP_NVM_WRITE = 0x20, |
| 227 | USB4_SWITCH_OP_NVM_AUTH = 0x21, |
| 228 | USB4_SWITCH_OP_NVM_READ = 0x22, |
| 229 | USB4_SWITCH_OP_NVM_SET_OFFSET = 0x23, |
| 230 | USB4_SWITCH_OP_DROM_READ = 0x24, |
| 231 | USB4_SWITCH_OP_NVM_SECTOR_SIZE = 0x25, |
Mika Westerberg | 56ad3ae | 2021-03-10 13:34:12 +0200 | [diff] [blame] | 232 | USB4_SWITCH_OP_BUFFER_ALLOC = 0x33, |
Mika Westerberg | 579f142 | 2020-11-12 15:45:18 +0200 | [diff] [blame] | 233 | }; |
| 234 | |
Rajmohan Mani | cf29b9af | 2019-12-17 15:33:43 +0300 | [diff] [blame] | 235 | /* Router TMU configuration */ |
| 236 | #define TMU_RTR_CS_0 0x00 |
| 237 | #define TMU_RTR_CS_0_TD BIT(27) |
| 238 | #define TMU_RTR_CS_0_UCAP BIT(30) |
| 239 | #define TMU_RTR_CS_1 0x01 |
| 240 | #define TMU_RTR_CS_1_LOCAL_TIME_NS_MASK GENMASK(31, 16) |
| 241 | #define TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT 16 |
| 242 | #define TMU_RTR_CS_2 0x02 |
| 243 | #define TMU_RTR_CS_3 0x03 |
| 244 | #define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0) |
| 245 | #define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16) |
| 246 | #define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16 |
| 247 | #define TMU_RTR_CS_22 0x16 |
| 248 | #define TMU_RTR_CS_24 0x18 |
Gil Fine | a28ec0e | 2021-12-17 03:16:38 +0200 | [diff] [blame] | 249 | #define TMU_RTR_CS_25 0x19 |
Rajmohan Mani | cf29b9af | 2019-12-17 15:33:43 +0300 | [diff] [blame] | 250 | |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 251 | enum tb_port_type { |
| 252 | TB_TYPE_INACTIVE = 0x000000, |
| 253 | TB_TYPE_PORT = 0x000001, |
| 254 | TB_TYPE_NHI = 0x000002, |
| 255 | /* TB_TYPE_ETHERNET = 0x020000, lower order bits are not known */ |
| 256 | /* TB_TYPE_SATA = 0x080000, lower order bits are not known */ |
| 257 | TB_TYPE_DP_HDMI_IN = 0x0e0101, |
| 258 | TB_TYPE_DP_HDMI_OUT = 0x0e0102, |
| 259 | TB_TYPE_PCIE_DOWN = 0x100101, |
| 260 | TB_TYPE_PCIE_UP = 0x100102, |
Rajmohan Mani | e6f8185 | 2019-12-17 15:33:44 +0300 | [diff] [blame] | 261 | TB_TYPE_USB3_DOWN = 0x200101, |
| 262 | TB_TYPE_USB3_UP = 0x200102, |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | /* Present on every port in TB_CF_PORT at address zero. */ |
| 266 | struct tb_regs_port_header { |
| 267 | /* DWORD 0 */ |
| 268 | u16 vendor_id; |
| 269 | u16 device_id; |
| 270 | /* DWORD 1 */ |
| 271 | u32 first_cap_offset:8; |
| 272 | u32 max_counters:11; |
Gil Fine | 54e4181 | 2020-06-29 20:30:52 +0300 | [diff] [blame] | 273 | u32 counters_support:1; |
| 274 | u32 __unknown1:4; |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 275 | u32 revision:8; |
| 276 | /* DWORD 2 */ |
| 277 | enum tb_port_type type:24; |
| 278 | u32 thunderbolt_version:8; |
| 279 | /* DWORD 3 */ |
| 280 | u32 __unknown2:20; |
| 281 | u32 port_number:6; |
| 282 | u32 __unknown3:6; |
| 283 | /* DWORD 4 */ |
| 284 | u32 nfc_credits; |
| 285 | /* DWORD 5 */ |
| 286 | u32 max_in_hop_id:11; |
| 287 | u32 max_out_hop_id:11; |
Nathan Ciobanu | c356915 | 2018-07-25 11:03:15 +0300 | [diff] [blame] | 288 | u32 __unknown4:10; |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 289 | /* DWORD 6 */ |
| 290 | u32 __unknown5; |
| 291 | /* DWORD 7 */ |
| 292 | u32 __unknown6; |
| 293 | |
| 294 | } __packed; |
| 295 | |
Mika Westerberg | 8f57d47 | 2019-09-06 11:59:00 +0300 | [diff] [blame] | 296 | /* Basic adapter configuration registers */ |
| 297 | #define ADP_CS_4 0x04 |
| 298 | #define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0) |
| 299 | #define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20) |
| 300 | #define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20 |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 301 | #define ADP_CS_4_LCK BIT(31) |
Mika Westerberg | 8f57d47 | 2019-09-06 11:59:00 +0300 | [diff] [blame] | 302 | #define ADP_CS_5 0x05 |
| 303 | #define ADP_CS_5_LCA_MASK GENMASK(28, 22) |
| 304 | #define ADP_CS_5_LCA_SHIFT 22 |
Mika Westerberg | 4f807e4 | 2018-09-17 16:30:49 +0300 | [diff] [blame] | 305 | |
Rajmohan Mani | cf29b9af | 2019-12-17 15:33:43 +0300 | [diff] [blame] | 306 | /* TMU adapter registers */ |
| 307 | #define TMU_ADP_CS_3 0x03 |
| 308 | #define TMU_ADP_CS_3_UDM BIT(29) |
Gil Fine | a28ec0e | 2021-12-17 03:16:38 +0200 | [diff] [blame] | 309 | #define TMU_ADP_CS_6 0x06 |
| 310 | #define TMU_ADP_CS_6_DTS BIT(1) |
Rajmohan Mani | cf29b9af | 2019-12-17 15:33:43 +0300 | [diff] [blame] | 311 | |
Mika Westerberg | 91c0c12 | 2019-03-21 19:03:00 +0200 | [diff] [blame] | 312 | /* Lane adapter registers */ |
| 313 | #define LANE_ADP_CS_0 0x00 |
| 314 | #define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20) |
| 315 | #define LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT 20 |
Gil Fine | 8a90e4f | 2021-12-17 03:16:39 +0200 | [diff] [blame] | 316 | #define LANE_ADP_CS_0_CL0S_SUPPORT BIT(26) |
| 317 | #define LANE_ADP_CS_0_CL1_SUPPORT BIT(27) |
Mika Westerberg | 91c0c12 | 2019-03-21 19:03:00 +0200 | [diff] [blame] | 318 | #define LANE_ADP_CS_1 0x01 |
| 319 | #define LANE_ADP_CS_1_TARGET_WIDTH_MASK GENMASK(9, 4) |
| 320 | #define LANE_ADP_CS_1_TARGET_WIDTH_SHIFT 4 |
| 321 | #define LANE_ADP_CS_1_TARGET_WIDTH_SINGLE 0x1 |
| 322 | #define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3 |
Gil Fine | 8a90e4f | 2021-12-17 03:16:39 +0200 | [diff] [blame] | 323 | #define LANE_ADP_CS_1_CL0S_ENABLE BIT(10) |
| 324 | #define LANE_ADP_CS_1_CL1_ENABLE BIT(11) |
Mika Westerberg | 341d451 | 2020-02-21 12:11:54 +0200 | [diff] [blame] | 325 | #define LANE_ADP_CS_1_LD BIT(14) |
Mika Westerberg | 91c0c12 | 2019-03-21 19:03:00 +0200 | [diff] [blame] | 326 | #define LANE_ADP_CS_1_LB BIT(15) |
| 327 | #define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16) |
| 328 | #define LANE_ADP_CS_1_CURRENT_SPEED_SHIFT 16 |
| 329 | #define LANE_ADP_CS_1_CURRENT_SPEED_GEN2 0x8 |
| 330 | #define LANE_ADP_CS_1_CURRENT_SPEED_GEN3 0x4 |
| 331 | #define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20) |
| 332 | #define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20 |
Gil Fine | 8a90e4f | 2021-12-17 03:16:39 +0200 | [diff] [blame] | 333 | #define LANE_ADP_CS_1_PMS BIT(30) |
Mika Westerberg | 91c0c12 | 2019-03-21 19:03:00 +0200 | [diff] [blame] | 334 | |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 335 | /* USB4 port registers */ |
Rajmohan Mani | 02d1285 | 2020-03-05 16:33:46 +0200 | [diff] [blame] | 336 | #define PORT_CS_1 0x01 |
| 337 | #define PORT_CS_1_LENGTH_SHIFT 8 |
| 338 | #define PORT_CS_1_TARGET_MASK GENMASK(18, 16) |
| 339 | #define PORT_CS_1_TARGET_SHIFT 16 |
| 340 | #define PORT_CS_1_RETIMER_INDEX_SHIFT 20 |
| 341 | #define PORT_CS_1_WNR_WRITE BIT(24) |
| 342 | #define PORT_CS_1_NR BIT(25) |
| 343 | #define PORT_CS_1_RC BIT(26) |
| 344 | #define PORT_CS_1_PND BIT(31) |
| 345 | #define PORT_CS_2 0x02 |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 346 | #define PORT_CS_18 0x12 |
| 347 | #define PORT_CS_18_BE BIT(8) |
Mika Westerberg | bbcf40b | 2020-03-04 17:09:14 +0200 | [diff] [blame] | 348 | #define PORT_CS_18_TCM BIT(9) |
Gil Fine | 8a90e4f | 2021-12-17 03:16:39 +0200 | [diff] [blame] | 349 | #define PORT_CS_18_CPS BIT(10) |
Mika Westerberg | b2911a5 | 2019-12-06 18:36:07 +0200 | [diff] [blame] | 350 | #define PORT_CS_18_WOU4S BIT(18) |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 351 | #define PORT_CS_19 0x13 |
| 352 | #define PORT_CS_19_PC BIT(3) |
Mika Westerberg | 284652a | 2020-04-09 14:23:32 +0300 | [diff] [blame] | 353 | #define PORT_CS_19_PID BIT(4) |
Mika Westerberg | b2911a5 | 2019-12-06 18:36:07 +0200 | [diff] [blame] | 354 | #define PORT_CS_19_WOC BIT(16) |
| 355 | #define PORT_CS_19_WOD BIT(17) |
| 356 | #define PORT_CS_19_WOU4 BIT(18) |
Mika Westerberg | b040798 | 2019-12-17 15:33:40 +0300 | [diff] [blame] | 357 | |
Mika Westerberg | 4f807e4 | 2018-09-17 16:30:49 +0300 | [diff] [blame] | 358 | /* Display Port adapter registers */ |
Mika Westerberg | 9817638 | 2019-09-06 11:32:15 +0300 | [diff] [blame] | 359 | #define ADP_DP_CS_0 0x00 |
| 360 | #define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16) |
| 361 | #define ADP_DP_CS_0_VIDEO_HOPID_SHIFT 16 |
| 362 | #define ADP_DP_CS_0_AE BIT(30) |
| 363 | #define ADP_DP_CS_0_VE BIT(31) |
| 364 | #define ADP_DP_CS_1_AUX_TX_HOPID_MASK GENMASK(10, 0) |
| 365 | #define ADP_DP_CS_1_AUX_RX_HOPID_MASK GENMASK(21, 11) |
| 366 | #define ADP_DP_CS_1_AUX_RX_HOPID_SHIFT 11 |
| 367 | #define ADP_DP_CS_2 0x02 |
| 368 | #define ADP_DP_CS_2_HDP BIT(6) |
| 369 | #define ADP_DP_CS_3 0x03 |
| 370 | #define ADP_DP_CS_3_HDPC BIT(9) |
| 371 | #define DP_LOCAL_CAP 0x04 |
| 372 | #define DP_REMOTE_CAP 0x05 |
Mika Westerberg | de718ac | 2019-02-15 18:18:47 +0200 | [diff] [blame] | 373 | #define DP_STATUS_CTRL 0x06 |
| 374 | #define DP_STATUS_CTRL_CMHS BIT(25) |
| 375 | #define DP_STATUS_CTRL_UF BIT(26) |
Mika Westerberg | a11b88a | 2019-03-26 16:03:48 +0300 | [diff] [blame] | 376 | #define DP_COMMON_CAP 0x07 |
| 377 | /* |
| 378 | * DP_COMMON_CAP offsets work also for DP_LOCAL_CAP and DP_REMOTE_CAP |
| 379 | * with exception of DPRX done. |
| 380 | */ |
| 381 | #define DP_COMMON_CAP_RATE_MASK GENMASK(11, 8) |
| 382 | #define DP_COMMON_CAP_RATE_SHIFT 8 |
| 383 | #define DP_COMMON_CAP_RATE_RBR 0x0 |
| 384 | #define DP_COMMON_CAP_RATE_HBR 0x1 |
| 385 | #define DP_COMMON_CAP_RATE_HBR2 0x2 |
| 386 | #define DP_COMMON_CAP_RATE_HBR3 0x3 |
| 387 | #define DP_COMMON_CAP_LANES_MASK GENMASK(14, 12) |
| 388 | #define DP_COMMON_CAP_LANES_SHIFT 12 |
| 389 | #define DP_COMMON_CAP_1_LANE 0x0 |
| 390 | #define DP_COMMON_CAP_2_LANES 0x1 |
| 391 | #define DP_COMMON_CAP_4_LANES 0x2 |
| 392 | #define DP_COMMON_CAP_DPRX_DONE BIT(31) |
Mika Westerberg | c5ee6fe | 2018-10-11 11:38:22 +0300 | [diff] [blame] | 393 | |
Mika Westerberg | 93f36ad | 2017-02-19 13:48:29 +0200 | [diff] [blame] | 394 | /* PCIe adapter registers */ |
Mika Westerberg | 778bfca | 2019-09-06 12:05:24 +0300 | [diff] [blame] | 395 | #define ADP_PCIE_CS_0 0x00 |
| 396 | #define ADP_PCIE_CS_0_PE BIT(31) |
Mika Westerberg | 93f36ad | 2017-02-19 13:48:29 +0200 | [diff] [blame] | 397 | |
Rajmohan Mani | e6f8185 | 2019-12-17 15:33:44 +0300 | [diff] [blame] | 398 | /* USB adapter registers */ |
| 399 | #define ADP_USB3_CS_0 0x00 |
| 400 | #define ADP_USB3_CS_0_V BIT(30) |
| 401 | #define ADP_USB3_CS_0_PE BIT(31) |
Mika Westerberg | 3b1d8d5 | 2020-02-21 23:14:41 +0200 | [diff] [blame] | 402 | #define ADP_USB3_CS_1 0x01 |
| 403 | #define ADP_USB3_CS_1_CUBW_MASK GENMASK(11, 0) |
| 404 | #define ADP_USB3_CS_1_CDBW_MASK GENMASK(23, 12) |
| 405 | #define ADP_USB3_CS_1_CDBW_SHIFT 12 |
| 406 | #define ADP_USB3_CS_1_HCA BIT(31) |
| 407 | #define ADP_USB3_CS_2 0x02 |
| 408 | #define ADP_USB3_CS_2_AUBW_MASK GENMASK(11, 0) |
| 409 | #define ADP_USB3_CS_2_ADBW_MASK GENMASK(23, 12) |
| 410 | #define ADP_USB3_CS_2_ADBW_SHIFT 12 |
| 411 | #define ADP_USB3_CS_2_CMR BIT(31) |
| 412 | #define ADP_USB3_CS_3 0x03 |
| 413 | #define ADP_USB3_CS_3_SCALE_MASK GENMASK(5, 0) |
| 414 | #define ADP_USB3_CS_4 0x04 |
| 415 | #define ADP_USB3_CS_4_ALR_MASK GENMASK(6, 0) |
| 416 | #define ADP_USB3_CS_4_ALR_20G 0x1 |
| 417 | #define ADP_USB3_CS_4_ULV BIT(7) |
| 418 | #define ADP_USB3_CS_4_MSLR_MASK GENMASK(18, 12) |
| 419 | #define ADP_USB3_CS_4_MSLR_SHIFT 12 |
| 420 | #define ADP_USB3_CS_4_MSLR_20G 0x1 |
Rajmohan Mani | e6f8185 | 2019-12-17 15:33:44 +0300 | [diff] [blame] | 421 | |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 422 | /* Hop register from TB_CFG_HOPS. 8 byte per entry. */ |
| 423 | struct tb_regs_hop { |
| 424 | /* DWORD 0 */ |
| 425 | u32 next_hop:11; /* |
| 426 | * hop to take after sending the packet through |
| 427 | * out_port (on the incoming port of the next switch) |
| 428 | */ |
| 429 | u32 out_port:6; /* next port of the path (on the same switch) */ |
| 430 | u32 initial_credits:8; |
| 431 | u32 unknown1:6; /* set to zero */ |
| 432 | bool enable:1; |
| 433 | |
| 434 | /* DWORD 1 */ |
| 435 | u32 weight:4; |
| 436 | u32 unknown2:4; /* set to zero */ |
| 437 | u32 priority:3; |
| 438 | bool drop_packages:1; |
| 439 | u32 counter:11; /* index into TB_CFG_COUNTERS on this port */ |
| 440 | bool counter_enable:1; |
| 441 | bool ingress_fc:1; |
| 442 | bool egress_fc:1; |
| 443 | bool ingress_shared_buffer:1; |
| 444 | bool egress_shared_buffer:1; |
Mika Westerberg | 4944269 | 2017-02-17 17:05:37 +0200 | [diff] [blame] | 445 | bool pending:1; |
| 446 | u32 unknown3:3; /* set to zero */ |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 447 | } __packed; |
| 448 | |
Gil Fine | 23ccd21 | 2021-12-17 03:16:41 +0200 | [diff] [blame] | 449 | /* TMU Thunderbolt 3 registers */ |
Gil Fine | 43f977b | 2021-12-17 03:16:43 +0200 | [diff] [blame] | 450 | #define TB_TIME_VSEC_3_CS_9 0x9 |
| 451 | #define TB_TIME_VSEC_3_CS_9_TMU_OBJ_MASK GENMASK(17, 16) |
| 452 | #define TB_TIME_VSEC_3_CS_26 0x1a |
| 453 | #define TB_TIME_VSEC_3_CS_26_TD BIT(22) |
| 454 | |
| 455 | /* |
| 456 | * Used for Titan Ridge only. Bits are part of the same register: TMU_ADP_CS_6 |
| 457 | * (see above) as in USB4 spec, but these specific bits used for Titan Ridge |
| 458 | * only and reserved in USB4 spec. |
| 459 | */ |
| 460 | #define TMU_ADP_CS_6_DISABLE_TMU_OBJ_MASK GENMASK(3, 2) |
| 461 | #define TMU_ADP_CS_6_DISABLE_TMU_OBJ_CL1 BIT(2) |
| 462 | #define TMU_ADP_CS_6_DISABLE_TMU_OBJ_CL2 BIT(3) |
| 463 | |
| 464 | /* Plug Events registers */ |
| 465 | #define TB_PLUG_EVENTS_PCIE_WR_DATA 0x1b |
| 466 | #define TB_PLUG_EVENTS_PCIE_CMD 0x1c |
| 467 | #define TB_PLUG_EVENTS_PCIE_CMD_DW_OFFSET_MASK GENMASK(9, 0) |
| 468 | #define TB_PLUG_EVENTS_PCIE_CMD_BR_SHIFT 10 |
| 469 | #define TB_PLUG_EVENTS_PCIE_CMD_BR_MASK GENMASK(17, 10) |
| 470 | #define TB_PLUG_EVENTS_PCIE_CMD_RD_WR_MASK BIT(21) |
| 471 | #define TB_PLUG_EVENTS_PCIE_CMD_WR 0x1 |
| 472 | #define TB_PLUG_EVENTS_PCIE_CMD_COMMAND_SHIFT 22 |
| 473 | #define TB_PLUG_EVENTS_PCIE_CMD_COMMAND_MASK GENMASK(24, 22) |
| 474 | #define TB_PLUG_EVENTS_PCIE_CMD_COMMAND_VAL 0x2 |
| 475 | #define TB_PLUG_EVENTS_PCIE_CMD_REQ_ACK_MASK BIT(30) |
| 476 | #define TB_PLUG_EVENTS_PCIE_CMD_TIMEOUT_MASK BIT(31) |
| 477 | #define TB_PLUG_EVENTS_PCIE_CMD_RD_DATA 0x1d |
| 478 | |
| 479 | /* CP Low Power registers */ |
| 480 | #define TB_LOW_PWR_C1_CL1 0x1 |
| 481 | #define TB_LOW_PWR_C1_CL1_OBJ_MASK GENMASK(4, 1) |
| 482 | #define TB_LOW_PWR_C1_CL2_OBJ_MASK GENMASK(4, 1) |
| 483 | #define TB_LOW_PWR_C1_PORT_A_MASK GENMASK(2, 1) |
| 484 | #define TB_LOW_PWR_C0_PORT_B_MASK GENMASK(4, 3) |
| 485 | #define TB_LOW_PWR_C3_CL1 0x3 |
Gil Fine | 23ccd21 | 2021-12-17 03:16:41 +0200 | [diff] [blame] | 486 | |
Mika Westerberg | a9be558 | 2019-01-09 16:42:12 +0200 | [diff] [blame] | 487 | /* Common link controller registers */ |
Gil Fine | 43f977b | 2021-12-17 03:16:43 +0200 | [diff] [blame] | 488 | #define TB_LC_DESC 0x02 |
| 489 | #define TB_LC_DESC_NLC_MASK GENMASK(3, 0) |
| 490 | #define TB_LC_DESC_SIZE_SHIFT 8 |
| 491 | #define TB_LC_DESC_SIZE_MASK GENMASK(15, 8) |
| 492 | #define TB_LC_DESC_PORT_SIZE_SHIFT 16 |
| 493 | #define TB_LC_DESC_PORT_SIZE_MASK GENMASK(27, 16) |
| 494 | #define TB_LC_FUSE 0x03 |
| 495 | #define TB_LC_SNK_ALLOCATION 0x10 |
| 496 | #define TB_LC_SNK_ALLOCATION_SNK0_MASK GENMASK(3, 0) |
| 497 | #define TB_LC_SNK_ALLOCATION_SNK0_CM 0x1 |
| 498 | #define TB_LC_SNK_ALLOCATION_SNK1_SHIFT 4 |
| 499 | #define TB_LC_SNK_ALLOCATION_SNK1_MASK GENMASK(7, 4) |
| 500 | #define TB_LC_SNK_ALLOCATION_SNK1_CM 0x1 |
| 501 | #define TB_LC_POWER 0x740 |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 502 | |
Mika Westerberg | e879a70 | 2018-10-11 12:33:08 +0300 | [diff] [blame] | 503 | /* Link controller registers */ |
Gil Fine | 43f977b | 2021-12-17 03:16:43 +0200 | [diff] [blame] | 504 | #define TB_LC_PORT_ATTR 0x8d |
| 505 | #define TB_LC_PORT_ATTR_BE BIT(12) |
Mika Westerberg | 91c0c12 | 2019-03-21 19:03:00 +0200 | [diff] [blame] | 506 | |
Gil Fine | 43f977b | 2021-12-17 03:16:43 +0200 | [diff] [blame] | 507 | #define TB_LC_SX_CTRL 0x96 |
| 508 | #define TB_LC_SX_CTRL_WOC BIT(1) |
| 509 | #define TB_LC_SX_CTRL_WOD BIT(2) |
| 510 | #define TB_LC_SX_CTRL_WODPC BIT(3) |
| 511 | #define TB_LC_SX_CTRL_WODPD BIT(4) |
| 512 | #define TB_LC_SX_CTRL_WOU4 BIT(5) |
| 513 | #define TB_LC_SX_CTRL_WOP BIT(6) |
| 514 | #define TB_LC_SX_CTRL_L1C BIT(16) |
| 515 | #define TB_LC_SX_CTRL_L1D BIT(17) |
| 516 | #define TB_LC_SX_CTRL_L2C BIT(20) |
| 517 | #define TB_LC_SX_CTRL_L2D BIT(21) |
| 518 | #define TB_LC_SX_CTRL_SLI BIT(29) |
| 519 | #define TB_LC_SX_CTRL_UPSTREAM BIT(30) |
| 520 | #define TB_LC_SX_CTRL_SLP BIT(31) |
| 521 | #define TB_LC_LINK_ATTR 0x97 |
| 522 | #define TB_LC_LINK_ATTR_CPS BIT(18) |
Mika Westerberg | e879a70 | 2018-10-11 12:33:08 +0300 | [diff] [blame] | 523 | |
Andreas Noever | 7adf609 | 2014-06-03 22:04:01 +0200 | [diff] [blame] | 524 | #endif |