tb_msgs.h 12 KB

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