Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Thunderbolt control channel messages
0004  *
0005  * Copyright (C) 2014 Andreas Noever <andreas.noever@gmail.com>
0006  * Copyright (C) 2017, Intel Corporation
0007  */
0008 
0009 #ifndef _TB_MSGS
0010 #define _TB_MSGS
0011 
0012 #include <linux/types.h>
0013 #include <linux/uuid.h>
0014 
0015 enum tb_cfg_space {
0016     TB_CFG_HOPS = 0,
0017     TB_CFG_PORT = 1,
0018     TB_CFG_SWITCH = 2,
0019     TB_CFG_COUNTERS = 3,
0020 };
0021 
0022 enum tb_cfg_error {
0023     TB_CFG_ERROR_PORT_NOT_CONNECTED = 0,
0024     TB_CFG_ERROR_LINK_ERROR = 1,
0025     TB_CFG_ERROR_INVALID_CONFIG_SPACE = 2,
0026     TB_CFG_ERROR_NO_SUCH_PORT = 4,
0027     TB_CFG_ERROR_ACK_PLUG_EVENT = 7, /* send as reply to TB_CFG_PKG_EVENT */
0028     TB_CFG_ERROR_LOOP = 8,
0029     TB_CFG_ERROR_HEC_ERROR_DETECTED = 12,
0030     TB_CFG_ERROR_FLOW_CONTROL_ERROR = 13,
0031     TB_CFG_ERROR_LOCK = 15,
0032 };
0033 
0034 /* common header */
0035 struct tb_cfg_header {
0036     u32 route_hi:22;
0037     u32 unknown:10; /* highest order bit is set on replies */
0038     u32 route_lo;
0039 } __packed;
0040 
0041 /* additional header for read/write packets */
0042 struct tb_cfg_address {
0043     u32 offset:13; /* in dwords */
0044     u32 length:6; /* in dwords */
0045     u32 port:6;
0046     enum tb_cfg_space space:2;
0047     u32 seq:2; /* sequence number  */
0048     u32 zero:3;
0049 } __packed;
0050 
0051 /* TB_CFG_PKG_READ, response for TB_CFG_PKG_WRITE */
0052 struct cfg_read_pkg {
0053     struct tb_cfg_header header;
0054     struct tb_cfg_address addr;
0055 } __packed;
0056 
0057 /* TB_CFG_PKG_WRITE, response for TB_CFG_PKG_READ */
0058 struct cfg_write_pkg {
0059     struct tb_cfg_header header;
0060     struct tb_cfg_address addr;
0061     u32 data[64]; /* maximum size, tb_cfg_address.length has 6 bits */
0062 } __packed;
0063 
0064 /* TB_CFG_PKG_ERROR */
0065 struct cfg_error_pkg {
0066     struct tb_cfg_header header;
0067     enum tb_cfg_error error:4;
0068     u32 zero1:4;
0069     u32 port:6;
0070     u32 zero2:2; /* Both should be zero, still they are different fields. */
0071     u32 zero3:14;
0072     u32 pg:2;
0073 } __packed;
0074 
0075 #define TB_CFG_ERROR_PG_HOT_PLUG    0x2
0076 #define TB_CFG_ERROR_PG_HOT_UNPLUG  0x3
0077 
0078 /* TB_CFG_PKG_EVENT */
0079 struct cfg_event_pkg {
0080     struct tb_cfg_header header;
0081     u32 port:6;
0082     u32 zero:25;
0083     bool unplug:1;
0084 } __packed;
0085 
0086 /* TB_CFG_PKG_RESET */
0087 struct cfg_reset_pkg {
0088     struct tb_cfg_header header;
0089 } __packed;
0090 
0091 /* TB_CFG_PKG_PREPARE_TO_SLEEP */
0092 struct cfg_pts_pkg {
0093     struct tb_cfg_header header;
0094     u32 data;
0095 } __packed;
0096 
0097 /* ICM messages */
0098 
0099 enum icm_pkg_code {
0100     ICM_GET_TOPOLOGY = 0x1,
0101     ICM_DRIVER_READY = 0x3,
0102     ICM_APPROVE_DEVICE = 0x4,
0103     ICM_CHALLENGE_DEVICE = 0x5,
0104     ICM_ADD_DEVICE_KEY = 0x6,
0105     ICM_GET_ROUTE = 0xa,
0106     ICM_APPROVE_XDOMAIN = 0x10,
0107     ICM_DISCONNECT_XDOMAIN = 0x11,
0108     ICM_PREBOOT_ACL = 0x18,
0109     ICM_USB4_SWITCH_OP = 0x20,
0110 };
0111 
0112 enum icm_event_code {
0113     ICM_EVENT_DEVICE_CONNECTED = 0x3,
0114     ICM_EVENT_DEVICE_DISCONNECTED = 0x4,
0115     ICM_EVENT_XDOMAIN_CONNECTED = 0x6,
0116     ICM_EVENT_XDOMAIN_DISCONNECTED = 0x7,
0117     ICM_EVENT_RTD3_VETO = 0xa,
0118 };
0119 
0120 struct icm_pkg_header {
0121     u8 code;
0122     u8 flags;
0123     u8 packet_id;
0124     u8 total_packets;
0125 };
0126 
0127 #define ICM_FLAGS_ERROR         BIT(0)
0128 #define ICM_FLAGS_NO_KEY        BIT(1)
0129 #define ICM_FLAGS_SLEVEL_SHIFT      3
0130 #define ICM_FLAGS_SLEVEL_MASK       GENMASK(4, 3)
0131 #define ICM_FLAGS_DUAL_LANE     BIT(5)
0132 #define ICM_FLAGS_SPEED_GEN3        BIT(7)
0133 #define ICM_FLAGS_WRITE         BIT(7)
0134 
0135 struct icm_pkg_driver_ready {
0136     struct icm_pkg_header hdr;
0137 };
0138 
0139 /* Falcon Ridge only messages */
0140 
0141 struct icm_fr_pkg_driver_ready_response {
0142     struct icm_pkg_header hdr;
0143     u8 romver;
0144     u8 ramver;
0145     u16 security_level;
0146 };
0147 
0148 #define ICM_FR_SLEVEL_MASK      0xf
0149 
0150 /* Falcon Ridge & Alpine Ridge common messages */
0151 
0152 struct icm_fr_pkg_get_topology {
0153     struct icm_pkg_header hdr;
0154 };
0155 
0156 #define ICM_GET_TOPOLOGY_PACKETS    14
0157 
0158 struct icm_fr_pkg_get_topology_response {
0159     struct icm_pkg_header hdr;
0160     u32 route_lo;
0161     u32 route_hi;
0162     u8 first_data;
0163     u8 second_data;
0164     u8 drom_i2c_address_index;
0165     u8 switch_index;
0166     u32 reserved[2];
0167     u32 ports[16];
0168     u32 port_hop_info[16];
0169 };
0170 
0171 #define ICM_SWITCH_USED         BIT(0)
0172 #define ICM_SWITCH_UPSTREAM_PORT_MASK   GENMASK(7, 1)
0173 #define ICM_SWITCH_UPSTREAM_PORT_SHIFT  1
0174 
0175 #define ICM_PORT_TYPE_MASK      GENMASK(23, 0)
0176 #define ICM_PORT_INDEX_SHIFT        24
0177 #define ICM_PORT_INDEX_MASK     GENMASK(31, 24)
0178 
0179 struct icm_fr_event_device_connected {
0180     struct icm_pkg_header hdr;
0181     uuid_t ep_uuid;
0182     u8 connection_key;
0183     u8 connection_id;
0184     u16 link_info;
0185     u32 ep_name[55];
0186 };
0187 
0188 #define ICM_LINK_INFO_LINK_MASK     0x7
0189 #define ICM_LINK_INFO_DEPTH_SHIFT   4
0190 #define ICM_LINK_INFO_DEPTH_MASK    GENMASK(7, 4)
0191 #define ICM_LINK_INFO_APPROVED      BIT(8)
0192 #define ICM_LINK_INFO_REJECTED      BIT(9)
0193 #define ICM_LINK_INFO_BOOT      BIT(10)
0194 
0195 struct icm_fr_pkg_approve_device {
0196     struct icm_pkg_header hdr;
0197     uuid_t ep_uuid;
0198     u8 connection_key;
0199     u8 connection_id;
0200     u16 reserved;
0201 };
0202 
0203 struct icm_fr_event_device_disconnected {
0204     struct icm_pkg_header hdr;
0205     u16 reserved;
0206     u16 link_info;
0207 };
0208 
0209 struct icm_fr_event_xdomain_connected {
0210     struct icm_pkg_header hdr;
0211     u16 reserved;
0212     u16 link_info;
0213     uuid_t remote_uuid;
0214     uuid_t local_uuid;
0215     u32 local_route_hi;
0216     u32 local_route_lo;
0217     u32 remote_route_hi;
0218     u32 remote_route_lo;
0219 };
0220 
0221 struct icm_fr_event_xdomain_disconnected {
0222     struct icm_pkg_header hdr;
0223     u16 reserved;
0224     u16 link_info;
0225     uuid_t remote_uuid;
0226 };
0227 
0228 struct icm_fr_pkg_add_device_key {
0229     struct icm_pkg_header hdr;
0230     uuid_t ep_uuid;
0231     u8 connection_key;
0232     u8 connection_id;
0233     u16 reserved;
0234     u32 key[8];
0235 };
0236 
0237 struct icm_fr_pkg_add_device_key_response {
0238     struct icm_pkg_header hdr;
0239     uuid_t ep_uuid;
0240     u8 connection_key;
0241     u8 connection_id;
0242     u16 reserved;
0243 };
0244 
0245 struct icm_fr_pkg_challenge_device {
0246     struct icm_pkg_header hdr;
0247     uuid_t ep_uuid;
0248     u8 connection_key;
0249     u8 connection_id;
0250     u16 reserved;
0251     u32 challenge[8];
0252 };
0253 
0254 struct icm_fr_pkg_challenge_device_response {
0255     struct icm_pkg_header hdr;
0256     uuid_t ep_uuid;
0257     u8 connection_key;
0258     u8 connection_id;
0259     u16 reserved;
0260     u32 challenge[8];
0261     u32 response[8];
0262 };
0263 
0264 struct icm_fr_pkg_approve_xdomain {
0265     struct icm_pkg_header hdr;
0266     u16 reserved;
0267     u16 link_info;
0268     uuid_t remote_uuid;
0269     u16 transmit_path;
0270     u16 transmit_ring;
0271     u16 receive_path;
0272     u16 receive_ring;
0273 };
0274 
0275 struct icm_fr_pkg_approve_xdomain_response {
0276     struct icm_pkg_header hdr;
0277     u16 reserved;
0278     u16 link_info;
0279     uuid_t remote_uuid;
0280     u16 transmit_path;
0281     u16 transmit_ring;
0282     u16 receive_path;
0283     u16 receive_ring;
0284 };
0285 
0286 /* Alpine Ridge only messages */
0287 
0288 struct icm_ar_pkg_driver_ready_response {
0289     struct icm_pkg_header hdr;
0290     u8 romver;
0291     u8 ramver;
0292     u16 info;
0293 };
0294 
0295 #define ICM_AR_FLAGS_RTD3       BIT(6)
0296 
0297 #define ICM_AR_INFO_SLEVEL_MASK     GENMASK(3, 0)
0298 #define ICM_AR_INFO_BOOT_ACL_SHIFT  7
0299 #define ICM_AR_INFO_BOOT_ACL_MASK   GENMASK(11, 7)
0300 #define ICM_AR_INFO_BOOT_ACL_SUPPORTED  BIT(13)
0301 
0302 struct icm_ar_pkg_get_route {
0303     struct icm_pkg_header hdr;
0304     u16 reserved;
0305     u16 link_info;
0306 };
0307 
0308 struct icm_ar_pkg_get_route_response {
0309     struct icm_pkg_header hdr;
0310     u16 reserved;
0311     u16 link_info;
0312     u32 route_hi;
0313     u32 route_lo;
0314 };
0315 
0316 struct icm_ar_boot_acl_entry {
0317     u32 uuid_lo;
0318     u32 uuid_hi;
0319 };
0320 
0321 #define ICM_AR_PREBOOT_ACL_ENTRIES  16
0322 
0323 struct icm_ar_pkg_preboot_acl {
0324     struct icm_pkg_header hdr;
0325     struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES];
0326 };
0327 
0328 struct icm_ar_pkg_preboot_acl_response {
0329     struct icm_pkg_header hdr;
0330     struct icm_ar_boot_acl_entry acl[ICM_AR_PREBOOT_ACL_ENTRIES];
0331 };
0332 
0333 /* Titan Ridge messages */
0334 
0335 struct icm_tr_pkg_driver_ready_response {
0336     struct icm_pkg_header hdr;
0337     u16 reserved1;
0338     u16 info;
0339     u32 nvm_version;
0340     u16 device_id;
0341     u16 reserved2;
0342 };
0343 
0344 #define ICM_TR_FLAGS_RTD3       BIT(6)
0345 
0346 #define ICM_TR_INFO_SLEVEL_MASK     GENMASK(2, 0)
0347 #define ICM_TR_INFO_PROTO_VERSION_MASK  GENMASK(6, 4)
0348 #define ICM_TR_INFO_PROTO_VERSION_SHIFT 4
0349 #define ICM_TR_INFO_BOOT_ACL_SHIFT  7
0350 #define ICM_TR_INFO_BOOT_ACL_MASK   GENMASK(12, 7)
0351 
0352 struct icm_tr_event_device_connected {
0353     struct icm_pkg_header hdr;
0354     uuid_t ep_uuid;
0355     u32 route_hi;
0356     u32 route_lo;
0357     u8 connection_id;
0358     u8 reserved;
0359     u16 link_info;
0360     u32 ep_name[55];
0361 };
0362 
0363 struct icm_tr_event_device_disconnected {
0364     struct icm_pkg_header hdr;
0365     u32 route_hi;
0366     u32 route_lo;
0367 };
0368 
0369 struct icm_tr_event_xdomain_connected {
0370     struct icm_pkg_header hdr;
0371     u16 reserved;
0372     u16 link_info;
0373     uuid_t remote_uuid;
0374     uuid_t local_uuid;
0375     u32 local_route_hi;
0376     u32 local_route_lo;
0377     u32 remote_route_hi;
0378     u32 remote_route_lo;
0379 };
0380 
0381 struct icm_tr_event_xdomain_disconnected {
0382     struct icm_pkg_header hdr;
0383     u32 route_hi;
0384     u32 route_lo;
0385     uuid_t remote_uuid;
0386 };
0387 
0388 struct icm_tr_pkg_approve_device {
0389     struct icm_pkg_header hdr;
0390     uuid_t ep_uuid;
0391     u32 route_hi;
0392     u32 route_lo;
0393     u8 connection_id;
0394     u8 reserved1[3];
0395 };
0396 
0397 struct icm_tr_pkg_add_device_key {
0398     struct icm_pkg_header hdr;
0399     uuid_t ep_uuid;
0400     u32 route_hi;
0401     u32 route_lo;
0402     u8 connection_id;
0403     u8 reserved[3];
0404     u32 key[8];
0405 };
0406 
0407 struct icm_tr_pkg_challenge_device {
0408     struct icm_pkg_header hdr;
0409     uuid_t ep_uuid;
0410     u32 route_hi;
0411     u32 route_lo;
0412     u8 connection_id;
0413     u8 reserved[3];
0414     u32 challenge[8];
0415 };
0416 
0417 struct icm_tr_pkg_approve_xdomain {
0418     struct icm_pkg_header hdr;
0419     u32 route_hi;
0420     u32 route_lo;
0421     uuid_t remote_uuid;
0422     u16 transmit_path;
0423     u16 transmit_ring;
0424     u16 receive_path;
0425     u16 receive_ring;
0426 };
0427 
0428 struct icm_tr_pkg_disconnect_xdomain {
0429     struct icm_pkg_header hdr;
0430     u8 stage;
0431     u8 reserved[3];
0432     u32 route_hi;
0433     u32 route_lo;
0434     uuid_t remote_uuid;
0435 };
0436 
0437 struct icm_tr_pkg_challenge_device_response {
0438     struct icm_pkg_header hdr;
0439     uuid_t ep_uuid;
0440     u32 route_hi;
0441     u32 route_lo;
0442     u8 connection_id;
0443     u8 reserved[3];
0444     u32 challenge[8];
0445     u32 response[8];
0446 };
0447 
0448 struct icm_tr_pkg_add_device_key_response {
0449     struct icm_pkg_header hdr;
0450     uuid_t ep_uuid;
0451     u32 route_hi;
0452     u32 route_lo;
0453     u8 connection_id;
0454     u8 reserved[3];
0455 };
0456 
0457 struct icm_tr_pkg_approve_xdomain_response {
0458     struct icm_pkg_header hdr;
0459     u32 route_hi;
0460     u32 route_lo;
0461     uuid_t remote_uuid;
0462     u16 transmit_path;
0463     u16 transmit_ring;
0464     u16 receive_path;
0465     u16 receive_ring;
0466 };
0467 
0468 struct icm_tr_pkg_disconnect_xdomain_response {
0469     struct icm_pkg_header hdr;
0470     u8 stage;
0471     u8 reserved[3];
0472     u32 route_hi;
0473     u32 route_lo;
0474     uuid_t remote_uuid;
0475 };
0476 
0477 /* Ice Lake messages */
0478 
0479 struct icm_icl_event_rtd3_veto {
0480     struct icm_pkg_header hdr;
0481     u32 veto_reason;
0482 };
0483 
0484 /* USB4 ICM messages */
0485 
0486 struct icm_usb4_switch_op {
0487     struct icm_pkg_header hdr;
0488     u32 route_hi;
0489     u32 route_lo;
0490     u32 metadata;
0491     u16 opcode;
0492     u16 data_len_valid;
0493     u32 data[16];
0494 };
0495 
0496 #define ICM_USB4_SWITCH_DATA_LEN_MASK   GENMASK(3, 0)
0497 #define ICM_USB4_SWITCH_DATA_VALID  BIT(4)
0498 
0499 struct icm_usb4_switch_op_response {
0500     struct icm_pkg_header hdr;
0501     u32 route_hi;
0502     u32 route_lo;
0503     u32 metadata;
0504     u16 opcode;
0505     u16 status;
0506     u32 data[16];
0507 };
0508 
0509 /* XDomain messages */
0510 
0511 struct tb_xdomain_header {
0512     u32 route_hi;
0513     u32 route_lo;
0514     u32 length_sn;
0515 };
0516 
0517 #define TB_XDOMAIN_LENGTH_MASK  GENMASK(5, 0)
0518 #define TB_XDOMAIN_SN_MASK  GENMASK(28, 27)
0519 #define TB_XDOMAIN_SN_SHIFT 27
0520 
0521 enum tb_xdp_type {
0522     UUID_REQUEST_OLD = 1,
0523     UUID_RESPONSE = 2,
0524     PROPERTIES_REQUEST,
0525     PROPERTIES_RESPONSE,
0526     PROPERTIES_CHANGED_REQUEST,
0527     PROPERTIES_CHANGED_RESPONSE,
0528     ERROR_RESPONSE,
0529     UUID_REQUEST = 12,
0530     LINK_STATE_STATUS_REQUEST = 15,
0531     LINK_STATE_STATUS_RESPONSE,
0532     LINK_STATE_CHANGE_REQUEST,
0533     LINK_STATE_CHANGE_RESPONSE,
0534 };
0535 
0536 struct tb_xdp_header {
0537     struct tb_xdomain_header xd_hdr;
0538     uuid_t uuid;
0539     u32 type;
0540 };
0541 
0542 struct tb_xdp_error_response {
0543     struct tb_xdp_header hdr;
0544     u32 error;
0545 };
0546 
0547 struct tb_xdp_link_state_status {
0548     struct tb_xdp_header hdr;
0549 };
0550 
0551 struct tb_xdp_link_state_status_response {
0552     union {
0553         struct tb_xdp_error_response err;
0554         struct {
0555             struct tb_xdp_header hdr;
0556             u32 status;
0557             u8 slw;
0558             u8 tlw;
0559             u8 sls;
0560             u8 tls;
0561         };
0562     };
0563 };
0564 
0565 struct tb_xdp_link_state_change {
0566     struct tb_xdp_header hdr;
0567     u8 tlw;
0568     u8 tls;
0569     u16 reserved;
0570 };
0571 
0572 struct tb_xdp_link_state_change_response {
0573     union {
0574         struct tb_xdp_error_response err;
0575         struct {
0576             struct tb_xdp_header hdr;
0577             u32 status;
0578         };
0579     };
0580 };
0581 
0582 struct tb_xdp_uuid {
0583     struct tb_xdp_header hdr;
0584 };
0585 
0586 struct tb_xdp_uuid_response {
0587     union {
0588         struct tb_xdp_error_response err;
0589         struct {
0590             struct tb_xdp_header hdr;
0591             uuid_t src_uuid;
0592             u32 src_route_hi;
0593             u32 src_route_lo;
0594         };
0595     };
0596 };
0597 
0598 struct tb_xdp_properties {
0599     struct tb_xdp_header hdr;
0600     uuid_t src_uuid;
0601     uuid_t dst_uuid;
0602     u16 offset;
0603     u16 reserved;
0604 };
0605 
0606 struct tb_xdp_properties_response {
0607     union {
0608         struct tb_xdp_error_response err;
0609         struct {
0610             struct tb_xdp_header hdr;
0611             uuid_t src_uuid;
0612             uuid_t dst_uuid;
0613             u16 offset;
0614             u16 data_length;
0615             u32 generation;
0616             u32 data[];
0617         };
0618     };
0619 };
0620 
0621 /*
0622  * Max length of data array single XDomain property response is allowed
0623  * to carry.
0624  */
0625 #define TB_XDP_PROPERTIES_MAX_DATA_LENGTH   \
0626     (((256 - 4 - sizeof(struct tb_xdp_properties_response))) / 4)
0627 
0628 /* Maximum size of the total property block in dwords we allow */
0629 #define TB_XDP_PROPERTIES_MAX_LENGTH        500
0630 
0631 struct tb_xdp_properties_changed {
0632     struct tb_xdp_header hdr;
0633     uuid_t src_uuid;
0634 };
0635 
0636 struct tb_xdp_properties_changed_response {
0637     union {
0638         struct tb_xdp_error_response err;
0639         struct tb_xdp_header hdr;
0640     };
0641 };
0642 
0643 enum tb_xdp_error {
0644     ERROR_SUCCESS,
0645     ERROR_UNKNOWN_PACKET,
0646     ERROR_UNKNOWN_DOMAIN,
0647     ERROR_NOT_SUPPORTED,
0648     ERROR_NOT_READY,
0649 };
0650 
0651 #endif