blob: b0a092baa6054f154b614904407bccfff1df53c7 [file] [log] [blame]
Mika Westerberg32af9432017-06-06 15:25:06 +03001/*
2 * Thunderbolt control channel messages
3 *
4 * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com>
5 * Copyright (C) 2017, Intel Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _TB_MSGS
13#define _TB_MSGS
14
15#include <linux/types.h>
Mika Westerbergf67cf492017-06-06 15:25:16 +030016#include <linux/uuid.h>
Mika Westerberg32af9432017-06-06 15:25:06 +030017
Mika Westerberg32af9432017-06-06 15:25:06 +030018enum tb_cfg_space {
19 TB_CFG_HOPS = 0,
20 TB_CFG_PORT = 1,
21 TB_CFG_SWITCH = 2,
22 TB_CFG_COUNTERS = 3,
23};
24
25enum tb_cfg_error {
26 TB_CFG_ERROR_PORT_NOT_CONNECTED = 0,
27 TB_CFG_ERROR_LINK_ERROR = 1,
28 TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2,
29 TB_CFG_ERROR_NO_SUCH_PORT = 4,
30 TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */
31 TB_CFG_ERROR_LOOP = 8,
32 TB_CFG_ERROR_HEC_ERROR_DETECTED = 12,
33 TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13,
34};
35
36/* common header */
37struct tb_cfg_header {
38 u32 route_hi:22;
39 u32 unknown:10; /* highest order bit is set on replies */
40 u32 route_lo;
41} __packed;
42
43/* additional header for read/write packets */
44struct tb_cfg_address {
45 u32 offset:13; /* in dwords */
46 u32 length:6; /* in dwords */
47 u32 port:6;
48 enum tb_cfg_space space:2;
49 u32 seq:2; /* sequence number */
50 u32 zero:3;
51} __packed;
52
53/* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */
54struct cfg_read_pkg {
55 struct tb_cfg_header header;
56 struct tb_cfg_address addr;
57} __packed;
58
59/* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */
60struct cfg_write_pkg {
61 struct tb_cfg_header header;
62 struct tb_cfg_address addr;
63 u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */
64} __packed;
65
66/* TB_CFG_PKG_ERROR */
67struct cfg_error_pkg {
68 struct tb_cfg_header header;
69 enum tb_cfg_error error:4;
70 u32 zero1:4;
71 u32 port:6;
72 u32 zero2:2; /* Both should be zero, still they are different fields. */
73 u32 zero3:16;
74} __packed;
75
76/* TB_CFG_PKG_EVENT */
77struct cfg_event_pkg {
78 struct tb_cfg_header header;
79 u32 port:6;
80 u32 zero:25;
81 bool unplug:1;
82} __packed;
83
84/* TB_CFG_PKG_RESET */
85struct cfg_reset_pkg {
86 struct tb_cfg_header header;
87} __packed;
88
89/* TB_CFG_PKG_PREPARE_TO_SLEEP */
90struct cfg_pts_pkg {
91 struct tb_cfg_header header;
92 u32 data;
93} __packed;
94
Mika Westerbergf67cf492017-06-06 15:25:16 +030095/* ICM messages */
96
97enum icm_pkg_code {
98 ICM_GET_TOPOLOGY = 0x1,
99 ICM_DRIVER_READY = 0x3,
100 ICM_APPROVE_DEVICE = 0x4,
101 ICM_CHALLENGE_DEVICE = 0x5,
102 ICM_ADD_DEVICE_KEY = 0x6,
103 ICM_GET_ROUTE = 0xa,
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300104 ICM_APPROVE_XDOMAIN = 0x10,
Mika Westerbergf67cf492017-06-06 15:25:16 +0300105};
106
107enum icm_event_code {
108 ICM_EVENT_DEVICE_CONNECTED = 3,
109 ICM_EVENT_DEVICE_DISCONNECTED = 4,
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300110 ICM_EVENT_XDOMAIN_CONNECTED = 6,
111 ICM_EVENT_XDOMAIN_DISCONNECTED = 7,
Mika Westerbergf67cf492017-06-06 15:25:16 +0300112};
113
114struct icm_pkg_header {
115 u8 code;
116 u8 flags;
117 u8 packet_id;
118 u8 total_packets;
Mika Westerberg80671702017-10-02 13:38:29 +0300119};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300120
121#define ICM_FLAGS_ERROR BIT(0)
122#define ICM_FLAGS_NO_KEY BIT(1)
123#define ICM_FLAGS_SLEVEL_SHIFT 3
124#define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3)
125
126struct icm_pkg_driver_ready {
127 struct icm_pkg_header hdr;
Mika Westerberg80671702017-10-02 13:38:29 +0300128};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300129
130struct icm_pkg_driver_ready_response {
131 struct icm_pkg_header hdr;
132 u8 romver;
133 u8 ramver;
134 u16 security_level;
Mika Westerberg80671702017-10-02 13:38:29 +0300135};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300136
137/* Falcon Ridge & Alpine Ridge common messages */
138
139struct icm_fr_pkg_get_topology {
140 struct icm_pkg_header hdr;
Mika Westerberg80671702017-10-02 13:38:29 +0300141};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300142
143#define ICM_GET_TOPOLOGY_PACKETS 14
144
145struct icm_fr_pkg_get_topology_response {
146 struct icm_pkg_header hdr;
147 u32 route_lo;
148 u32 route_hi;
149 u8 first_data;
150 u8 second_data;
151 u8 drom_i2c_address_index;
152 u8 switch_index;
153 u32 reserved[2];
154 u32 ports[16];
155 u32 port_hop_info[16];
Mika Westerberg80671702017-10-02 13:38:29 +0300156};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300157
158#define ICM_SWITCH_USED BIT(0)
159#define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1)
160#define ICM_SWITCH_UPSTREAM_PORT_SHIFT 1
161
162#define ICM_PORT_TYPE_MASK GENMASK(23, 0)
163#define ICM_PORT_INDEX_SHIFT 24
164#define ICM_PORT_INDEX_MASK GENMASK(31, 24)
165
166struct icm_fr_event_device_connected {
167 struct icm_pkg_header hdr;
Christoph Hellwig7c39ffe2017-07-18 15:30:05 +0200168 uuid_t ep_uuid;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300169 u8 connection_key;
170 u8 connection_id;
171 u16 link_info;
172 u32 ep_name[55];
Mika Westerberg80671702017-10-02 13:38:29 +0300173};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300174
175#define ICM_LINK_INFO_LINK_MASK 0x7
176#define ICM_LINK_INFO_DEPTH_SHIFT 4
177#define ICM_LINK_INFO_DEPTH_MASK GENMASK(7, 4)
178#define ICM_LINK_INFO_APPROVED BIT(8)
179
180struct icm_fr_pkg_approve_device {
181 struct icm_pkg_header hdr;
Christoph Hellwig7c39ffe2017-07-18 15:30:05 +0200182 uuid_t ep_uuid;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300183 u8 connection_key;
184 u8 connection_id;
185 u16 reserved;
Mika Westerberg80671702017-10-02 13:38:29 +0300186};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300187
188struct icm_fr_event_device_disconnected {
189 struct icm_pkg_header hdr;
190 u16 reserved;
191 u16 link_info;
Mika Westerberg80671702017-10-02 13:38:29 +0300192};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300193
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300194struct icm_fr_event_xdomain_connected {
195 struct icm_pkg_header hdr;
196 u16 reserved;
197 u16 link_info;
198 uuid_t remote_uuid;
199 uuid_t local_uuid;
200 u32 local_route_hi;
201 u32 local_route_lo;
202 u32 remote_route_hi;
203 u32 remote_route_lo;
204};
205
206struct icm_fr_event_xdomain_disconnected {
207 struct icm_pkg_header hdr;
208 u16 reserved;
209 u16 link_info;
210 uuid_t remote_uuid;
211};
212
Mika Westerbergf67cf492017-06-06 15:25:16 +0300213struct icm_fr_pkg_add_device_key {
214 struct icm_pkg_header hdr;
Christoph Hellwig7c39ffe2017-07-18 15:30:05 +0200215 uuid_t ep_uuid;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300216 u8 connection_key;
217 u8 connection_id;
218 u16 reserved;
219 u32 key[8];
Mika Westerberg80671702017-10-02 13:38:29 +0300220};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300221
222struct icm_fr_pkg_add_device_key_response {
223 struct icm_pkg_header hdr;
Christoph Hellwig7c39ffe2017-07-18 15:30:05 +0200224 uuid_t ep_uuid;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300225 u8 connection_key;
226 u8 connection_id;
227 u16 reserved;
Mika Westerberg80671702017-10-02 13:38:29 +0300228};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300229
230struct icm_fr_pkg_challenge_device {
231 struct icm_pkg_header hdr;
Christoph Hellwig7c39ffe2017-07-18 15:30:05 +0200232 uuid_t ep_uuid;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300233 u8 connection_key;
234 u8 connection_id;
235 u16 reserved;
236 u32 challenge[8];
Mika Westerberg80671702017-10-02 13:38:29 +0300237};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300238
239struct icm_fr_pkg_challenge_device_response {
240 struct icm_pkg_header hdr;
Christoph Hellwig7c39ffe2017-07-18 15:30:05 +0200241 uuid_t ep_uuid;
Mika Westerbergf67cf492017-06-06 15:25:16 +0300242 u8 connection_key;
243 u8 connection_id;
244 u16 reserved;
245 u32 challenge[8];
246 u32 response[8];
Mika Westerberg80671702017-10-02 13:38:29 +0300247};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300248
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300249struct icm_fr_pkg_approve_xdomain {
250 struct icm_pkg_header hdr;
251 u16 reserved;
252 u16 link_info;
253 uuid_t remote_uuid;
254 u16 transmit_path;
255 u16 transmit_ring;
256 u16 receive_path;
257 u16 receive_ring;
258};
259
260struct icm_fr_pkg_approve_xdomain_response {
261 struct icm_pkg_header hdr;
262 u16 reserved;
263 u16 link_info;
264 uuid_t remote_uuid;
265 u16 transmit_path;
266 u16 transmit_ring;
267 u16 receive_path;
268 u16 receive_ring;
269};
270
Mika Westerbergf67cf492017-06-06 15:25:16 +0300271/* Alpine Ridge only messages */
272
273struct icm_ar_pkg_get_route {
274 struct icm_pkg_header hdr;
275 u16 reserved;
276 u16 link_info;
Mika Westerberg80671702017-10-02 13:38:29 +0300277};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300278
279struct icm_ar_pkg_get_route_response {
280 struct icm_pkg_header hdr;
281 u16 reserved;
282 u16 link_info;
283 u32 route_hi;
284 u32 route_lo;
Mika Westerberg80671702017-10-02 13:38:29 +0300285};
Mika Westerbergf67cf492017-06-06 15:25:16 +0300286
Mika Westerbergd1ff7022017-10-02 13:38:34 +0300287/* XDomain messages */
288
289struct tb_xdomain_header {
290 u32 route_hi;
291 u32 route_lo;
292 u32 length_sn;
293};
294
295#define TB_XDOMAIN_LENGTH_MASK GENMASK(5, 0)
296#define TB_XDOMAIN_SN_MASK GENMASK(28, 27)
297#define TB_XDOMAIN_SN_SHIFT 27
298
299enum tb_xdp_type {
300 UUID_REQUEST_OLD = 1,
301 UUID_RESPONSE = 2,
302 PROPERTIES_REQUEST,
303 PROPERTIES_RESPONSE,
304 PROPERTIES_CHANGED_REQUEST,
305 PROPERTIES_CHANGED_RESPONSE,
306 ERROR_RESPONSE,
307 UUID_REQUEST = 12,
308};
309
310struct tb_xdp_header {
311 struct tb_xdomain_header xd_hdr;
312 uuid_t uuid;
313 u32 type;
314};
315
316struct tb_xdp_properties {
317 struct tb_xdp_header hdr;
318 uuid_t src_uuid;
319 uuid_t dst_uuid;
320 u16 offset;
321 u16 reserved;
322};
323
324struct tb_xdp_properties_response {
325 struct tb_xdp_header hdr;
326 uuid_t src_uuid;
327 uuid_t dst_uuid;
328 u16 offset;
329 u16 data_length;
330 u32 generation;
331 u32 data[0];
332};
333
334/*
335 * Max length of data array single XDomain property response is allowed
336 * to carry.
337 */
338#define TB_XDP_PROPERTIES_MAX_DATA_LENGTH \
339 (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4)
340
341/* Maximum size of the total property block in dwords we allow */
342#define TB_XDP_PROPERTIES_MAX_LENGTH 500
343
344struct tb_xdp_properties_changed {
345 struct tb_xdp_header hdr;
346 uuid_t src_uuid;
347};
348
349struct tb_xdp_properties_changed_response {
350 struct tb_xdp_header hdr;
351};
352
353enum tb_xdp_error {
354 ERROR_SUCCESS,
355 ERROR_UNKNOWN_PACKET,
356 ERROR_UNKNOWN_DOMAIN,
357 ERROR_NOT_SUPPORTED,
358 ERROR_NOT_READY,
359};
360
361struct tb_xdp_error_response {
362 struct tb_xdp_header hdr;
363 u32 error;
364};
365
Mika Westerberg32af9432017-06-06 15:25:06 +0300366#endif