tb_msgs.h 11 KB

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