tb_msgs.h 12 KB

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