1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2001-2021 Intel Corporation 3 */ 4 5 #ifndef _VIRTCHNL_H_ 6 #define _VIRTCHNL_H_ 7 8 /* Description: 9 * This header file describes the VF-PF communication protocol used 10 * by the drivers for all devices starting from our 40G product line 11 * 12 * Admin queue buffer usage: 13 * desc->opcode is always aqc_opc_send_msg_to_pf 14 * flags, retval, datalen, and data addr are all used normally. 15 * The Firmware copies the cookie fields when sending messages between the 16 * PF and VF, but uses all other fields internally. Due to this limitation, 17 * we must send all messages as "indirect", i.e. using an external buffer. 18 * 19 * All the VSI indexes are relative to the VF. Each VF can have maximum of 20 * three VSIs. All the queue indexes are relative to the VSI. Each VF can 21 * have a maximum of sixteen queues for all of its VSIs. 22 * 23 * The PF is required to return a status code in v_retval for all messages 24 * except RESET_VF, which does not require any response. The return value 25 * is of status_code type, defined in the shared type.h. 26 * 27 * In general, VF driver initialization should roughly follow the order of 28 * these opcodes. The VF driver must first validate the API version of the 29 * PF driver, then request a reset, then get resources, then configure 30 * queues and interrupts. After these operations are complete, the VF 31 * driver may start its queues, optionally add MAC and VLAN filters, and 32 * process traffic. 33 */ 34 35 /* START GENERIC DEFINES 36 * Need to ensure the following enums and defines hold the same meaning and 37 * value in current and future projects 38 */ 39 40 /* Error Codes */ 41 enum virtchnl_status_code { 42 VIRTCHNL_STATUS_SUCCESS = 0, 43 VIRTCHNL_STATUS_ERR_PARAM = -5, 44 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18, 45 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38, 46 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39, 47 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40, 48 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53, 49 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64, 50 }; 51 52 /* Backward compatibility */ 53 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM 54 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED 55 56 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0 57 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1 58 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2 59 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3 60 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4 61 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5 62 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6 63 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7 64 65 enum virtchnl_link_speed { 66 VIRTCHNL_LINK_SPEED_UNKNOWN = 0, 67 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT), 68 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT), 69 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT), 70 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT), 71 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT), 72 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT), 73 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT), 74 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT), 75 }; 76 77 /* for hsplit_0 field of Rx HMC context */ 78 /* deprecated with IAVF 1.0 */ 79 enum virtchnl_rx_hsplit { 80 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0, 81 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1, 82 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2, 83 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4, 84 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8, 85 }; 86 87 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS 6 88 /* END GENERIC DEFINES */ 89 90 /* Opcodes for VF-PF communication. These are placed in the v_opcode field 91 * of the virtchnl_msg structure. 92 */ 93 enum virtchnl_ops { 94 /* The PF sends status change events to VFs using 95 * the VIRTCHNL_OP_EVENT opcode. 96 * VFs send requests to the PF using the other ops. 97 * Use of "advanced opcode" features must be negotiated as part of capabilities 98 * exchange and are not considered part of base mode feature set. 99 */ 100 VIRTCHNL_OP_UNKNOWN = 0, 101 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */ 102 VIRTCHNL_OP_RESET_VF = 2, 103 VIRTCHNL_OP_GET_VF_RESOURCES = 3, 104 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4, 105 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5, 106 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6, 107 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7, 108 VIRTCHNL_OP_ENABLE_QUEUES = 8, 109 VIRTCHNL_OP_DISABLE_QUEUES = 9, 110 VIRTCHNL_OP_ADD_ETH_ADDR = 10, 111 VIRTCHNL_OP_DEL_ETH_ADDR = 11, 112 VIRTCHNL_OP_ADD_VLAN = 12, 113 VIRTCHNL_OP_DEL_VLAN = 13, 114 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14, 115 VIRTCHNL_OP_GET_STATS = 15, 116 VIRTCHNL_OP_RSVD = 16, 117 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */ 118 /* opcode 19 is reserved */ 119 /* opcodes 20, 21, and 22 are reserved */ 120 VIRTCHNL_OP_CONFIG_RSS_KEY = 23, 121 VIRTCHNL_OP_CONFIG_RSS_LUT = 24, 122 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25, 123 VIRTCHNL_OP_SET_RSS_HENA = 26, 124 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27, 125 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28, 126 VIRTCHNL_OP_REQUEST_QUEUES = 29, 127 VIRTCHNL_OP_ENABLE_CHANNELS = 30, 128 VIRTCHNL_OP_DISABLE_CHANNELS = 31, 129 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32, 130 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33, 131 /* opcodes 34, 35, 36, and 37 are reserved */ 132 VIRTCHNL_OP_DCF_VLAN_OFFLOAD = 38, 133 VIRTCHNL_OP_DCF_CMD_DESC = 39, 134 VIRTCHNL_OP_DCF_CMD_BUFF = 40, 135 VIRTCHNL_OP_DCF_DISABLE = 41, 136 VIRTCHNL_OP_DCF_GET_VSI_MAP = 42, 137 VIRTCHNL_OP_DCF_GET_PKG_INFO = 43, 138 VIRTCHNL_OP_GET_SUPPORTED_RXDIDS = 44, 139 VIRTCHNL_OP_ADD_RSS_CFG = 45, 140 VIRTCHNL_OP_DEL_RSS_CFG = 46, 141 VIRTCHNL_OP_ADD_FDIR_FILTER = 47, 142 VIRTCHNL_OP_DEL_FDIR_FILTER = 48, 143 VIRTCHNL_OP_QUERY_FDIR_FILTER = 49, 144 VIRTCHNL_OP_GET_MAX_RSS_QREGION = 50, 145 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS = 51, 146 VIRTCHNL_OP_ADD_VLAN_V2 = 52, 147 VIRTCHNL_OP_DEL_VLAN_V2 = 53, 148 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 = 54, 149 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 = 55, 150 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 = 56, 151 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 = 57, 152 VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 = 58, 153 VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 = 59, 154 VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107, 155 VIRTCHNL_OP_DISABLE_QUEUES_V2 = 108, 156 VIRTCHNL_OP_MAP_QUEUE_VECTOR = 111, 157 VIRTCHNL_OP_MAX, 158 }; 159 160 static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode) 161 { 162 switch (v_opcode) { 163 case VIRTCHNL_OP_UNKNOWN: 164 return "VIRTCHNL_OP_UNKNOWN"; 165 case VIRTCHNL_OP_VERSION: 166 return "VIRTCHNL_OP_VERSION"; 167 case VIRTCHNL_OP_RESET_VF: 168 return "VIRTCHNL_OP_RESET_VF"; 169 case VIRTCHNL_OP_GET_VF_RESOURCES: 170 return "VIRTCHNL_OP_GET_VF_RESOURCES"; 171 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 172 return "VIRTCHNL_OP_CONFIG_TX_QUEUE"; 173 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 174 return "VIRTCHNL_OP_CONFIG_RX_QUEUE"; 175 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 176 return "VIRTCHNL_OP_CONFIG_VSI_QUEUES"; 177 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 178 return "VIRTCHNL_OP_CONFIG_IRQ_MAP"; 179 case VIRTCHNL_OP_ENABLE_QUEUES: 180 return "VIRTCHNL_OP_ENABLE_QUEUES"; 181 case VIRTCHNL_OP_DISABLE_QUEUES: 182 return "VIRTCHNL_OP_DISABLE_QUEUES"; 183 case VIRTCHNL_OP_ADD_ETH_ADDR: 184 return "VIRTCHNL_OP_ADD_ETH_ADDR"; 185 case VIRTCHNL_OP_DEL_ETH_ADDR: 186 return "VIRTCHNL_OP_DEL_ETH_ADDR"; 187 case VIRTCHNL_OP_ADD_VLAN: 188 return "VIRTCHNL_OP_ADD_VLAN"; 189 case VIRTCHNL_OP_DEL_VLAN: 190 return "VIRTCHNL_OP_DEL_VLAN"; 191 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 192 return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE"; 193 case VIRTCHNL_OP_GET_STATS: 194 return "VIRTCHNL_OP_GET_STATS"; 195 case VIRTCHNL_OP_RSVD: 196 return "VIRTCHNL_OP_RSVD"; 197 case VIRTCHNL_OP_EVENT: 198 return "VIRTCHNL_OP_EVENT"; 199 case VIRTCHNL_OP_CONFIG_RSS_KEY: 200 return "VIRTCHNL_OP_CONFIG_RSS_KEY"; 201 case VIRTCHNL_OP_CONFIG_RSS_LUT: 202 return "VIRTCHNL_OP_CONFIG_RSS_LUT"; 203 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 204 return "VIRTCHNL_OP_GET_RSS_HENA_CAPS"; 205 case VIRTCHNL_OP_SET_RSS_HENA: 206 return "VIRTCHNL_OP_SET_RSS_HENA"; 207 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 208 return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING"; 209 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 210 return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING"; 211 case VIRTCHNL_OP_REQUEST_QUEUES: 212 return "VIRTCHNL_OP_REQUEST_QUEUES"; 213 case VIRTCHNL_OP_ENABLE_CHANNELS: 214 return "VIRTCHNL_OP_ENABLE_CHANNELS"; 215 case VIRTCHNL_OP_DISABLE_CHANNELS: 216 return "VIRTCHNL_OP_DISABLE_CHANNELS"; 217 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 218 return "VIRTCHNL_OP_ADD_CLOUD_FILTER"; 219 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 220 return "VIRTCHNL_OP_DEL_CLOUD_FILTER"; 221 case VIRTCHNL_OP_DCF_CMD_DESC: 222 return "VIRTCHNL_OP_DCF_CMD_DESC"; 223 case VIRTCHNL_OP_DCF_CMD_BUFF: 224 return "VIRTCHHNL_OP_DCF_CMD_BUFF"; 225 case VIRTCHNL_OP_DCF_DISABLE: 226 return "VIRTCHNL_OP_DCF_DISABLE"; 227 case VIRTCHNL_OP_DCF_GET_VSI_MAP: 228 return "VIRTCHNL_OP_DCF_GET_VSI_MAP"; 229 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS: 230 return "VIRTCHNL_OP_GET_SUPPORTED_RXDIDS"; 231 case VIRTCHNL_OP_ADD_RSS_CFG: 232 return "VIRTCHNL_OP_ADD_RSS_CFG"; 233 case VIRTCHNL_OP_DEL_RSS_CFG: 234 return "VIRTCHNL_OP_DEL_RSS_CFG"; 235 case VIRTCHNL_OP_ADD_FDIR_FILTER: 236 return "VIRTCHNL_OP_ADD_FDIR_FILTER"; 237 case VIRTCHNL_OP_DEL_FDIR_FILTER: 238 return "VIRTCHNL_OP_DEL_FDIR_FILTER"; 239 case VIRTCHNL_OP_QUERY_FDIR_FILTER: 240 return "VIRTCHNL_OP_QUERY_FDIR_FILTER"; 241 case VIRTCHNL_OP_GET_MAX_RSS_QREGION: 242 return "VIRTCHNL_OP_GET_MAX_RSS_QREGION"; 243 case VIRTCHNL_OP_ENABLE_QUEUES_V2: 244 return "VIRTCHNL_OP_ENABLE_QUEUES_V2"; 245 case VIRTCHNL_OP_DISABLE_QUEUES_V2: 246 return "VIRTCHNL_OP_DISABLE_QUEUES_V2"; 247 case VIRTCHNL_OP_MAP_QUEUE_VECTOR: 248 return "VIRTCHNL_OP_MAP_QUEUE_VECTOR"; 249 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: 250 return "VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS"; 251 case VIRTCHNL_OP_ADD_VLAN_V2: 252 return "VIRTCHNL_OP_ADD_VLAN_V2"; 253 case VIRTCHNL_OP_DEL_VLAN_V2: 254 return "VIRTCHNL_OP_DEL_VLAN_V2"; 255 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2: 256 return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2"; 257 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2: 258 return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2"; 259 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2: 260 return "VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2"; 261 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2: 262 return "VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2"; 263 case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2: 264 return "VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2"; 265 case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2: 266 return "VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2"; 267 case VIRTCHNL_OP_MAX: 268 return "VIRTCHNL_OP_MAX"; 269 default: 270 return "Unsupported (update virtchnl.h)"; 271 } 272 } 273 274 /* These macros are used to generate compilation errors if a structure/union 275 * is not exactly the correct length. It gives a divide by zero error if the 276 * structure/union is not of the correct size, otherwise it creates an enum 277 * that is never used. 278 */ 279 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ 280 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } 281 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \ 282 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) } 283 284 /* Virtual channel message descriptor. This overlays the admin queue 285 * descriptor. All other data is passed in external buffers. 286 */ 287 288 struct virtchnl_msg { 289 u8 pad[8]; /* AQ flags/opcode/len/retval fields */ 290 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */ 291 enum virtchnl_status_code v_retval; /* ditto for desc->retval */ 292 u32 vfid; /* used by PF when sending to VF */ 293 }; 294 295 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg); 296 297 /* Message descriptions and data structures. */ 298 299 /* VIRTCHNL_OP_VERSION 300 * VF posts its version number to the PF. PF responds with its version number 301 * in the same format, along with a return code. 302 * Reply from PF has its major/minor versions also in param0 and param1. 303 * If there is a major version mismatch, then the VF cannot operate. 304 * If there is a minor version mismatch, then the VF can operate but should 305 * add a warning to the system log. 306 * 307 * This enum element MUST always be specified as == 1, regardless of other 308 * changes in the API. The PF must always respond to this message without 309 * error regardless of version mismatch. 310 */ 311 #define VIRTCHNL_VERSION_MAJOR 1 312 #define VIRTCHNL_VERSION_MINOR 1 313 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0 314 315 struct virtchnl_version_info { 316 u32 major; 317 u32 minor; 318 }; 319 320 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info); 321 322 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) 323 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) 324 325 /* VIRTCHNL_OP_RESET_VF 326 * VF sends this request to PF with no parameters 327 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register 328 * until reset completion is indicated. The admin queue must be reinitialized 329 * after this operation. 330 * 331 * When reset is complete, PF must ensure that all queues in all VSIs associated 332 * with the VF are stopped, all queue configurations in the HMC are set to 0, 333 * and all MAC and VLAN filters (except the default MAC address) on all VSIs 334 * are cleared. 335 */ 336 337 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV 338 * vsi_type should always be 6 for backward compatibility. Add other fields 339 * as needed. 340 */ 341 enum virtchnl_vsi_type { 342 VIRTCHNL_VSI_TYPE_INVALID = 0, 343 VIRTCHNL_VSI_SRIOV = 6, 344 }; 345 346 /* VIRTCHNL_OP_GET_VF_RESOURCES 347 * Version 1.0 VF sends this request to PF with no parameters 348 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities 349 * PF responds with an indirect message containing 350 * virtchnl_vf_resource and one or more 351 * virtchnl_vsi_resource structures. 352 */ 353 354 struct virtchnl_vsi_resource { 355 u16 vsi_id; 356 u16 num_queue_pairs; 357 enum virtchnl_vsi_type vsi_type; 358 u16 qset_handle; 359 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 360 }; 361 362 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource); 363 364 /* VF capability flags 365 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including 366 * TX/RX Checksum offloading and TSO for non-tunnelled packets. 367 */ 368 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001 369 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002 370 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004 371 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008 372 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010 373 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020 374 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040 375 #define VIRTCHNL_VF_OFFLOAD_CRC 0x00000080 376 /* 0X00000100 is reserved */ 377 #define VIRTCHNL_VF_LARGE_NUM_QPAIRS 0x00000200 378 #define VIRTCHNL_VF_OFFLOAD_VLAN_V2 0x00008000 379 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000 380 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000 381 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000 382 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000 383 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000 384 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000 385 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000 386 #define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000 387 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2 0X01000000 388 #define VIRTCHNL_VF_OFFLOAD_USO 0X02000000 389 #define VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC 0X04000000 390 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF 0X08000000 391 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF 0X10000000 392 /* 0X20000000 is reserved */ 393 #define VIRTCHNL_VF_CAP_DCF 0X40000000 394 /* 0X80000000 is reserved */ 395 396 /* Define below the capability flags that are not offloads */ 397 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080 398 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \ 399 VIRTCHNL_VF_OFFLOAD_VLAN | \ 400 VIRTCHNL_VF_OFFLOAD_RSS_PF) 401 402 struct virtchnl_vf_resource { 403 u16 num_vsis; 404 u16 num_queue_pairs; 405 u16 max_vectors; 406 u16 max_mtu; 407 408 u32 vf_cap_flags; 409 u32 rss_key_size; 410 u32 rss_lut_size; 411 412 struct virtchnl_vsi_resource vsi_res[1]; 413 }; 414 415 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource); 416 417 /* VIRTCHNL_OP_CONFIG_TX_QUEUE 418 * VF sends this message to set up parameters for one TX queue. 419 * External data buffer contains one instance of virtchnl_txq_info. 420 * PF configures requested queue and returns a status code. 421 */ 422 423 /* Tx queue config info */ 424 struct virtchnl_txq_info { 425 u16 vsi_id; 426 u16 queue_id; 427 u16 ring_len; /* number of descriptors, multiple of 8 */ 428 u16 headwb_enabled; /* deprecated with AVF 1.0 */ 429 u64 dma_ring_addr; 430 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ 431 }; 432 433 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info); 434 435 /* VIRTCHNL_OP_CONFIG_RX_QUEUE 436 * VF sends this message to set up parameters for one RX queue. 437 * External data buffer contains one instance of virtchnl_rxq_info. 438 * PF configures requested queue and returns a status code. The 439 * crc_disable flag disables CRC stripping on the VF. Setting 440 * the crc_disable flag to 1 will disable CRC stripping for each 441 * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC 442 * offload must have been set prior to sending this info or the PF 443 * will ignore the request. This flag should be set the same for 444 * all of the queues for a VF. 445 */ 446 447 /* Rx queue config info */ 448 struct virtchnl_rxq_info { 449 u16 vsi_id; 450 u16 queue_id; 451 u32 ring_len; /* number of descriptors, multiple of 32 */ 452 u16 hdr_size; 453 u16 splithdr_enabled; /* deprecated with AVF 1.0 */ 454 u32 databuffer_size; 455 u32 max_pkt_size; 456 u8 crc_disable; 457 /* only used when VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC is supported */ 458 u8 rxdid; 459 u8 pad1[2]; 460 u64 dma_ring_addr; 461 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */ 462 u32 pad2; 463 }; 464 465 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info); 466 467 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES 468 * VF sends this message to set parameters for active TX and RX queues 469 * associated with the specified VSI. 470 * PF configures queues and returns status. 471 * If the number of queues specified is greater than the number of queues 472 * associated with the VSI, an error is returned and no queues are configured. 473 * NOTE: The VF is not required to configure all queues in a single request. 474 * It may send multiple messages. PF drivers must correctly handle all VF 475 * requests. 476 */ 477 struct virtchnl_queue_pair_info { 478 /* NOTE: vsi_id and queue_id should be identical for both queues. */ 479 struct virtchnl_txq_info txq; 480 struct virtchnl_rxq_info rxq; 481 }; 482 483 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); 484 485 struct virtchnl_vsi_queue_config_info { 486 u16 vsi_id; 487 u16 num_queue_pairs; 488 u32 pad; 489 struct virtchnl_queue_pair_info qpair[1]; 490 }; 491 492 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info); 493 494 /* VIRTCHNL_OP_REQUEST_QUEUES 495 * VF sends this message to request the PF to allocate additional queues to 496 * this VF. Each VF gets a guaranteed number of queues on init but asking for 497 * additional queues must be negotiated. This is a best effort request as it 498 * is possible the PF does not have enough queues left to support the request. 499 * If the PF cannot support the number requested it will respond with the 500 * maximum number it is able to support. If the request is successful, PF will 501 * then reset the VF to institute required changes. 502 */ 503 504 /* VF resource request */ 505 struct virtchnl_vf_res_request { 506 u16 num_queue_pairs; 507 }; 508 509 /* VIRTCHNL_OP_CONFIG_IRQ_MAP 510 * VF uses this message to map vectors to queues. 511 * The rxq_map and txq_map fields are bitmaps used to indicate which queues 512 * are to be associated with the specified vector. 513 * The "other" causes are always mapped to vector 0. The VF may not request 514 * that vector 0 be used for traffic. 515 * PF configures interrupt mapping and returns status. 516 * NOTE: due to hardware requirements, all active queues (both TX and RX) 517 * should be mapped to interrupts, even if the driver intends to operate 518 * only in polling mode. In this case the interrupt may be disabled, but 519 * the ITR timer will still run to trigger writebacks. 520 */ 521 struct virtchnl_vector_map { 522 u16 vsi_id; 523 u16 vector_id; 524 u16 rxq_map; 525 u16 txq_map; 526 u16 rxitr_idx; 527 u16 txitr_idx; 528 }; 529 530 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); 531 532 struct virtchnl_irq_map_info { 533 u16 num_vectors; 534 struct virtchnl_vector_map vecmap[1]; 535 }; 536 537 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info); 538 539 /* VIRTCHNL_OP_ENABLE_QUEUES 540 * VIRTCHNL_OP_DISABLE_QUEUES 541 * VF sends these message to enable or disable TX/RX queue pairs. 542 * The queues fields are bitmaps indicating which queues to act upon. 543 * (Currently, we only support 16 queues per VF, but we make the field 544 * u32 to allow for expansion.) 545 * PF performs requested action and returns status. 546 * NOTE: The VF is not required to enable/disable all queues in a single 547 * request. It may send multiple messages. 548 * PF drivers must correctly handle all VF requests. 549 */ 550 struct virtchnl_queue_select { 551 u16 vsi_id; 552 u16 pad; 553 u32 rx_queues; 554 u32 tx_queues; 555 }; 556 557 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select); 558 559 /* VIRTCHNL_OP_GET_MAX_RSS_QREGION 560 * 561 * if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 562 * then this op must be supported. 563 * 564 * VF sends this message in order to query the max RSS queue region 565 * size supported by PF, when VIRTCHNL_VF_LARGE_NUM_QPAIRS is enabled. 566 * This information should be used when configuring the RSS LUT and/or 567 * configuring queue region based filters. 568 * 569 * The maximum RSS queue region is 2^qregion_width. So, a qregion_width 570 * of 6 would inform the VF that the PF supports a maximum RSS queue region 571 * of 64. 572 * 573 * A queue region represents a range of queues that can be used to configure 574 * a RSS LUT. For example, if a VF is given 64 queues, but only a max queue 575 * region size of 16 (i.e. 2^qregion_width = 16) then it will only be able 576 * to configure the RSS LUT with queue indices from 0 to 15. However, other 577 * filters can be used to direct packets to queues >15 via specifying a queue 578 * base/offset and queue region width. 579 */ 580 struct virtchnl_max_rss_qregion { 581 u16 vport_id; 582 u16 qregion_width; 583 u8 pad[4]; 584 }; 585 586 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_max_rss_qregion); 587 588 /* VIRTCHNL_OP_ADD_ETH_ADDR 589 * VF sends this message in order to add one or more unicast or multicast 590 * address filters for the specified VSI. 591 * PF adds the filters and returns status. 592 */ 593 594 /* VIRTCHNL_OP_DEL_ETH_ADDR 595 * VF sends this message in order to remove one or more unicast or multicast 596 * filters for the specified VSI. 597 * PF removes the filters and returns status. 598 */ 599 600 /* VIRTCHNL_ETHER_ADDR_LEGACY 601 * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad 602 * bytes. Moving forward all VF drivers should not set type to 603 * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy 604 * behavior. The control plane function (i.e. PF) can use a best effort method 605 * of tracking the primary/device unicast in this case, but there is no 606 * guarantee and functionality depends on the implementation of the PF. 607 */ 608 609 /* VIRTCHNL_ETHER_ADDR_PRIMARY 610 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the 611 * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and 612 * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane 613 * function (i.e. PF) to accurately track and use this MAC address for 614 * displaying on the host and for VM/function reset. 615 */ 616 617 /* VIRTCHNL_ETHER_ADDR_EXTRA 618 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra 619 * unicast and/or multicast filters that are being added/deleted via 620 * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively. 621 */ 622 struct virtchnl_ether_addr { 623 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 624 u8 type; 625 #define VIRTCHNL_ETHER_ADDR_LEGACY 0 626 #define VIRTCHNL_ETHER_ADDR_PRIMARY 1 627 #define VIRTCHNL_ETHER_ADDR_EXTRA 2 628 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK 3 /* first two bits of type are valid */ 629 u8 pad; 630 }; 631 632 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); 633 634 struct virtchnl_ether_addr_list { 635 u16 vsi_id; 636 u16 num_elements; 637 struct virtchnl_ether_addr list[1]; 638 }; 639 640 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list); 641 642 /* VIRTCHNL_OP_ADD_VLAN 643 * VF sends this message to add one or more VLAN tag filters for receives. 644 * PF adds the filters and returns status. 645 * If a port VLAN is configured by the PF, this operation will return an 646 * error to the VF. 647 */ 648 649 /* VIRTCHNL_OP_DEL_VLAN 650 * VF sends this message to remove one or more VLAN tag filters for receives. 651 * PF removes the filters and returns status. 652 * If a port VLAN is configured by the PF, this operation will return an 653 * error to the VF. 654 */ 655 656 struct virtchnl_vlan_filter_list { 657 u16 vsi_id; 658 u16 num_elements; 659 u16 vlan_id[1]; 660 }; 661 662 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); 663 664 /* This enum is used for all of the VIRTCHNL_VF_OFFLOAD_VLAN_V2_CAPS related 665 * structures and opcodes. 666 * 667 * VIRTCHNL_VLAN_UNSUPPORTED - This field is not supported and if a VF driver 668 * populates it the PF should return VIRTCHNL_STATUS_ERR_NOT_SUPPORTED. 669 * 670 * VIRTCHNL_VLAN_ETHERTYPE_8100 - This field supports 0x8100 ethertype. 671 * VIRTCHNL_VLAN_ETHERTYPE_88A8 - This field supports 0x88A8 ethertype. 672 * VIRTCHNL_VLAN_ETHERTYPE_9100 - This field supports 0x9100 ethertype. 673 * 674 * VIRTCHNL_VLAN_ETHERTYPE_AND - Used when multiple ethertypes can be supported 675 * by the PF concurrently. For example, if the PF can support 676 * VIRTCHNL_VLAN_ETHERTYPE_8100 AND VIRTCHNL_VLAN_ETHERTYPE_88A8 filters it 677 * would OR the following bits: 678 * 679 * VIRTHCNL_VLAN_ETHERTYPE_8100 | 680 * VIRTCHNL_VLAN_ETHERTYPE_88A8 | 681 * VIRTCHNL_VLAN_ETHERTYPE_AND; 682 * 683 * The VF would interpret this as VLAN filtering can be supported on both 0x8100 684 * and 0x88A8 VLAN ethertypes. 685 * 686 * VIRTCHNL_ETHERTYPE_XOR - Used when only a single ethertype can be supported 687 * by the PF concurrently. For example if the PF can support 688 * VIRTCHNL_VLAN_ETHERTYPE_8100 XOR VIRTCHNL_VLAN_ETHERTYPE_88A8 stripping 689 * offload it would OR the following bits: 690 * 691 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 692 * VIRTCHNL_VLAN_ETHERTYPE_88A8 | 693 * VIRTCHNL_VLAN_ETHERTYPE_XOR; 694 * 695 * The VF would interpret this as VLAN stripping can be supported on either 696 * 0x8100 or 0x88a8 VLAN ethertypes. So when requesting VLAN stripping via 697 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 the specified ethertype will override 698 * the previously set value. 699 * 700 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 - Used to tell the VF to insert and/or 701 * strip the VLAN tag using the L2TAG1 field of the Tx/Rx descriptors. 702 * 703 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to insert hardware 704 * offloaded VLAN tags using the L2TAG2 field of the Tx descriptor. 705 * 706 * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 - Used to tell the VF to strip hardware 707 * offloaded VLAN tags using the L2TAG2_2 field of the Rx descriptor. 708 * 709 * VIRTCHNL_VLAN_PRIO - This field supports VLAN priority bits. This is used for 710 * VLAN filtering if the underlying PF supports it. 711 * 712 * VIRTCHNL_VLAN_TOGGLE_ALLOWED - This field is used to say whether a 713 * certain VLAN capability can be toggled. For example if the underlying PF/CP 714 * allows the VF to toggle VLAN filtering, stripping, and/or insertion it should 715 * set this bit along with the supported ethertypes. 716 */ 717 enum virtchnl_vlan_support { 718 VIRTCHNL_VLAN_UNSUPPORTED = 0, 719 VIRTCHNL_VLAN_ETHERTYPE_8100 = 0x00000001, 720 VIRTCHNL_VLAN_ETHERTYPE_88A8 = 0x00000002, 721 VIRTCHNL_VLAN_ETHERTYPE_9100 = 0x00000004, 722 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1 = 0x00000100, 723 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2 = 0x00000200, 724 VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 = 0x00000400, 725 VIRTCHNL_VLAN_PRIO = 0x01000000, 726 VIRTCHNL_VLAN_FILTER_MASK = 0x10000000, 727 VIRTCHNL_VLAN_ETHERTYPE_AND = 0x20000000, 728 VIRTCHNL_VLAN_ETHERTYPE_XOR = 0x40000000, 729 VIRTCHNL_VLAN_TOGGLE = 0x80000000 730 }; 731 732 /* This structure is used as part of the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS 733 * for filtering, insertion, and stripping capabilities. 734 * 735 * If only outer capabilities are supported (for filtering, insertion, and/or 736 * stripping) then this refers to the outer most or single VLAN from the VF's 737 * perspective. 738 * 739 * If only inner capabilities are supported (for filtering, insertion, and/or 740 * stripping) then this refers to the outer most or single VLAN from the VF's 741 * perspective. Functionally this is the same as if only outer capabilities are 742 * supported. The VF driver is just forced to use the inner fields when 743 * adding/deleting filters and enabling/disabling offloads (if supported). 744 * 745 * If both outer and inner capabilities are supported (for filtering, insertion, 746 * and/or stripping) then outer refers to the outer most or single VLAN and 747 * inner refers to the second VLAN, if it exists, in the packet. 748 * 749 * There is no support for tunneled VLAN offloads, so outer or inner are never 750 * referring to a tunneled packet from the VF's perspective. 751 */ 752 struct virtchnl_vlan_supported_caps { 753 u32 outer; 754 u32 inner; 755 }; 756 757 /* The PF populates these fields based on the supported VLAN filtering. If a 758 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will 759 * reject any VIRTCHNL_OP_ADD_VLAN_V2 or VIRTCHNL_OP_DEL_VLAN_V2 messages using 760 * the unsupported fields. 761 * 762 * Also, a VF is only allowed to toggle its VLAN filtering setting if the 763 * VIRTCHNL_VLAN_TOGGLE bit is set. 764 * 765 * The ethertype(s) specified in the ethertype_init field are the ethertypes 766 * enabled for VLAN filtering. VLAN filtering in this case refers to the outer 767 * most VLAN from the VF's perspective. If both inner and outer filtering are 768 * allowed then ethertype_init only refers to the outer most VLAN as only 769 * VLAN ethertype supported for inner VLAN filtering is 770 * VIRTCHNL_VLAN_ETHERTYPE_8100. By default, inner VLAN filtering is disabled 771 * when both inner and outer filtering are allowed. 772 * 773 * The max_filters field tells the VF how many VLAN filters it's allowed to have 774 * at any one time. If it exceeds this amount and tries to add another filter, 775 * then the request will be rejected by the PF. To prevent failures, the VF 776 * should keep track of how many VLAN filters it has added and not attempt to 777 * add more than max_filters. 778 */ 779 struct virtchnl_vlan_filtering_caps { 780 struct virtchnl_vlan_supported_caps filtering_support; 781 u32 ethertype_init; 782 u16 max_filters; 783 u8 pad[2]; 784 }; 785 786 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_filtering_caps); 787 788 /* This enum is used for the virtchnl_vlan_offload_caps structure to specify 789 * if the PF supports a different ethertype for stripping and insertion. 790 * 791 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION - The ethertype(s) specified 792 * for stripping affect the ethertype(s) specified for insertion and visa versa 793 * as well. If the VF tries to configure VLAN stripping via 794 * VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 with VIRTCHNL_VLAN_ETHERTYPE_8100 then 795 * that will be the ethertype for both stripping and insertion. 796 * 797 * VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED - The ethertype(s) specified for 798 * stripping do not affect the ethertype(s) specified for insertion and visa 799 * versa. 800 */ 801 enum virtchnl_vlan_ethertype_match { 802 VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION = 0, 803 VIRTCHNL_ETHERTYPE_MATCH_NOT_REQUIRED = 1, 804 }; 805 806 /* The PF populates these fields based on the supported VLAN offloads. If a 807 * field is VIRTCHNL_VLAN_UNSUPPORTED then it's not supported and the PF will 808 * reject any VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 or 809 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 messages using the unsupported fields. 810 * 811 * Also, a VF is only allowed to toggle its VLAN offload setting if the 812 * VIRTCHNL_VLAN_TOGGLE_ALLOWED bit is set. 813 * 814 * The VF driver needs to be aware of how the tags are stripped by hardware and 815 * inserted by the VF driver based on the level of offload support. The PF will 816 * populate these fields based on where the VLAN tags are expected to be 817 * offloaded via the VIRTHCNL_VLAN_TAG_LOCATION_* bits. The VF will need to 818 * interpret these fields. See the definition of the 819 * VIRTCHNL_VLAN_TAG_LOCATION_* bits above the virtchnl_vlan_support 820 * enumeration. 821 */ 822 struct virtchnl_vlan_offload_caps { 823 struct virtchnl_vlan_supported_caps stripping_support; 824 struct virtchnl_vlan_supported_caps insertion_support; 825 u32 ethertype_init; 826 u8 ethertype_match; 827 u8 pad[3]; 828 }; 829 830 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_vlan_offload_caps); 831 832 /* VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS 833 * VF sends this message to determine its VLAN capabilities. 834 * 835 * PF will mark which capabilities it supports based on hardware support and 836 * current configuration. For example, if a port VLAN is configured the PF will 837 * not allow outer VLAN filtering, stripping, or insertion to be configured so 838 * it will block these features from the VF. 839 * 840 * The VF will need to cross reference its capabilities with the PFs 841 * capabilities in the response message from the PF to determine the VLAN 842 * support. 843 */ 844 struct virtchnl_vlan_caps { 845 struct virtchnl_vlan_filtering_caps filtering; 846 struct virtchnl_vlan_offload_caps offloads; 847 }; 848 849 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_caps); 850 851 struct virtchnl_vlan { 852 u16 tci; /* tci[15:13] = PCP and tci[11:0] = VID */ 853 u16 tci_mask; /* only valid if VIRTCHNL_VLAN_FILTER_MASK set in 854 * filtering caps 855 */ 856 u16 tpid; /* 0x8100, 0x88a8, etc. and only type(s) set in 857 * filtering caps. Note that tpid here does not refer to 858 * VIRTCHNL_VLAN_ETHERTYPE_*, but it refers to the 859 * actual 2-byte VLAN TPID 860 */ 861 u8 pad[2]; 862 }; 863 864 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_vlan); 865 866 struct virtchnl_vlan_filter { 867 struct virtchnl_vlan inner; 868 struct virtchnl_vlan outer; 869 u8 pad[16]; 870 }; 871 872 VIRTCHNL_CHECK_STRUCT_LEN(32, virtchnl_vlan_filter); 873 874 /* VIRTCHNL_OP_ADD_VLAN_V2 875 * VIRTCHNL_OP_DEL_VLAN_V2 876 * 877 * VF sends these messages to add/del one or more VLAN tag filters for Rx 878 * traffic. 879 * 880 * The PF attempts to add the filters and returns status. 881 * 882 * The VF should only ever attempt to add/del virtchnl_vlan_filter(s) using the 883 * supported fields negotiated via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS. 884 */ 885 struct virtchnl_vlan_filter_list_v2 { 886 u16 vport_id; 887 u16 num_elements; 888 u8 pad[4]; 889 struct virtchnl_vlan_filter filters[1]; 890 }; 891 892 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_vlan_filter_list_v2); 893 894 /* VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 895 * VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2 896 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 897 * VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2 898 * 899 * VF sends this message to enable or disable VLAN stripping or insertion. It 900 * also needs to specify an ethertype. The VF knows which VLAN ethertypes are 901 * allowed and whether or not it's allowed to enable/disable the specific 902 * offload via the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to 903 * parse the virtchnl_vlan_caps.offloads fields to determine which offload 904 * messages are allowed. 905 * 906 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the 907 * following manner the VF will be allowed to enable and/or disable 0x8100 inner 908 * VLAN insertion and/or stripping via the opcodes listed above. Inner in this 909 * case means the outer most or single VLAN from the VF's perspective. This is 910 * because no outer offloads are supported. See the comments above the 911 * virtchnl_vlan_supported_caps structure for more details. 912 * 913 * virtchnl_vlan_caps.offloads.stripping_support.inner = 914 * VIRTCHNL_VLAN_TOGGLE | 915 * VIRTCHNL_VLAN_ETHERTYPE_8100; 916 * 917 * virtchnl_vlan_caps.offloads.insertion_support.inner = 918 * VIRTCHNL_VLAN_TOGGLE | 919 * VIRTCHNL_VLAN_ETHERTYPE_8100; 920 * 921 * In order to enable inner (again note that in this case inner is the outer 922 * most or single VLAN from the VF's perspective) VLAN stripping for 0x8100 923 * VLANs, the VF would populate the virtchnl_vlan_setting structure in the 924 * following manner and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message. 925 * 926 * virtchnl_vlan_setting.inner_ethertype_setting = 927 * VIRTCHNL_VLAN_ETHERTYPE_8100; 928 * 929 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on 930 * initialization. 931 * 932 * The reason that VLAN TPID(s) are not being used for the 933 * outer_ethertype_setting and inner_ethertype_setting fields is because it's 934 * possible a device could support VLAN insertion and/or stripping offload on 935 * multiple ethertypes concurrently, so this method allows a VF to request 936 * multiple ethertypes in one message using the virtchnl_vlan_support 937 * enumeration. 938 * 939 * For example, if the PF populates the virtchnl_vlan_caps.offloads in the 940 * following manner the VF will be allowed to enable 0x8100 and 0x88a8 outer 941 * VLAN insertion and stripping simultaneously. The 942 * virtchnl_vlan_caps.offloads.ethertype_match field will also have to be 943 * populated based on what the PF can support. 944 * 945 * virtchnl_vlan_caps.offloads.stripping_support.outer = 946 * VIRTCHNL_VLAN_TOGGLE | 947 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 948 * VIRTCHNL_VLAN_ETHERTYPE_88A8 | 949 * VIRTCHNL_VLAN_ETHERTYPE_AND; 950 * 951 * virtchnl_vlan_caps.offloads.insertion_support.outer = 952 * VIRTCHNL_VLAN_TOGGLE | 953 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 954 * VIRTCHNL_VLAN_ETHERTYPE_88A8 | 955 * VIRTCHNL_VLAN_ETHERTYPE_AND; 956 * 957 * In order to enable outer VLAN stripping for 0x8100 and 0x88a8 VLANs, the VF 958 * would populate the virthcnl_vlan_offload_structure in the following manner 959 * and send the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2 message. 960 * 961 * virtchnl_vlan_setting.outer_ethertype_setting = 962 * VIRTHCNL_VLAN_ETHERTYPE_8100 | 963 * VIRTHCNL_VLAN_ETHERTYPE_88A8; 964 * 965 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on 966 * initialization. 967 * 968 * There is also the case where a PF and the underlying hardware can support 969 * VLAN offloads on multiple ethertypes, but not concurrently. For example, if 970 * the PF populates the virtchnl_vlan_caps.offloads in the following manner the 971 * VF will be allowed to enable and/or disable 0x8100 XOR 0x88a8 outer VLAN 972 * offloads. The ethertypes must match for stripping and insertion. 973 * 974 * virtchnl_vlan_caps.offloads.stripping_support.outer = 975 * VIRTCHNL_VLAN_TOGGLE | 976 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 977 * VIRTCHNL_VLAN_ETHERTYPE_88A8 | 978 * VIRTCHNL_VLAN_ETHERTYPE_XOR; 979 * 980 * virtchnl_vlan_caps.offloads.insertion_support.outer = 981 * VIRTCHNL_VLAN_TOGGLE | 982 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 983 * VIRTCHNL_VLAN_ETHERTYPE_88A8 | 984 * VIRTCHNL_VLAN_ETHERTYPE_XOR; 985 * 986 * virtchnl_vlan_caps.offloads.ethertype_match = 987 * VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION; 988 * 989 * In order to enable outer VLAN stripping for 0x88a8 VLANs, the VF would 990 * populate the virtchnl_vlan_setting structure in the following manner and send 991 * the VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2. Also, this will change the 992 * ethertype for VLAN insertion if it's enabled. So, for completeness, a 993 * VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2 with the same ethertype should be sent. 994 * 995 * virtchnl_vlan_setting.outer_ethertype_setting = VIRTHCNL_VLAN_ETHERTYPE_88A8; 996 * 997 * virtchnl_vlan_setting.vport_id = vport_id or vsi_id assigned to the VF on 998 * initialization. 999 * 1000 * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2 1001 * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 1002 * 1003 * VF sends this message to enable or disable VLAN filtering. It also needs to 1004 * specify an ethertype. The VF knows which VLAN ethertypes are allowed and 1005 * whether or not it's allowed to enable/disable filtering via the 1006 * VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. The VF needs to 1007 * parse the virtchnl_vlan_caps.filtering fields to determine which, if any, 1008 * filtering messages are allowed. 1009 * 1010 * For example, if the PF populates the virtchnl_vlan_caps.filtering in the 1011 * following manner the VF will be allowed to enable/disable 0x8100 and 0x88a8 1012 * outer VLAN filtering together. Note, that the VIRTCHNL_VLAN_ETHERTYPE_AND 1013 * means that all filtering ethertypes will to be enabled and disabled together 1014 * regardless of the request from the VF. This means that the underlying 1015 * hardware only supports VLAN filtering for all VLAN the specified ethertypes 1016 * or none of them. 1017 * 1018 * virtchnl_vlan_caps.filtering.filtering_support.outer = 1019 * VIRTCHNL_VLAN_TOGGLE | 1020 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 1021 * VIRTHCNL_VLAN_ETHERTYPE_88A8 | 1022 * VIRTCHNL_VLAN_ETHERTYPE_9100 | 1023 * VIRTCHNL_VLAN_ETHERTYPE_AND; 1024 * 1025 * In order to enable outer VLAN filtering for 0x88a8 and 0x8100 VLANs (0x9100 1026 * VLANs aren't supported by the VF driver), the VF would populate the 1027 * virtchnl_vlan_setting structure in the following manner and send the 1028 * VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2. The same message format would be used 1029 * to disable outer VLAN filtering for 0x88a8 and 0x8100 VLANs, but the 1030 * VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2 opcode is used. 1031 * 1032 * virtchnl_vlan_setting.outer_ethertype_setting = 1033 * VIRTCHNL_VLAN_ETHERTYPE_8100 | 1034 * VIRTCHNL_VLAN_ETHERTYPE_88A8; 1035 * 1036 */ 1037 struct virtchnl_vlan_setting { 1038 u32 outer_ethertype_setting; 1039 u32 inner_ethertype_setting; 1040 u16 vport_id; 1041 u8 pad[6]; 1042 }; 1043 1044 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vlan_setting); 1045 1046 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE 1047 * VF sends VSI id and flags. 1048 * PF returns status code in retval. 1049 * Note: we assume that broadcast accept mode is always enabled. 1050 */ 1051 struct virtchnl_promisc_info { 1052 u16 vsi_id; 1053 u16 flags; 1054 }; 1055 1056 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info); 1057 1058 #define FLAG_VF_UNICAST_PROMISC 0x00000001 1059 #define FLAG_VF_MULTICAST_PROMISC 0x00000002 1060 1061 /* VIRTCHNL_OP_GET_STATS 1062 * VF sends this message to request stats for the selected VSI. VF uses 1063 * the virtchnl_queue_select struct to specify the VSI. The queue_id 1064 * field is ignored by the PF. 1065 * 1066 * PF replies with struct virtchnl_eth_stats in an external buffer. 1067 */ 1068 1069 struct virtchnl_eth_stats { 1070 u64 rx_bytes; /* received bytes */ 1071 u64 rx_unicast; /* received unicast pkts */ 1072 u64 rx_multicast; /* received multicast pkts */ 1073 u64 rx_broadcast; /* received broadcast pkts */ 1074 u64 rx_discards; 1075 u64 rx_unknown_protocol; 1076 u64 tx_bytes; /* transmitted bytes */ 1077 u64 tx_unicast; /* transmitted unicast pkts */ 1078 u64 tx_multicast; /* transmitted multicast pkts */ 1079 u64 tx_broadcast; /* transmitted broadcast pkts */ 1080 u64 tx_discards; 1081 u64 tx_errors; 1082 }; 1083 1084 /* VIRTCHNL_OP_CONFIG_RSS_KEY 1085 * VIRTCHNL_OP_CONFIG_RSS_LUT 1086 * VF sends these messages to configure RSS. Only supported if both PF 1087 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during 1088 * configuration negotiation. If this is the case, then the RSS fields in 1089 * the VF resource struct are valid. 1090 * Both the key and LUT are initialized to 0 by the PF, meaning that 1091 * RSS is effectively disabled until set up by the VF. 1092 */ 1093 struct virtchnl_rss_key { 1094 u16 vsi_id; 1095 u16 key_len; 1096 u8 key[1]; /* RSS hash key, packed bytes */ 1097 }; 1098 1099 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); 1100 1101 struct virtchnl_rss_lut { 1102 u16 vsi_id; 1103 u16 lut_entries; 1104 u8 lut[1]; /* RSS lookup table */ 1105 }; 1106 1107 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut); 1108 1109 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS 1110 * VIRTCHNL_OP_SET_RSS_HENA 1111 * VF sends these messages to get and set the hash filter enable bits for RSS. 1112 * By default, the PF sets these to all possible traffic types that the 1113 * hardware supports. The VF can query this value if it wants to change the 1114 * traffic types that are hashed by the hardware. 1115 */ 1116 struct virtchnl_rss_hena { 1117 u64 hena; 1118 }; 1119 1120 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena); 1121 1122 /* Type of RSS algorithm */ 1123 enum virtchnl_rss_algorithm { 1124 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0, 1125 VIRTCHNL_RSS_ALG_XOR_ASYMMETRIC = 1, 1126 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2, 1127 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3, 1128 }; 1129 1130 /* This is used by PF driver to enforce how many channels can be supported. 1131 * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise 1132 * PF driver will allow only max 4 channels 1133 */ 1134 #define VIRTCHNL_MAX_ADQ_CHANNELS 4 1135 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16 1136 1137 /* VIRTCHNL_OP_ENABLE_CHANNELS 1138 * VIRTCHNL_OP_DISABLE_CHANNELS 1139 * VF sends these messages to enable or disable channels based on 1140 * the user specified queue count and queue offset for each traffic class. 1141 * This struct encompasses all the information that the PF needs from 1142 * VF to create a channel. 1143 */ 1144 struct virtchnl_channel_info { 1145 u16 count; /* number of queues in a channel */ 1146 u16 offset; /* queues in a channel start from 'offset' */ 1147 u32 pad; 1148 u64 max_tx_rate; 1149 }; 1150 1151 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info); 1152 1153 struct virtchnl_tc_info { 1154 u32 num_tc; 1155 u32 pad; 1156 struct virtchnl_channel_info list[1]; 1157 }; 1158 1159 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info); 1160 1161 /* VIRTCHNL_ADD_CLOUD_FILTER 1162 * VIRTCHNL_DEL_CLOUD_FILTER 1163 * VF sends these messages to add or delete a cloud filter based on the 1164 * user specified match and action filters. These structures encompass 1165 * all the information that the PF needs from the VF to add/delete a 1166 * cloud filter. 1167 */ 1168 1169 struct virtchnl_l4_spec { 1170 u8 src_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 1171 u8 dst_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 1172 /* vlan_prio is part of this 16 bit field even from OS perspective 1173 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio 1174 * in future, when decided to offload vlan_prio, pass that information 1175 * as part of the "vlan_id" field, Bit14..12 1176 */ 1177 __be16 vlan_id; 1178 __be16 pad; /* reserved for future use */ 1179 __be32 src_ip[4]; 1180 __be32 dst_ip[4]; 1181 __be16 src_port; 1182 __be16 dst_port; 1183 }; 1184 1185 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec); 1186 1187 union virtchnl_flow_spec { 1188 struct virtchnl_l4_spec tcp_spec; 1189 u8 buffer[128]; /* reserved for future use */ 1190 }; 1191 1192 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec); 1193 1194 enum virtchnl_action { 1195 /* action types */ 1196 VIRTCHNL_ACTION_DROP = 0, 1197 VIRTCHNL_ACTION_TC_REDIRECT, 1198 VIRTCHNL_ACTION_PASSTHRU, 1199 VIRTCHNL_ACTION_QUEUE, 1200 VIRTCHNL_ACTION_Q_REGION, 1201 VIRTCHNL_ACTION_MARK, 1202 VIRTCHNL_ACTION_COUNT, 1203 }; 1204 1205 enum virtchnl_flow_type { 1206 /* flow types */ 1207 VIRTCHNL_TCP_V4_FLOW = 0, 1208 VIRTCHNL_TCP_V6_FLOW, 1209 VIRTCHNL_UDP_V4_FLOW, 1210 VIRTCHNL_UDP_V6_FLOW, 1211 }; 1212 1213 struct virtchnl_filter { 1214 union virtchnl_flow_spec data; 1215 union virtchnl_flow_spec mask; 1216 enum virtchnl_flow_type flow_type; 1217 enum virtchnl_action action; 1218 u32 action_meta; 1219 u8 field_flags; 1220 }; 1221 1222 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter); 1223 1224 /* VIRTCHNL_OP_DCF_GET_VSI_MAP 1225 * VF sends this message to get VSI mapping table. 1226 * PF responds with an indirect message containing VF's 1227 * HW VSI IDs. 1228 * The index of vf_vsi array is the logical VF ID, the 1229 * value of vf_vsi array is the VF's HW VSI ID with its 1230 * valid configuration. 1231 */ 1232 struct virtchnl_dcf_vsi_map { 1233 u16 pf_vsi; /* PF's HW VSI ID */ 1234 u16 num_vfs; /* The actual number of VFs allocated */ 1235 #define VIRTCHNL_DCF_VF_VSI_ID_S 0 1236 #define VIRTCHNL_DCF_VF_VSI_ID_M (0xFFF << VIRTCHNL_DCF_VF_VSI_ID_S) 1237 #define VIRTCHNL_DCF_VF_VSI_VALID BIT(15) 1238 u16 vf_vsi[1]; 1239 }; 1240 1241 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_dcf_vsi_map); 1242 1243 #define PKG_NAME_SIZE 32 1244 #define DSN_SIZE 8 1245 1246 struct pkg_version { 1247 u8 major; 1248 u8 minor; 1249 u8 update; 1250 u8 draft; 1251 }; 1252 1253 VIRTCHNL_CHECK_STRUCT_LEN(4, pkg_version); 1254 1255 struct virtchnl_pkg_info { 1256 struct pkg_version pkg_ver; 1257 u32 track_id; 1258 char pkg_name[PKG_NAME_SIZE]; 1259 u8 dsn[DSN_SIZE]; 1260 }; 1261 1262 VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_pkg_info); 1263 1264 /* VIRTCHNL_OP_DCF_VLAN_OFFLOAD 1265 * DCF negotiates the VIRTCHNL_VF_OFFLOAD_VLAN_V2 capability firstly to get 1266 * the double VLAN configuration, then DCF sends this message to configure the 1267 * outer or inner VLAN offloads (insertion and strip) for the target VF. 1268 */ 1269 struct virtchnl_dcf_vlan_offload { 1270 u16 vf_id; 1271 u16 tpid; 1272 u16 vlan_flags; 1273 #define VIRTCHNL_DCF_VLAN_TYPE_S 0 1274 #define VIRTCHNL_DCF_VLAN_TYPE_M \ 1275 (0x1 << VIRTCHNL_DCF_VLAN_TYPE_S) 1276 #define VIRTCHNL_DCF_VLAN_TYPE_INNER 0x0 1277 #define VIRTCHNL_DCF_VLAN_TYPE_OUTER 0x1 1278 #define VIRTCHNL_DCF_VLAN_INSERT_MODE_S 1 1279 #define VIRTCHNL_DCF_VLAN_INSERT_MODE_M \ 1280 (0x7 << VIRTCHNL_DCF_VLAN_INSERT_MODE_S) 1281 #define VIRTCHNL_DCF_VLAN_INSERT_DISABLE 0x1 1282 #define VIRTCHNL_DCF_VLAN_INSERT_PORT_BASED 0x2 1283 #define VIRTCHNL_DCF_VLAN_INSERT_VIA_TX_DESC 0x3 1284 #define VIRTCHNL_DCF_VLAN_STRIP_MODE_S 4 1285 #define VIRTCHNL_DCF_VLAN_STRIP_MODE_M \ 1286 (0x7 << VIRTCHNL_DCF_VLAN_STRIP_MODE_S) 1287 #define VIRTCHNL_DCF_VLAN_STRIP_DISABLE 0x1 1288 #define VIRTCHNL_DCF_VLAN_STRIP_ONLY 0x2 1289 #define VIRTCHNL_DCF_VLAN_STRIP_INTO_RX_DESC 0x3 1290 u16 vlan_id; 1291 u16 pad[4]; 1292 }; 1293 1294 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_dcf_vlan_offload); 1295 1296 struct virtchnl_supported_rxdids { 1297 u64 supported_rxdids; 1298 }; 1299 1300 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_supported_rxdids); 1301 1302 /* VIRTCHNL_OP_EVENT 1303 * PF sends this message to inform the VF driver of events that may affect it. 1304 * No direct response is expected from the VF, though it may generate other 1305 * messages in response to this one. 1306 */ 1307 enum virtchnl_event_codes { 1308 VIRTCHNL_EVENT_UNKNOWN = 0, 1309 VIRTCHNL_EVENT_LINK_CHANGE, 1310 VIRTCHNL_EVENT_RESET_IMPENDING, 1311 VIRTCHNL_EVENT_PF_DRIVER_CLOSE, 1312 VIRTCHNL_EVENT_DCF_VSI_MAP_UPDATE, 1313 }; 1314 1315 #define PF_EVENT_SEVERITY_INFO 0 1316 #define PF_EVENT_SEVERITY_ATTENTION 1 1317 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2 1318 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255 1319 1320 struct virtchnl_pf_event { 1321 enum virtchnl_event_codes event; 1322 union { 1323 /* If the PF driver does not support the new speed reporting 1324 * capabilities then use link_event else use link_event_adv to 1325 * get the speed and link information. The ability to understand 1326 * new speeds is indicated by setting the capability flag 1327 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter 1328 * in virtchnl_vf_resource struct and can be used to determine 1329 * which link event struct to use below. 1330 */ 1331 struct { 1332 enum virtchnl_link_speed link_speed; 1333 u8 link_status; 1334 } link_event; 1335 struct { 1336 /* link_speed provided in Mbps */ 1337 u32 link_speed; 1338 u8 link_status; 1339 } link_event_adv; 1340 struct { 1341 u16 vf_id; 1342 u16 vsi_id; 1343 } vf_vsi_map; 1344 } event_data; 1345 1346 int severity; 1347 }; 1348 1349 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); 1350 1351 1352 /* VF reset states - these are written into the RSTAT register: 1353 * VFGEN_RSTAT on the VF 1354 * When the PF initiates a reset, it writes 0 1355 * When the reset is complete, it writes 1 1356 * When the PF detects that the VF has recovered, it writes 2 1357 * VF checks this register periodically to determine if a reset has occurred, 1358 * then polls it to know when the reset is complete. 1359 * If either the PF or VF reads the register while the hardware 1360 * is in a reset state, it will return DEADBEEF, which, when masked 1361 * will result in 3. 1362 */ 1363 enum virtchnl_vfr_states { 1364 VIRTCHNL_VFR_INPROGRESS = 0, 1365 VIRTCHNL_VFR_COMPLETED, 1366 VIRTCHNL_VFR_VFACTIVE, 1367 }; 1368 1369 #define VIRTCHNL_MAX_NUM_PROTO_HDRS 32 1370 #define PROTO_HDR_SHIFT 5 1371 #define PROTO_HDR_FIELD_START(proto_hdr_type) \ 1372 (proto_hdr_type << PROTO_HDR_SHIFT) 1373 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1) 1374 1375 /* VF use these macros to configure each protocol header. 1376 * Specify which protocol headers and protocol header fields base on 1377 * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field. 1378 * @param hdr: a struct of virtchnl_proto_hdr 1379 * @param hdr_type: ETH/IPV4/TCP, etc 1380 * @param field: SRC/DST/TEID/SPI, etc 1381 */ 1382 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \ 1383 ((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK)) 1384 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \ 1385 ((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK)) 1386 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \ 1387 ((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK)) 1388 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector) 1389 1390 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \ 1391 (VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \ 1392 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field)) 1393 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \ 1394 (VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \ 1395 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field)) 1396 1397 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \ 1398 ((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type) 1399 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \ 1400 (((hdr)->type) >> PROTO_HDR_SHIFT) 1401 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \ 1402 ((hdr)->type == ((val) >> PROTO_HDR_SHIFT)) 1403 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \ 1404 (VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) && \ 1405 VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val)) 1406 1407 /* Protocol header type within a packet segment. A segment consists of one or 1408 * more protocol headers that make up a logical group of protocol headers. Each 1409 * logical group of protocol headers encapsulates or is encapsulated using/by 1410 * tunneling or encapsulation protocols for network virtualization. 1411 */ 1412 enum virtchnl_proto_hdr_type { 1413 VIRTCHNL_PROTO_HDR_NONE, 1414 VIRTCHNL_PROTO_HDR_ETH, 1415 VIRTCHNL_PROTO_HDR_S_VLAN, 1416 VIRTCHNL_PROTO_HDR_C_VLAN, 1417 VIRTCHNL_PROTO_HDR_IPV4, 1418 VIRTCHNL_PROTO_HDR_IPV6, 1419 VIRTCHNL_PROTO_HDR_TCP, 1420 VIRTCHNL_PROTO_HDR_UDP, 1421 VIRTCHNL_PROTO_HDR_SCTP, 1422 VIRTCHNL_PROTO_HDR_GTPU_IP, 1423 VIRTCHNL_PROTO_HDR_GTPU_EH, 1424 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN, 1425 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP, 1426 VIRTCHNL_PROTO_HDR_PPPOE, 1427 VIRTCHNL_PROTO_HDR_L2TPV3, 1428 VIRTCHNL_PROTO_HDR_ESP, 1429 VIRTCHNL_PROTO_HDR_AH, 1430 VIRTCHNL_PROTO_HDR_PFCP, 1431 VIRTCHNL_PROTO_HDR_GTPC, 1432 VIRTCHNL_PROTO_HDR_ECPRI, 1433 }; 1434 1435 /* Protocol header field within a protocol header. */ 1436 enum virtchnl_proto_hdr_field { 1437 /* ETHER */ 1438 VIRTCHNL_PROTO_HDR_ETH_SRC = 1439 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH), 1440 VIRTCHNL_PROTO_HDR_ETH_DST, 1441 VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE, 1442 /* S-VLAN */ 1443 VIRTCHNL_PROTO_HDR_S_VLAN_ID = 1444 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN), 1445 /* C-VLAN */ 1446 VIRTCHNL_PROTO_HDR_C_VLAN_ID = 1447 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN), 1448 /* IPV4 */ 1449 VIRTCHNL_PROTO_HDR_IPV4_SRC = 1450 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4), 1451 VIRTCHNL_PROTO_HDR_IPV4_DST, 1452 VIRTCHNL_PROTO_HDR_IPV4_DSCP, 1453 VIRTCHNL_PROTO_HDR_IPV4_TTL, 1454 VIRTCHNL_PROTO_HDR_IPV4_PROT, 1455 /* IPV6 */ 1456 VIRTCHNL_PROTO_HDR_IPV6_SRC = 1457 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6), 1458 VIRTCHNL_PROTO_HDR_IPV6_DST, 1459 VIRTCHNL_PROTO_HDR_IPV6_TC, 1460 VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT, 1461 VIRTCHNL_PROTO_HDR_IPV6_PROT, 1462 /* IPV6 Prefix */ 1463 VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_SRC, 1464 VIRTCHNL_PROTO_HDR_IPV6_PREFIX32_DST, 1465 VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_SRC, 1466 VIRTCHNL_PROTO_HDR_IPV6_PREFIX40_DST, 1467 VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_SRC, 1468 VIRTCHNL_PROTO_HDR_IPV6_PREFIX48_DST, 1469 VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_SRC, 1470 VIRTCHNL_PROTO_HDR_IPV6_PREFIX56_DST, 1471 VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_SRC, 1472 VIRTCHNL_PROTO_HDR_IPV6_PREFIX64_DST, 1473 VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_SRC, 1474 VIRTCHNL_PROTO_HDR_IPV6_PREFIX96_DST, 1475 /* TCP */ 1476 VIRTCHNL_PROTO_HDR_TCP_SRC_PORT = 1477 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP), 1478 VIRTCHNL_PROTO_HDR_TCP_DST_PORT, 1479 /* UDP */ 1480 VIRTCHNL_PROTO_HDR_UDP_SRC_PORT = 1481 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP), 1482 VIRTCHNL_PROTO_HDR_UDP_DST_PORT, 1483 /* SCTP */ 1484 VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT = 1485 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP), 1486 VIRTCHNL_PROTO_HDR_SCTP_DST_PORT, 1487 /* GTPU_IP */ 1488 VIRTCHNL_PROTO_HDR_GTPU_IP_TEID = 1489 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP), 1490 /* GTPU_EH */ 1491 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU = 1492 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH), 1493 VIRTCHNL_PROTO_HDR_GTPU_EH_QFI, 1494 /* PPPOE */ 1495 VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID = 1496 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE), 1497 /* L2TPV3 */ 1498 VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID = 1499 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3), 1500 /* ESP */ 1501 VIRTCHNL_PROTO_HDR_ESP_SPI = 1502 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP), 1503 /* AH */ 1504 VIRTCHNL_PROTO_HDR_AH_SPI = 1505 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH), 1506 /* PFCP */ 1507 VIRTCHNL_PROTO_HDR_PFCP_S_FIELD = 1508 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP), 1509 VIRTCHNL_PROTO_HDR_PFCP_SEID, 1510 /* GTPC */ 1511 VIRTCHNL_PROTO_HDR_GTPC_TEID = 1512 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPC), 1513 /* ECPRI */ 1514 VIRTCHNL_PROTO_HDR_ECPRI_MSG_TYPE = 1515 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ECPRI), 1516 VIRTCHNL_PROTO_HDR_ECPRI_PC_RTC_ID, 1517 }; 1518 1519 struct virtchnl_proto_hdr { 1520 enum virtchnl_proto_hdr_type type; 1521 u32 field_selector; /* a bit mask to select field for header type */ 1522 u8 buffer[64]; 1523 /** 1524 * binary buffer in network order for specific header type. 1525 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4 1526 * header is expected to be copied into the buffer. 1527 */ 1528 }; 1529 1530 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr); 1531 1532 struct virtchnl_proto_hdrs { 1533 u8 tunnel_level; 1534 /** 1535 * specify where protocol header start from. 1536 * 0 - from the outer layer 1537 * 1 - from the first inner layer 1538 * 2 - from the second inner layer 1539 * .... 1540 **/ 1541 int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */ 1542 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS]; 1543 }; 1544 1545 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs); 1546 1547 struct virtchnl_rss_cfg { 1548 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */ 1549 enum virtchnl_rss_algorithm rss_algorithm; /* rss algorithm type */ 1550 u8 reserved[128]; /* reserve for future */ 1551 }; 1552 1553 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg); 1554 1555 /* action configuration for FDIR */ 1556 struct virtchnl_filter_action { 1557 enum virtchnl_action type; 1558 union { 1559 /* used for queue and qgroup action */ 1560 struct { 1561 u16 index; 1562 u8 region; 1563 } queue; 1564 /* used for count action */ 1565 struct { 1566 /* share counter ID with other flow rules */ 1567 u8 shared; 1568 u32 id; /* counter ID */ 1569 } count; 1570 /* used for mark action */ 1571 u32 mark_id; 1572 u8 reserve[32]; 1573 } act_conf; 1574 }; 1575 1576 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action); 1577 1578 #define VIRTCHNL_MAX_NUM_ACTIONS 8 1579 1580 struct virtchnl_filter_action_set { 1581 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */ 1582 int count; 1583 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS]; 1584 }; 1585 1586 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set); 1587 1588 /* pattern and action for FDIR rule */ 1589 struct virtchnl_fdir_rule { 1590 struct virtchnl_proto_hdrs proto_hdrs; 1591 struct virtchnl_filter_action_set action_set; 1592 }; 1593 1594 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule); 1595 1596 /* query information to retrieve fdir rule counters. 1597 * PF will fill out this structure to reset counter. 1598 */ 1599 struct virtchnl_fdir_query_info { 1600 u32 match_packets_valid:1; 1601 u32 match_bytes_valid:1; 1602 u32 reserved:30; /* Reserved, must be zero. */ 1603 u32 pad; 1604 u64 matched_packets; /* Number of packets for this rule. */ 1605 u64 matched_bytes; /* Number of bytes through this rule. */ 1606 }; 1607 1608 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_fdir_query_info); 1609 1610 /* Status returned to VF after VF requests FDIR commands 1611 * VIRTCHNL_FDIR_SUCCESS 1612 * VF FDIR related request is successfully done by PF 1613 * The request can be OP_ADD/DEL/QUERY_FDIR_FILTER. 1614 * 1615 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE 1616 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource. 1617 * 1618 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST 1619 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed. 1620 * 1621 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT 1622 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule. 1623 * 1624 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST 1625 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist. 1626 * 1627 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID 1628 * OP_ADD_FDIR_FILTER request is failed due to parameters validation 1629 * or HW doesn't support. 1630 * 1631 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT 1632 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out 1633 * for programming. 1634 * 1635 * VIRTCHNL_FDIR_FAILURE_QUERY_INVALID 1636 * OP_QUERY_FDIR_FILTER request is failed due to parameters validation, 1637 * for example, VF query counter of a rule who has no counter action. 1638 */ 1639 enum virtchnl_fdir_prgm_status { 1640 VIRTCHNL_FDIR_SUCCESS = 0, 1641 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE, 1642 VIRTCHNL_FDIR_FAILURE_RULE_EXIST, 1643 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT, 1644 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST, 1645 VIRTCHNL_FDIR_FAILURE_RULE_INVALID, 1646 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT, 1647 VIRTCHNL_FDIR_FAILURE_QUERY_INVALID, 1648 }; 1649 1650 /* VIRTCHNL_OP_ADD_FDIR_FILTER 1651 * VF sends this request to PF by filling out vsi_id, 1652 * validate_only and rule_cfg. PF will return flow_id 1653 * if the request is successfully done and return add_status to VF. 1654 */ 1655 struct virtchnl_fdir_add { 1656 u16 vsi_id; /* INPUT */ 1657 /* 1658 * 1 for validating a fdir rule, 0 for creating a fdir rule. 1659 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER. 1660 */ 1661 u16 validate_only; /* INPUT */ 1662 u32 flow_id; /* OUTPUT */ 1663 struct virtchnl_fdir_rule rule_cfg; /* INPUT */ 1664 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 1665 }; 1666 1667 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add); 1668 1669 /* VIRTCHNL_OP_DEL_FDIR_FILTER 1670 * VF sends this request to PF by filling out vsi_id 1671 * and flow_id. PF will return del_status to VF. 1672 */ 1673 struct virtchnl_fdir_del { 1674 u16 vsi_id; /* INPUT */ 1675 u16 pad; 1676 u32 flow_id; /* INPUT */ 1677 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 1678 }; 1679 1680 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del); 1681 1682 /* VIRTCHNL_OP_QUERY_FDIR_FILTER 1683 * VF sends this request to PF by filling out vsi_id, 1684 * flow_id and reset_counter. PF will return query_info 1685 * and query_status to VF. 1686 */ 1687 struct virtchnl_fdir_query { 1688 u16 vsi_id; /* INPUT */ 1689 u16 pad1[3]; 1690 u32 flow_id; /* INPUT */ 1691 u32 reset_counter:1; /* INPUT */ 1692 struct virtchnl_fdir_query_info query_info; /* OUTPUT */ 1693 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 1694 u32 pad2; 1695 }; 1696 1697 VIRTCHNL_CHECK_STRUCT_LEN(48, virtchnl_fdir_query); 1698 1699 /* TX and RX queue types are valid in legacy as well as split queue models. 1700 * With Split Queue model, 2 additional types are introduced - TX_COMPLETION 1701 * and RX_BUFFER. In split queue model, RX corresponds to the queue where HW 1702 * posts completions. 1703 */ 1704 enum virtchnl_queue_type { 1705 VIRTCHNL_QUEUE_TYPE_TX = 0, 1706 VIRTCHNL_QUEUE_TYPE_RX = 1, 1707 VIRTCHNL_QUEUE_TYPE_TX_COMPLETION = 2, 1708 VIRTCHNL_QUEUE_TYPE_RX_BUFFER = 3, 1709 VIRTCHNL_QUEUE_TYPE_CONFIG_TX = 4, 1710 VIRTCHNL_QUEUE_TYPE_CONFIG_RX = 5 1711 }; 1712 1713 1714 /* structure to specify a chunk of contiguous queues */ 1715 struct virtchnl_queue_chunk { 1716 enum virtchnl_queue_type type; 1717 u16 start_queue_id; 1718 u16 num_queues; 1719 }; 1720 1721 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_queue_chunk); 1722 1723 /* structure to specify several chunks of contiguous queues */ 1724 struct virtchnl_queue_chunks { 1725 u16 num_chunks; 1726 u16 rsvd; 1727 struct virtchnl_queue_chunk chunks[1]; 1728 }; 1729 1730 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_chunks); 1731 1732 1733 /* VIRTCHNL_OP_ENABLE_QUEUES_V2 1734 * VIRTCHNL_OP_DISABLE_QUEUES_V2 1735 * VIRTCHNL_OP_DEL_QUEUES 1736 * 1737 * If VIRTCHNL_CAP_EXT_FEATURES was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 1738 * then all of these ops are available. 1739 * 1740 * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 1741 * then VIRTCHNL_OP_ENABLE_QUEUES_V2 and VIRTCHNL_OP_DISABLE_QUEUES_V2 are 1742 * available. 1743 * 1744 * PF sends these messages to enable, disable or delete queues specified in 1745 * chunks. PF sends virtchnl_del_ena_dis_queues struct to specify the queues 1746 * to be enabled/disabled/deleted. Also applicable to single queue RX or 1747 * TX. CP performs requested action and returns status. 1748 */ 1749 struct virtchnl_del_ena_dis_queues { 1750 u16 vport_id; 1751 u16 pad; 1752 struct virtchnl_queue_chunks chunks; 1753 }; 1754 1755 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_del_ena_dis_queues); 1756 1757 /* Virtchannel interrupt throttling rate index */ 1758 enum virtchnl_itr_idx { 1759 VIRTCHNL_ITR_IDX_0 = 0, 1760 VIRTCHNL_ITR_IDX_1 = 1, 1761 VIRTCHNL_ITR_IDX_NO_ITR = 3, 1762 }; 1763 1764 /* Queue to vector mapping */ 1765 struct virtchnl_queue_vector { 1766 u16 queue_id; 1767 u16 vector_id; 1768 u8 pad[4]; 1769 enum virtchnl_itr_idx itr_idx; 1770 enum virtchnl_queue_type queue_type; 1771 }; 1772 1773 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queue_vector); 1774 1775 /* VIRTCHNL_OP_MAP_QUEUE_VECTOR 1776 * VIRTCHNL_OP_UNMAP_QUEUE_VECTOR 1777 * 1778 * If VIRTCHNL_CAP_EXT_FEATURES was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 1779 * then all of these ops are available. 1780 * 1781 * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 1782 * then only VIRTCHNL_OP_MAP_QUEUE_VECTOR is available. 1783 * 1784 * PF sends this message to map or unmap queues to vectors and ITR index 1785 * registers. External data buffer contains virtchnl_queue_vector_maps structure 1786 * that contains num_qv_maps of virtchnl_queue_vector structures. 1787 * CP maps the requested queue vector maps after validating the queue and vector 1788 * ids and returns a status code. 1789 */ 1790 struct virtchnl_queue_vector_maps { 1791 u16 vport_id; 1792 u16 num_qv_maps; 1793 u8 pad[4]; 1794 struct virtchnl_queue_vector qv_maps[1]; 1795 }; 1796 1797 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps); 1798 1799 1800 /* Since VF messages are limited by u16 size, precalculate the maximum possible 1801 * values of nested elements in virtchnl structures that virtual channel can 1802 * possibly handle in a single message. 1803 */ 1804 enum virtchnl_vector_limits { 1805 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX = 1806 ((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) / 1807 sizeof(struct virtchnl_queue_pair_info), 1808 1809 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX = 1810 ((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) / 1811 sizeof(struct virtchnl_vector_map), 1812 1813 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX = 1814 ((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) / 1815 sizeof(struct virtchnl_ether_addr), 1816 1817 VIRTCHNL_OP_ADD_DEL_VLAN_MAX = 1818 ((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) / 1819 sizeof(u16), 1820 1821 1822 VIRTCHNL_OP_ENABLE_CHANNELS_MAX = 1823 ((u16)(~0) - sizeof(struct virtchnl_tc_info)) / 1824 sizeof(struct virtchnl_channel_info), 1825 1826 VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX = 1827 ((u16)(~0) - sizeof(struct virtchnl_del_ena_dis_queues)) / 1828 sizeof(struct virtchnl_queue_chunk), 1829 1830 VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX = 1831 ((u16)(~0) - sizeof(struct virtchnl_queue_vector_maps)) / 1832 sizeof(struct virtchnl_queue_vector), 1833 1834 VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX = 1835 ((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list_v2)) / 1836 sizeof(struct virtchnl_vlan_filter), 1837 }; 1838 1839 /** 1840 * virtchnl_vc_validate_vf_msg 1841 * @ver: Virtchnl version info 1842 * @v_opcode: Opcode for the message 1843 * @msg: pointer to the msg buffer 1844 * @msglen: msg length 1845 * 1846 * validate msg format against struct for each opcode 1847 */ 1848 static inline int 1849 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, 1850 u8 *msg, u16 msglen) 1851 { 1852 bool err_msg_format = false; 1853 u32 valid_len = 0; 1854 1855 /* Validate message length. */ 1856 switch (v_opcode) { 1857 case VIRTCHNL_OP_VERSION: 1858 valid_len = sizeof(struct virtchnl_version_info); 1859 break; 1860 case VIRTCHNL_OP_RESET_VF: 1861 break; 1862 case VIRTCHNL_OP_GET_VF_RESOURCES: 1863 if (VF_IS_V11(ver)) 1864 valid_len = sizeof(u32); 1865 break; 1866 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 1867 valid_len = sizeof(struct virtchnl_txq_info); 1868 break; 1869 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 1870 valid_len = sizeof(struct virtchnl_rxq_info); 1871 break; 1872 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 1873 valid_len = sizeof(struct virtchnl_vsi_queue_config_info); 1874 if (msglen >= valid_len) { 1875 struct virtchnl_vsi_queue_config_info *vqc = 1876 (struct virtchnl_vsi_queue_config_info *)msg; 1877 1878 if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs > 1879 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) { 1880 err_msg_format = true; 1881 break; 1882 } 1883 1884 valid_len += (vqc->num_queue_pairs * 1885 sizeof(struct 1886 virtchnl_queue_pair_info)); 1887 } 1888 break; 1889 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1890 valid_len = sizeof(struct virtchnl_irq_map_info); 1891 if (msglen >= valid_len) { 1892 struct virtchnl_irq_map_info *vimi = 1893 (struct virtchnl_irq_map_info *)msg; 1894 1895 if (vimi->num_vectors == 0 || vimi->num_vectors > 1896 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) { 1897 err_msg_format = true; 1898 break; 1899 } 1900 1901 valid_len += (vimi->num_vectors * 1902 sizeof(struct virtchnl_vector_map)); 1903 } 1904 break; 1905 case VIRTCHNL_OP_ENABLE_QUEUES: 1906 case VIRTCHNL_OP_DISABLE_QUEUES: 1907 valid_len = sizeof(struct virtchnl_queue_select); 1908 break; 1909 case VIRTCHNL_OP_GET_MAX_RSS_QREGION: 1910 break; 1911 case VIRTCHNL_OP_ADD_ETH_ADDR: 1912 case VIRTCHNL_OP_DEL_ETH_ADDR: 1913 valid_len = sizeof(struct virtchnl_ether_addr_list); 1914 if (msglen >= valid_len) { 1915 struct virtchnl_ether_addr_list *veal = 1916 (struct virtchnl_ether_addr_list *)msg; 1917 1918 if (veal->num_elements == 0 || veal->num_elements > 1919 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) { 1920 err_msg_format = true; 1921 break; 1922 } 1923 1924 valid_len += veal->num_elements * 1925 sizeof(struct virtchnl_ether_addr); 1926 } 1927 break; 1928 case VIRTCHNL_OP_ADD_VLAN: 1929 case VIRTCHNL_OP_DEL_VLAN: 1930 valid_len = sizeof(struct virtchnl_vlan_filter_list); 1931 if (msglen >= valid_len) { 1932 struct virtchnl_vlan_filter_list *vfl = 1933 (struct virtchnl_vlan_filter_list *)msg; 1934 1935 if (vfl->num_elements == 0 || vfl->num_elements > 1936 VIRTCHNL_OP_ADD_DEL_VLAN_MAX) { 1937 err_msg_format = true; 1938 break; 1939 } 1940 1941 valid_len += vfl->num_elements * sizeof(u16); 1942 } 1943 break; 1944 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 1945 valid_len = sizeof(struct virtchnl_promisc_info); 1946 break; 1947 case VIRTCHNL_OP_GET_STATS: 1948 valid_len = sizeof(struct virtchnl_queue_select); 1949 break; 1950 case VIRTCHNL_OP_CONFIG_RSS_KEY: 1951 valid_len = sizeof(struct virtchnl_rss_key); 1952 if (msglen >= valid_len) { 1953 struct virtchnl_rss_key *vrk = 1954 (struct virtchnl_rss_key *)msg; 1955 1956 if (vrk->key_len == 0) { 1957 /* zero length is allowed as input */ 1958 break; 1959 } 1960 1961 valid_len += vrk->key_len - 1; 1962 } 1963 break; 1964 case VIRTCHNL_OP_CONFIG_RSS_LUT: 1965 valid_len = sizeof(struct virtchnl_rss_lut); 1966 if (msglen >= valid_len) { 1967 struct virtchnl_rss_lut *vrl = 1968 (struct virtchnl_rss_lut *)msg; 1969 1970 if (vrl->lut_entries == 0) { 1971 /* zero entries is allowed as input */ 1972 break; 1973 } 1974 1975 valid_len += vrl->lut_entries - 1; 1976 } 1977 break; 1978 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 1979 break; 1980 case VIRTCHNL_OP_SET_RSS_HENA: 1981 valid_len = sizeof(struct virtchnl_rss_hena); 1982 break; 1983 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 1984 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 1985 break; 1986 case VIRTCHNL_OP_REQUEST_QUEUES: 1987 valid_len = sizeof(struct virtchnl_vf_res_request); 1988 break; 1989 case VIRTCHNL_OP_ENABLE_CHANNELS: 1990 valid_len = sizeof(struct virtchnl_tc_info); 1991 if (msglen >= valid_len) { 1992 struct virtchnl_tc_info *vti = 1993 (struct virtchnl_tc_info *)msg; 1994 1995 if (vti->num_tc == 0 || vti->num_tc > 1996 VIRTCHNL_OP_ENABLE_CHANNELS_MAX) { 1997 err_msg_format = true; 1998 break; 1999 } 2000 2001 valid_len += (vti->num_tc - 1) * 2002 sizeof(struct virtchnl_channel_info); 2003 } 2004 break; 2005 case VIRTCHNL_OP_DISABLE_CHANNELS: 2006 break; 2007 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 2008 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 2009 valid_len = sizeof(struct virtchnl_filter); 2010 break; 2011 case VIRTCHNL_OP_DCF_VLAN_OFFLOAD: 2012 valid_len = sizeof(struct virtchnl_dcf_vlan_offload); 2013 break; 2014 case VIRTCHNL_OP_DCF_CMD_DESC: 2015 case VIRTCHNL_OP_DCF_CMD_BUFF: 2016 /* These two opcodes are specific to handle the AdminQ command, 2017 * so the validation needs to be done in PF's context. 2018 */ 2019 valid_len = msglen; 2020 break; 2021 case VIRTCHNL_OP_DCF_DISABLE: 2022 case VIRTCHNL_OP_DCF_GET_VSI_MAP: 2023 case VIRTCHNL_OP_DCF_GET_PKG_INFO: 2024 break; 2025 case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS: 2026 break; 2027 case VIRTCHNL_OP_ADD_RSS_CFG: 2028 case VIRTCHNL_OP_DEL_RSS_CFG: 2029 valid_len = sizeof(struct virtchnl_rss_cfg); 2030 break; 2031 case VIRTCHNL_OP_ADD_FDIR_FILTER: 2032 valid_len = sizeof(struct virtchnl_fdir_add); 2033 break; 2034 case VIRTCHNL_OP_DEL_FDIR_FILTER: 2035 valid_len = sizeof(struct virtchnl_fdir_del); 2036 break; 2037 case VIRTCHNL_OP_QUERY_FDIR_FILTER: 2038 valid_len = sizeof(struct virtchnl_fdir_query); 2039 break; 2040 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: 2041 break; 2042 case VIRTCHNL_OP_ADD_VLAN_V2: 2043 case VIRTCHNL_OP_DEL_VLAN_V2: 2044 valid_len = sizeof(struct virtchnl_vlan_filter_list_v2); 2045 if (msglen >= valid_len) { 2046 struct virtchnl_vlan_filter_list_v2 *vfl = 2047 (struct virtchnl_vlan_filter_list_v2 *)msg; 2048 2049 if (vfl->num_elements == 0 || vfl->num_elements > 2050 VIRTCHNL_OP_ADD_DEL_VLAN_V2_MAX) { 2051 err_msg_format = true; 2052 break; 2053 } 2054 2055 valid_len += (vfl->num_elements - 1) * 2056 sizeof(struct virtchnl_vlan_filter); 2057 } 2058 break; 2059 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2: 2060 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2: 2061 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2: 2062 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2: 2063 case VIRTCHNL_OP_ENABLE_VLAN_FILTERING_V2: 2064 case VIRTCHNL_OP_DISABLE_VLAN_FILTERING_V2: 2065 valid_len = sizeof(struct virtchnl_vlan_setting); 2066 break; 2067 case VIRTCHNL_OP_ENABLE_QUEUES_V2: 2068 case VIRTCHNL_OP_DISABLE_QUEUES_V2: 2069 valid_len = sizeof(struct virtchnl_del_ena_dis_queues); 2070 if (msglen >= valid_len) { 2071 struct virtchnl_del_ena_dis_queues *qs = 2072 (struct virtchnl_del_ena_dis_queues *)msg; 2073 if (qs->chunks.num_chunks == 0 || 2074 qs->chunks.num_chunks > VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX) { 2075 err_msg_format = true; 2076 break; 2077 } 2078 valid_len += (qs->chunks.num_chunks - 1) * 2079 sizeof(struct virtchnl_queue_chunk); 2080 } 2081 break; 2082 case VIRTCHNL_OP_MAP_QUEUE_VECTOR: 2083 valid_len = sizeof(struct virtchnl_queue_vector_maps); 2084 if (msglen >= valid_len) { 2085 struct virtchnl_queue_vector_maps *v_qp = 2086 (struct virtchnl_queue_vector_maps *)msg; 2087 if (v_qp->num_qv_maps == 0 || 2088 v_qp->num_qv_maps > VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) { 2089 err_msg_format = true; 2090 break; 2091 } 2092 valid_len += (v_qp->num_qv_maps - 1) * 2093 sizeof(struct virtchnl_queue_vector); 2094 } 2095 break; 2096 /* These are always errors coming from the VF. */ 2097 case VIRTCHNL_OP_EVENT: 2098 case VIRTCHNL_OP_UNKNOWN: 2099 default: 2100 return VIRTCHNL_STATUS_ERR_PARAM; 2101 } 2102 /* few more checks */ 2103 if (err_msg_format || valid_len != msglen) 2104 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH; 2105 2106 return 0; 2107 } 2108 #endif /* _VIRTCHNL_H_ */ 2109