xref: /openbmc/linux/drivers/thunderbolt/tb_msgs.h (revision 8795a739)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Thunderbolt control channel messages
4  *
5  * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com>
6  * Copyright (C) 2017, Intel Corporation
7  */
8 
9 #ifndef _TB_MSGS
10 #define _TB_MSGS
11 
12 #include <linux/types.h>
13 #include <linux/uuid.h>
14 
15 enum tb_cfg_space {
16 	TB_CFG_HOPS = 0,
17 	TB_CFG_PORT = 1,
18 	TB_CFG_SWITCH = 2,
19 	TB_CFG_COUNTERS = 3,
20 };
21 
22 enum tb_cfg_error {
23 	TB_CFG_ERROR_PORT_NOT_CONNECTED = 0,
24 	TB_CFG_ERROR_LINK_ERROR = 1,
25 	TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2,
26 	TB_CFG_ERROR_NO_SUCH_PORT = 4,
27 	TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */
28 	TB_CFG_ERROR_LOOP = 8,
29 	TB_CFG_ERROR_HEC_ERROR_DETECTED = 12,
30 	TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13,
31 };
32 
33 /* common header */
34 struct tb_cfg_header {
35 	u32 route_hi:22;
36 	u32 unknown:10; /* highest order bit is set on replies */
37 	u32 route_lo;
38 } __packed;
39 
40 /* additional header for read/write packets */
41 struct tb_cfg_address {
42 	u32 offset:13; /* in dwords */
43 	u32 length:6; /* in dwords */
44 	u32 port:6;
45 	enum tb_cfg_space space:2;
46 	u32 seq:2; /* sequence number  */
47 	u32 zero:3;
48 } __packed;
49 
50 /* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */
51 struct cfg_read_pkg {
52 	struct tb_cfg_header header;
53 	struct tb_cfg_address addr;
54 } __packed;
55 
56 /* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */
57 struct cfg_write_pkg {
58 	struct tb_cfg_header header;
59 	struct tb_cfg_address addr;
60 	u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */
61 } __packed;
62 
63 /* TB_CFG_PKG_ERROR */
64 struct cfg_error_pkg {
65 	struct tb_cfg_header header;
66 	enum tb_cfg_error error:4;
67 	u32 zero1:4;
68 	u32 port:6;
69 	u32 zero2:2; /* Both should be zero, still they are different fields. */
70 	u32 zero3:16;
71 } __packed;
72 
73 /* TB_CFG_PKG_EVENT */
74 struct cfg_event_pkg {
75 	struct tb_cfg_header header;
76 	u32 port:6;
77 	u32 zero:25;
78 	bool unplug:1;
79 } __packed;
80 
81 /* TB_CFG_PKG_RESET */
82 struct cfg_reset_pkg {
83 	struct tb_cfg_header header;
84 } __packed;
85 
86 /* TB_CFG_PKG_PREPARE_TO_SLEEP */
87 struct cfg_pts_pkg {
88 	struct tb_cfg_header header;
89 	u32 data;
90 } __packed;
91 
92 /* ICM messages */
93 
94 enum icm_pkg_code {
95 	ICM_GET_TOPOLOGY = 0x1,
96 	ICM_DRIVER_READY = 0x3,
97 	ICM_APPROVE_DEVICE = 0x4,
98 	ICM_CHALLENGE_DEVICE = 0x5,
99 	ICM_ADD_DEVICE_KEY = 0x6,
100 	ICM_GET_ROUTE = 0xa,
101 	ICM_APPROVE_XDOMAIN = 0x10,
102 	ICM_DISCONNECT_XDOMAIN = 0x11,
103 	ICM_PREBOOT_ACL = 0x18,
104 };
105 
106 enum icm_event_code {
107 	ICM_EVENT_DEVICE_CONNECTED = 0x3,
108 	ICM_EVENT_DEVICE_DISCONNECTED = 0x4,
109 	ICM_EVENT_XDOMAIN_CONNECTED = 0x6,
110 	ICM_EVENT_XDOMAIN_DISCONNECTED = 0x7,
111 	ICM_EVENT_RTD3_VETO = 0xa,
112 };
113 
114 struct icm_pkg_header {
115 	u8 code;
116 	u8 flags;
117 	u8 packet_id;
118 	u8 total_packets;
119 };
120 
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 #define ICM_FLAGS_WRITE			BIT(7)
126 
127 struct icm_pkg_driver_ready {
128 	struct icm_pkg_header hdr;
129 };
130 
131 /* Falcon Ridge only messages */
132 
133 struct icm_fr_pkg_driver_ready_response {
134 	struct icm_pkg_header hdr;
135 	u8 romver;
136 	u8 ramver;
137 	u16 security_level;
138 };
139 
140 #define ICM_FR_SLEVEL_MASK		0xf
141 
142 /* Falcon Ridge & Alpine Ridge common messages */
143 
144 struct icm_fr_pkg_get_topology {
145 	struct icm_pkg_header hdr;
146 };
147 
148 #define ICM_GET_TOPOLOGY_PACKETS	14
149 
150 struct icm_fr_pkg_get_topology_response {
151 	struct icm_pkg_header hdr;
152 	u32 route_lo;
153 	u32 route_hi;
154 	u8 first_data;
155 	u8 second_data;
156 	u8 drom_i2c_address_index;
157 	u8 switch_index;
158 	u32 reserved[2];
159 	u32 ports[16];
160 	u32 port_hop_info[16];
161 };
162 
163 #define ICM_SWITCH_USED			BIT(0)
164 #define ICM_SWITCH_UPSTREAM_PORT_MASK	GENMASK(7, 1)
165 #define ICM_SWITCH_UPSTREAM_PORT_SHIFT	1
166 
167 #define ICM_PORT_TYPE_MASK		GENMASK(23, 0)
168 #define ICM_PORT_INDEX_SHIFT		24
169 #define ICM_PORT_INDEX_MASK		GENMASK(31, 24)
170 
171 struct icm_fr_event_device_connected {
172 	struct icm_pkg_header hdr;
173 	uuid_t ep_uuid;
174 	u8 connection_key;
175 	u8 connection_id;
176 	u16 link_info;
177 	u32 ep_name[55];
178 };
179 
180 #define ICM_LINK_INFO_LINK_MASK		0x7
181 #define ICM_LINK_INFO_DEPTH_SHIFT	4
182 #define ICM_LINK_INFO_DEPTH_MASK	GENMASK(7, 4)
183 #define ICM_LINK_INFO_APPROVED		BIT(8)
184 #define ICM_LINK_INFO_REJECTED		BIT(9)
185 #define ICM_LINK_INFO_BOOT		BIT(10)
186 
187 struct icm_fr_pkg_approve_device {
188 	struct icm_pkg_header hdr;
189 	uuid_t ep_uuid;
190 	u8 connection_key;
191 	u8 connection_id;
192 	u16 reserved;
193 };
194 
195 struct icm_fr_event_device_disconnected {
196 	struct icm_pkg_header hdr;
197 	u16 reserved;
198 	u16 link_info;
199 };
200 
201 struct icm_fr_event_xdomain_connected {
202 	struct icm_pkg_header hdr;
203 	u16 reserved;
204 	u16 link_info;
205 	uuid_t remote_uuid;
206 	uuid_t local_uuid;
207 	u32 local_route_hi;
208 	u32 local_route_lo;
209 	u32 remote_route_hi;
210 	u32 remote_route_lo;
211 };
212 
213 struct icm_fr_event_xdomain_disconnected {
214 	struct icm_pkg_header hdr;
215 	u16 reserved;
216 	u16 link_info;
217 	uuid_t remote_uuid;
218 };
219 
220 struct icm_fr_pkg_add_device_key {
221 	struct icm_pkg_header hdr;
222 	uuid_t ep_uuid;
223 	u8 connection_key;
224 	u8 connection_id;
225 	u16 reserved;
226 	u32 key[8];
227 };
228 
229 struct icm_fr_pkg_add_device_key_response {
230 	struct icm_pkg_header hdr;
231 	uuid_t ep_uuid;
232 	u8 connection_key;
233 	u8 connection_id;
234 	u16 reserved;
235 };
236 
237 struct icm_fr_pkg_challenge_device {
238 	struct icm_pkg_header hdr;
239 	uuid_t ep_uuid;
240 	u8 connection_key;
241 	u8 connection_id;
242 	u16 reserved;
243 	u32 challenge[8];
244 };
245 
246 struct icm_fr_pkg_challenge_device_response {
247 	struct icm_pkg_header hdr;
248 	uuid_t ep_uuid;
249 	u8 connection_key;
250 	u8 connection_id;
251 	u16 reserved;
252 	u32 challenge[8];
253 	u32 response[8];
254 };
255 
256 struct icm_fr_pkg_approve_xdomain {
257 	struct icm_pkg_header hdr;
258 	u16 reserved;
259 	u16 link_info;
260 	uuid_t remote_uuid;
261 	u16 transmit_path;
262 	u16 transmit_ring;
263 	u16 receive_path;
264 	u16 receive_ring;
265 };
266 
267 struct icm_fr_pkg_approve_xdomain_response {
268 	struct icm_pkg_header hdr;
269 	u16 reserved;
270 	u16 link_info;
271 	uuid_t remote_uuid;
272 	u16 transmit_path;
273 	u16 transmit_ring;
274 	u16 receive_path;
275 	u16 receive_ring;
276 };
277 
278 /* Alpine Ridge only messages */
279 
280 struct icm_ar_pkg_driver_ready_response {
281 	struct icm_pkg_header hdr;
282 	u8 romver;
283 	u8 ramver;
284 	u16 info;
285 };
286 
287 #define ICM_AR_FLAGS_RTD3		BIT(6)
288 
289 #define ICM_AR_INFO_SLEVEL_MASK		GENMASK(3, 0)
290 #define ICM_AR_INFO_BOOT_ACL_SHIFT	7
291 #define ICM_AR_INFO_BOOT_ACL_MASK	GENMASK(11, 7)
292 #define ICM_AR_INFO_BOOT_ACL_SUPPORTED	BIT(13)
293 
294 struct icm_ar_pkg_get_route {
295 	struct icm_pkg_header hdr;
296 	u16 reserved;
297 	u16 link_info;
298 };
299 
300 struct icm_ar_pkg_get_route_response {
301 	struct icm_pkg_header hdr;
302 	u16 reserved;
303 	u16 link_info;
304 	u32 route_hi;
305 	u32 route_lo;
306 };
307 
308 struct icm_ar_boot_acl_entry {
309 	u32 uuid_lo;
310 	u32 uuid_hi;
311 };
312 
313 #define ICM_AR_PREBOOT_ACL_ENTRIES	16
314 
315 struct icm_ar_pkg_preboot_acl {
316 	struct icm_pkg_header hdr;
317 	struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES];
318 };
319 
320 struct icm_ar_pkg_preboot_acl_response {
321 	struct icm_pkg_header hdr;
322 	struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES];
323 };
324 
325 /* Titan Ridge messages */
326 
327 struct icm_tr_pkg_driver_ready_response {
328 	struct icm_pkg_header hdr;
329 	u16 reserved1;
330 	u16 info;
331 	u32 nvm_version;
332 	u16 device_id;
333 	u16 reserved2;
334 };
335 
336 #define ICM_TR_FLAGS_RTD3		BIT(6)
337 
338 #define ICM_TR_INFO_SLEVEL_MASK		GENMASK(2, 0)
339 #define ICM_TR_INFO_BOOT_ACL_SHIFT	7
340 #define ICM_TR_INFO_BOOT_ACL_MASK	GENMASK(12, 7)
341 
342 struct icm_tr_event_device_connected {
343 	struct icm_pkg_header hdr;
344 	uuid_t ep_uuid;
345 	u32 route_hi;
346 	u32 route_lo;
347 	u8 connection_id;
348 	u8 reserved;
349 	u16 link_info;
350 	u32 ep_name[55];
351 };
352 
353 struct icm_tr_event_device_disconnected {
354 	struct icm_pkg_header hdr;
355 	u32 route_hi;
356 	u32 route_lo;
357 };
358 
359 struct icm_tr_event_xdomain_connected {
360 	struct icm_pkg_header hdr;
361 	u16 reserved;
362 	u16 link_info;
363 	uuid_t remote_uuid;
364 	uuid_t local_uuid;
365 	u32 local_route_hi;
366 	u32 local_route_lo;
367 	u32 remote_route_hi;
368 	u32 remote_route_lo;
369 };
370 
371 struct icm_tr_event_xdomain_disconnected {
372 	struct icm_pkg_header hdr;
373 	u32 route_hi;
374 	u32 route_lo;
375 	uuid_t remote_uuid;
376 };
377 
378 struct icm_tr_pkg_approve_device {
379 	struct icm_pkg_header hdr;
380 	uuid_t ep_uuid;
381 	u32 route_hi;
382 	u32 route_lo;
383 	u8 connection_id;
384 	u8 reserved1[3];
385 };
386 
387 struct icm_tr_pkg_add_device_key {
388 	struct icm_pkg_header hdr;
389 	uuid_t ep_uuid;
390 	u32 route_hi;
391 	u32 route_lo;
392 	u8 connection_id;
393 	u8 reserved[3];
394 	u32 key[8];
395 };
396 
397 struct icm_tr_pkg_challenge_device {
398 	struct icm_pkg_header hdr;
399 	uuid_t ep_uuid;
400 	u32 route_hi;
401 	u32 route_lo;
402 	u8 connection_id;
403 	u8 reserved[3];
404 	u32 challenge[8];
405 };
406 
407 struct icm_tr_pkg_approve_xdomain {
408 	struct icm_pkg_header hdr;
409 	u32 route_hi;
410 	u32 route_lo;
411 	uuid_t remote_uuid;
412 	u16 transmit_path;
413 	u16 transmit_ring;
414 	u16 receive_path;
415 	u16 receive_ring;
416 };
417 
418 struct icm_tr_pkg_disconnect_xdomain {
419 	struct icm_pkg_header hdr;
420 	u8 stage;
421 	u8 reserved[3];
422 	u32 route_hi;
423 	u32 route_lo;
424 	uuid_t remote_uuid;
425 };
426 
427 struct icm_tr_pkg_challenge_device_response {
428 	struct icm_pkg_header hdr;
429 	uuid_t ep_uuid;
430 	u32 route_hi;
431 	u32 route_lo;
432 	u8 connection_id;
433 	u8 reserved[3];
434 	u32 challenge[8];
435 	u32 response[8];
436 };
437 
438 struct icm_tr_pkg_add_device_key_response {
439 	struct icm_pkg_header hdr;
440 	uuid_t ep_uuid;
441 	u32 route_hi;
442 	u32 route_lo;
443 	u8 connection_id;
444 	u8 reserved[3];
445 };
446 
447 struct icm_tr_pkg_approve_xdomain_response {
448 	struct icm_pkg_header hdr;
449 	u32 route_hi;
450 	u32 route_lo;
451 	uuid_t remote_uuid;
452 	u16 transmit_path;
453 	u16 transmit_ring;
454 	u16 receive_path;
455 	u16 receive_ring;
456 };
457 
458 struct icm_tr_pkg_disconnect_xdomain_response {
459 	struct icm_pkg_header hdr;
460 	u8 stage;
461 	u8 reserved[3];
462 	u32 route_hi;
463 	u32 route_lo;
464 	uuid_t remote_uuid;
465 };
466 
467 /* Ice Lake messages */
468 
469 struct icm_icl_event_rtd3_veto {
470 	struct icm_pkg_header hdr;
471 	u32 veto_reason;
472 };
473 
474 /* XDomain messages */
475 
476 struct tb_xdomain_header {
477 	u32 route_hi;
478 	u32 route_lo;
479 	u32 length_sn;
480 };
481 
482 #define TB_XDOMAIN_LENGTH_MASK	GENMASK(5, 0)
483 #define TB_XDOMAIN_SN_MASK	GENMASK(28, 27)
484 #define TB_XDOMAIN_SN_SHIFT	27
485 
486 enum tb_xdp_type {
487 	UUID_REQUEST_OLD = 1,
488 	UUID_RESPONSE = 2,
489 	PROPERTIES_REQUEST,
490 	PROPERTIES_RESPONSE,
491 	PROPERTIES_CHANGED_REQUEST,
492 	PROPERTIES_CHANGED_RESPONSE,
493 	ERROR_RESPONSE,
494 	UUID_REQUEST = 12,
495 };
496 
497 struct tb_xdp_header {
498 	struct tb_xdomain_header xd_hdr;
499 	uuid_t uuid;
500 	u32 type;
501 };
502 
503 struct tb_xdp_uuid {
504 	struct tb_xdp_header hdr;
505 };
506 
507 struct tb_xdp_uuid_response {
508 	struct tb_xdp_header hdr;
509 	uuid_t src_uuid;
510 	u32 src_route_hi;
511 	u32 src_route_lo;
512 };
513 
514 struct tb_xdp_properties {
515 	struct tb_xdp_header hdr;
516 	uuid_t src_uuid;
517 	uuid_t dst_uuid;
518 	u16 offset;
519 	u16 reserved;
520 };
521 
522 struct tb_xdp_properties_response {
523 	struct tb_xdp_header hdr;
524 	uuid_t src_uuid;
525 	uuid_t dst_uuid;
526 	u16 offset;
527 	u16 data_length;
528 	u32 generation;
529 	u32 data[0];
530 };
531 
532 /*
533  * Max length of data array single XDomain property response is allowed
534  * to carry.
535  */
536 #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH	\
537 	(((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4)
538 
539 /* Maximum size of the total property block in dwords we allow */
540 #define TB_XDP_PROPERTIES_MAX_LENGTH		500
541 
542 struct tb_xdp_properties_changed {
543 	struct tb_xdp_header hdr;
544 	uuid_t src_uuid;
545 };
546 
547 struct tb_xdp_properties_changed_response {
548 	struct tb_xdp_header hdr;
549 };
550 
551 enum tb_xdp_error {
552 	ERROR_SUCCESS,
553 	ERROR_UNKNOWN_PACKET,
554 	ERROR_UNKNOWN_DOMAIN,
555 	ERROR_NOT_SUPPORTED,
556 	ERROR_NOT_READY,
557 };
558 
559 struct tb_xdp_error_response {
560 	struct tb_xdp_header hdr;
561 	u32 error;
562 };
563 
564 #endif
565