blob: ec1a5d1f7c942686b619b2b6ca851b81c454154f [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)
183#define ROUTER_CS_5_HCO BIT(26)
184#define ROUTER_CS_5_CV BIT(31)
185#define ROUTER_CS_6 0x06
186#define ROUTER_CS_6_SLPR BIT(0)
187#define ROUTER_CS_6_TNS BIT(1)
188#define ROUTER_CS_6_HCI BIT(18)
189#define ROUTER_CS_6_CR BIT(25)
190#define ROUTER_CS_7 0x07
191#define ROUTER_CS_9 0x09
192#define ROUTER_CS_25 0x19
193#define ROUTER_CS_26 0x1a
194#define ROUTER_CS_26_STATUS_MASK GENMASK(29, 24)
195#define ROUTER_CS_26_STATUS_SHIFT 24
196#define ROUTER_CS_26_ONS BIT(30)
197#define ROUTER_CS_26_OV BIT(31)
198
Rajmohan Manicf29b9af2019-12-17 15:33:43 +0300199/* Router TMU configuration */
200#define TMU_RTR_CS_0 0x00
201#define TMU_RTR_CS_0_TD BIT(27)
202#define TMU_RTR_CS_0_UCAP BIT(30)
203#define TMU_RTR_CS_1 0x01
204#define TMU_RTR_CS_1_LOCAL_TIME_NS_MASK GENMASK(31, 16)
205#define TMU_RTR_CS_1_LOCAL_TIME_NS_SHIFT 16
206#define TMU_RTR_CS_2 0x02
207#define TMU_RTR_CS_3 0x03
208#define TMU_RTR_CS_3_LOCAL_TIME_NS_MASK GENMASK(15, 0)
209#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_MASK GENMASK(31, 16)
210#define TMU_RTR_CS_3_TS_PACKET_INTERVAL_SHIFT 16
211#define TMU_RTR_CS_22 0x16
212#define TMU_RTR_CS_24 0x18
213
Andreas Noever7adf6092014-06-03 22:04:01 +0200214enum tb_port_type {
215 TB_TYPE_INACTIVE = 0x000000,
216 TB_TYPE_PORT = 0x000001,
217 TB_TYPE_NHI = 0x000002,
218 /* TB_TYPE_ETHERNET = 0x020000, lower order bits are not known */
219 /* TB_TYPE_SATA = 0x080000, lower order bits are not known */
220 TB_TYPE_DP_HDMI_IN = 0x0e0101,
221 TB_TYPE_DP_HDMI_OUT = 0x0e0102,
222 TB_TYPE_PCIE_DOWN = 0x100101,
223 TB_TYPE_PCIE_UP = 0x100102,
224 /* TB_TYPE_USB = 0x200000, lower order bits are not known */
225};
226
227/* Present on every port in TB_CF_PORT at address zero. */
228struct tb_regs_port_header {
229 /* DWORD 0 */
230 u16 vendor_id;
231 u16 device_id;
232 /* DWORD 1 */
233 u32 first_cap_offset:8;
234 u32 max_counters:11;
235 u32 __unknown1:5;
236 u32 revision:8;
237 /* DWORD 2 */
238 enum tb_port_type type:24;
239 u32 thunderbolt_version:8;
240 /* DWORD 3 */
241 u32 __unknown2:20;
242 u32 port_number:6;
243 u32 __unknown3:6;
244 /* DWORD 4 */
245 u32 nfc_credits;
246 /* DWORD 5 */
247 u32 max_in_hop_id:11;
248 u32 max_out_hop_id:11;
Nathan Ciobanuc3569152018-07-25 11:03:15 +0300249 u32 __unknown4:10;
Andreas Noever7adf6092014-06-03 22:04:01 +0200250 /* DWORD 6 */
251 u32 __unknown5;
252 /* DWORD 7 */
253 u32 __unknown6;
254
255} __packed;
256
Mika Westerberg8f57d472019-09-06 11:59:00 +0300257/* Basic adapter configuration registers */
258#define ADP_CS_4 0x04
259#define ADP_CS_4_NFC_BUFFERS_MASK GENMASK(9, 0)
260#define ADP_CS_4_TOTAL_BUFFERS_MASK GENMASK(29, 20)
261#define ADP_CS_4_TOTAL_BUFFERS_SHIFT 20
Mika Westerbergb0407982019-12-17 15:33:40 +0300262#define ADP_CS_4_LCK BIT(31)
Mika Westerberg8f57d472019-09-06 11:59:00 +0300263#define ADP_CS_5 0x05
264#define ADP_CS_5_LCA_MASK GENMASK(28, 22)
265#define ADP_CS_5_LCA_SHIFT 22
Mika Westerberg4f807e42018-09-17 16:30:49 +0300266
Rajmohan Manicf29b9af2019-12-17 15:33:43 +0300267/* TMU adapter registers */
268#define TMU_ADP_CS_3 0x03
269#define TMU_ADP_CS_3_UDM BIT(29)
270
Mika Westerberg91c0c122019-03-21 19:03:00 +0200271/* Lane adapter registers */
272#define LANE_ADP_CS_0 0x00
273#define LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK GENMASK(25, 20)
274#define LANE_ADP_CS_0_SUPPORTED_WIDTH_SHIFT 20
275#define LANE_ADP_CS_1 0x01
276#define LANE_ADP_CS_1_TARGET_WIDTH_MASK GENMASK(9, 4)
277#define LANE_ADP_CS_1_TARGET_WIDTH_SHIFT 4
278#define LANE_ADP_CS_1_TARGET_WIDTH_SINGLE 0x1
279#define LANE_ADP_CS_1_TARGET_WIDTH_DUAL 0x3
280#define LANE_ADP_CS_1_LB BIT(15)
281#define LANE_ADP_CS_1_CURRENT_SPEED_MASK GENMASK(19, 16)
282#define LANE_ADP_CS_1_CURRENT_SPEED_SHIFT 16
283#define LANE_ADP_CS_1_CURRENT_SPEED_GEN2 0x8
284#define LANE_ADP_CS_1_CURRENT_SPEED_GEN3 0x4
285#define LANE_ADP_CS_1_CURRENT_WIDTH_MASK GENMASK(25, 20)
286#define LANE_ADP_CS_1_CURRENT_WIDTH_SHIFT 20
287
Mika Westerbergb0407982019-12-17 15:33:40 +0300288/* USB4 port registers */
289#define PORT_CS_18 0x12
290#define PORT_CS_18_BE BIT(8)
291#define PORT_CS_19 0x13
292#define PORT_CS_19_PC BIT(3)
293
Mika Westerberg4f807e42018-09-17 16:30:49 +0300294/* Display Port adapter registers */
Mika Westerberg98176382019-09-06 11:32:15 +0300295#define ADP_DP_CS_0 0x00
296#define ADP_DP_CS_0_VIDEO_HOPID_MASK GENMASK(26, 16)
297#define ADP_DP_CS_0_VIDEO_HOPID_SHIFT 16
298#define ADP_DP_CS_0_AE BIT(30)
299#define ADP_DP_CS_0_VE BIT(31)
300#define ADP_DP_CS_1_AUX_TX_HOPID_MASK GENMASK(10, 0)
301#define ADP_DP_CS_1_AUX_RX_HOPID_MASK GENMASK(21, 11)
302#define ADP_DP_CS_1_AUX_RX_HOPID_SHIFT 11
303#define ADP_DP_CS_2 0x02
304#define ADP_DP_CS_2_HDP BIT(6)
305#define ADP_DP_CS_3 0x03
306#define ADP_DP_CS_3_HDPC BIT(9)
307#define DP_LOCAL_CAP 0x04
308#define DP_REMOTE_CAP 0x05
Mika Westerbergde718ac2019-02-15 18:18:47 +0200309#define DP_STATUS_CTRL 0x06
310#define DP_STATUS_CTRL_CMHS BIT(25)
311#define DP_STATUS_CTRL_UF BIT(26)
Mika Westerberga11b88a2019-03-26 16:03:48 +0300312#define DP_COMMON_CAP 0x07
313/*
314 * DP_COMMON_CAP offsets work also for DP_LOCAL_CAP and DP_REMOTE_CAP
315 * with exception of DPRX done.
316 */
317#define DP_COMMON_CAP_RATE_MASK GENMASK(11, 8)
318#define DP_COMMON_CAP_RATE_SHIFT 8
319#define DP_COMMON_CAP_RATE_RBR 0x0
320#define DP_COMMON_CAP_RATE_HBR 0x1
321#define DP_COMMON_CAP_RATE_HBR2 0x2
322#define DP_COMMON_CAP_RATE_HBR3 0x3
323#define DP_COMMON_CAP_LANES_MASK GENMASK(14, 12)
324#define DP_COMMON_CAP_LANES_SHIFT 12
325#define DP_COMMON_CAP_1_LANE 0x0
326#define DP_COMMON_CAP_2_LANES 0x1
327#define DP_COMMON_CAP_4_LANES 0x2
328#define DP_COMMON_CAP_DPRX_DONE BIT(31)
Mika Westerbergc5ee6fe2018-10-11 11:38:22 +0300329
Mika Westerberg93f36ad2017-02-19 13:48:29 +0200330/* PCIe adapter registers */
Mika Westerberg778bfca2019-09-06 12:05:24 +0300331#define ADP_PCIE_CS_0 0x00
332#define ADP_PCIE_CS_0_PE BIT(31)
Mika Westerberg93f36ad2017-02-19 13:48:29 +0200333
Andreas Noever7adf6092014-06-03 22:04:01 +0200334/* Hop register from TB_CFG_HOPS. 8 byte per entry. */
335struct tb_regs_hop {
336 /* DWORD 0 */
337 u32 next_hop:11; /*
338 * hop to take after sending the packet through
339 * out_port (on the incoming port of the next switch)
340 */
341 u32 out_port:6; /* next port of the path (on the same switch) */
342 u32 initial_credits:8;
343 u32 unknown1:6; /* set to zero */
344 bool enable:1;
345
346 /* DWORD 1 */
347 u32 weight:4;
348 u32 unknown2:4; /* set to zero */
349 u32 priority:3;
350 bool drop_packages:1;
351 u32 counter:11; /* index into TB_CFG_COUNTERS on this port */
352 bool counter_enable:1;
353 bool ingress_fc:1;
354 bool egress_fc:1;
355 bool ingress_shared_buffer:1;
356 bool egress_shared_buffer:1;
Mika Westerberg49442692017-02-17 17:05:37 +0200357 bool pending:1;
358 u32 unknown3:3; /* set to zero */
Andreas Noever7adf6092014-06-03 22:04:01 +0200359} __packed;
360
Mika Westerberga9be5582019-01-09 16:42:12 +0200361/* Common link controller registers */
Mika Westerberge879a702018-10-11 12:33:08 +0300362#define TB_LC_DESC 0x02
Mika Westerberg5480dfc2019-01-09 17:25:43 +0200363#define TB_LC_DESC_NLC_MASK GENMASK(3, 0)
Mika Westerberge879a702018-10-11 12:33:08 +0300364#define TB_LC_DESC_SIZE_SHIFT 8
365#define TB_LC_DESC_SIZE_MASK GENMASK(15, 8)
366#define TB_LC_DESC_PORT_SIZE_SHIFT 16
367#define TB_LC_DESC_PORT_SIZE_MASK GENMASK(27, 16)
Mika Westerberga9be5582019-01-09 16:42:12 +0200368#define TB_LC_FUSE 0x03
Mika Westerberg8afe9092019-03-26 15:52:30 +0300369#define TB_LC_SNK_ALLOCATION 0x10
370#define TB_LC_SNK_ALLOCATION_SNK0_MASK GENMASK(3, 0)
371#define TB_LC_SNK_ALLOCATION_SNK0_CM 0x1
372#define TB_LC_SNK_ALLOCATION_SNK1_SHIFT 4
373#define TB_LC_SNK_ALLOCATION_SNK1_MASK GENMASK(7, 4)
374#define TB_LC_SNK_ALLOCATION_SNK1_CM 0x1
Andreas Noever7adf6092014-06-03 22:04:01 +0200375
Mika Westerberge879a702018-10-11 12:33:08 +0300376/* Link controller registers */
Mika Westerberg91c0c122019-03-21 19:03:00 +0200377#define TB_LC_PORT_ATTR 0x8d
378#define TB_LC_PORT_ATTR_BE BIT(12)
379
Mika Westerberge879a702018-10-11 12:33:08 +0300380#define TB_LC_SX_CTRL 0x96
381#define TB_LC_SX_CTRL_L1C BIT(16)
382#define TB_LC_SX_CTRL_L2C BIT(20)
383#define TB_LC_SX_CTRL_UPSTREAM BIT(30)
Mika Westerberg5480dfc2019-01-09 17:25:43 +0200384#define TB_LC_SX_CTRL_SLP BIT(31)
Mika Westerberge879a702018-10-11 12:33:08 +0300385
Andreas Noever7adf6092014-06-03 22:04:01 +0200386#endif