tb_msgs.h 10 KB

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