Mika Westerberg | 32af943 | 2017-06-06 15:25:06 +0300 | [diff] [blame] | 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> |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 16 | #include <linux/uuid.h> |
Mika Westerberg | 32af943 | 2017-06-06 15:25:06 +0300 | [diff] [blame] | 17 | |
Mika Westerberg | 32af943 | 2017-06-06 15:25:06 +0300 | [diff] [blame] | 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 | |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 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, |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 104 | ICM_APPROVE_XDOMAIN = 0x10, |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | enum icm_event_code { |
| 108 | ICM_EVENT_DEVICE_CONNECTED = 3, |
| 109 | ICM_EVENT_DEVICE_DISCONNECTED = 4, |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 110 | ICM_EVENT_XDOMAIN_CONNECTED = 6, |
| 111 | ICM_EVENT_XDOMAIN_DISCONNECTED = 7, |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct icm_pkg_header { |
| 115 | u8 code; |
| 116 | u8 flags; |
| 117 | u8 packet_id; |
| 118 | u8 total_packets; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 119 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 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; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 128 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 129 | |
| 130 | struct icm_pkg_driver_ready_response { |
| 131 | struct icm_pkg_header hdr; |
| 132 | u8 romver; |
| 133 | u8 ramver; |
| 134 | u16 security_level; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 135 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 136 | |
| 137 | /* Falcon Ridge & Alpine Ridge common messages */ |
| 138 | |
| 139 | struct icm_fr_pkg_get_topology { |
| 140 | struct icm_pkg_header hdr; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 141 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 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]; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 156 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 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; |
Christoph Hellwig | 7c39ffe | 2017-07-18 15:30:05 +0200 | [diff] [blame] | 168 | uuid_t ep_uuid; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 169 | u8 connection_key; |
| 170 | u8 connection_id; |
| 171 | u16 link_info; |
| 172 | u32 ep_name[55]; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 173 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 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 | |
| 180 | struct icm_fr_pkg_approve_device { |
| 181 | struct icm_pkg_header hdr; |
Christoph Hellwig | 7c39ffe | 2017-07-18 15:30:05 +0200 | [diff] [blame] | 182 | uuid_t ep_uuid; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 183 | u8 connection_key; |
| 184 | u8 connection_id; |
| 185 | u16 reserved; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 186 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 187 | |
| 188 | struct icm_fr_event_device_disconnected { |
| 189 | struct icm_pkg_header hdr; |
| 190 | u16 reserved; |
| 191 | u16 link_info; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 192 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 193 | |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 194 | struct icm_fr_event_xdomain_connected { |
| 195 | struct icm_pkg_header hdr; |
| 196 | u16 reserved; |
| 197 | u16 link_info; |
| 198 | uuid_t remote_uuid; |
| 199 | uuid_t local_uuid; |
| 200 | u32 local_route_hi; |
| 201 | u32 local_route_lo; |
| 202 | u32 remote_route_hi; |
| 203 | u32 remote_route_lo; |
| 204 | }; |
| 205 | |
| 206 | struct icm_fr_event_xdomain_disconnected { |
| 207 | struct icm_pkg_header hdr; |
| 208 | u16 reserved; |
| 209 | u16 link_info; |
| 210 | uuid_t remote_uuid; |
| 211 | }; |
| 212 | |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 213 | struct icm_fr_pkg_add_device_key { |
| 214 | struct icm_pkg_header hdr; |
Christoph Hellwig | 7c39ffe | 2017-07-18 15:30:05 +0200 | [diff] [blame] | 215 | uuid_t ep_uuid; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 216 | u8 connection_key; |
| 217 | u8 connection_id; |
| 218 | u16 reserved; |
| 219 | u32 key[8]; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 220 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 221 | |
| 222 | struct icm_fr_pkg_add_device_key_response { |
| 223 | struct icm_pkg_header hdr; |
Christoph Hellwig | 7c39ffe | 2017-07-18 15:30:05 +0200 | [diff] [blame] | 224 | uuid_t ep_uuid; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 225 | u8 connection_key; |
| 226 | u8 connection_id; |
| 227 | u16 reserved; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 228 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 229 | |
| 230 | struct icm_fr_pkg_challenge_device { |
| 231 | struct icm_pkg_header hdr; |
Christoph Hellwig | 7c39ffe | 2017-07-18 15:30:05 +0200 | [diff] [blame] | 232 | uuid_t ep_uuid; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 233 | u8 connection_key; |
| 234 | u8 connection_id; |
| 235 | u16 reserved; |
| 236 | u32 challenge[8]; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 237 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 238 | |
| 239 | struct icm_fr_pkg_challenge_device_response { |
| 240 | struct icm_pkg_header hdr; |
Christoph Hellwig | 7c39ffe | 2017-07-18 15:30:05 +0200 | [diff] [blame] | 241 | uuid_t ep_uuid; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 242 | u8 connection_key; |
| 243 | u8 connection_id; |
| 244 | u16 reserved; |
| 245 | u32 challenge[8]; |
| 246 | u32 response[8]; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 247 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 248 | |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 249 | struct icm_fr_pkg_approve_xdomain { |
| 250 | struct icm_pkg_header hdr; |
| 251 | u16 reserved; |
| 252 | u16 link_info; |
| 253 | uuid_t remote_uuid; |
| 254 | u16 transmit_path; |
| 255 | u16 transmit_ring; |
| 256 | u16 receive_path; |
| 257 | u16 receive_ring; |
| 258 | }; |
| 259 | |
| 260 | struct icm_fr_pkg_approve_xdomain_response { |
| 261 | struct icm_pkg_header hdr; |
| 262 | u16 reserved; |
| 263 | u16 link_info; |
| 264 | uuid_t remote_uuid; |
| 265 | u16 transmit_path; |
| 266 | u16 transmit_ring; |
| 267 | u16 receive_path; |
| 268 | u16 receive_ring; |
| 269 | }; |
| 270 | |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 271 | /* Alpine Ridge only messages */ |
| 272 | |
| 273 | struct icm_ar_pkg_get_route { |
| 274 | struct icm_pkg_header hdr; |
| 275 | u16 reserved; |
| 276 | u16 link_info; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 277 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 278 | |
| 279 | struct icm_ar_pkg_get_route_response { |
| 280 | struct icm_pkg_header hdr; |
| 281 | u16 reserved; |
| 282 | u16 link_info; |
| 283 | u32 route_hi; |
| 284 | u32 route_lo; |
Mika Westerberg | 8067170 | 2017-10-02 13:38:29 +0300 | [diff] [blame] | 285 | }; |
Mika Westerberg | f67cf49 | 2017-06-06 15:25:16 +0300 | [diff] [blame] | 286 | |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 287 | /* XDomain messages */ |
| 288 | |
| 289 | struct tb_xdomain_header { |
| 290 | u32 route_hi; |
| 291 | u32 route_lo; |
| 292 | u32 length_sn; |
| 293 | }; |
| 294 | |
| 295 | #define TB_XDOMAIN_LENGTH_MASK GENMASK(5, 0) |
| 296 | #define TB_XDOMAIN_SN_MASK GENMASK(28, 27) |
| 297 | #define TB_XDOMAIN_SN_SHIFT 27 |
| 298 | |
| 299 | enum tb_xdp_type { |
| 300 | UUID_REQUEST_OLD = 1, |
| 301 | UUID_RESPONSE = 2, |
| 302 | PROPERTIES_REQUEST, |
| 303 | PROPERTIES_RESPONSE, |
| 304 | PROPERTIES_CHANGED_REQUEST, |
| 305 | PROPERTIES_CHANGED_RESPONSE, |
| 306 | ERROR_RESPONSE, |
| 307 | UUID_REQUEST = 12, |
| 308 | }; |
| 309 | |
| 310 | struct tb_xdp_header { |
| 311 | struct tb_xdomain_header xd_hdr; |
| 312 | uuid_t uuid; |
| 313 | u32 type; |
| 314 | }; |
| 315 | |
| 316 | struct tb_xdp_properties { |
| 317 | struct tb_xdp_header hdr; |
| 318 | uuid_t src_uuid; |
| 319 | uuid_t dst_uuid; |
| 320 | u16 offset; |
| 321 | u16 reserved; |
| 322 | }; |
| 323 | |
| 324 | struct tb_xdp_properties_response { |
| 325 | struct tb_xdp_header hdr; |
| 326 | uuid_t src_uuid; |
| 327 | uuid_t dst_uuid; |
| 328 | u16 offset; |
| 329 | u16 data_length; |
| 330 | u32 generation; |
| 331 | u32 data[0]; |
| 332 | }; |
| 333 | |
| 334 | /* |
| 335 | * Max length of data array single XDomain property response is allowed |
| 336 | * to carry. |
| 337 | */ |
| 338 | #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH \ |
| 339 | (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4) |
| 340 | |
| 341 | /* Maximum size of the total property block in dwords we allow */ |
| 342 | #define TB_XDP_PROPERTIES_MAX_LENGTH 500 |
| 343 | |
| 344 | struct tb_xdp_properties_changed { |
| 345 | struct tb_xdp_header hdr; |
| 346 | uuid_t src_uuid; |
| 347 | }; |
| 348 | |
| 349 | struct tb_xdp_properties_changed_response { |
| 350 | struct tb_xdp_header hdr; |
| 351 | }; |
| 352 | |
| 353 | enum tb_xdp_error { |
| 354 | ERROR_SUCCESS, |
| 355 | ERROR_UNKNOWN_PACKET, |
| 356 | ERROR_UNKNOWN_DOMAIN, |
| 357 | ERROR_NOT_SUPPORTED, |
| 358 | ERROR_NOT_READY, |
| 359 | }; |
| 360 | |
| 361 | struct tb_xdp_error_response { |
| 362 | struct tb_xdp_header hdr; |
| 363 | u32 error; |
| 364 | }; |
| 365 | |
Mika Westerberg | 32af943 | 2017-06-06 15:25:06 +0300 | [diff] [blame] | 366 | #endif |