tb_msgs.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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_pkg_type {
  16. TB_CFG_PKG_READ = 1,
  17. TB_CFG_PKG_WRITE = 2,
  18. TB_CFG_PKG_ERROR = 3,
  19. TB_CFG_PKG_NOTIFY_ACK = 4,
  20. TB_CFG_PKG_EVENT = 5,
  21. TB_CFG_PKG_XDOMAIN_REQ = 6,
  22. TB_CFG_PKG_XDOMAIN_RESP = 7,
  23. TB_CFG_PKG_OVERRIDE = 8,
  24. TB_CFG_PKG_RESET = 9,
  25. TB_CFG_PKG_ICM_EVENT = 10,
  26. TB_CFG_PKG_ICM_CMD = 11,
  27. TB_CFG_PKG_ICM_RESP = 12,
  28. TB_CFG_PKG_PREPARE_TO_SLEEP = 0xd,
  29. };
  30. enum tb_cfg_space {
  31. TB_CFG_HOPS = 0,
  32. TB_CFG_PORT = 1,
  33. TB_CFG_SWITCH = 2,
  34. TB_CFG_COUNTERS = 3,
  35. };
  36. enum tb_cfg_error {
  37. TB_CFG_ERROR_PORT_NOT_CONNECTED = 0,
  38. TB_CFG_ERROR_LINK_ERROR = 1,
  39. TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2,
  40. TB_CFG_ERROR_NO_SUCH_PORT = 4,
  41. TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */
  42. TB_CFG_ERROR_LOOP = 8,
  43. TB_CFG_ERROR_HEC_ERROR_DETECTED = 12,
  44. TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13,
  45. };
  46. /* common header */
  47. struct tb_cfg_header {
  48. u32 route_hi:22;
  49. u32 unknown:10; /* highest order bit is set on replies */
  50. u32 route_lo;
  51. } __packed;
  52. /* additional header for read/write packets */
  53. struct tb_cfg_address {
  54. u32 offset:13; /* in dwords */
  55. u32 length:6; /* in dwords */
  56. u32 port:6;
  57. enum tb_cfg_space space:2;
  58. u32 seq:2; /* sequence number */
  59. u32 zero:3;
  60. } __packed;
  61. /* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */
  62. struct cfg_read_pkg {
  63. struct tb_cfg_header header;
  64. struct tb_cfg_address addr;
  65. } __packed;
  66. /* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */
  67. struct cfg_write_pkg {
  68. struct tb_cfg_header header;
  69. struct tb_cfg_address addr;
  70. u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */
  71. } __packed;
  72. /* TB_CFG_PKG_ERROR */
  73. struct cfg_error_pkg {
  74. struct tb_cfg_header header;
  75. enum tb_cfg_error error:4;
  76. u32 zero1:4;
  77. u32 port:6;
  78. u32 zero2:2; /* Both should be zero, still they are different fields. */
  79. u32 zero3:16;
  80. } __packed;
  81. /* TB_CFG_PKG_EVENT */
  82. struct cfg_event_pkg {
  83. struct tb_cfg_header header;
  84. u32 port:6;
  85. u32 zero:25;
  86. bool unplug:1;
  87. } __packed;
  88. /* TB_CFG_PKG_RESET */
  89. struct cfg_reset_pkg {
  90. struct tb_cfg_header header;
  91. } __packed;
  92. /* TB_CFG_PKG_PREPARE_TO_SLEEP */
  93. struct cfg_pts_pkg {
  94. struct tb_cfg_header header;
  95. u32 data;
  96. } __packed;
  97. /* ICM messages */
  98. enum icm_pkg_code {
  99. ICM_GET_TOPOLOGY = 0x1,
  100. ICM_DRIVER_READY = 0x3,
  101. ICM_APPROVE_DEVICE = 0x4,
  102. ICM_CHALLENGE_DEVICE = 0x5,
  103. ICM_ADD_DEVICE_KEY = 0x6,
  104. ICM_GET_ROUTE = 0xa,
  105. };
  106. enum icm_event_code {
  107. ICM_EVENT_DEVICE_CONNECTED = 3,
  108. ICM_EVENT_DEVICE_DISCONNECTED = 4,
  109. };
  110. struct icm_pkg_header {
  111. u8 code;
  112. u8 flags;
  113. u8 packet_id;
  114. u8 total_packets;
  115. } __packed;
  116. #define ICM_FLAGS_ERROR BIT(0)
  117. #define ICM_FLAGS_NO_KEY BIT(1)
  118. #define ICM_FLAGS_SLEVEL_SHIFT 3
  119. #define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3)
  120. struct icm_pkg_driver_ready {
  121. struct icm_pkg_header hdr;
  122. } __packed;
  123. struct icm_pkg_driver_ready_response {
  124. struct icm_pkg_header hdr;
  125. u8 romver;
  126. u8 ramver;
  127. u16 security_level;
  128. } __packed;
  129. /* Falcon Ridge & Alpine Ridge common messages */
  130. struct icm_fr_pkg_get_topology {
  131. struct icm_pkg_header hdr;
  132. } __packed;
  133. #define ICM_GET_TOPOLOGY_PACKETS 14
  134. struct icm_fr_pkg_get_topology_response {
  135. struct icm_pkg_header hdr;
  136. u32 route_lo;
  137. u32 route_hi;
  138. u8 first_data;
  139. u8 second_data;
  140. u8 drom_i2c_address_index;
  141. u8 switch_index;
  142. u32 reserved[2];
  143. u32 ports[16];
  144. u32 port_hop_info[16];
  145. } __packed;
  146. #define ICM_SWITCH_USED BIT(0)
  147. #define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1)
  148. #define ICM_SWITCH_UPSTREAM_PORT_SHIFT 1
  149. #define ICM_PORT_TYPE_MASK GENMASK(23, 0)
  150. #define ICM_PORT_INDEX_SHIFT 24
  151. #define ICM_PORT_INDEX_MASK GENMASK(31, 24)
  152. struct icm_fr_event_device_connected {
  153. struct icm_pkg_header hdr;
  154. uuid_t ep_uuid;
  155. u8 connection_key;
  156. u8 connection_id;
  157. u16 link_info;
  158. u32 ep_name[55];
  159. } __packed;
  160. #define ICM_LINK_INFO_LINK_MASK 0x7
  161. #define ICM_LINK_INFO_DEPTH_SHIFT 4
  162. #define ICM_LINK_INFO_DEPTH_MASK GENMASK(7, 4)
  163. #define ICM_LINK_INFO_APPROVED BIT(8)
  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. } __packed;
  171. struct icm_fr_event_device_disconnected {
  172. struct icm_pkg_header hdr;
  173. u16 reserved;
  174. u16 link_info;
  175. } __packed;
  176. struct icm_fr_pkg_add_device_key {
  177. struct icm_pkg_header hdr;
  178. uuid_t ep_uuid;
  179. u8 connection_key;
  180. u8 connection_id;
  181. u16 reserved;
  182. u32 key[8];
  183. } __packed;
  184. struct icm_fr_pkg_add_device_key_response {
  185. struct icm_pkg_header hdr;
  186. uuid_t ep_uuid;
  187. u8 connection_key;
  188. u8 connection_id;
  189. u16 reserved;
  190. } __packed;
  191. struct icm_fr_pkg_challenge_device {
  192. struct icm_pkg_header hdr;
  193. uuid_t ep_uuid;
  194. u8 connection_key;
  195. u8 connection_id;
  196. u16 reserved;
  197. u32 challenge[8];
  198. } __packed;
  199. struct icm_fr_pkg_challenge_device_response {
  200. struct icm_pkg_header hdr;
  201. uuid_t ep_uuid;
  202. u8 connection_key;
  203. u8 connection_id;
  204. u16 reserved;
  205. u32 challenge[8];
  206. u32 response[8];
  207. } __packed;
  208. /* Alpine Ridge only messages */
  209. struct icm_ar_pkg_get_route {
  210. struct icm_pkg_header hdr;
  211. u16 reserved;
  212. u16 link_info;
  213. } __packed;
  214. struct icm_ar_pkg_get_route_response {
  215. struct icm_pkg_header hdr;
  216. u16 reserved;
  217. u16 link_info;
  218. u32 route_hi;
  219. u32 route_lo;
  220. } __packed;
  221. #endif