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 12 #ifndef _TB_MSGS 13 #define _TB_MSGS 14 15 #include <linux/types.h> 16 #include <linux/uuid.h> 17 18 enum tb_cfg_space { 19 TB_CFG_HOPS = 0, 20 TB_CFG_PORT = 1, 21 TB_CFG_SWITCH = 2, 22 TB_CFG_COUNTERS = 3, 23 }; 24 25 enum tb_cfg_error { 26 TB_CFG_ERROR_PORT_NOT_CONNECTED = 0, 27 TB_CFG_ERROR_LINK_ERROR = 1, 28 TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2, 29 TB_CFG_ERROR_NO_SUCH_PORT = 4, 30 TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */ 31 TB_CFG_ERROR_LOOP = 8, 32 TB_CFG_ERROR_HEC_ERROR_DETECTED = 12, 33 TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13, 34 }; 35 36 /* common header */ 37 struct tb_cfg_header { 38 u32 route_hi:22; 39 u32 unknown:10; /* highest order bit is set on replies */ 40 u32 route_lo; 41 } __packed; 42 43 /* additional header for read/write packets */ 44 struct tb_cfg_address { 45 u32 offset:13; /* in dwords */ 46 u32 length:6; /* in dwords */ 47 u32 port:6; 48 enum tb_cfg_space space:2; 49 u32 seq:2; /* sequence number */ 50 u32 zero:3; 51 } __packed; 52 53 /* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */ 54 struct cfg_read_pkg { 55 struct tb_cfg_header header; 56 struct tb_cfg_address addr; 57 } __packed; 58 59 /* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */ 60 struct cfg_write_pkg { 61 struct tb_cfg_header header; 62 struct tb_cfg_address addr; 63 u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */ 64 } __packed; 65 66 /* TB_CFG_PKG_ERROR */ 67 struct cfg_error_pkg { 68 struct tb_cfg_header header; 69 enum tb_cfg_error error:4; 70 u32 zero1:4; 71 u32 port:6; 72 u32 zero2:2; /* Both should be zero, still they are different fields. */ 73 u32 zero3:16; 74 } __packed; 75 76 /* TB_CFG_PKG_EVENT */ 77 struct cfg_event_pkg { 78 struct tb_cfg_header header; 79 u32 port:6; 80 u32 zero:25; 81 bool unplug:1; 82 } __packed; 83 84 /* TB_CFG_PKG_RESET */ 85 struct cfg_reset_pkg { 86 struct tb_cfg_header header; 87 } __packed; 88 89 /* TB_CFG_PKG_PREPARE_TO_SLEEP */ 90 struct cfg_pts_pkg { 91 struct tb_cfg_header header; 92 u32 data; 93 } __packed; 94 95 /* ICM messages */ 96 97 enum icm_pkg_code { 98 ICM_GET_TOPOLOGY = 0x1, 99 ICM_DRIVER_READY = 0x3, 100 ICM_APPROVE_DEVICE = 0x4, 101 ICM_CHALLENGE_DEVICE = 0x5, 102 ICM_ADD_DEVICE_KEY = 0x6, 103 ICM_GET_ROUTE = 0xa, 104 ICM_APPROVE_XDOMAIN = 0x10, 105 }; 106 107 enum icm_event_code { 108 ICM_EVENT_DEVICE_CONNECTED = 3, 109 ICM_EVENT_DEVICE_DISCONNECTED = 4, 110 ICM_EVENT_XDOMAIN_CONNECTED = 6, 111 ICM_EVENT_XDOMAIN_DISCONNECTED = 7, 112 }; 113 114 struct icm_pkg_header { 115 u8 code; 116 u8 flags; 117 u8 packet_id; 118 u8 total_packets; 119 }; 120 121 #define ICM_FLAGS_ERROR BIT(0) 122 #define ICM_FLAGS_NO_KEY BIT(1) 123 #define ICM_FLAGS_SLEVEL_SHIFT 3 124 #define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3) 125 126 struct icm_pkg_driver_ready { 127 struct icm_pkg_header hdr; 128 }; 129 130 /* Falcon Ridge & Alpine Ridge common messages */ 131 132 struct icm_fr_pkg_driver_ready_response { 133 struct icm_pkg_header hdr; 134 u8 romver; 135 u8 ramver; 136 u16 security_level; 137 }; 138 139 #define ICM_FR_SLEVEL_MASK 0xf 140 141 struct icm_fr_pkg_get_topology { 142 struct icm_pkg_header hdr; 143 }; 144 145 #define ICM_GET_TOPOLOGY_PACKETS 14 146 147 struct icm_fr_pkg_get_topology_response { 148 struct icm_pkg_header hdr; 149 u32 route_lo; 150 u32 route_hi; 151 u8 first_data; 152 u8 second_data; 153 u8 drom_i2c_address_index; 154 u8 switch_index; 155 u32 reserved[2]; 156 u32 ports[16]; 157 u32 port_hop_info[16]; 158 }; 159 160 #define ICM_SWITCH_USED BIT(0) 161 #define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1) 162 #define ICM_SWITCH_UPSTREAM_PORT_SHIFT 1 163 164 #define ICM_PORT_TYPE_MASK GENMASK(23, 0) 165 #define ICM_PORT_INDEX_SHIFT 24 166 #define ICM_PORT_INDEX_MASK GENMASK(31, 24) 167 168 struct icm_fr_event_device_connected { 169 struct icm_pkg_header hdr; 170 uuid_t ep_uuid; 171 u8 connection_key; 172 u8 connection_id; 173 u16 link_info; 174 u32 ep_name[55]; 175 }; 176 177 #define ICM_LINK_INFO_LINK_MASK 0x7 178 #define ICM_LINK_INFO_DEPTH_SHIFT 4 179 #define ICM_LINK_INFO_DEPTH_MASK GENMASK(7, 4) 180 #define ICM_LINK_INFO_APPROVED BIT(8) 181 #define ICM_LINK_INFO_REJECTED BIT(9) 182 #define ICM_LINK_INFO_BOOT BIT(10) 183 184 struct icm_fr_pkg_approve_device { 185 struct icm_pkg_header hdr; 186 uuid_t ep_uuid; 187 u8 connection_key; 188 u8 connection_id; 189 u16 reserved; 190 }; 191 192 struct icm_fr_event_device_disconnected { 193 struct icm_pkg_header hdr; 194 u16 reserved; 195 u16 link_info; 196 }; 197 198 struct icm_fr_event_xdomain_connected { 199 struct icm_pkg_header hdr; 200 u16 reserved; 201 u16 link_info; 202 uuid_t remote_uuid; 203 uuid_t local_uuid; 204 u32 local_route_hi; 205 u32 local_route_lo; 206 u32 remote_route_hi; 207 u32 remote_route_lo; 208 }; 209 210 struct icm_fr_event_xdomain_disconnected { 211 struct icm_pkg_header hdr; 212 u16 reserved; 213 u16 link_info; 214 uuid_t remote_uuid; 215 }; 216 217 struct icm_fr_pkg_add_device_key { 218 struct icm_pkg_header hdr; 219 uuid_t ep_uuid; 220 u8 connection_key; 221 u8 connection_id; 222 u16 reserved; 223 u32 key[8]; 224 }; 225 226 struct icm_fr_pkg_add_device_key_response { 227 struct icm_pkg_header hdr; 228 uuid_t ep_uuid; 229 u8 connection_key; 230 u8 connection_id; 231 u16 reserved; 232 }; 233 234 struct icm_fr_pkg_challenge_device { 235 struct icm_pkg_header hdr; 236 uuid_t ep_uuid; 237 u8 connection_key; 238 u8 connection_id; 239 u16 reserved; 240 u32 challenge[8]; 241 }; 242 243 struct icm_fr_pkg_challenge_device_response { 244 struct icm_pkg_header hdr; 245 uuid_t ep_uuid; 246 u8 connection_key; 247 u8 connection_id; 248 u16 reserved; 249 u32 challenge[8]; 250 u32 response[8]; 251 }; 252 253 struct icm_fr_pkg_approve_xdomain { 254 struct icm_pkg_header hdr; 255 u16 reserved; 256 u16 link_info; 257 uuid_t remote_uuid; 258 u16 transmit_path; 259 u16 transmit_ring; 260 u16 receive_path; 261 u16 receive_ring; 262 }; 263 264 struct icm_fr_pkg_approve_xdomain_response { 265 struct icm_pkg_header hdr; 266 u16 reserved; 267 u16 link_info; 268 uuid_t remote_uuid; 269 u16 transmit_path; 270 u16 transmit_ring; 271 u16 receive_path; 272 u16 receive_ring; 273 }; 274 275 /* Alpine Ridge only messages */ 276 277 struct icm_ar_pkg_get_route { 278 struct icm_pkg_header hdr; 279 u16 reserved; 280 u16 link_info; 281 }; 282 283 struct icm_ar_pkg_get_route_response { 284 struct icm_pkg_header hdr; 285 u16 reserved; 286 u16 link_info; 287 u32 route_hi; 288 u32 route_lo; 289 }; 290 291 /* XDomain messages */ 292 293 struct tb_xdomain_header { 294 u32 route_hi; 295 u32 route_lo; 296 u32 length_sn; 297 }; 298 299 #define TB_XDOMAIN_LENGTH_MASK GENMASK(5, 0) 300 #define TB_XDOMAIN_SN_MASK GENMASK(28, 27) 301 #define TB_XDOMAIN_SN_SHIFT 27 302 303 enum tb_xdp_type { 304 UUID_REQUEST_OLD = 1, 305 UUID_RESPONSE = 2, 306 PROPERTIES_REQUEST, 307 PROPERTIES_RESPONSE, 308 PROPERTIES_CHANGED_REQUEST, 309 PROPERTIES_CHANGED_RESPONSE, 310 ERROR_RESPONSE, 311 UUID_REQUEST = 12, 312 }; 313 314 struct tb_xdp_header { 315 struct tb_xdomain_header xd_hdr; 316 uuid_t uuid; 317 u32 type; 318 }; 319 320 struct tb_xdp_properties { 321 struct tb_xdp_header hdr; 322 uuid_t src_uuid; 323 uuid_t dst_uuid; 324 u16 offset; 325 u16 reserved; 326 }; 327 328 struct tb_xdp_properties_response { 329 struct tb_xdp_header hdr; 330 uuid_t src_uuid; 331 uuid_t dst_uuid; 332 u16 offset; 333 u16 data_length; 334 u32 generation; 335 u32 data[0]; 336 }; 337 338 /* 339 * Max length of data array single XDomain property response is allowed 340 * to carry. 341 */ 342 #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH \ 343 (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4) 344 345 /* Maximum size of the total property block in dwords we allow */ 346 #define TB_XDP_PROPERTIES_MAX_LENGTH 500 347 348 struct tb_xdp_properties_changed { 349 struct tb_xdp_header hdr; 350 uuid_t src_uuid; 351 }; 352 353 struct tb_xdp_properties_changed_response { 354 struct tb_xdp_header hdr; 355 }; 356 357 enum tb_xdp_error { 358 ERROR_SUCCESS, 359 ERROR_UNKNOWN_PACKET, 360 ERROR_UNKNOWN_DOMAIN, 361 ERROR_NOT_SUPPORTED, 362 ERROR_NOT_READY, 363 }; 364 365 struct tb_xdp_error_response { 366 struct tb_xdp_header hdr; 367 u32 error; 368 }; 369 370 #endif 371