tb_msgs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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_RTD3_VETO = 0xa,
  106. };
  107. struct icm_pkg_header {
  108. u8 code;
  109. u8 flags;
  110. u8 packet_id;
  111. u8 total_packets;
  112. };
  113. #define ICM_FLAGS_ERROR BIT(0)
  114. #define ICM_FLAGS_NO_KEY BIT(1)
  115. #define ICM_FLAGS_SLEVEL_SHIFT 3
  116. #define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3)
  117. #define ICM_FLAGS_DUAL_LANE BIT(5)
  118. #define ICM_FLAGS_SPEED_GEN3 BIT(7)
  119. #define ICM_FLAGS_WRITE BIT(7)
  120. struct icm_pkg_driver_ready {
  121. struct icm_pkg_header hdr;
  122. };
  123. /* Falcon Ridge only messages */
  124. struct icm_fr_pkg_driver_ready_response {
  125. struct icm_pkg_header hdr;
  126. u8 romver;
  127. u8 ramver;
  128. u16 security_level;
  129. };
  130. #define ICM_FR_SLEVEL_MASK 0xf
  131. /* Falcon Ridge & Alpine Ridge common messages */
  132. struct icm_fr_pkg_get_topology {
  133. struct icm_pkg_header hdr;
  134. };
  135. #define ICM_GET_TOPOLOGY_PACKETS 14
  136. struct icm_fr_pkg_get_topology_response {
  137. struct icm_pkg_header hdr;
  138. u32 route_lo;
  139. u32 route_hi;
  140. u8 first_data;
  141. u8 second_data;
  142. u8 drom_i2c_address_index;
  143. u8 switch_index;
  144. u32 reserved[2];
  145. u32 ports[16];
  146. u32 port_hop_info[16];
  147. };
  148. #define ICM_SWITCH_USED BIT(0)
  149. #define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1)
  150. #define ICM_SWITCH_UPSTREAM_PORT_SHIFT 1
  151. #define ICM_PORT_TYPE_MASK GENMASK(23, 0)
  152. #define ICM_PORT_INDEX_SHIFT 24
  153. #define ICM_PORT_INDEX_MASK GENMASK(31, 24)
  154. struct icm_fr_event_device_connected {
  155. struct icm_pkg_header hdr;
  156. uuid_t ep_uuid;
  157. u8 connection_key;
  158. u8 connection_id;
  159. u16 link_info;
  160. u32 ep_name[55];
  161. };
  162. #define ICM_LINK_INFO_LINK_MASK 0x7
  163. #define ICM_LINK_INFO_DEPTH_SHIFT 4
  164. #define ICM_LINK_INFO_DEPTH_MASK GENMASK(7, 4)
  165. #define ICM_LINK_INFO_APPROVED BIT(8)
  166. #define ICM_LINK_INFO_REJECTED BIT(9)
  167. #define ICM_LINK_INFO_BOOT BIT(10)
  168. struct icm_fr_pkg_approve_device {
  169. struct icm_pkg_header hdr;
  170. uuid_t ep_uuid;
  171. u8 connection_key;
  172. u8 connection_id;
  173. u16 reserved;
  174. };
  175. struct icm_fr_event_device_disconnected {
  176. struct icm_pkg_header hdr;
  177. u16 reserved;
  178. u16 link_info;
  179. };
  180. struct icm_fr_event_xdomain_connected {
  181. struct icm_pkg_header hdr;
  182. u16 reserved;
  183. u16 link_info;
  184. uuid_t remote_uuid;
  185. uuid_t local_uuid;
  186. u32 local_route_hi;
  187. u32 local_route_lo;
  188. u32 remote_route_hi;
  189. u32 remote_route_lo;
  190. };
  191. struct icm_fr_event_xdomain_disconnected {
  192. struct icm_pkg_header hdr;
  193. u16 reserved;
  194. u16 link_info;
  195. uuid_t remote_uuid;
  196. };
  197. struct icm_fr_pkg_add_device_key {
  198. struct icm_pkg_header hdr;
  199. uuid_t ep_uuid;
  200. u8 connection_key;
  201. u8 connection_id;
  202. u16 reserved;
  203. u32 key[8];
  204. };
  205. struct icm_fr_pkg_add_device_key_response {
  206. struct icm_pkg_header hdr;
  207. uuid_t ep_uuid;
  208. u8 connection_key;
  209. u8 connection_id;
  210. u16 reserved;
  211. };
  212. struct icm_fr_pkg_challenge_device {
  213. struct icm_pkg_header hdr;
  214. uuid_t ep_uuid;
  215. u8 connection_key;
  216. u8 connection_id;
  217. u16 reserved;
  218. u32 challenge[8];
  219. };
  220. struct icm_fr_pkg_challenge_device_response {
  221. struct icm_pkg_header hdr;
  222. uuid_t ep_uuid;
  223. u8 connection_key;
  224. u8 connection_id;
  225. u16 reserved;
  226. u32 challenge[8];
  227. u32 response[8];
  228. };
  229. struct icm_fr_pkg_approve_xdomain {
  230. struct icm_pkg_header hdr;
  231. u16 reserved;
  232. u16 link_info;
  233. uuid_t remote_uuid;
  234. u16 transmit_path;
  235. u16 transmit_ring;
  236. u16 receive_path;
  237. u16 receive_ring;
  238. };
  239. struct icm_fr_pkg_approve_xdomain_response {
  240. struct icm_pkg_header hdr;
  241. u16 reserved;
  242. u16 link_info;
  243. uuid_t remote_uuid;
  244. u16 transmit_path;
  245. u16 transmit_ring;
  246. u16 receive_path;
  247. u16 receive_ring;
  248. };
  249. /* Alpine Ridge only messages */
  250. struct icm_ar_pkg_driver_ready_response {
  251. struct icm_pkg_header hdr;
  252. u8 romver;
  253. u8 ramver;
  254. u16 info;
  255. };
  256. #define ICM_AR_FLAGS_RTD3 BIT(6)
  257. #define ICM_AR_INFO_SLEVEL_MASK GENMASK(3, 0)
  258. #define ICM_AR_INFO_BOOT_ACL_SHIFT 7
  259. #define ICM_AR_INFO_BOOT_ACL_MASK GENMASK(11, 7)
  260. #define ICM_AR_INFO_BOOT_ACL_SUPPORTED BIT(13)
  261. struct icm_ar_pkg_get_route {
  262. struct icm_pkg_header hdr;
  263. u16 reserved;
  264. u16 link_info;
  265. };
  266. struct icm_ar_pkg_get_route_response {
  267. struct icm_pkg_header hdr;
  268. u16 reserved;
  269. u16 link_info;
  270. u32 route_hi;
  271. u32 route_lo;
  272. };
  273. struct icm_ar_boot_acl_entry {
  274. u32 uuid_lo;
  275. u32 uuid_hi;
  276. };
  277. #define ICM_AR_PREBOOT_ACL_ENTRIES 16
  278. struct icm_ar_pkg_preboot_acl {
  279. struct icm_pkg_header hdr;
  280. struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES];
  281. };
  282. struct icm_ar_pkg_preboot_acl_response {
  283. struct icm_pkg_header hdr;
  284. struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES];
  285. };
  286. /* Titan Ridge messages */
  287. struct icm_tr_pkg_driver_ready_response {
  288. struct icm_pkg_header hdr;
  289. u16 reserved1;
  290. u16 info;
  291. u32 nvm_version;
  292. u16 device_id;
  293. u16 reserved2;
  294. };
  295. #define ICM_TR_FLAGS_RTD3 BIT(6)
  296. #define ICM_TR_INFO_SLEVEL_MASK GENMASK(2, 0)
  297. #define ICM_TR_INFO_PROTO_VERSION_MASK GENMASK(6, 4)
  298. #define ICM_TR_INFO_PROTO_VERSION_SHIFT 4
  299. #define ICM_TR_INFO_BOOT_ACL_SHIFT 7
  300. #define ICM_TR_INFO_BOOT_ACL_MASK GENMASK(12, 7)
  301. struct icm_tr_event_device_connected {
  302. struct icm_pkg_header hdr;
  303. uuid_t ep_uuid;
  304. u32 route_hi;
  305. u32 route_lo;
  306. u8 connection_id;
  307. u8 reserved;
  308. u16 link_info;
  309. u32 ep_name[55];
  310. };
  311. struct icm_tr_event_device_disconnected {
  312. struct icm_pkg_header hdr;
  313. u32 route_hi;
  314. u32 route_lo;
  315. };
  316. struct icm_tr_event_xdomain_connected {
  317. struct icm_pkg_header hdr;
  318. u16 reserved;
  319. u16 link_info;
  320. uuid_t remote_uuid;
  321. uuid_t local_uuid;
  322. u32 local_route_hi;
  323. u32 local_route_lo;
  324. u32 remote_route_hi;
  325. u32 remote_route_lo;
  326. };
  327. struct icm_tr_event_xdomain_disconnected {
  328. struct icm_pkg_header hdr;
  329. u32 route_hi;
  330. u32 route_lo;
  331. uuid_t remote_uuid;
  332. };
  333. struct icm_tr_pkg_approve_device {
  334. struct icm_pkg_header hdr;
  335. uuid_t ep_uuid;
  336. u32 route_hi;
  337. u32 route_lo;
  338. u8 connection_id;
  339. u8 reserved1[3];
  340. };
  341. struct icm_tr_pkg_add_device_key {
  342. struct icm_pkg_header hdr;
  343. uuid_t ep_uuid;
  344. u32 route_hi;
  345. u32 route_lo;
  346. u8 connection_id;
  347. u8 reserved[3];
  348. u32 key[8];
  349. };
  350. struct icm_tr_pkg_challenge_device {
  351. struct icm_pkg_header hdr;
  352. uuid_t ep_uuid;
  353. u32 route_hi;
  354. u32 route_lo;
  355. u8 connection_id;
  356. u8 reserved[3];
  357. u32 challenge[8];
  358. };
  359. struct icm_tr_pkg_approve_xdomain {
  360. struct icm_pkg_header hdr;
  361. u32 route_hi;
  362. u32 route_lo;
  363. uuid_t remote_uuid;
  364. u16 transmit_path;
  365. u16 transmit_ring;
  366. u16 receive_path;
  367. u16 receive_ring;
  368. };
  369. struct icm_tr_pkg_disconnect_xdomain {
  370. struct icm_pkg_header hdr;
  371. u8 stage;
  372. u8 reserved[3];
  373. u32 route_hi;
  374. u32 route_lo;
  375. uuid_t remote_uuid;
  376. };
  377. struct icm_tr_pkg_challenge_device_response {
  378. struct icm_pkg_header hdr;
  379. uuid_t ep_uuid;
  380. u32 route_hi;
  381. u32 route_lo;
  382. u8 connection_id;
  383. u8 reserved[3];
  384. u32 challenge[8];
  385. u32 response[8];
  386. };
  387. struct icm_tr_pkg_add_device_key_response {
  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. };
  395. struct icm_tr_pkg_approve_xdomain_response {
  396. struct icm_pkg_header hdr;
  397. u32 route_hi;
  398. u32 route_lo;
  399. uuid_t remote_uuid;
  400. u16 transmit_path;
  401. u16 transmit_ring;
  402. u16 receive_path;
  403. u16 receive_ring;
  404. };
  405. struct icm_tr_pkg_disconnect_xdomain_response {
  406. struct icm_pkg_header hdr;
  407. u8 stage;
  408. u8 reserved[3];
  409. u32 route_hi;
  410. u32 route_lo;
  411. uuid_t remote_uuid;
  412. };
  413. /* Ice Lake messages */
  414. struct icm_icl_event_rtd3_veto {
  415. struct icm_pkg_header hdr;
  416. u32 veto_reason;
  417. };
  418. /* USB4 ICM messages */
  419. struct icm_usb4_switch_op {
  420. struct icm_pkg_header hdr;
  421. u32 route_hi;
  422. u32 route_lo;
  423. u32 metadata;
  424. u16 opcode;
  425. u16 data_len_valid;
  426. u32 data[16];
  427. };
  428. #define ICM_USB4_SWITCH_DATA_LEN_MASK GENMASK(3, 0)
  429. #define ICM_USB4_SWITCH_DATA_VALID BIT(4)
  430. struct icm_usb4_switch_op_response {
  431. struct icm_pkg_header hdr;
  432. u32 route_hi;
  433. u32 route_lo;
  434. u32 metadata;
  435. u16 opcode;
  436. u16 status;
  437. u32 data[16];
  438. };
  439. /* XDomain messages */
  440. struct tb_xdomain_header {
  441. u32 route_hi;
  442. u32 route_lo;
  443. u32 length_sn;
  444. };
  445. #define TB_XDOMAIN_LENGTH_MASK GENMASK(5, 0)
  446. #define TB_XDOMAIN_SN_MASK GENMASK(28, 27)
  447. #define TB_XDOMAIN_SN_SHIFT 27
  448. enum tb_xdp_type {
  449. UUID_REQUEST_OLD = 1,
  450. UUID_RESPONSE = 2,
  451. PROPERTIES_REQUEST,
  452. PROPERTIES_RESPONSE,
  453. PROPERTIES_CHANGED_REQUEST,
  454. PROPERTIES_CHANGED_RESPONSE,
  455. ERROR_RESPONSE,
  456. UUID_REQUEST = 12,
  457. LINK_STATE_STATUS_REQUEST = 15,
  458. LINK_STATE_STATUS_RESPONSE,
  459. LINK_STATE_CHANGE_REQUEST,
  460. LINK_STATE_CHANGE_RESPONSE,
  461. };
  462. struct tb_xdp_header {
  463. struct tb_xdomain_header xd_hdr;
  464. uuid_t uuid;
  465. u32 type;
  466. };
  467. struct tb_xdp_error_response {
  468. struct tb_xdp_header hdr;
  469. u32 error;
  470. };
  471. struct tb_xdp_link_state_status {
  472. struct tb_xdp_header hdr;
  473. };
  474. struct tb_xdp_link_state_status_response {
  475. union {
  476. struct tb_xdp_error_response err;
  477. struct {
  478. struct tb_xdp_header hdr;
  479. u32 status;
  480. u8 slw;
  481. u8 tlw;
  482. u8 sls;
  483. u8 tls;
  484. };
  485. };
  486. };
  487. struct tb_xdp_link_state_change {
  488. struct tb_xdp_header hdr;
  489. u8 tlw;
  490. u8 tls;
  491. u16 reserved;
  492. };
  493. struct tb_xdp_link_state_change_response {
  494. union {
  495. struct tb_xdp_error_response err;
  496. struct {
  497. struct tb_xdp_header hdr;
  498. u32 status;
  499. };
  500. };
  501. };
  502. struct tb_xdp_uuid {
  503. struct tb_xdp_header hdr;
  504. };
  505. struct tb_xdp_uuid_response {
  506. union {
  507. struct tb_xdp_error_response err;
  508. struct {
  509. struct tb_xdp_header hdr;
  510. uuid_t src_uuid;
  511. u32 src_route_hi;
  512. u32 src_route_lo;
  513. };
  514. };
  515. };
  516. struct tb_xdp_properties {
  517. struct tb_xdp_header hdr;
  518. uuid_t src_uuid;
  519. uuid_t dst_uuid;
  520. u16 offset;
  521. u16 reserved;
  522. };
  523. struct tb_xdp_properties_response {
  524. union {
  525. struct tb_xdp_error_response err;
  526. struct {
  527. struct tb_xdp_header hdr;
  528. uuid_t src_uuid;
  529. uuid_t dst_uuid;
  530. u16 offset;
  531. u16 data_length;
  532. u32 generation;
  533. u32 data[];
  534. };
  535. };
  536. };
  537. /*
  538. * Max length of data array single XDomain property response is allowed
  539. * to carry.
  540. */
  541. #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH \
  542. (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4)
  543. /* Maximum size of the total property block in dwords we allow */
  544. #define TB_XDP_PROPERTIES_MAX_LENGTH 500
  545. struct tb_xdp_properties_changed {
  546. struct tb_xdp_header hdr;
  547. uuid_t src_uuid;
  548. };
  549. struct tb_xdp_properties_changed_response {
  550. union {
  551. struct tb_xdp_error_response err;
  552. struct tb_xdp_header hdr;
  553. };
  554. };
  555. enum tb_xdp_error {
  556. ERROR_SUCCESS,
  557. ERROR_UNKNOWN_PACKET,
  558. ERROR_UNKNOWN_DOMAIN,
  559. ERROR_NOT_SUPPORTED,
  560. ERROR_NOT_READY,
  561. };
  562. #endif