tb_msgs.h 11 KB

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