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 struct icm_pkg_driver_ready_response { 131 struct icm_pkg_header hdr; 132 u8 romver; 133 u8 ramver; 134 u16 security_level; 135 }; 136 137 /* Falcon Ridge & Alpine Ridge common messages */ 138 139 struct icm_fr_pkg_get_topology { 140 struct icm_pkg_header hdr; 141 }; 142 143 #define ICM_GET_TOPOLOGY_PACKETS 14 144 145 struct icm_fr_pkg_get_topology_response { 146 struct icm_pkg_header hdr; 147 u32 route_lo; 148 u32 route_hi; 149 u8 first_data; 150 u8 second_data; 151 u8 drom_i2c_address_index; 152 u8 switch_index; 153 u32 reserved[2]; 154 u32 ports[16]; 155 u32 port_hop_info[16]; 156 }; 157 158 #define ICM_SWITCH_USED BIT(0) 159 #define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1) 160 #define ICM_SWITCH_UPSTREAM_PORT_SHIFT 1 161 162 #define ICM_PORT_TYPE_MASK GENMASK(23, 0) 163 #define ICM_PORT_INDEX_SHIFT 24 164 #define ICM_PORT_INDEX_MASK GENMASK(31, 24) 165 166 struct icm_fr_event_device_connected { 167 struct icm_pkg_header hdr; 168 uuid_t ep_uuid; 169 u8 connection_key; 170 u8 connection_id; 171 u16 link_info; 172 u32 ep_name[55]; 173 }; 174 175 #define ICM_LINK_INFO_LINK_MASK 0x7 176 #define ICM_LINK_INFO_DEPTH_SHIFT 4 177 #define ICM_LINK_INFO_DEPTH_MASK GENMASK(7, 4) 178 #define ICM_LINK_INFO_APPROVED BIT(8) 179 #define ICM_LINK_INFO_REJECTED BIT(9) 180 181 struct icm_fr_pkg_approve_device { 182 struct icm_pkg_header hdr; 183 uuid_t ep_uuid; 184 u8 connection_key; 185 u8 connection_id; 186 u16 reserved; 187 }; 188 189 struct icm_fr_event_device_disconnected { 190 struct icm_pkg_header hdr; 191 u16 reserved; 192 u16 link_info; 193 }; 194 195 struct icm_fr_event_xdomain_connected { 196 struct icm_pkg_header hdr; 197 u16 reserved; 198 u16 link_info; 199 uuid_t remote_uuid; 200 uuid_t local_uuid; 201 u32 local_route_hi; 202 u32 local_route_lo; 203 u32 remote_route_hi; 204 u32 remote_route_lo; 205 }; 206 207 struct icm_fr_event_xdomain_disconnected { 208 struct icm_pkg_header hdr; 209 u16 reserved; 210 u16 link_info; 211 uuid_t remote_uuid; 212 }; 213 214 struct icm_fr_pkg_add_device_key { 215 struct icm_pkg_header hdr; 216 uuid_t ep_uuid; 217 u8 connection_key; 218 u8 connection_id; 219 u16 reserved; 220 u32 key[8]; 221 }; 222 223 struct icm_fr_pkg_add_device_key_response { 224 struct icm_pkg_header hdr; 225 uuid_t ep_uuid; 226 u8 connection_key; 227 u8 connection_id; 228 u16 reserved; 229 }; 230 231 struct icm_fr_pkg_challenge_device { 232 struct icm_pkg_header hdr; 233 uuid_t ep_uuid; 234 u8 connection_key; 235 u8 connection_id; 236 u16 reserved; 237 u32 challenge[8]; 238 }; 239 240 struct icm_fr_pkg_challenge_device_response { 241 struct icm_pkg_header hdr; 242 uuid_t ep_uuid; 243 u8 connection_key; 244 u8 connection_id; 245 u16 reserved; 246 u32 challenge[8]; 247 u32 response[8]; 248 }; 249 250 struct icm_fr_pkg_approve_xdomain { 251 struct icm_pkg_header hdr; 252 u16 reserved; 253 u16 link_info; 254 uuid_t remote_uuid; 255 u16 transmit_path; 256 u16 transmit_ring; 257 u16 receive_path; 258 u16 receive_ring; 259 }; 260 261 struct icm_fr_pkg_approve_xdomain_response { 262 struct icm_pkg_header hdr; 263 u16 reserved; 264 u16 link_info; 265 uuid_t remote_uuid; 266 u16 transmit_path; 267 u16 transmit_ring; 268 u16 receive_path; 269 u16 receive_ring; 270 }; 271 272 /* Alpine Ridge only messages */ 273 274 struct icm_ar_pkg_get_route { 275 struct icm_pkg_header hdr; 276 u16 reserved; 277 u16 link_info; 278 }; 279 280 struct icm_ar_pkg_get_route_response { 281 struct icm_pkg_header hdr; 282 u16 reserved; 283 u16 link_info; 284 u32 route_hi; 285 u32 route_lo; 286 }; 287 288 /* XDomain messages */ 289 290 struct tb_xdomain_header { 291 u32 route_hi; 292 u32 route_lo; 293 u32 length_sn; 294 }; 295 296 #define TB_XDOMAIN_LENGTH_MASK GENMASK(5, 0) 297 #define TB_XDOMAIN_SN_MASK GENMASK(28, 27) 298 #define TB_XDOMAIN_SN_SHIFT 27 299 300 enum tb_xdp_type { 301 UUID_REQUEST_OLD = 1, 302 UUID_RESPONSE = 2, 303 PROPERTIES_REQUEST, 304 PROPERTIES_RESPONSE, 305 PROPERTIES_CHANGED_REQUEST, 306 PROPERTIES_CHANGED_RESPONSE, 307 ERROR_RESPONSE, 308 UUID_REQUEST = 12, 309 }; 310 311 struct tb_xdp_header { 312 struct tb_xdomain_header xd_hdr; 313 uuid_t uuid; 314 u32 type; 315 }; 316 317 struct tb_xdp_properties { 318 struct tb_xdp_header hdr; 319 uuid_t src_uuid; 320 uuid_t dst_uuid; 321 u16 offset; 322 u16 reserved; 323 }; 324 325 struct tb_xdp_properties_response { 326 struct tb_xdp_header hdr; 327 uuid_t src_uuid; 328 uuid_t dst_uuid; 329 u16 offset; 330 u16 data_length; 331 u32 generation; 332 u32 data[0]; 333 }; 334 335 /* 336 * Max length of data array single XDomain property response is allowed 337 * to carry. 338 */ 339 #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH \ 340 (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4) 341 342 /* Maximum size of the total property block in dwords we allow */ 343 #define TB_XDP_PROPERTIES_MAX_LENGTH 500 344 345 struct tb_xdp_properties_changed { 346 struct tb_xdp_header hdr; 347 uuid_t src_uuid; 348 }; 349 350 struct tb_xdp_properties_changed_response { 351 struct tb_xdp_header hdr; 352 }; 353 354 enum tb_xdp_error { 355 ERROR_SUCCESS, 356 ERROR_UNKNOWN_PACKET, 357 ERROR_UNKNOWN_DOMAIN, 358 ERROR_NOT_SUPPORTED, 359 ERROR_NOT_READY, 360 }; 361 362 struct tb_xdp_error_response { 363 struct tb_xdp_header hdr; 364 u32 error; 365 }; 366 367 #endif 368