1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2024 Cisco Systems, Inc. All rights reserved. 3 */ 4 5 #ifndef _ENIC_SRIOV_H_ 6 #define _ENIC_SRIOV_H_ 7 8 /* 9 * SR-IOV VF and PF drivers exchange control messages through 10 * the admin channel. Those messages are all defined here. 11 * 12 * VF_ prefix means the VF driver initiates the request. 13 * PF_ prefix means the PF driver initiates the request. 14 */ 15 enum enic_mbox_msg_type { 16 ENIC_MBOX_VF_CAPABILITY_REQUEST, 17 ENIC_MBOX_VF_CAPABILITY_REPLY, 18 ENIC_MBOX_VF_REGISTER_REQUEST, 19 ENIC_MBOX_VF_REGISTER_REPLY, 20 ENIC_MBOX_VF_UNREGISTER_REQUEST, 21 ENIC_MBOX_VF_UNREGISTER_REPLY, 22 ENIC_MBOX_PF_LINK_STATE_NOTIF, 23 ENIC_MBOX_PF_LINK_STATE_ACK, 24 ENIC_MBOX_PF_GET_STATS_REQUEST, 25 ENIC_MBOX_PF_GET_STATS_REPLY, 26 ENIC_MBOX_VF_ADD_DEL_MAC_REQUEST, 27 ENIC_MBOX_VF_ADD_DEL_MAC_REPLY, 28 ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF, 29 ENIC_MBOX_PF_SET_ADMIN_MAC_ACK, 30 ENIC_MBOX_VF_SET_PKT_FILTER_FLAGS_REQUEST, 31 ENIC_MBOX_VF_SET_PKT_FILTER_FLAGS_REPLY, 32 ENIC_MBOX_MAX 33 }; 34 35 /* 36 * Special value for {src,dst}_vnic_id. 0xffff means PF. 37 * For VF, vnic_id is the VF id. 38 */ 39 #define ENIC_MBOX_DST_PF 0xffff 40 41 struct enic_mbox_hdr { 42 uint16_t src_vnic_id; 43 uint16_t dst_vnic_id; 44 uint8_t msg_type; 45 uint8_t flags; 46 uint16_t msg_len; 47 uint64_t msg_num; 48 }; 49 50 #define ENIC_MBOX_ERR_GENERIC RTE_BIT32(0) 51 52 struct enic_mbox_generic_reply_msg { 53 uint16_t ret_major; 54 uint16_t ret_minor; 55 }; 56 57 /* 58 * ENIC_MBOX_VF_CAPABILITY_REQUEST 59 * ENIC_MBOX_VF_CAPABILITY_REPLY 60 */ 61 #define ENIC_MBOX_CAP_VERSION_0 0 62 #define ENIC_MBOX_CAP_VERSION_1 1 63 #define ENIC_MBOX_CAP_VERSION_INVALID 0xffffffff 64 65 struct enic_mbox_vf_capability_msg { 66 struct enic_mbox_hdr hdr; 67 uint32_t version; 68 uint32_t reserved[32]; /* 128B for future use */ 69 }; 70 71 struct enic_mbox_vf_capability_reply_msg { 72 struct enic_mbox_hdr hdr; 73 struct enic_mbox_generic_reply_msg generic_reply; 74 uint32_t version; 75 uint32_t reserved[32]; /* 128B for future use */ 76 }; 77 78 /* 79 * ENIC_MBOX_VF_REGISTER_REQUEST 80 * ENIC_MBOX_VF_REGISTER_REPLY 81 * ENIC_MBOX_VF_UNREGISTER_REQUEST 82 * ENIC_MBOX_VF_UNREGISTER_REPLY 83 */ 84 struct enic_mbox_vf_register_msg { 85 struct enic_mbox_hdr hdr; 86 }; 87 88 struct enic_mbox_vf_register_reply_msg { 89 struct enic_mbox_hdr hdr; 90 struct enic_mbox_generic_reply_msg generic_reply; 91 }; 92 93 struct enic_mbox_vf_unregister_msg { 94 struct enic_mbox_hdr hdr; 95 }; 96 97 struct enic_mbox_vf_unregister_reply_msg { 98 struct enic_mbox_hdr hdr; 99 struct enic_mbox_generic_reply_msg generic_reply; 100 }; 101 102 /* 103 * ENIC_MBOX_PF_LINK_STATE_NOTIF 104 * ENIC_MBOX_PF_LINK_STATE_ACK 105 */ 106 #define ENIC_MBOX_LINK_STATE_DISABLE 0 107 #define ENIC_MBOX_LINK_STATE_ENABLE 1 108 struct enic_mbox_pf_link_state_notif_msg { 109 struct enic_mbox_hdr hdr; 110 uint32_t link_state; 111 }; 112 113 struct enic_mbox_pf_link_state_ack_msg { 114 struct enic_mbox_hdr hdr; 115 struct enic_mbox_generic_reply_msg generic_reply; 116 }; 117 118 /* 119 * ENIC_MBOX_PF_GET_STATS_REQUEST 120 * ENIC_MBOX_PF_GET_STATS_REPLY 121 */ 122 #define ENIC_MBOX_GET_STATS_RX RTE_BIT32(0) 123 #define ENIC_MBOX_GET_STATS_TX RTE_BIT32(1) 124 #define ENIC_MBOX_GET_STATS_ALL (ENIC_MBOX_GET_STATS_RX | ENIC_MBOX_GET_STATS_TX) 125 126 struct enic_mbox_pf_get_stats_msg { 127 struct enic_mbox_hdr hdr; 128 uint16_t flags; 129 uint16_t pad; 130 }; 131 132 struct enic_mbox_pf_get_stats_reply { 133 struct vnic_stats vnic_stats; 134 /* The size of the struct vnic_stats is guaranteed to not change, but 135 * the number of counters (in the rx/tx elements of that struct) that 136 * are actually init may vary depending on the driver version (new 137 * fields may be added to the rsvd blocks). 138 * These two variables tell us how much of the tx/rx blocks inside 139 * struct vnic_stats the VF driver knows about according to its 140 * definition of that data structure. 141 */ 142 uint8_t num_rx_stats; 143 uint8_t num_tx_stats; 144 uint8_t pad[6]; 145 }; 146 147 struct enic_mbox_pf_get_stats_reply_msg { 148 struct enic_mbox_hdr hdr; 149 struct enic_mbox_generic_reply_msg generic_reply; 150 struct enic_mbox_pf_get_stats_reply stats; 151 }; 152 153 /* 154 * ENIC_MBOX_VF_ADD_DEL_MAC_REQUEST 155 * ENIC_MBOX_VF_ADD_DEL_MAC_REPLY 156 */ 157 /* enic_mac_addr.flags: Lower 8 bits are used in VF->PF direction (request) */ 158 #define MAC_ADDR_FLAG_ADD RTE_BIT32(0) 159 #define MAC_ADDR_FLAG_STATION RTE_BIT32(1) 160 161 struct enic_mac_addr { 162 uint8_t addr[RTE_ETHER_ADDR_LEN]; 163 uint16_t flags; 164 }; 165 166 struct enic_mbox_vf_add_del_mac_msg { 167 struct enic_mbox_hdr hdr; 168 uint16_t num_addrs; 169 uint16_t pad; 170 /* This can be mac_addr[], but the driver only uses 1 element */ 171 struct enic_mac_addr mac_addr; 172 }; 173 174 struct enic_mbox_vf_add_del_mac_reply_msg { 175 struct enic_mbox_hdr hdr; 176 struct enic_mbox_generic_reply_msg generic_reply; 177 struct enic_mbox_vf_add_del_mac_msg detailed_reply[]; 178 }; 179 180 /* 181 * ENIC_MBOX_VF_SET_PKT_FILTER_FLAGS_REQUEST 182 * ENIC_MBOX_VF_SET_PKT_FILTER_FLAGS_REPLY 183 */ 184 #define ENIC_MBOX_PKT_FILTER_DIRECTED RTE_BIT32(0) 185 #define ENIC_MBOX_PKT_FILTER_MULTICAST RTE_BIT32(1) 186 #define ENIC_MBOX_PKT_FILTER_BROADCAST RTE_BIT32(2) 187 #define ENIC_MBOX_PKT_FILTER_PROMISC RTE_BIT32(3) 188 #define ENIC_MBOX_PKT_FILTER_ALLMULTI RTE_BIT32(4) 189 190 struct enic_mbox_vf_set_pkt_filter_flags_msg { 191 struct enic_mbox_hdr hdr; 192 uint16_t flags; 193 uint16_t pad; 194 }; 195 196 struct enic_mbox_vf_set_pkt_filter_flags_reply_msg { 197 struct enic_mbox_hdr hdr; 198 struct enic_mbox_generic_reply_msg generic_reply; 199 }; 200 201 int enic_enable_vf_admin_chan(struct enic *enic); 202 int enic_disable_vf_admin_chan(struct enic *enic, bool unregister); 203 void enic_poll_vf_admin_chan(struct enic *enic); 204 205 /* devcmds that may go through PF driver */ 206 int enic_dev_packet_filter(struct enic *enic, int directed, int multicast, 207 int broadcast, int promisc, int allmulti); 208 int enic_dev_add_addr(struct enic *enic, uint8_t *addr); 209 int enic_dev_del_addr(struct enic *enic, uint8_t *addr); 210 211 #endif /* _ENIC_SRIOV_H_ */ 212