1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Thunderbolt control channel messages 4 * 5 * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com> 6 * Copyright (C) 2017, Intel Corporation 7 */ 8 9 #ifndef _TB_MSGS 10 #define _TB_MSGS 11 12 #include <linux/types.h> 13 #include <linux/uuid.h> 14 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 22 enum tb_cfg_error { 23 TB_CFG_ERROR_PORT_NOT_CONNECTED = 0, 24 TB_CFG_ERROR_LINK_ERROR = 1, 25 TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2, 26 TB_CFG_ERROR_NO_SUCH_PORT = 4, 27 TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */ 28 TB_CFG_ERROR_LOOP = 8, 29 TB_CFG_ERROR_HEC_ERROR_DETECTED = 12, 30 TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13, 31 TB_CFG_ERROR_LOCK = 15, 32 TB_CFG_ERROR_DP_BW = 32, 33 TB_CFG_ERROR_ROP_CMPLT = 33, 34 TB_CFG_ERROR_POP_CMPLT = 34, 35 TB_CFG_ERROR_PCIE_WAKE = 35, 36 TB_CFG_ERROR_DP_CON_CHANGE = 36, 37 TB_CFG_ERROR_DPTX_DISCOVERY = 37, 38 TB_CFG_ERROR_LINK_RECOVERY = 38, 39 TB_CFG_ERROR_ASYM_LINK = 39, 40 }; 41 42 /* common header */ 43 struct tb_cfg_header { 44 u32 route_hi:22; 45 u32 unknown:10; /* highest order bit is set on replies */ 46 u32 route_lo; 47 } __packed; 48 49 /* additional header for read/write packets */ 50 struct tb_cfg_address { 51 u32 offset:13; /* in dwords */ 52 u32 length:6; /* in dwords */ 53 u32 port:6; 54 enum tb_cfg_space space:2; 55 u32 seq:2; /* sequence number */ 56 u32 zero:3; 57 } __packed; 58 59 /* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */ 60 struct cfg_read_pkg { 61 struct tb_cfg_header header; 62 struct tb_cfg_address addr; 63 } __packed; 64 65 /* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */ 66 struct cfg_write_pkg { 67 struct tb_cfg_header header; 68 struct tb_cfg_address addr; 69 u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */ 70 } __packed; 71 72 /* TB_CFG_PKG_ERROR */ 73 struct cfg_error_pkg { 74 struct tb_cfg_header header; 75 enum tb_cfg_error error:8; 76 u32 port:6; 77 u32 reserved:16; 78 u32 pg:2; 79 } __packed; 80 81 struct cfg_ack_pkg { 82 struct tb_cfg_header header; 83 }; 84 85 #define TB_CFG_ERROR_PG_HOT_PLUG 0x2 86 #define TB_CFG_ERROR_PG_HOT_UNPLUG 0x3 87 88 /* TB_CFG_PKG_EVENT */ 89 struct cfg_event_pkg { 90 struct tb_cfg_header header; 91 u32 port:6; 92 u32 zero:25; 93 bool unplug:1; 94 } __packed; 95 96 /* TB_CFG_PKG_RESET */ 97 struct cfg_reset_pkg { 98 struct tb_cfg_header header; 99 } __packed; 100 101 /* ICM messages */ 102 103 enum icm_pkg_code { 104 ICM_GET_TOPOLOGY = 0x1, 105 ICM_DRIVER_READY = 0x3, 106 ICM_APPROVE_DEVICE = 0x4, 107 ICM_CHALLENGE_DEVICE = 0x5, 108 ICM_ADD_DEVICE_KEY = 0x6, 109 ICM_GET_ROUTE = 0xa, 110 ICM_APPROVE_XDOMAIN = 0x10, 111 ICM_DISCONNECT_XDOMAIN = 0x11, 112 ICM_PREBOOT_ACL = 0x18, 113 ICM_USB4_SWITCH_OP = 0x20, 114 }; 115 116 enum icm_event_code { 117 ICM_EVENT_DEVICE_CONNECTED = 0x3, 118 ICM_EVENT_DEVICE_DISCONNECTED = 0x4, 119 ICM_EVENT_XDOMAIN_CONNECTED = 0x6, 120 ICM_EVENT_XDOMAIN_DISCONNECTED = 0x7, 121 ICM_EVENT_DP_CONFIG_CHANGED = 0x8, 122 ICM_EVENT_RTD3_VETO = 0xa, 123 }; 124 125 struct icm_pkg_header { 126 u8 code; 127 u8 flags; 128 u8 packet_id; 129 u8 total_packets; 130 }; 131 132 #define ICM_FLAGS_ERROR BIT(0) 133 #define ICM_FLAGS_NO_KEY BIT(1) 134 #define ICM_FLAGS_SLEVEL_SHIFT 3 135 #define ICM_FLAGS_SLEVEL_MASK GENMASK(4, 3) 136 #define ICM_FLAGS_DUAL_LANE BIT(5) 137 #define ICM_FLAGS_SPEED_GEN3 BIT(7) 138 #define ICM_FLAGS_WRITE BIT(7) 139 140 struct icm_pkg_driver_ready { 141 struct icm_pkg_header hdr; 142 }; 143 144 /* Falcon Ridge only messages */ 145 146 struct icm_fr_pkg_driver_ready_response { 147 struct icm_pkg_header hdr; 148 u8 romver; 149 u8 ramver; 150 u16 security_level; 151 }; 152 153 #define ICM_FR_SLEVEL_MASK 0xf 154 155 /* Falcon Ridge & Alpine Ridge common messages */ 156 157 struct icm_fr_pkg_get_topology { 158 struct icm_pkg_header hdr; 159 }; 160 161 #define ICM_GET_TOPOLOGY_PACKETS 14 162 163 struct icm_fr_pkg_get_topology_response { 164 struct icm_pkg_header hdr; 165 u32 route_lo; 166 u32 route_hi; 167 u8 first_data; 168 u8 second_data; 169 u8 drom_i2c_address_index; 170 u8 switch_index; 171 u32 reserved[2]; 172 u32 ports[16]; 173 u32 port_hop_info[16]; 174 }; 175 176 #define ICM_SWITCH_USED BIT(0) 177 #define ICM_SWITCH_UPSTREAM_PORT_MASK GENMASK(7, 1) 178 #define ICM_SWITCH_UPSTREAM_PORT_SHIFT 1 179 180 #define ICM_PORT_TYPE_MASK GENMASK(23, 0) 181 #define ICM_PORT_INDEX_SHIFT 24 182 #define ICM_PORT_INDEX_MASK GENMASK(31, 24) 183 184 struct icm_fr_event_device_connected { 185 struct icm_pkg_header hdr; 186 uuid_t ep_uuid; 187 u8 connection_key; 188 u8 connection_id; 189 u16 link_info; 190 u32 ep_name[55]; 191 }; 192 193 #define ICM_LINK_INFO_LINK_MASK 0x7 194 #define ICM_LINK_INFO_DEPTH_SHIFT 4 195 #define ICM_LINK_INFO_DEPTH_MASK GENMASK(7, 4) 196 #define ICM_LINK_INFO_APPROVED BIT(8) 197 #define ICM_LINK_INFO_REJECTED BIT(9) 198 #define ICM_LINK_INFO_BOOT BIT(10) 199 200 struct icm_fr_pkg_approve_device { 201 struct icm_pkg_header hdr; 202 uuid_t ep_uuid; 203 u8 connection_key; 204 u8 connection_id; 205 u16 reserved; 206 }; 207 208 struct icm_fr_event_device_disconnected { 209 struct icm_pkg_header hdr; 210 u16 reserved; 211 u16 link_info; 212 }; 213 214 struct icm_fr_event_xdomain_connected { 215 struct icm_pkg_header hdr; 216 u16 reserved; 217 u16 link_info; 218 uuid_t remote_uuid; 219 uuid_t local_uuid; 220 u32 local_route_hi; 221 u32 local_route_lo; 222 u32 remote_route_hi; 223 u32 remote_route_lo; 224 }; 225 226 struct icm_fr_event_xdomain_disconnected { 227 struct icm_pkg_header hdr; 228 u16 reserved; 229 u16 link_info; 230 uuid_t remote_uuid; 231 }; 232 233 struct icm_fr_pkg_add_device_key { 234 struct icm_pkg_header hdr; 235 uuid_t ep_uuid; 236 u8 connection_key; 237 u8 connection_id; 238 u16 reserved; 239 u32 key[8]; 240 }; 241 242 struct icm_fr_pkg_add_device_key_response { 243 struct icm_pkg_header hdr; 244 uuid_t ep_uuid; 245 u8 connection_key; 246 u8 connection_id; 247 u16 reserved; 248 }; 249 250 struct icm_fr_pkg_challenge_device { 251 struct icm_pkg_header hdr; 252 uuid_t ep_uuid; 253 u8 connection_key; 254 u8 connection_id; 255 u16 reserved; 256 u32 challenge[8]; 257 }; 258 259 struct icm_fr_pkg_challenge_device_response { 260 struct icm_pkg_header hdr; 261 uuid_t ep_uuid; 262 u8 connection_key; 263 u8 connection_id; 264 u16 reserved; 265 u32 challenge[8]; 266 u32 response[8]; 267 }; 268 269 struct icm_fr_pkg_approve_xdomain { 270 struct icm_pkg_header hdr; 271 u16 reserved; 272 u16 link_info; 273 uuid_t remote_uuid; 274 u16 transmit_path; 275 u16 transmit_ring; 276 u16 receive_path; 277 u16 receive_ring; 278 }; 279 280 struct icm_fr_pkg_approve_xdomain_response { 281 struct icm_pkg_header hdr; 282 u16 reserved; 283 u16 link_info; 284 uuid_t remote_uuid; 285 u16 transmit_path; 286 u16 transmit_ring; 287 u16 receive_path; 288 u16 receive_ring; 289 }; 290 291 /* Alpine Ridge only messages */ 292 293 struct icm_ar_pkg_driver_ready_response { 294 struct icm_pkg_header hdr; 295 u8 romver; 296 u8 ramver; 297 u16 info; 298 }; 299 300 #define ICM_AR_FLAGS_RTD3 BIT(6) 301 302 #define ICM_AR_INFO_SLEVEL_MASK GENMASK(3, 0) 303 #define ICM_AR_INFO_BOOT_ACL_SHIFT 7 304 #define ICM_AR_INFO_BOOT_ACL_MASK GENMASK(11, 7) 305 #define ICM_AR_INFO_BOOT_ACL_SUPPORTED BIT(13) 306 307 struct icm_ar_pkg_get_route { 308 struct icm_pkg_header hdr; 309 u16 reserved; 310 u16 link_info; 311 }; 312 313 struct icm_ar_pkg_get_route_response { 314 struct icm_pkg_header hdr; 315 u16 reserved; 316 u16 link_info; 317 u32 route_hi; 318 u32 route_lo; 319 }; 320 321 struct icm_ar_boot_acl_entry { 322 u32 uuid_lo; 323 u32 uuid_hi; 324 }; 325 326 #define ICM_AR_PREBOOT_ACL_ENTRIES 16 327 328 struct icm_ar_pkg_preboot_acl { 329 struct icm_pkg_header hdr; 330 struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES]; 331 }; 332 333 struct icm_ar_pkg_preboot_acl_response { 334 struct icm_pkg_header hdr; 335 struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES]; 336 }; 337 338 /* Titan Ridge messages */ 339 340 struct icm_tr_pkg_driver_ready_response { 341 struct icm_pkg_header hdr; 342 u16 reserved1; 343 u16 info; 344 u32 nvm_version; 345 u16 device_id; 346 u16 reserved2; 347 }; 348 349 #define ICM_TR_FLAGS_RTD3 BIT(6) 350 351 #define ICM_TR_INFO_SLEVEL_MASK GENMASK(2, 0) 352 #define ICM_TR_INFO_PROTO_VERSION_MASK GENMASK(6, 4) 353 #define ICM_TR_INFO_PROTO_VERSION_SHIFT 4 354 #define ICM_TR_INFO_BOOT_ACL_SHIFT 7 355 #define ICM_TR_INFO_BOOT_ACL_MASK GENMASK(12, 7) 356 357 struct icm_tr_event_device_connected { 358 struct icm_pkg_header hdr; 359 uuid_t ep_uuid; 360 u32 route_hi; 361 u32 route_lo; 362 u8 connection_id; 363 u8 reserved; 364 u16 link_info; 365 u32 ep_name[55]; 366 }; 367 368 struct icm_tr_event_device_disconnected { 369 struct icm_pkg_header hdr; 370 u32 route_hi; 371 u32 route_lo; 372 }; 373 374 struct icm_tr_event_xdomain_connected { 375 struct icm_pkg_header hdr; 376 u16 reserved; 377 u16 link_info; 378 uuid_t remote_uuid; 379 uuid_t local_uuid; 380 u32 local_route_hi; 381 u32 local_route_lo; 382 u32 remote_route_hi; 383 u32 remote_route_lo; 384 }; 385 386 struct icm_tr_event_xdomain_disconnected { 387 struct icm_pkg_header hdr; 388 u32 route_hi; 389 u32 route_lo; 390 uuid_t remote_uuid; 391 }; 392 393 struct icm_tr_pkg_approve_device { 394 struct icm_pkg_header hdr; 395 uuid_t ep_uuid; 396 u32 route_hi; 397 u32 route_lo; 398 u8 connection_id; 399 u8 reserved1[3]; 400 }; 401 402 struct icm_tr_pkg_add_device_key { 403 struct icm_pkg_header hdr; 404 uuid_t ep_uuid; 405 u32 route_hi; 406 u32 route_lo; 407 u8 connection_id; 408 u8 reserved[3]; 409 u32 key[8]; 410 }; 411 412 struct icm_tr_pkg_challenge_device { 413 struct icm_pkg_header hdr; 414 uuid_t ep_uuid; 415 u32 route_hi; 416 u32 route_lo; 417 u8 connection_id; 418 u8 reserved[3]; 419 u32 challenge[8]; 420 }; 421 422 struct icm_tr_pkg_approve_xdomain { 423 struct icm_pkg_header hdr; 424 u32 route_hi; 425 u32 route_lo; 426 uuid_t remote_uuid; 427 u16 transmit_path; 428 u16 transmit_ring; 429 u16 receive_path; 430 u16 receive_ring; 431 }; 432 433 struct icm_tr_pkg_disconnect_xdomain { 434 struct icm_pkg_header hdr; 435 u8 stage; 436 u8 reserved[3]; 437 u32 route_hi; 438 u32 route_lo; 439 uuid_t remote_uuid; 440 }; 441 442 struct icm_tr_pkg_challenge_device_response { 443 struct icm_pkg_header hdr; 444 uuid_t ep_uuid; 445 u32 route_hi; 446 u32 route_lo; 447 u8 connection_id; 448 u8 reserved[3]; 449 u32 challenge[8]; 450 u32 response[8]; 451 }; 452 453 struct icm_tr_pkg_add_device_key_response { 454 struct icm_pkg_header hdr; 455 uuid_t ep_uuid; 456 u32 route_hi; 457 u32 route_lo; 458 u8 connection_id; 459 u8 reserved[3]; 460 }; 461 462 struct icm_tr_pkg_approve_xdomain_response { 463 struct icm_pkg_header hdr; 464 u32 route_hi; 465 u32 route_lo; 466 uuid_t remote_uuid; 467 u16 transmit_path; 468 u16 transmit_ring; 469 u16 receive_path; 470 u16 receive_ring; 471 }; 472 473 struct icm_tr_pkg_disconnect_xdomain_response { 474 struct icm_pkg_header hdr; 475 u8 stage; 476 u8 reserved[3]; 477 u32 route_hi; 478 u32 route_lo; 479 uuid_t remote_uuid; 480 }; 481 482 /* Ice Lake messages */ 483 484 struct icm_icl_event_rtd3_veto { 485 struct icm_pkg_header hdr; 486 u32 veto_reason; 487 }; 488 489 /* USB4 ICM messages */ 490 491 struct icm_usb4_switch_op { 492 struct icm_pkg_header hdr; 493 u32 route_hi; 494 u32 route_lo; 495 u32 metadata; 496 u16 opcode; 497 u16 data_len_valid; 498 u32 data[16]; 499 }; 500 501 #define ICM_USB4_SWITCH_DATA_LEN_MASK GENMASK(3, 0) 502 #define ICM_USB4_SWITCH_DATA_VALID BIT(4) 503 504 struct icm_usb4_switch_op_response { 505 struct icm_pkg_header hdr; 506 u32 route_hi; 507 u32 route_lo; 508 u32 metadata; 509 u16 opcode; 510 u16 status; 511 u32 data[16]; 512 }; 513 514 /* XDomain messages */ 515 516 struct tb_xdomain_header { 517 u32 route_hi; 518 u32 route_lo; 519 u32 length_sn; 520 }; 521 522 #define TB_XDOMAIN_LENGTH_MASK GENMASK(5, 0) 523 #define TB_XDOMAIN_SN_MASK GENMASK(28, 27) 524 #define TB_XDOMAIN_SN_SHIFT 27 525 526 enum tb_xdp_type { 527 UUID_REQUEST_OLD = 1, 528 UUID_RESPONSE = 2, 529 PROPERTIES_REQUEST, 530 PROPERTIES_RESPONSE, 531 PROPERTIES_CHANGED_REQUEST, 532 PROPERTIES_CHANGED_RESPONSE, 533 ERROR_RESPONSE, 534 UUID_REQUEST = 12, 535 LINK_STATE_STATUS_REQUEST = 15, 536 LINK_STATE_STATUS_RESPONSE, 537 LINK_STATE_CHANGE_REQUEST, 538 LINK_STATE_CHANGE_RESPONSE, 539 }; 540 541 struct tb_xdp_header { 542 struct tb_xdomain_header xd_hdr; 543 uuid_t uuid; 544 u32 type; 545 }; 546 547 struct tb_xdp_error_response { 548 struct tb_xdp_header hdr; 549 u32 error; 550 }; 551 552 struct tb_xdp_link_state_status { 553 struct tb_xdp_header hdr; 554 }; 555 556 struct tb_xdp_link_state_status_response { 557 union { 558 struct tb_xdp_error_response err; 559 struct { 560 struct tb_xdp_header hdr; 561 u32 status; 562 u8 slw; 563 u8 tlw; 564 u8 sls; 565 u8 tls; 566 }; 567 }; 568 }; 569 570 struct tb_xdp_link_state_change { 571 struct tb_xdp_header hdr; 572 u8 tlw; 573 u8 tls; 574 u16 reserved; 575 }; 576 577 struct tb_xdp_link_state_change_response { 578 union { 579 struct tb_xdp_error_response err; 580 struct { 581 struct tb_xdp_header hdr; 582 u32 status; 583 }; 584 }; 585 }; 586 587 struct tb_xdp_uuid { 588 struct tb_xdp_header hdr; 589 }; 590 591 struct tb_xdp_uuid_response { 592 union { 593 struct tb_xdp_error_response err; 594 struct { 595 struct tb_xdp_header hdr; 596 uuid_t src_uuid; 597 u32 src_route_hi; 598 u32 src_route_lo; 599 }; 600 }; 601 }; 602 603 struct tb_xdp_properties { 604 struct tb_xdp_header hdr; 605 uuid_t src_uuid; 606 uuid_t dst_uuid; 607 u16 offset; 608 u16 reserved; 609 }; 610 611 struct tb_xdp_properties_response { 612 union { 613 struct tb_xdp_error_response err; 614 struct { 615 struct tb_xdp_header hdr; 616 uuid_t src_uuid; 617 uuid_t dst_uuid; 618 u16 offset; 619 u16 data_length; 620 u32 generation; 621 u32 data[]; 622 }; 623 }; 624 }; 625 626 /* 627 * Max length of data array single XDomain property response is allowed 628 * to carry. 629 */ 630 #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH \ 631 (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4) 632 633 /* Maximum size of the total property block in dwords we allow */ 634 #define TB_XDP_PROPERTIES_MAX_LENGTH 500 635 636 struct tb_xdp_properties_changed { 637 struct tb_xdp_header hdr; 638 uuid_t src_uuid; 639 }; 640 641 struct tb_xdp_properties_changed_response { 642 union { 643 struct tb_xdp_error_response err; 644 struct tb_xdp_header hdr; 645 }; 646 }; 647 648 enum tb_xdp_error { 649 ERROR_SUCCESS, 650 ERROR_UNKNOWN_PACKET, 651 ERROR_UNKNOWN_DOMAIN, 652 ERROR_NOT_SUPPORTED, 653 ERROR_NOT_READY, 654 }; 655 656 #endif 657