blob: 77d4b8598835a4784349f3b64ed2d91221bd637f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andreas Noever7adf6092014-06-03 22:04:01 +02002/*
Mika Westerberg15c67842018-10-01 12:31:22 +03003 * Thunderbolt driver - Port/Switch config area registers
Andreas Noever7adf6092014-06-03 22:04:01 +02004 *
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 Westerberg15c67842018-10-01 12:31:22 +030010 * Copyright (C) 2018, Intel Corporation
Andreas Noever7adf6092014-06-03 22:04:01 +020011 */
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 Westerbergda2da042017-06-06 15:24:58 +030028enum tb_switch_cap {
Rajmohan Manicf29b9af2019-12-17 15:33:43 +030029 TB_SWITCH_CAP_TMU = 0x03,
Mika Westerbergda2da042017-06-06 15:24:58 +030030 TB_SWITCH_CAP_VSE = 0x05,
31};
32
33enum tb_switch_vse_cap {
34 TB_VSE_CAP_PLUG_EVENTS = 0x01, /* also EEPROM */
35 TB_VSE_CAP_TIME2 = 0x03,
36 TB_VSE_CAP_IECS = 0x04,
37 TB_VSE_CAP_LINK_CONTROLLER = 0x06, /* also IECS */
38};
39
40enum tb_port_cap {
41 TB_PORT_CAP_PHY = 0x01,
42 TB_PORT_CAP_TIME1 = 0x03,
43 TB_PORT_CAP_ADAP = 0x04,
44 TB_PORT_CAP_VSE = 0x05,
Mika Westerbergb0407982019-12-17 15:33:40 +030045 TB_PORT_CAP_USB4 = 0x06,
Andreas Noever7adf6092014-06-03 22:04:01 +020046};
47
48enum tb_port_state {
49 TB_PORT_DISABLED = 0, /* tb_cap_phy.disable == 1 */
50 TB_PORT_CONNECTING = 1, /* retry */
51 TB_PORT_UP = 2,
52 TB_PORT_UNPLUGGED = 7,
53};
54
55/* capability headers */
56
57struct tb_cap_basic {
58 u8 next;
59 /* enum tb_cap cap:8; prevent "narrower than values of its type" */
60 u8 cap; /* if cap == 0x05 then we have a extended capability */
61} __packed;
62
Mika Westerbergda2da042017-06-06 15:24:58 +030063/**
64 * struct tb_cap_extended_short - Switch extended short capability
65 * @next: Pointer to the next capability. If @next and @length are zero
66 * then we have a long cap.
67 * @cap: Base capability ID (see &enum tb_switch_cap)
68 * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap)
69 * @length: Length of this capability
70 */
Andreas Noever7adf6092014-06-03 22:04:01 +020071struct tb_cap_extended_short {
Mika Westerbergda2da042017-06-06 15:24:58 +030072 u8 next;
73 u8 cap;
74 u8 vsec_id;
Andreas Noever7adf6092014-06-03 22:04:01 +020075 u8 length;
76} __packed;
77
Mika Westerbergda2da042017-06-06 15:24:58 +030078/**
79 * struct tb_cap_extended_long - Switch extended long capability
80 * @zero1: This field should be zero
81 * @cap: Base capability ID (see &enum tb_switch_cap)
82 * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap)
83 * @zero2: This field should be zero
84 * @next: Pointer to the next capability
85 * @length: Length of this capability
86 */
Andreas Noever7adf6092014-06-03 22:04:01 +020087struct tb_cap_extended_long {
88 u8 zero1;
Mika Westerbergda2da042017-06-06 15:24:58 +030089 u8 cap;
90 u8 vsec_id;
Andreas Noever7adf6092014-06-03 22:04:01 +020091 u8 zero2;
92 u16 next;
93 u16 length;
94} __packed;
95
96/* capabilities */
97
98struct tb_cap_link_controller {
99 struct tb_cap_extended_long cap_header;
100 u32 count:4; /* number of link controllers */
101 u32 unknown1:4;
102 u32 base_offset:8; /*
103 * offset (into this capability) of the configuration
104 * area of the first link controller
105 */
106 u32 length:12; /* link controller configuration area length */
107 u32 unknown2:4; /* TODO check that length is correct */
108} __packed;
109
110struct tb_cap_phy {
111 struct tb_cap_basic cap_header;
112 u32 unknown1:16;
113 u32 unknown2:14;
114 bool disable:1;
115 u32 unknown3:11;
116 enum tb_port_state state:4;
117 u32 unknown4:2;
118} __packed;
119
120struct tb_eeprom_ctl {
121 bool clock:1; /* send pulse to transfer one bit */
122 bool access_low:1; /* set to 0 before access */
123 bool data_out:1; /* to eeprom */
124 bool data_in:1; /* from eeprom */
125 bool access_high:1; /* set to 1 before access */
126 bool not_present:1; /* should be 0 */
127 bool unknown1:1;
128 bool present:1; /* should be 1 */
129 u32 unknown2:24;
130} __packed;
131
132struct tb_cap_plug_events {
133 struct tb_cap_extended_short cap_header;
134 u32 __unknown1:2;
135 u32 plug_events:5;
136 u32 __unknown2:25;
137 u32 __unknown3;
138 u32 __unknown4;
139 struct tb_eeprom_ctl eeprom_ctl;
140 u32 __unknown5[7];
141 u32 drom_offset; /* 32 bit register, but eeprom addresses are 16 bit */
142} __packed;
143
144/* device headers */
145
146/* Present on port 0 in TB_CFG_SWITCH at address zero. */
147struct tb_regs_switch_header {
148 /* DWORD 0 */
149 u16 vendor_id;
150 u16 device_id;
151 /* DWORD 1 */
152 u32 first_cap_offset:8;
153 u32 upstream_port_number:6;
154 u32 max_port_number:6;
155 u32 depth:3;
156 u32 __unknown1:1;
157 u32 revision:8;
158 /* DWORD 2 */
159 u32 route_lo;
160 /* DWORD 3 */
161 u32 route_hi:31;
162 bool enabled:1;
163 /* DWORD 4 */
164 u32 plug_events_delay:8; /*
165 * RW, pause between plug events in
166 * milliseconds. Writing 0x00 is interpreted
167 * as 255ms.
168 */
Mika Westerbergb0407982019-12-17 15:33:40 +0300169 u32 cmuv:8;
170 u32 __unknown4:8;
Andreas Noever7adf6092014-06-03 22:04:01 +0200171 u32 thunderbolt_version:8;
172} __packed;
173
Mika Westerbergb0407982019-12-17 15:33:40 +0300174/* USB4 version 1.0 */
175#define USB4_VERSION_1_0 0x20
176
177#define ROUTER_CS_1 0x01
178#define ROUTER_CS_4 0x04
179#define ROUTER_CS_5 0x05
180#define ROUTER_CS_5_SLP BIT(0)
181#define ROUTER_CS_5_C3S BIT(23)
182#define ROUTER_CS_5_PTO BIT(24)
Rajmohan Manie6f81852019-12-17 15:33:44 +0300183#define ROUTER_CS_5_UTO BIT(25)
Mika Westerbergb0407982019-12-17 15:33:40 +0300184#define ROUTER_CS_5_HCO BIT(26)
185#define ROUTER_CS_5_CV BIT(31)
186#define ROUTER_CS_6 0x06
187#define ROUTER_CS_6_SLPR BIT(0)
188#define ROUTER_CS_6_TNS BIT(1)
189#define ROUTER_CS_6_HCI BIT(18)
190#define ROUTER_CS_6_CR BIT(25)
191#define ROUTER_CS_7 0x07
192#define ROUTER_CS_9 0x09
193#define ROUTER_CS_25 0x19
194#define ROUTER_CS_26 0x1a
195#define ROUTER_CS_26_STATUS_MASK GENMASK(29, 24)
196#define ROUTER_CS_26_STATUS_SHIFT 24
197#define ROUTER_CS_26_ONS BIT(30)
198#define ROUTER_CS_26_OV BIT(31)
199
Rajmohan Manicf29b9af2019-12-17 15:33:43 +0300200/* Router TMU configuration */
201#define TMU_RTR_CS_0 0x00
202#define TMU_RTR_CS_0_TD BIT(27)
203#define TMU_RTR_CS_0_UCAP BIT(30)
204#define TMU_RTR_CS_1 0x01
205#define TMU_RTR_CS_1_LOCAL_TIME_NS_MASK GENMASK(31, 16)
206#define TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT 16
207#define TMU_RTR_CS_2 0x02
208#define TMU_RTR_CS_3 0x03
209#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0)
210#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16)
211#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16
212#define TMU_RTR_CS_22 0x16
213#define TMU_RTR_CS_24 0x18
214
Andreas Noever7adf6092014-06-03 22:04:01 +0200215enum tb_port_type {
216 TB_TYPE_INACTIVE = 0x000000,
217 TB_TYPE_PORT = 0x000001,
218 TB_TYPE_NHI = 0x000002,
219 /* TB_TYPE_ETHERNET = 0x020000, lower order bits are not known */
220 /* TB_TYPE_SATA = 0x080000, lower order bits are not known */
221 TB_TYPE_DP_HDMI_IN = 0x0e0101,
222 TB_TYPE_DP_HDMI_OUT = 0x0e0102,
223 TB_TYPE_PCIE_DOWN = 0x100101,
224 TB_TYPE_PCIE_UP = 0x100102,
Rajmohan Manie6f81852019-12-17 15:33:44 +0300225 TB_TYPE_USB3_DOWN = 0x200101,
226 TB_TYPE_USB3_UP = 0x200102,
Andreas Noever7adf6092014-06-03 22:04:01 +0200227};
228
229/* Present on every port in TB_CF_PORT at address zero. */
230struct tb_regs_port_header {
231 /* DWORD 0 */
232 u16 vendor_id;
233 u16 device_id;
234 /* DWORD 1 */
235 u32 first_cap_offset:8;
236 u32 max_counters:11;
237 u32 __unknown1:5;
238 u32 revision:8;
239 /* DWORD 2 */
240 enum tb_port_type type:24;
241 u32 thunderbolt_version:8;
242 /* DWORD 3 */
243 u32 __unknown2:20;
244 u32 port_number:6;
245 u32 __unknown3:6;
246 /* DWORD 4 */
247 u32 nfc_credits;
248 /* DWORD 5 */
249 u32 max_in_hop_id:11;
250 u32 max_out_hop_id:11;
Nathan Ciobanuc3569152018-07-25 11:03:15 +0300251 u32 __unknown4:10;
Andreas Noever7adf6092014-06-03 22:04:01 +0200252 /* DWORD 6 */
253 u32 __unknown5;
254 /* DWORD 7 */
255 u32 __unknown6;
256
257} __packed;
258
Mika Westerberg8f57d472019-09-06 11:59:00 +0300259/* Basic adapter configuration registers */
260#define ADP_CS_4 0x04
261#define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0)
262#define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20)
263#define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20
Mika Westerbergb0407982019-12-17 15:33:40 +0300264#define ADP_CS_4_LCK BIT(31)
Mika Westerberg8f57d472019-09-06 11:59:00 +0300265#define ADP_CS_5 0x05
266#define ADP_CS_5_LCA_MASK GENMASK(28, 22)
267#define ADP_CS_5_LCA_SHIFT 22
Mika Westerberg4f807e42018-09-17 16:30:49 +0300268
Rajmohan Manicf29b9af2019-12-17 15:33:43 +0300269/* TMU adapter registers */
270#define TMU_ADP_CS_3 0x03
271#define TMU_ADP_CS_3_UDM BIT(29)
272
Mika Westerberg91c0c122019-03-21 19:03:00 +0200273/* Lane adapter registers */
274#define LANE_ADP_CS_0 0x00
275#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20)
276#define LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT 20
277#define LANE_ADP_CS_1 0x01
278#define LANE_ADP_CS_1_TARGET_WIDTH_MASK GENMASK(9, 4)
279#define LANE_ADP_CS_1_TARGET_WIDTH_SHIFT 4
280#define LANE_ADP_CS_1_TARGET_WIDTH_SINGLE 0x1
281#define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3
282#define LANE_ADP_CS_1_LB BIT(15)
283#define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16)
284#define LANE_ADP_CS_1_CURRENT_SPEED_SHIFT 16
285#define LANE_ADP_CS_1_CURRENT_SPEED_GEN2 0x8
286#define LANE_ADP_CS_1_CURRENT_SPEED_GEN3 0x4
287#define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20)
288#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20
289
Mika Westerbergb0407982019-12-17 15:33:40 +0300290/* USB4 port registers */
291#define PORT_CS_18 0x12
292#define PORT_CS_18_BE BIT(8)
Mika Westerbergbbcf40b2020-03-04 17:09:14 +0200293#define PORT_CS_18_TCM BIT(9)
Mika Westerbergb0407982019-12-17 15:33:40 +0300294#define PORT_CS_19 0x13
295#define PORT_CS_19_PC BIT(3)
296
Mika Westerberg4f807e42018-09-17 16:30:49 +0300297/* Display Port adapter registers */
Mika Westerberg98176382019-09-06 11:32:15 +0300298#define ADP_DP_CS_0 0x00
299#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16)
300#define ADP_DP_CS_0_VIDEO_HOPID_SHIFT 16
301#define ADP_DP_CS_0_AE BIT(30)
302#define ADP_DP_CS_0_VE BIT(31)
303#define ADP_DP_CS_1_AUX_TX_HOPID_MASK GENMASK(10, 0)
304#define ADP_DP_CS_1_AUX_RX_HOPID_MASK GENMASK(21, 11)
305#define ADP_DP_CS_1_AUX_RX_HOPID_SHIFT 11
306#define ADP_DP_CS_2 0x02
307#define ADP_DP_CS_2_HDP BIT(6)
308#define ADP_DP_CS_3 0x03
309#define ADP_DP_CS_3_HDPC BIT(9)
310#define DP_LOCAL_CAP 0x04
311#define DP_REMOTE_CAP 0x05
Mika Westerbergde718ac2019-02-15 18:18:47 +0200312#define DP_STATUS_CTRL 0x06
313#define DP_STATUS_CTRL_CMHS BIT(25)
314#define DP_STATUS_CTRL_UF BIT(26)
Mika Westerberga11b88a2019-03-26 16:03:48 +0300315#define DP_COMMON_CAP 0x07
316/*
317 * DP_COMMON_CAP offsets work also for DP_LOCAL_CAP and DP_REMOTE_CAP
318 * with exception of DPRX done.
319 */
320#define DP_COMMON_CAP_RATE_MASK GENMASK(11, 8)
321#define DP_COMMON_CAP_RATE_SHIFT 8
322#define DP_COMMON_CAP_RATE_RBR 0x0
323#define DP_COMMON_CAP_RATE_HBR 0x1
324#define DP_COMMON_CAP_RATE_HBR2 0x2
325#define DP_COMMON_CAP_RATE_HBR3 0x3
326#define DP_COMMON_CAP_LANES_MASK GENMASK(14, 12)
327#define DP_COMMON_CAP_LANES_SHIFT 12
328#define DP_COMMON_CAP_1_LANE 0x0
329#define DP_COMMON_CAP_2_LANES 0x1
330#define DP_COMMON_CAP_4_LANES 0x2
331#define DP_COMMON_CAP_DPRX_DONE BIT(31)
Mika Westerbergc5ee6fe2018-10-11 11:38:22 +0300332
Mika Westerberg93f36ad2017-02-19 13:48:29 +0200333/* PCIe adapter registers */
Mika Westerberg778bfca2019-09-06 12:05:24 +0300334#define ADP_PCIE_CS_0 0x00
335#define ADP_PCIE_CS_0_PE BIT(31)
Mika Westerberg93f36ad2017-02-19 13:48:29 +0200336
Rajmohan Manie6f81852019-12-17 15:33:44 +0300337/* USB adapter registers */
338#define ADP_USB3_CS_0 0x00
339#define ADP_USB3_CS_0_V BIT(30)
340#define ADP_USB3_CS_0_PE BIT(31)
341
Andreas Noever7adf6092014-06-03 22:04:01 +0200342/* Hop register from TB_CFG_HOPS. 8 byte per entry. */
343struct tb_regs_hop {
344 /* DWORD 0 */
345 u32 next_hop:11; /*
346 * hop to take after sending the packet through
347 * out_port (on the incoming port of the next switch)
348 */
349 u32 out_port:6; /* next port of the path (on the same switch) */
350 u32 initial_credits:8;
351 u32 unknown1:6; /* set to zero */
352 bool enable:1;
353
354 /* DWORD 1 */
355 u32 weight:4;
356 u32 unknown2:4; /* set to zero */
357 u32 priority:3;
358 bool drop_packages:1;
359 u32 counter:11; /* index into TB_CFG_COUNTERS on this port */
360 bool counter_enable:1;
361 bool ingress_fc:1;
362 bool egress_fc:1;
363 bool ingress_shared_buffer:1;
364 bool egress_shared_buffer:1;
Mika Westerberg49442692017-02-17 17:05:37 +0200365 bool pending:1;
366 u32 unknown3:3; /* set to zero */
Andreas Noever7adf6092014-06-03 22:04:01 +0200367} __packed;
368
Mika Westerberga9be5582019-01-09 16:42:12 +0200369/* Common link controller registers */
Mika Westerberge879a702018-10-11 12:33:08 +0300370#define TB_LC_DESC 0x02
Mika Westerberg5480dfc2019-01-09 17:25:43 +0200371#define TB_LC_DESC_NLC_MASK GENMASK(3, 0)
Mika Westerberge879a702018-10-11 12:33:08 +0300372#define TB_LC_DESC_SIZE_SHIFT 8
373#define TB_LC_DESC_SIZE_MASK GENMASK(15, 8)
374#define TB_LC_DESC_PORT_SIZE_SHIFT 16
375#define TB_LC_DESC_PORT_SIZE_MASK GENMASK(27, 16)
Mika Westerberga9be5582019-01-09 16:42:12 +0200376#define TB_LC_FUSE 0x03
Mika Westerberg8afe9092019-03-26 15:52:30 +0300377#define TB_LC_SNK_ALLOCATION 0x10
378#define TB_LC_SNK_ALLOCATION_SNK0_MASK GENMASK(3, 0)
379#define TB_LC_SNK_ALLOCATION_SNK0_CM 0x1
380#define TB_LC_SNK_ALLOCATION_SNK1_SHIFT 4
381#define TB_LC_SNK_ALLOCATION_SNK1_MASK GENMASK(7, 4)
382#define TB_LC_SNK_ALLOCATION_SNK1_CM 0x1
Andreas Noever7adf6092014-06-03 22:04:01 +0200383
Mika Westerberge879a702018-10-11 12:33:08 +0300384/* Link controller registers */
Mika Westerberg91c0c122019-03-21 19:03:00 +0200385#define TB_LC_PORT_ATTR 0x8d
386#define TB_LC_PORT_ATTR_BE BIT(12)
387
Mika Westerberge879a702018-10-11 12:33:08 +0300388#define TB_LC_SX_CTRL 0x96
389#define TB_LC_SX_CTRL_L1C BIT(16)
390#define TB_LC_SX_CTRL_L2C BIT(20)
391#define TB_LC_SX_CTRL_UPSTREAM BIT(30)
Mika Westerberg5480dfc2019-01-09 17:25:43 +0200392#define TB_LC_SX_CTRL_SLP BIT(31)
Mika Westerberge879a702018-10-11 12:33:08 +0300393
Andreas Noever7adf6092014-06-03 22:04:01 +0200394#endif