1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright (c) 2021, Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * 3. Neither the name of the Intel Corporation nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 /*$FreeBSD$*/ 32 33 #ifndef _VIRTCHNL_H_ 34 #define _VIRTCHNL_H_ 35 36 /* Description: 37 * This header file describes the VF-PF communication protocol used 38 * by the drivers for all devices starting from our 40G product line 39 * 40 * Admin queue buffer usage: 41 * desc->opcode is always aqc_opc_send_msg_to_pf 42 * flags, retval, datalen, and data addr are all used normally. 43 * The Firmware copies the cookie fields when sending messages between the 44 * PF and VF, but uses all other fields internally. Due to this limitation, 45 * we must send all messages as "indirect", i.e. using an external buffer. 46 * 47 * All the VSI indexes are relative to the VF. Each VF can have maximum of 48 * three VSIs. All the queue indexes are relative to the VSI. Each VF can 49 * have a maximum of sixteen queues for all of its VSIs. 50 * 51 * The PF is required to return a status code in v_retval for all messages 52 * except RESET_VF, which does not require any response. The return value 53 * is of status_code type, defined in the shared type.h. 54 * 55 * In general, VF driver initialization should roughly follow the order of 56 * these opcodes. The VF driver must first validate the API version of the 57 * PF driver, then request a reset, then get resources, then configure 58 * queues and interrupts. After these operations are complete, the VF 59 * driver may start its queues, optionally add MAC and VLAN filters, and 60 * process traffic. 61 */ 62 63 /* START GENERIC DEFINES 64 * Need to ensure the following enums and defines hold the same meaning and 65 * value in current and future projects 66 */ 67 68 /* Error Codes */ 69 enum virtchnl_status_code { 70 VIRTCHNL_STATUS_SUCCESS = 0, 71 VIRTCHNL_STATUS_ERR_PARAM = -5, 72 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18, 73 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38, 74 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39, 75 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40, 76 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53, 77 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64, 78 }; 79 80 /* Backward compatibility */ 81 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM 82 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED 83 84 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0 85 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1 86 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2 87 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3 88 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4 89 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5 90 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6 91 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7 92 93 enum virtchnl_link_speed { 94 VIRTCHNL_LINK_SPEED_UNKNOWN = 0, 95 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT), 96 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT), 97 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT), 98 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT), 99 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT), 100 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT), 101 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT), 102 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT), 103 }; 104 105 /* for hsplit_0 field of Rx HMC context */ 106 /* deprecated with AVF 1.0 */ 107 enum virtchnl_rx_hsplit { 108 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0, 109 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1, 110 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2, 111 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4, 112 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8, 113 }; 114 115 #define VIRTCHNL_ETH_LENGTH_OF_ADDRESS 6 116 /* END GENERIC DEFINES */ 117 118 /* Opcodes for VF-PF communication. These are placed in the v_opcode field 119 * of the virtchnl_msg structure. 120 */ 121 enum virtchnl_ops { 122 /* The PF sends status change events to VFs using 123 * the VIRTCHNL_OP_EVENT opcode. 124 * VFs send requests to the PF using the other ops. 125 * Use of "advanced opcode" features must be negotiated as part of capabilities 126 * exchange and are not considered part of base mode feature set. 127 */ 128 VIRTCHNL_OP_UNKNOWN = 0, 129 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */ 130 VIRTCHNL_OP_RESET_VF = 2, 131 VIRTCHNL_OP_GET_VF_RESOURCES = 3, 132 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4, 133 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5, 134 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6, 135 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7, 136 VIRTCHNL_OP_ENABLE_QUEUES = 8, 137 VIRTCHNL_OP_DISABLE_QUEUES = 9, 138 VIRTCHNL_OP_ADD_ETH_ADDR = 10, 139 VIRTCHNL_OP_DEL_ETH_ADDR = 11, 140 VIRTCHNL_OP_ADD_VLAN = 12, 141 VIRTCHNL_OP_DEL_VLAN = 13, 142 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14, 143 VIRTCHNL_OP_GET_STATS = 15, 144 VIRTCHNL_OP_RSVD = 16, 145 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */ 146 /* opcode 19 is reserved */ 147 /* opcodes 20, 21, and 22 are reserved */ 148 VIRTCHNL_OP_CONFIG_RSS_KEY = 23, 149 VIRTCHNL_OP_CONFIG_RSS_LUT = 24, 150 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25, 151 VIRTCHNL_OP_SET_RSS_HENA = 26, 152 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27, 153 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28, 154 VIRTCHNL_OP_REQUEST_QUEUES = 29, 155 VIRTCHNL_OP_ENABLE_CHANNELS = 30, 156 VIRTCHNL_OP_DISABLE_CHANNELS = 31, 157 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32, 158 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33, 159 /* opcode 34 is reserved */ 160 /* opcodes 39, 40, 41, 42 and 43 are reserved */ 161 /* opcode 44 is reserved */ 162 /* opcode 45, 46, 47, 48 and 49 are reserved */ 163 VIRTCHNL_OP_GET_MAX_RSS_QREGION = 50, 164 VIRTCHNL_OP_ENABLE_QUEUES_V2 = 107, 165 VIRTCHNL_OP_DISABLE_QUEUES_V2 = 108, 166 VIRTCHNL_OP_MAP_QUEUE_VECTOR = 111, 167 VIRTCHNL_OP_MAX, 168 }; 169 170 static inline const char *virtchnl_op_str(enum virtchnl_ops v_opcode) 171 { 172 switch (v_opcode) { 173 case VIRTCHNL_OP_UNKNOWN: 174 return "VIRTCHNL_OP_UNKNOWN"; 175 case VIRTCHNL_OP_VERSION: 176 return "VIRTCHNL_OP_VERSION"; 177 case VIRTCHNL_OP_RESET_VF: 178 return "VIRTCHNL_OP_RESET_VF"; 179 case VIRTCHNL_OP_GET_VF_RESOURCES: 180 return "VIRTCHNL_OP_GET_VF_RESOURCES"; 181 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 182 return "VIRTCHNL_OP_CONFIG_TX_QUEUE"; 183 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 184 return "VIRTCHNL_OP_CONFIG_RX_QUEUE"; 185 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 186 return "VIRTCHNL_OP_CONFIG_VSI_QUEUES"; 187 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 188 return "VIRTCHNL_OP_CONFIG_IRQ_MAP"; 189 case VIRTCHNL_OP_ENABLE_QUEUES: 190 return "VIRTCHNL_OP_ENABLE_QUEUES"; 191 case VIRTCHNL_OP_DISABLE_QUEUES: 192 return "VIRTCHNL_OP_DISABLE_QUEUES"; 193 case VIRTCHNL_OP_ADD_ETH_ADDR: 194 return "VIRTCHNL_OP_ADD_ETH_ADDR"; 195 case VIRTCHNL_OP_DEL_ETH_ADDR: 196 return "VIRTCHNL_OP_DEL_ETH_ADDR"; 197 case VIRTCHNL_OP_ADD_VLAN: 198 return "VIRTCHNL_OP_ADD_VLAN"; 199 case VIRTCHNL_OP_DEL_VLAN: 200 return "VIRTCHNL_OP_DEL_VLAN"; 201 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 202 return "VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE"; 203 case VIRTCHNL_OP_GET_STATS: 204 return "VIRTCHNL_OP_GET_STATS"; 205 case VIRTCHNL_OP_RSVD: 206 return "VIRTCHNL_OP_RSVD"; 207 case VIRTCHNL_OP_EVENT: 208 return "VIRTCHNL_OP_EVENT"; 209 case VIRTCHNL_OP_CONFIG_RSS_KEY: 210 return "VIRTCHNL_OP_CONFIG_RSS_KEY"; 211 case VIRTCHNL_OP_CONFIG_RSS_LUT: 212 return "VIRTCHNL_OP_CONFIG_RSS_LUT"; 213 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 214 return "VIRTCHNL_OP_GET_RSS_HENA_CAPS"; 215 case VIRTCHNL_OP_SET_RSS_HENA: 216 return "VIRTCHNL_OP_SET_RSS_HENA"; 217 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 218 return "VIRTCHNL_OP_ENABLE_VLAN_STRIPPING"; 219 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 220 return "VIRTCHNL_OP_DISABLE_VLAN_STRIPPING"; 221 case VIRTCHNL_OP_REQUEST_QUEUES: 222 return "VIRTCHNL_OP_REQUEST_QUEUES"; 223 case VIRTCHNL_OP_ENABLE_CHANNELS: 224 return "VIRTCHNL_OP_ENABLE_CHANNELS"; 225 case VIRTCHNL_OP_DISABLE_CHANNELS: 226 return "VIRTCHNL_OP_DISABLE_CHANNELS"; 227 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 228 return "VIRTCHNL_OP_ADD_CLOUD_FILTER"; 229 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 230 return "VIRTCHNL_OP_DEL_CLOUD_FILTER"; 231 case VIRTCHNL_OP_GET_MAX_RSS_QREGION: 232 return "VIRTCHNL_OP_GET_MAX_RSS_QREGION"; 233 case VIRTCHNL_OP_ENABLE_QUEUES_V2: 234 return "VIRTCHNL_OP_ENABLE_QUEUES_V2"; 235 case VIRTCHNL_OP_DISABLE_QUEUES_V2: 236 return "VIRTCHNL_OP_DISABLE_QUEUES_V2"; 237 case VIRTCHNL_OP_MAP_QUEUE_VECTOR: 238 return "VIRTCHNL_OP_MAP_QUEUE_VECTOR"; 239 case VIRTCHNL_OP_MAX: 240 return "VIRTCHNL_OP_MAX"; 241 default: 242 return "Unsupported (update virtchnl.h)"; 243 } 244 } 245 246 /* These macros are used to generate compilation errors if a structure/union 247 * is not exactly the correct length. It gives a divide by zero error if the 248 * structure/union is not of the correct size, otherwise it creates an enum 249 * that is never used. 250 */ 251 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ 252 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } 253 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \ 254 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) } 255 256 /* Virtual channel message descriptor. This overlays the admin queue 257 * descriptor. All other data is passed in external buffers. 258 */ 259 260 struct virtchnl_msg { 261 u8 pad[8]; /* AQ flags/opcode/len/retval fields */ 262 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */ 263 enum virtchnl_status_code v_retval; /* ditto for desc->retval */ 264 u32 vfid; /* used by PF when sending to VF */ 265 }; 266 267 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg); 268 269 /* Message descriptions and data structures. */ 270 271 /* VIRTCHNL_OP_VERSION 272 * VF posts its version number to the PF. PF responds with its version number 273 * in the same format, along with a return code. 274 * Reply from PF has its major/minor versions also in param0 and param1. 275 * If there is a major version mismatch, then the VF cannot operate. 276 * If there is a minor version mismatch, then the VF can operate but should 277 * add a warning to the system log. 278 * 279 * This enum element MUST always be specified as == 1, regardless of other 280 * changes in the API. The PF must always respond to this message without 281 * error regardless of version mismatch. 282 */ 283 #define VIRTCHNL_VERSION_MAJOR 1 284 #define VIRTCHNL_VERSION_MINOR 1 285 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0 286 287 struct virtchnl_version_info { 288 u32 major; 289 u32 minor; 290 }; 291 292 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info); 293 294 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) 295 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) 296 297 /* VIRTCHNL_OP_RESET_VF 298 * VF sends this request to PF with no parameters 299 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register 300 * until reset completion is indicated. The admin queue must be reinitialized 301 * after this operation. 302 * 303 * When reset is complete, PF must ensure that all queues in all VSIs associated 304 * with the VF are stopped, all queue configurations in the HMC are set to 0, 305 * and all MAC and VLAN filters (except the default MAC address) on all VSIs 306 * are cleared. 307 */ 308 309 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV 310 * vsi_type should always be 6 for backward compatibility. Add other fields 311 * as needed. 312 */ 313 enum virtchnl_vsi_type { 314 VIRTCHNL_VSI_TYPE_INVALID = 0, 315 VIRTCHNL_VSI_SRIOV = 6, 316 }; 317 318 /* VIRTCHNL_OP_GET_VF_RESOURCES 319 * Version 1.0 VF sends this request to PF with no parameters 320 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities 321 * PF responds with an indirect message containing 322 * virtchnl_vf_resource and one or more 323 * virtchnl_vsi_resource structures. 324 */ 325 326 struct virtchnl_vsi_resource { 327 u16 vsi_id; 328 u16 num_queue_pairs; 329 enum virtchnl_vsi_type vsi_type; 330 u16 qset_handle; 331 u8 default_mac_addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 332 }; 333 334 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource); 335 336 /* VF capability flags 337 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including 338 * TX/RX Checksum offloading and TSO for non-tunnelled packets. 339 */ 340 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001 341 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002 342 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004 343 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008 344 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010 345 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020 346 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040 347 #define VIRTCHNL_VF_OFFLOAD_CRC 0x00000080 348 /* 0X00000100 is reserved */ 349 #define VIRTCHNL_VF_LARGE_NUM_QPAIRS 0x00000200 350 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000 351 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000 352 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000 353 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000 354 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000 355 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000 356 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000 357 #define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000 358 #define VIRTCHNL_VF_OFFLOAD_ADQ_V2 0X01000000 359 #define VIRTCHNL_VF_OFFLOAD_USO 0X02000000 360 /* 0x04000000 is reserved */ 361 /* 0X08000000 and 0X10000000 are reserved */ 362 /* 0X20000000 is reserved */ 363 /* 0X40000000 is reserved */ 364 365 /* Define below the capability flags that are not offloads */ 366 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080 367 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \ 368 VIRTCHNL_VF_OFFLOAD_VLAN | \ 369 VIRTCHNL_VF_OFFLOAD_RSS_PF) 370 371 struct virtchnl_vf_resource { 372 u16 num_vsis; 373 u16 num_queue_pairs; 374 u16 max_vectors; 375 u16 max_mtu; 376 377 u32 vf_cap_flags; 378 u32 rss_key_size; 379 u32 rss_lut_size; 380 381 struct virtchnl_vsi_resource vsi_res[1]; 382 }; 383 384 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource); 385 386 /* VIRTCHNL_OP_CONFIG_TX_QUEUE 387 * VF sends this message to set up parameters for one TX queue. 388 * External data buffer contains one instance of virtchnl_txq_info. 389 * PF configures requested queue and returns a status code. 390 */ 391 392 /* Tx queue config info */ 393 struct virtchnl_txq_info { 394 u16 vsi_id; 395 u16 queue_id; 396 u16 ring_len; /* number of descriptors, multiple of 8 */ 397 u16 headwb_enabled; /* deprecated with AVF 1.0 */ 398 u64 dma_ring_addr; 399 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ 400 }; 401 402 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info); 403 404 /* VIRTCHNL_OP_CONFIG_RX_QUEUE 405 * VF sends this message to set up parameters for one RX queue. 406 * External data buffer contains one instance of virtchnl_rxq_info. 407 * PF configures requested queue and returns a status code. The 408 * crc_disable flag disables CRC stripping on the VF. Setting 409 * the crc_disable flag to 1 will disable CRC stripping for each 410 * queue in the VF where the flag is set. The VIRTCHNL_VF_OFFLOAD_CRC 411 * offload must have been set prior to sending this info or the PF 412 * will ignore the request. This flag should be set the same for 413 * all of the queues for a VF. 414 */ 415 416 /* Rx queue config info */ 417 struct virtchnl_rxq_info { 418 u16 vsi_id; 419 u16 queue_id; 420 u32 ring_len; /* number of descriptors, multiple of 32 */ 421 u16 hdr_size; 422 u16 splithdr_enabled; /* deprecated with AVF 1.0 */ 423 u32 databuffer_size; 424 u32 max_pkt_size; 425 u8 crc_disable; 426 u8 pad1[3]; 427 u64 dma_ring_addr; 428 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */ 429 u32 pad2; 430 }; 431 432 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info); 433 434 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES 435 * VF sends this message to set parameters for active TX and RX queues 436 * associated with the specified VSI. 437 * PF configures queues and returns status. 438 * If the number of queues specified is greater than the number of queues 439 * associated with the VSI, an error is returned and no queues are configured. 440 * NOTE: The VF is not required to configure all queues in a single request. 441 * It may send multiple messages. PF drivers must correctly handle all VF 442 * requests. 443 */ 444 struct virtchnl_queue_pair_info { 445 /* NOTE: vsi_id and queue_id should be identical for both queues. */ 446 struct virtchnl_txq_info txq; 447 struct virtchnl_rxq_info rxq; 448 }; 449 450 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); 451 452 struct virtchnl_vsi_queue_config_info { 453 u16 vsi_id; 454 u16 num_queue_pairs; 455 u32 pad; 456 struct virtchnl_queue_pair_info qpair[1]; 457 }; 458 459 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info); 460 461 /* VIRTCHNL_OP_REQUEST_QUEUES 462 * VF sends this message to request the PF to allocate additional queues to 463 * this VF. Each VF gets a guaranteed number of queues on init but asking for 464 * additional queues must be negotiated. This is a best effort request as it 465 * is possible the PF does not have enough queues left to support the request. 466 * If the PF cannot support the number requested it will respond with the 467 * maximum number it is able to support. If the request is successful, PF will 468 * then reset the VF to institute required changes. 469 */ 470 471 /* VF resource request */ 472 struct virtchnl_vf_res_request { 473 u16 num_queue_pairs; 474 }; 475 476 /* VIRTCHNL_OP_CONFIG_IRQ_MAP 477 * VF uses this message to map vectors to queues. 478 * The rxq_map and txq_map fields are bitmaps used to indicate which queues 479 * are to be associated with the specified vector. 480 * The "other" causes are always mapped to vector 0. The VF may not request 481 * that vector 0 be used for traffic. 482 * PF configures interrupt mapping and returns status. 483 * NOTE: due to hardware requirements, all active queues (both TX and RX) 484 * should be mapped to interrupts, even if the driver intends to operate 485 * only in polling mode. In this case the interrupt may be disabled, but 486 * the ITR timer will still run to trigger writebacks. 487 */ 488 struct virtchnl_vector_map { 489 u16 vsi_id; 490 u16 vector_id; 491 u16 rxq_map; 492 u16 txq_map; 493 u16 rxitr_idx; 494 u16 txitr_idx; 495 }; 496 497 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); 498 499 struct virtchnl_irq_map_info { 500 u16 num_vectors; 501 struct virtchnl_vector_map vecmap[1]; 502 }; 503 504 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info); 505 506 /* VIRTCHNL_OP_ENABLE_QUEUES 507 * VIRTCHNL_OP_DISABLE_QUEUES 508 * VF sends these message to enable or disable TX/RX queue pairs. 509 * The queues fields are bitmaps indicating which queues to act upon. 510 * (Currently, we only support 16 queues per VF, but we make the field 511 * u32 to allow for expansion.) 512 * PF performs requested action and returns status. 513 * NOTE: The VF is not required to enable/disable all queues in a single 514 * request. It may send multiple messages. 515 * PF drivers must correctly handle all VF requests. 516 */ 517 struct virtchnl_queue_select { 518 u16 vsi_id; 519 u16 pad; 520 u32 rx_queues; 521 u32 tx_queues; 522 }; 523 524 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select); 525 526 /* VIRTCHNL_OP_GET_MAX_RSS_QREGION 527 * 528 * if VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 529 * then this op must be supported. 530 * 531 * VF sends this message in order to query the max RSS queue region 532 * size supported by PF, when VIRTCHNL_VF_LARGE_NUM_QPAIRS is enabled. 533 * This information should be used when configuring the RSS LUT and/or 534 * configuring queue region based filters. 535 * 536 * The maximum RSS queue region is 2^qregion_width. So, a qregion_width 537 * of 6 would inform the VF that the PF supports a maximum RSS queue region 538 * of 64. 539 * 540 * A queue region represents a range of queues that can be used to configure 541 * a RSS LUT. For example, if a VF is given 64 queues, but only a max queue 542 * region size of 16 (i.e. 2^qregion_width = 16) then it will only be able 543 * to configure the RSS LUT with queue indices from 0 to 15. However, other 544 * filters can be used to direct packets to queues >15 via specifying a queue 545 * base/offset and queue region width. 546 */ 547 struct virtchnl_max_rss_qregion { 548 u16 vport_id; 549 u16 qregion_width; 550 u8 pad[4]; 551 }; 552 553 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_max_rss_qregion); 554 555 /* VIRTCHNL_OP_ADD_ETH_ADDR 556 * VF sends this message in order to add one or more unicast or multicast 557 * address filters for the specified VSI. 558 * PF adds the filters and returns status. 559 */ 560 561 /* VIRTCHNL_OP_DEL_ETH_ADDR 562 * VF sends this message in order to remove one or more unicast or multicast 563 * filters for the specified VSI. 564 * PF removes the filters and returns status. 565 */ 566 567 /* VIRTCHNL_ETHER_ADDR_LEGACY 568 * Prior to adding the @type member to virtchnl_ether_addr, there were 2 pad 569 * bytes. Moving forward all VF drivers should not set type to 570 * VIRTCHNL_ETHER_ADDR_LEGACY. This is only here to not break previous/legacy 571 * behavior. The control plane function (i.e. PF) can use a best effort method 572 * of tracking the primary/device unicast in this case, but there is no 573 * guarantee and functionality depends on the implementation of the PF. 574 */ 575 576 /* VIRTCHNL_ETHER_ADDR_PRIMARY 577 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_PRIMARY for the 578 * primary/device unicast MAC address filter for VIRTCHNL_OP_ADD_ETH_ADDR and 579 * VIRTCHNL_OP_DEL_ETH_ADDR. This allows for the underlying control plane 580 * function (i.e. PF) to accurately track and use this MAC address for 581 * displaying on the host and for VM/function reset. 582 */ 583 584 /* VIRTCHNL_ETHER_ADDR_EXTRA 585 * All VF drivers should set @type to VIRTCHNL_ETHER_ADDR_EXTRA for any extra 586 * unicast and/or multicast filters that are being added/deleted via 587 * VIRTCHNL_OP_DEL_ETH_ADDR/VIRTCHNL_OP_ADD_ETH_ADDR respectively. 588 */ 589 struct virtchnl_ether_addr { 590 u8 addr[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 591 u8 type; 592 #define VIRTCHNL_ETHER_ADDR_LEGACY 0 593 #define VIRTCHNL_ETHER_ADDR_PRIMARY 1 594 #define VIRTCHNL_ETHER_ADDR_EXTRA 2 595 #define VIRTCHNL_ETHER_ADDR_TYPE_MASK 3 /* first two bits of type are valid */ 596 u8 pad; 597 }; 598 599 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); 600 601 struct virtchnl_ether_addr_list { 602 u16 vsi_id; 603 u16 num_elements; 604 struct virtchnl_ether_addr list[1]; 605 }; 606 607 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list); 608 609 /* VIRTCHNL_OP_ADD_VLAN 610 * VF sends this message to add one or more VLAN tag filters for receives. 611 * PF adds the filters and returns status. 612 * If a port VLAN is configured by the PF, this operation will return an 613 * error to the VF. 614 */ 615 616 /* VIRTCHNL_OP_DEL_VLAN 617 * VF sends this message to remove one or more VLAN tag filters for receives. 618 * PF removes the filters and returns status. 619 * If a port VLAN is configured by the PF, this operation will return an 620 * error to the VF. 621 */ 622 623 struct virtchnl_vlan_filter_list { 624 u16 vsi_id; 625 u16 num_elements; 626 u16 vlan_id[1]; 627 }; 628 629 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); 630 631 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE 632 * VF sends VSI id and flags. 633 * PF returns status code in retval. 634 * Note: we assume that broadcast accept mode is always enabled. 635 */ 636 struct virtchnl_promisc_info { 637 u16 vsi_id; 638 u16 flags; 639 }; 640 641 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info); 642 643 #define FLAG_VF_UNICAST_PROMISC 0x00000001 644 #define FLAG_VF_MULTICAST_PROMISC 0x00000002 645 646 /* VIRTCHNL_OP_GET_STATS 647 * VF sends this message to request stats for the selected VSI. VF uses 648 * the virtchnl_queue_select struct to specify the VSI. The queue_id 649 * field is ignored by the PF. 650 * 651 * PF replies with struct virtchnl_eth_stats in an external buffer. 652 */ 653 654 struct virtchnl_eth_stats { 655 u64 rx_bytes; /* received bytes */ 656 u64 rx_unicast; /* received unicast pkts */ 657 u64 rx_multicast; /* received multicast pkts */ 658 u64 rx_broadcast; /* received broadcast pkts */ 659 u64 rx_discards; 660 u64 rx_unknown_protocol; 661 u64 tx_bytes; /* transmitted bytes */ 662 u64 tx_unicast; /* transmitted unicast pkts */ 663 u64 tx_multicast; /* transmitted multicast pkts */ 664 u64 tx_broadcast; /* transmitted broadcast pkts */ 665 u64 tx_discards; 666 u64 tx_errors; 667 }; 668 669 /* VIRTCHNL_OP_CONFIG_RSS_KEY 670 * VIRTCHNL_OP_CONFIG_RSS_LUT 671 * VF sends these messages to configure RSS. Only supported if both PF 672 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during 673 * configuration negotiation. If this is the case, then the RSS fields in 674 * the VF resource struct are valid. 675 * Both the key and LUT are initialized to 0 by the PF, meaning that 676 * RSS is effectively disabled until set up by the VF. 677 */ 678 struct virtchnl_rss_key { 679 u16 vsi_id; 680 u16 key_len; 681 u8 key[1]; /* RSS hash key, packed bytes */ 682 }; 683 684 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); 685 686 struct virtchnl_rss_lut { 687 u16 vsi_id; 688 u16 lut_entries; 689 u8 lut[1]; /* RSS lookup table */ 690 }; 691 692 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut); 693 694 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS 695 * VIRTCHNL_OP_SET_RSS_HENA 696 * VF sends these messages to get and set the hash filter enable bits for RSS. 697 * By default, the PF sets these to all possible traffic types that the 698 * hardware supports. The VF can query this value if it wants to change the 699 * traffic types that are hashed by the hardware. 700 */ 701 struct virtchnl_rss_hena { 702 u64 hena; 703 }; 704 705 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena); 706 707 /* This is used by PF driver to enforce how many channels can be supported. 708 * When ADQ_V2 capability is negotiated, it will allow 16 channels otherwise 709 * PF driver will allow only max 4 channels 710 */ 711 #define VIRTCHNL_MAX_ADQ_CHANNELS 4 712 #define VIRTCHNL_MAX_ADQ_V2_CHANNELS 16 713 714 /* VIRTCHNL_OP_ENABLE_CHANNELS 715 * VIRTCHNL_OP_DISABLE_CHANNELS 716 * VF sends these messages to enable or disable channels based on 717 * the user specified queue count and queue offset for each traffic class. 718 * This struct encompasses all the information that the PF needs from 719 * VF to create a channel. 720 */ 721 struct virtchnl_channel_info { 722 u16 count; /* number of queues in a channel */ 723 u16 offset; /* queues in a channel start from 'offset' */ 724 u32 pad; 725 u64 max_tx_rate; 726 }; 727 728 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info); 729 730 struct virtchnl_tc_info { 731 u32 num_tc; 732 u32 pad; 733 struct virtchnl_channel_info list[1]; 734 }; 735 736 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info); 737 738 /* VIRTCHNL_ADD_CLOUD_FILTER 739 * VIRTCHNL_DEL_CLOUD_FILTER 740 * VF sends these messages to add or delete a cloud filter based on the 741 * user specified match and action filters. These structures encompass 742 * all the information that the PF needs from the VF to add/delete a 743 * cloud filter. 744 */ 745 746 struct virtchnl_l4_spec { 747 u8 src_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 748 u8 dst_mac[VIRTCHNL_ETH_LENGTH_OF_ADDRESS]; 749 /* vlan_prio is part of this 16 bit field even from OS perspective 750 * vlan_id:12 is actual vlan_id, then vlanid:bit14..12 is vlan_prio 751 * in future, when decided to offload vlan_prio, pass that information 752 * as part of the "vlan_id" field, Bit14..12 753 */ 754 __be16 vlan_id; 755 __be16 pad; /* reserved for future use */ 756 __be32 src_ip[4]; 757 __be32 dst_ip[4]; 758 __be16 src_port; 759 __be16 dst_port; 760 }; 761 762 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec); 763 764 union virtchnl_flow_spec { 765 struct virtchnl_l4_spec tcp_spec; 766 u8 buffer[128]; /* reserved for future use */ 767 }; 768 769 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec); 770 771 enum virtchnl_action { 772 /* action types */ 773 VIRTCHNL_ACTION_DROP = 0, 774 VIRTCHNL_ACTION_TC_REDIRECT, 775 VIRTCHNL_ACTION_PASSTHRU, 776 VIRTCHNL_ACTION_QUEUE, 777 VIRTCHNL_ACTION_Q_REGION, 778 VIRTCHNL_ACTION_MARK, 779 VIRTCHNL_ACTION_COUNT, 780 }; 781 782 enum virtchnl_flow_type { 783 /* flow types */ 784 VIRTCHNL_TCP_V4_FLOW = 0, 785 VIRTCHNL_TCP_V6_FLOW, 786 VIRTCHNL_UDP_V4_FLOW, 787 VIRTCHNL_UDP_V6_FLOW, 788 }; 789 790 struct virtchnl_filter { 791 union virtchnl_flow_spec data; 792 union virtchnl_flow_spec mask; 793 enum virtchnl_flow_type flow_type; 794 enum virtchnl_action action; 795 u32 action_meta; 796 u8 field_flags; 797 }; 798 799 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter); 800 801 /* VIRTCHNL_OP_EVENT 802 * PF sends this message to inform the VF driver of events that may affect it. 803 * No direct response is expected from the VF, though it may generate other 804 * messages in response to this one. 805 */ 806 enum virtchnl_event_codes { 807 VIRTCHNL_EVENT_UNKNOWN = 0, 808 VIRTCHNL_EVENT_LINK_CHANGE, 809 VIRTCHNL_EVENT_RESET_IMPENDING, 810 VIRTCHNL_EVENT_PF_DRIVER_CLOSE, 811 }; 812 813 #define PF_EVENT_SEVERITY_INFO 0 814 #define PF_EVENT_SEVERITY_ATTENTION 1 815 #define PF_EVENT_SEVERITY_ACTION_REQUIRED 2 816 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255 817 818 struct virtchnl_pf_event { 819 enum virtchnl_event_codes event; 820 union { 821 /* If the PF driver does not support the new speed reporting 822 * capabilities then use link_event else use link_event_adv to 823 * get the speed and link information. The ability to understand 824 * new speeds is indicated by setting the capability flag 825 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter 826 * in virtchnl_vf_resource struct and can be used to determine 827 * which link event struct to use below. 828 */ 829 struct { 830 enum virtchnl_link_speed link_speed; 831 u8 link_status; 832 } link_event; 833 struct { 834 /* link_speed provided in Mbps */ 835 u32 link_speed; 836 u8 link_status; 837 } link_event_adv; 838 } event_data; 839 840 int severity; 841 }; 842 843 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); 844 845 /* VF reset states - these are written into the RSTAT register: 846 * VFGEN_RSTAT on the VF 847 * When the PF initiates a reset, it writes 0 848 * When the reset is complete, it writes 1 849 * When the PF detects that the VF has recovered, it writes 2 850 * VF checks this register periodically to determine if a reset has occurred, 851 * then polls it to know when the reset is complete. 852 * If either the PF or VF reads the register while the hardware 853 * is in a reset state, it will return DEADBEEF, which, when masked 854 * will result in 3. 855 */ 856 enum virtchnl_vfr_states { 857 VIRTCHNL_VFR_INPROGRESS = 0, 858 VIRTCHNL_VFR_COMPLETED, 859 VIRTCHNL_VFR_VFACTIVE, 860 }; 861 862 /* TX and RX queue types are valid in legacy as well as split queue models. 863 * With Split Queue model, 2 additional types are introduced - TX_COMPLETION 864 * and RX_BUFFER. In split queue model, RX corresponds to the queue where HW 865 * posts completions. 866 */ 867 enum virtchnl_queue_type { 868 VIRTCHNL_QUEUE_TYPE_TX = 0, 869 VIRTCHNL_QUEUE_TYPE_RX = 1, 870 VIRTCHNL_QUEUE_TYPE_TX_COMPLETION = 2, 871 VIRTCHNL_QUEUE_TYPE_RX_BUFFER = 3, 872 VIRTCHNL_QUEUE_TYPE_CONFIG_TX = 4, 873 VIRTCHNL_QUEUE_TYPE_CONFIG_RX = 5 874 }; 875 876 /* structure to specify a chunk of contiguous queues */ 877 struct virtchnl_queue_chunk { 878 enum virtchnl_queue_type type; 879 u16 start_queue_id; 880 u16 num_queues; 881 }; 882 883 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_queue_chunk); 884 885 /* structure to specify several chunks of contiguous queues */ 886 struct virtchnl_queue_chunks { 887 u16 num_chunks; 888 u16 rsvd; 889 struct virtchnl_queue_chunk chunks[1]; 890 }; 891 892 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_chunks); 893 894 /* VIRTCHNL_OP_ENABLE_QUEUES_V2 895 * VIRTCHNL_OP_DISABLE_QUEUES_V2 896 * VIRTCHNL_OP_DEL_QUEUES 897 * 898 * If VIRTCHNL_CAP_EXT_FEATURES was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 899 * then all of these ops are available. 900 * 901 * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 902 * then VIRTCHNL_OP_ENABLE_QUEUES_V2 and VIRTCHNL_OP_DISABLE_QUEUES_V2 are 903 * available. 904 * 905 * PF sends these messages to enable, disable or delete queues specified in 906 * chunks. PF sends virtchnl_del_ena_dis_queues struct to specify the queues 907 * to be enabled/disabled/deleted. Also applicable to single queue RX or 908 * TX. CP performs requested action and returns status. 909 */ 910 struct virtchnl_del_ena_dis_queues { 911 u16 vport_id; 912 u16 pad; 913 struct virtchnl_queue_chunks chunks; 914 }; 915 916 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_del_ena_dis_queues); 917 918 /* Virtchannel interrupt throttling rate index */ 919 enum virtchnl_itr_idx { 920 VIRTCHNL_ITR_IDX_0 = 0, 921 VIRTCHNL_ITR_IDX_1 = 1, 922 VIRTCHNL_ITR_IDX_NO_ITR = 3, 923 }; 924 925 /* Queue to vector mapping */ 926 struct virtchnl_queue_vector { 927 u16 queue_id; 928 u16 vector_id; 929 u8 pad[4]; 930 enum virtchnl_itr_idx itr_idx; 931 enum virtchnl_queue_type queue_type; 932 }; 933 934 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_queue_vector); 935 936 /* VIRTCHNL_OP_MAP_QUEUE_VECTOR 937 * VIRTCHNL_OP_UNMAP_QUEUE_VECTOR 938 * 939 * If VIRTCHNL_CAP_EXT_FEATURES was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 940 * then all of these ops are available. 941 * 942 * If VIRTCHNL_VF_LARGE_NUM_QPAIRS was negotiated in VIRTCHNL_OP_GET_VF_RESOURCES 943 * then only VIRTCHNL_OP_MAP_QUEUE_VECTOR is available. 944 * 945 * PF sends this message to map or unmap queues to vectors and ITR index 946 * registers. External data buffer contains virtchnl_queue_vector_maps structure 947 * that contains num_qv_maps of virtchnl_queue_vector structures. 948 * CP maps the requested queue vector maps after validating the queue and vector 949 * ids and returns a status code. 950 */ 951 struct virtchnl_queue_vector_maps { 952 u16 vport_id; 953 u16 num_qv_maps; 954 u8 pad[4]; 955 struct virtchnl_queue_vector qv_maps[1]; 956 }; 957 958 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_queue_vector_maps); 959 960 /* Since VF messages are limited by u16 size, precalculate the maximum possible 961 * values of nested elements in virtchnl structures that virtual channel can 962 * possibly handle in a single message. 963 */ 964 enum virtchnl_vector_limits { 965 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX = 966 ((u16)(~0) - sizeof(struct virtchnl_vsi_queue_config_info)) / 967 sizeof(struct virtchnl_queue_pair_info), 968 969 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX = 970 ((u16)(~0) - sizeof(struct virtchnl_irq_map_info)) / 971 sizeof(struct virtchnl_vector_map), 972 973 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX = 974 ((u16)(~0) - sizeof(struct virtchnl_ether_addr_list)) / 975 sizeof(struct virtchnl_ether_addr), 976 977 VIRTCHNL_OP_ADD_DEL_VLAN_MAX = 978 ((u16)(~0) - sizeof(struct virtchnl_vlan_filter_list)) / 979 sizeof(u16), 980 981 VIRTCHNL_OP_ENABLE_CHANNELS_MAX = 982 ((u16)(~0) - sizeof(struct virtchnl_tc_info)) / 983 sizeof(struct virtchnl_channel_info), 984 985 VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX = 986 ((u16)(~0) - sizeof(struct virtchnl_del_ena_dis_queues)) / 987 sizeof(struct virtchnl_queue_chunk), 988 989 VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX = 990 ((u16)(~0) - sizeof(struct virtchnl_queue_vector_maps)) / 991 sizeof(struct virtchnl_queue_vector), 992 }; 993 994 /** 995 * virtchnl_vc_validate_vf_msg 996 * @ver: Virtchnl version info 997 * @v_opcode: Opcode for the message 998 * @msg: pointer to the msg buffer 999 * @msglen: msg length 1000 * 1001 * validate msg format against struct for each opcode 1002 */ 1003 static inline int 1004 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, 1005 u8 *msg, u16 msglen) 1006 { 1007 bool err_msg_format = false; 1008 u32 valid_len = 0; 1009 1010 /* Validate message length. */ 1011 switch (v_opcode) { 1012 case VIRTCHNL_OP_VERSION: 1013 valid_len = sizeof(struct virtchnl_version_info); 1014 break; 1015 case VIRTCHNL_OP_RESET_VF: 1016 break; 1017 case VIRTCHNL_OP_GET_VF_RESOURCES: 1018 if (VF_IS_V11(ver)) 1019 valid_len = sizeof(u32); 1020 break; 1021 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 1022 valid_len = sizeof(struct virtchnl_txq_info); 1023 break; 1024 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 1025 valid_len = sizeof(struct virtchnl_rxq_info); 1026 break; 1027 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 1028 valid_len = sizeof(struct virtchnl_vsi_queue_config_info); 1029 if (msglen >= valid_len) { 1030 struct virtchnl_vsi_queue_config_info *vqc = 1031 (struct virtchnl_vsi_queue_config_info *)msg; 1032 1033 if (vqc->num_queue_pairs == 0 || vqc->num_queue_pairs > 1034 VIRTCHNL_OP_CONFIG_VSI_QUEUES_MAX) { 1035 err_msg_format = true; 1036 break; 1037 } 1038 1039 valid_len += (vqc->num_queue_pairs * 1040 sizeof(struct 1041 virtchnl_queue_pair_info)); 1042 } 1043 break; 1044 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1045 valid_len = sizeof(struct virtchnl_irq_map_info); 1046 if (msglen >= valid_len) { 1047 struct virtchnl_irq_map_info *vimi = 1048 (struct virtchnl_irq_map_info *)msg; 1049 1050 if (vimi->num_vectors == 0 || vimi->num_vectors > 1051 VIRTCHNL_OP_CONFIG_IRQ_MAP_MAX) { 1052 err_msg_format = true; 1053 break; 1054 } 1055 1056 valid_len += (vimi->num_vectors * 1057 sizeof(struct virtchnl_vector_map)); 1058 } 1059 break; 1060 case VIRTCHNL_OP_ENABLE_QUEUES: 1061 case VIRTCHNL_OP_DISABLE_QUEUES: 1062 valid_len = sizeof(struct virtchnl_queue_select); 1063 break; 1064 case VIRTCHNL_OP_GET_MAX_RSS_QREGION: 1065 break; 1066 case VIRTCHNL_OP_ADD_ETH_ADDR: 1067 case VIRTCHNL_OP_DEL_ETH_ADDR: 1068 valid_len = sizeof(struct virtchnl_ether_addr_list); 1069 if (msglen >= valid_len) { 1070 struct virtchnl_ether_addr_list *veal = 1071 (struct virtchnl_ether_addr_list *)msg; 1072 1073 if (veal->num_elements == 0 || veal->num_elements > 1074 VIRTCHNL_OP_ADD_DEL_ETH_ADDR_MAX) { 1075 err_msg_format = true; 1076 break; 1077 } 1078 1079 valid_len += veal->num_elements * 1080 sizeof(struct virtchnl_ether_addr); 1081 } 1082 break; 1083 case VIRTCHNL_OP_ADD_VLAN: 1084 case VIRTCHNL_OP_DEL_VLAN: 1085 valid_len = sizeof(struct virtchnl_vlan_filter_list); 1086 if (msglen >= valid_len) { 1087 struct virtchnl_vlan_filter_list *vfl = 1088 (struct virtchnl_vlan_filter_list *)msg; 1089 1090 if (vfl->num_elements == 0 || vfl->num_elements > 1091 VIRTCHNL_OP_ADD_DEL_VLAN_MAX) { 1092 err_msg_format = true; 1093 break; 1094 } 1095 1096 valid_len += vfl->num_elements * sizeof(u16); 1097 } 1098 break; 1099 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 1100 valid_len = sizeof(struct virtchnl_promisc_info); 1101 break; 1102 case VIRTCHNL_OP_GET_STATS: 1103 valid_len = sizeof(struct virtchnl_queue_select); 1104 break; 1105 case VIRTCHNL_OP_CONFIG_RSS_KEY: 1106 valid_len = sizeof(struct virtchnl_rss_key); 1107 if (msglen >= valid_len) { 1108 struct virtchnl_rss_key *vrk = 1109 (struct virtchnl_rss_key *)msg; 1110 1111 if (vrk->key_len == 0) { 1112 /* zero length is allowed as input */ 1113 break; 1114 } 1115 1116 valid_len += vrk->key_len - 1; 1117 } 1118 break; 1119 case VIRTCHNL_OP_CONFIG_RSS_LUT: 1120 valid_len = sizeof(struct virtchnl_rss_lut); 1121 if (msglen >= valid_len) { 1122 struct virtchnl_rss_lut *vrl = 1123 (struct virtchnl_rss_lut *)msg; 1124 1125 if (vrl->lut_entries == 0) { 1126 /* zero entries is allowed as input */ 1127 break; 1128 } 1129 1130 valid_len += vrl->lut_entries - 1; 1131 } 1132 break; 1133 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 1134 break; 1135 case VIRTCHNL_OP_SET_RSS_HENA: 1136 valid_len = sizeof(struct virtchnl_rss_hena); 1137 break; 1138 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 1139 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 1140 break; 1141 case VIRTCHNL_OP_REQUEST_QUEUES: 1142 valid_len = sizeof(struct virtchnl_vf_res_request); 1143 break; 1144 case VIRTCHNL_OP_ENABLE_CHANNELS: 1145 valid_len = sizeof(struct virtchnl_tc_info); 1146 if (msglen >= valid_len) { 1147 struct virtchnl_tc_info *vti = 1148 (struct virtchnl_tc_info *)msg; 1149 1150 if (vti->num_tc == 0 || vti->num_tc > 1151 VIRTCHNL_OP_ENABLE_CHANNELS_MAX) { 1152 err_msg_format = true; 1153 break; 1154 } 1155 1156 valid_len += (vti->num_tc - 1) * 1157 sizeof(struct virtchnl_channel_info); 1158 } 1159 break; 1160 case VIRTCHNL_OP_DISABLE_CHANNELS: 1161 break; 1162 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 1163 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 1164 valid_len = sizeof(struct virtchnl_filter); 1165 break; 1166 case VIRTCHNL_OP_ENABLE_QUEUES_V2: 1167 case VIRTCHNL_OP_DISABLE_QUEUES_V2: 1168 valid_len = sizeof(struct virtchnl_del_ena_dis_queues); 1169 if (msglen >= valid_len) { 1170 struct virtchnl_del_ena_dis_queues *qs = 1171 (struct virtchnl_del_ena_dis_queues *)msg; 1172 if (qs->chunks.num_chunks == 0 || 1173 qs->chunks.num_chunks > VIRTCHNL_OP_ENABLE_DISABLE_DEL_QUEUES_V2_MAX) { 1174 err_msg_format = true; 1175 break; 1176 } 1177 valid_len += (qs->chunks.num_chunks - 1) * 1178 sizeof(struct virtchnl_queue_chunk); 1179 } 1180 break; 1181 case VIRTCHNL_OP_MAP_QUEUE_VECTOR: 1182 valid_len = sizeof(struct virtchnl_queue_vector_maps); 1183 if (msglen >= valid_len) { 1184 struct virtchnl_queue_vector_maps *v_qp = 1185 (struct virtchnl_queue_vector_maps *)msg; 1186 if (v_qp->num_qv_maps == 0 || 1187 v_qp->num_qv_maps > VIRTCHNL_OP_MAP_UNMAP_QUEUE_VECTOR_MAX) { 1188 err_msg_format = true; 1189 break; 1190 } 1191 valid_len += (v_qp->num_qv_maps - 1) * 1192 sizeof(struct virtchnl_queue_vector); 1193 } 1194 break; 1195 /* These are always errors coming from the VF. */ 1196 case VIRTCHNL_OP_EVENT: 1197 case VIRTCHNL_OP_UNKNOWN: 1198 default: 1199 return VIRTCHNL_STATUS_ERR_PARAM; 1200 } 1201 /* few more checks */ 1202 if (err_msg_format || valid_len != msglen) 1203 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH; 1204 1205 return 0; 1206 } 1207 #endif /* _VIRTCHNL_H_ */ 1208