1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - Port/Switch config area registers
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.
9 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
10 * Copyright (C) 2018, Intel Corporation
16 #include <linux/types.h>
19 #define TB_ROUTE_SHIFT 8 /* number of bits in a port entry of a route */
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)
26 #define TB_MAX_CONFIG_RW_LENGTH 60
29 TB_SWITCH_CAP_VSE
= 0x05,
32 enum tb_switch_vse_cap
{
33 TB_VSE_CAP_PLUG_EVENTS
= 0x01, /* also EEPROM */
34 TB_VSE_CAP_TIME2
= 0x03,
35 TB_VSE_CAP_IECS
= 0x04,
36 TB_VSE_CAP_LINK_CONTROLLER
= 0x06, /* also IECS */
40 TB_PORT_CAP_PHY
= 0x01,
41 TB_PORT_CAP_TIME1
= 0x03,
42 TB_PORT_CAP_ADAP
= 0x04,
43 TB_PORT_CAP_VSE
= 0x05,
47 TB_PORT_DISABLED
= 0, /* tb_cap_phy.disable == 1 */
48 TB_PORT_CONNECTING
= 1, /* retry */
50 TB_PORT_UNPLUGGED
= 7,
53 /* capability headers */
57 /* enum tb_cap cap:8; prevent "narrower than values of its type" */
58 u8 cap
; /* if cap == 0x05 then we have a extended capability */
62 * struct tb_cap_extended_short - Switch extended short capability
63 * @next: Pointer to the next capability. If @next and @length are zero
64 * then we have a long cap.
65 * @cap: Base capability ID (see &enum tb_switch_cap)
66 * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap)
67 * @length: Length of this capability
69 struct tb_cap_extended_short
{
77 * struct tb_cap_extended_long - Switch extended long capability
78 * @zero1: This field should be zero
79 * @cap: Base capability ID (see &enum tb_switch_cap)
80 * @vsec_id: Vendor specific capability ID (see &enum switch_vse_cap)
81 * @zero2: This field should be zero
82 * @next: Pointer to the next capability
83 * @length: Length of this capability
85 struct tb_cap_extended_long
{
96 struct tb_cap_link_controller
{
97 struct tb_cap_extended_long cap_header
;
98 u32 count
:4; /* number of link controllers */
100 u32 base_offset
:8; /*
101 * offset (into this capability) of the configuration
102 * area of the first link controller
104 u32 length
:12; /* link controller configuration area length */
105 u32 unknown2
:4; /* TODO check that length is correct */
109 struct tb_cap_basic cap_header
;
114 enum tb_port_state state
:4;
118 struct tb_eeprom_ctl
{
119 bool clock
:1; /* send pulse to transfer one bit */
120 bool access_low
:1; /* set to 0 before access */
121 bool data_out
:1; /* to eeprom */
122 bool data_in
:1; /* from eeprom */
123 bool access_high
:1; /* set to 1 before access */
124 bool not_present
:1; /* should be 0 */
126 bool present
:1; /* should be 1 */
130 struct tb_cap_plug_events
{
131 struct tb_cap_extended_short cap_header
;
137 struct tb_eeprom_ctl eeprom_ctl
;
139 u32 drom_offset
; /* 32 bit register, but eeprom addresses are 16 bit */
144 /* Present on port 0 in TB_CFG_SWITCH at address zero. */
145 struct tb_regs_switch_header
{
150 u32 first_cap_offset
:8;
151 u32 upstream_port_number
:6;
152 u32 max_port_number
:6;
162 u32 plug_events_delay
:8; /*
163 * RW, pause between plug events in
164 * milliseconds. Writing 0x00 is interpreted
168 u32 thunderbolt_version
:8;
172 TB_TYPE_INACTIVE
= 0x000000,
173 TB_TYPE_PORT
= 0x000001,
174 TB_TYPE_NHI
= 0x000002,
175 /* TB_TYPE_ETHERNET = 0x020000, lower order bits are not known */
176 /* TB_TYPE_SATA = 0x080000, lower order bits are not known */
177 TB_TYPE_DP_HDMI_IN
= 0x0e0101,
178 TB_TYPE_DP_HDMI_OUT
= 0x0e0102,
179 TB_TYPE_PCIE_DOWN
= 0x100101,
180 TB_TYPE_PCIE_UP
= 0x100102,
181 /* TB_TYPE_USB = 0x200000, lower order bits are not known */
184 /* Present on every port in TB_CF_PORT at address zero. */
185 struct tb_regs_port_header
{
190 u32 first_cap_offset
:8;
195 enum tb_port_type type
:24;
196 u32 thunderbolt_version
:8;
204 u32 max_in_hop_id
:11;
205 u32 max_out_hop_id
:11;
214 /* Hop register from TB_CFG_HOPS. 8 byte per entry. */
218 * hop to take after sending the packet through
219 * out_port (on the incoming port of the next switch)
221 u32 out_port
:6; /* next port of the path (on the same switch) */
222 u32 initial_credits
:8;
223 u32 unknown1
:6; /* set to zero */
228 u32 unknown2
:4; /* set to zero */
230 bool drop_packages
:1;
231 u32 counter
:11; /* index into TB_CFG_COUNTERS on this port */
232 bool counter_enable
:1;
235 bool ingress_shared_buffer
:1;
236 bool egress_shared_buffer
:1;
237 u32 unknown3
:4; /* set to zero */