1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /******************************************************************************* 3 * 4 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver 5 * Copyright(c) 2013 - 2014 Intel Corporation. 6 * 7 * Contact Information: 8 * e1000-devel Mailing List <[email protected]> 9 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 10 * 11 ******************************************************************************/ 12 13 #ifndef _VIRTCHNL_H_ 14 #define _VIRTCHNL_H_ 15 16 /* Description: 17 * This header file describes the VF-PF communication protocol used 18 * by the drivers for all devices starting from our 40G product line 19 * 20 * Admin queue buffer usage: 21 * desc->opcode is always aqc_opc_send_msg_to_pf 22 * flags, retval, datalen, and data addr are all used normally. 23 * The Firmware copies the cookie fields when sending messages between the 24 * PF and VF, but uses all other fields internally. Due to this limitation, 25 * we must send all messages as "indirect", i.e. using an external buffer. 26 * 27 * All the VSI indexes are relative to the VF. Each VF can have maximum of 28 * three VSIs. All the queue indexes are relative to the VSI. Each VF can 29 * have a maximum of sixteen queues for all of its VSIs. 30 * 31 * The PF is required to return a status code in v_retval for all messages 32 * except RESET_VF, which does not require any response. The return value 33 * is of status_code type, defined in the shared type.h. 34 * 35 * In general, VF driver initialization should roughly follow the order of 36 * these opcodes. The VF driver must first validate the API version of the 37 * PF driver, then request a reset, then get resources, then configure 38 * queues and interrupts. After these operations are complete, the VF 39 * driver may start its queues, optionally add MAC and VLAN filters, and 40 * process traffic. 41 */ 42 43 /* START GENERIC DEFINES 44 * Need to ensure the following enums and defines hold the same meaning and 45 * value in current and future projects 46 */ 47 48 /* Error Codes */ 49 enum virtchnl_status_code { 50 VIRTCHNL_STATUS_SUCCESS = 0, 51 VIRTCHNL_STATUS_ERR_PARAM = -5, 52 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18, 53 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38, 54 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39, 55 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40, 56 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53, 57 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64, 58 }; 59 60 /* Backward compatibility */ 61 #define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM 62 #define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED 63 64 #define VIRTCHNL_LINK_SPEED_2_5GB_SHIFT 0x0 65 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1 66 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2 67 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3 68 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4 69 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5 70 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6 71 #define VIRTCHNL_LINK_SPEED_5GB_SHIFT 0x7 72 73 enum virtchnl_link_speed { 74 VIRTCHNL_LINK_SPEED_UNKNOWN = 0, 75 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT), 76 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT), 77 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT), 78 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT), 79 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT), 80 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT), 81 VIRTCHNL_LINK_SPEED_2_5GB = BIT(VIRTCHNL_LINK_SPEED_2_5GB_SHIFT), 82 VIRTCHNL_LINK_SPEED_5GB = BIT(VIRTCHNL_LINK_SPEED_5GB_SHIFT), 83 }; 84 85 /* for hsplit_0 field of Rx HMC context */ 86 /* deprecated with AVF 1.0 */ 87 enum virtchnl_rx_hsplit { 88 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0, 89 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1, 90 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2, 91 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4, 92 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8, 93 }; 94 95 /* END GENERIC DEFINES */ 96 97 /* Opcodes for VF-PF communication. These are placed in the v_opcode field 98 * of the virtchnl_msg structure. 99 */ 100 enum virtchnl_ops { 101 /* The PF sends status change events to VFs using 102 * the VIRTCHNL_OP_EVENT opcode. 103 * VFs send requests to the PF using the other ops. 104 * Use of "advanced opcode" features must be negotiated as part of capabilities 105 * exchange and are not considered part of base mode feature set. 106 */ 107 VIRTCHNL_OP_UNKNOWN = 0, 108 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */ 109 VIRTCHNL_OP_RESET_VF = 2, 110 VIRTCHNL_OP_GET_VF_RESOURCES = 3, 111 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4, 112 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5, 113 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6, 114 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7, 115 VIRTCHNL_OP_ENABLE_QUEUES = 8, 116 VIRTCHNL_OP_DISABLE_QUEUES = 9, 117 VIRTCHNL_OP_ADD_ETH_ADDR = 10, 118 VIRTCHNL_OP_DEL_ETH_ADDR = 11, 119 VIRTCHNL_OP_ADD_VLAN = 12, 120 VIRTCHNL_OP_DEL_VLAN = 13, 121 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14, 122 VIRTCHNL_OP_GET_STATS = 15, 123 VIRTCHNL_OP_RSVD = 16, 124 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */ 125 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */ 126 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */ 127 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */ 128 VIRTCHNL_OP_CONFIG_RSS_KEY = 23, 129 VIRTCHNL_OP_CONFIG_RSS_LUT = 24, 130 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25, 131 VIRTCHNL_OP_SET_RSS_HENA = 26, 132 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27, 133 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28, 134 VIRTCHNL_OP_REQUEST_QUEUES = 29, 135 VIRTCHNL_OP_ENABLE_CHANNELS = 30, 136 VIRTCHNL_OP_DISABLE_CHANNELS = 31, 137 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32, 138 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33, 139 /* opcode 34 - 44 are reserved */ 140 VIRTCHNL_OP_ADD_RSS_CFG = 45, 141 VIRTCHNL_OP_DEL_RSS_CFG = 46, 142 VIRTCHNL_OP_ADD_FDIR_FILTER = 47, 143 VIRTCHNL_OP_DEL_FDIR_FILTER = 48, 144 VIRTCHNL_OP_MAX, 145 }; 146 147 /* These macros are used to generate compilation errors if a structure/union 148 * is not exactly the correct length. It gives a divide by zero error if the 149 * structure/union is not of the correct size, otherwise it creates an enum 150 * that is never used. 151 */ 152 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ 153 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } 154 #define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \ 155 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) } 156 157 /* Virtual channel message descriptor. This overlays the admin queue 158 * descriptor. All other data is passed in external buffers. 159 */ 160 161 struct virtchnl_msg { 162 u8 pad[8]; /* AQ flags/opcode/len/retval fields */ 163 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */ 164 enum virtchnl_status_code v_retval; /* ditto for desc->retval */ 165 u32 vfid; /* used by PF when sending to VF */ 166 }; 167 168 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg); 169 170 /* Message descriptions and data structures. */ 171 172 /* VIRTCHNL_OP_VERSION 173 * VF posts its version number to the PF. PF responds with its version number 174 * in the same format, along with a return code. 175 * Reply from PF has its major/minor versions also in param0 and param1. 176 * If there is a major version mismatch, then the VF cannot operate. 177 * If there is a minor version mismatch, then the VF can operate but should 178 * add a warning to the system log. 179 * 180 * This enum element MUST always be specified as == 1, regardless of other 181 * changes in the API. The PF must always respond to this message without 182 * error regardless of version mismatch. 183 */ 184 #define VIRTCHNL_VERSION_MAJOR 1 185 #define VIRTCHNL_VERSION_MINOR 1 186 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0 187 188 struct virtchnl_version_info { 189 u32 major; 190 u32 minor; 191 }; 192 193 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info); 194 195 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) 196 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) 197 198 /* VIRTCHNL_OP_RESET_VF 199 * VF sends this request to PF with no parameters 200 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register 201 * until reset completion is indicated. The admin queue must be reinitialized 202 * after this operation. 203 * 204 * When reset is complete, PF must ensure that all queues in all VSIs associated 205 * with the VF are stopped, all queue configurations in the HMC are set to 0, 206 * and all MAC and VLAN filters (except the default MAC address) on all VSIs 207 * are cleared. 208 */ 209 210 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV 211 * vsi_type should always be 6 for backward compatibility. Add other fields 212 * as needed. 213 */ 214 enum virtchnl_vsi_type { 215 VIRTCHNL_VSI_TYPE_INVALID = 0, 216 VIRTCHNL_VSI_SRIOV = 6, 217 }; 218 219 /* VIRTCHNL_OP_GET_VF_RESOURCES 220 * Version 1.0 VF sends this request to PF with no parameters 221 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities 222 * PF responds with an indirect message containing 223 * virtchnl_vf_resource and one or more 224 * virtchnl_vsi_resource structures. 225 */ 226 227 struct virtchnl_vsi_resource { 228 u16 vsi_id; 229 u16 num_queue_pairs; 230 enum virtchnl_vsi_type vsi_type; 231 u16 qset_handle; 232 u8 default_mac_addr[ETH_ALEN]; 233 }; 234 235 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource); 236 237 /* VF capability flags 238 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including 239 * TX/RX Checksum offloading and TSO for non-tunnelled packets. 240 */ 241 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001 242 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002 243 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004 244 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008 245 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010 246 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020 247 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040 248 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000 249 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000 250 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000 251 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000 252 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000 253 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000 254 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000 255 #define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000 256 #define VIRTCHNL_VF_OFFLOAD_USO 0X02000000 257 #define VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF 0X08000000 258 #define VIRTCHNL_VF_OFFLOAD_FDIR_PF 0X10000000 259 260 /* Define below the capability flags that are not offloads */ 261 #define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080 262 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \ 263 VIRTCHNL_VF_OFFLOAD_VLAN | \ 264 VIRTCHNL_VF_OFFLOAD_RSS_PF) 265 266 struct virtchnl_vf_resource { 267 u16 num_vsis; 268 u16 num_queue_pairs; 269 u16 max_vectors; 270 u16 max_mtu; 271 272 u32 vf_cap_flags; 273 u32 rss_key_size; 274 u32 rss_lut_size; 275 276 struct virtchnl_vsi_resource vsi_res[1]; 277 }; 278 279 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource); 280 281 /* VIRTCHNL_OP_CONFIG_TX_QUEUE 282 * VF sends this message to set up parameters for one TX queue. 283 * External data buffer contains one instance of virtchnl_txq_info. 284 * PF configures requested queue and returns a status code. 285 */ 286 287 /* Tx queue config info */ 288 struct virtchnl_txq_info { 289 u16 vsi_id; 290 u16 queue_id; 291 u16 ring_len; /* number of descriptors, multiple of 8 */ 292 u16 headwb_enabled; /* deprecated with AVF 1.0 */ 293 u64 dma_ring_addr; 294 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ 295 }; 296 297 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info); 298 299 /* VIRTCHNL_OP_CONFIG_RX_QUEUE 300 * VF sends this message to set up parameters for one RX queue. 301 * External data buffer contains one instance of virtchnl_rxq_info. 302 * PF configures requested queue and returns a status code. 303 */ 304 305 /* Rx queue config info */ 306 struct virtchnl_rxq_info { 307 u16 vsi_id; 308 u16 queue_id; 309 u32 ring_len; /* number of descriptors, multiple of 32 */ 310 u16 hdr_size; 311 u16 splithdr_enabled; /* deprecated with AVF 1.0 */ 312 u32 databuffer_size; 313 u32 max_pkt_size; 314 u32 pad1; 315 u64 dma_ring_addr; 316 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */ 317 u32 pad2; 318 }; 319 320 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info); 321 322 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES 323 * VF sends this message to set parameters for all active TX and RX queues 324 * associated with the specified VSI. 325 * PF configures queues and returns status. 326 * If the number of queues specified is greater than the number of queues 327 * associated with the VSI, an error is returned and no queues are configured. 328 */ 329 struct virtchnl_queue_pair_info { 330 /* NOTE: vsi_id and queue_id should be identical for both queues. */ 331 struct virtchnl_txq_info txq; 332 struct virtchnl_rxq_info rxq; 333 }; 334 335 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); 336 337 struct virtchnl_vsi_queue_config_info { 338 u16 vsi_id; 339 u16 num_queue_pairs; 340 u32 pad; 341 struct virtchnl_queue_pair_info qpair[1]; 342 }; 343 344 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info); 345 346 /* VIRTCHNL_OP_REQUEST_QUEUES 347 * VF sends this message to request the PF to allocate additional queues to 348 * this VF. Each VF gets a guaranteed number of queues on init but asking for 349 * additional queues must be negotiated. This is a best effort request as it 350 * is possible the PF does not have enough queues left to support the request. 351 * If the PF cannot support the number requested it will respond with the 352 * maximum number it is able to support. If the request is successful, PF will 353 * then reset the VF to institute required changes. 354 */ 355 356 /* VF resource request */ 357 struct virtchnl_vf_res_request { 358 u16 num_queue_pairs; 359 }; 360 361 /* VIRTCHNL_OP_CONFIG_IRQ_MAP 362 * VF uses this message to map vectors to queues. 363 * The rxq_map and txq_map fields are bitmaps used to indicate which queues 364 * are to be associated with the specified vector. 365 * The "other" causes are always mapped to vector 0. 366 * PF configures interrupt mapping and returns status. 367 */ 368 struct virtchnl_vector_map { 369 u16 vsi_id; 370 u16 vector_id; 371 u16 rxq_map; 372 u16 txq_map; 373 u16 rxitr_idx; 374 u16 txitr_idx; 375 }; 376 377 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); 378 379 struct virtchnl_irq_map_info { 380 u16 num_vectors; 381 struct virtchnl_vector_map vecmap[1]; 382 }; 383 384 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info); 385 386 /* VIRTCHNL_OP_ENABLE_QUEUES 387 * VIRTCHNL_OP_DISABLE_QUEUES 388 * VF sends these message to enable or disable TX/RX queue pairs. 389 * The queues fields are bitmaps indicating which queues to act upon. 390 * (Currently, we only support 16 queues per VF, but we make the field 391 * u32 to allow for expansion.) 392 * PF performs requested action and returns status. 393 */ 394 struct virtchnl_queue_select { 395 u16 vsi_id; 396 u16 pad; 397 u32 rx_queues; 398 u32 tx_queues; 399 }; 400 401 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select); 402 403 /* VIRTCHNL_OP_ADD_ETH_ADDR 404 * VF sends this message in order to add one or more unicast or multicast 405 * address filters for the specified VSI. 406 * PF adds the filters and returns status. 407 */ 408 409 /* VIRTCHNL_OP_DEL_ETH_ADDR 410 * VF sends this message in order to remove one or more unicast or multicast 411 * filters for the specified VSI. 412 * PF removes the filters and returns status. 413 */ 414 415 struct virtchnl_ether_addr { 416 u8 addr[ETH_ALEN]; 417 u8 pad[2]; 418 }; 419 420 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); 421 422 struct virtchnl_ether_addr_list { 423 u16 vsi_id; 424 u16 num_elements; 425 struct virtchnl_ether_addr list[1]; 426 }; 427 428 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list); 429 430 /* VIRTCHNL_OP_ADD_VLAN 431 * VF sends this message to add one or more VLAN tag filters for receives. 432 * PF adds the filters and returns status. 433 * If a port VLAN is configured by the PF, this operation will return an 434 * error to the VF. 435 */ 436 437 /* VIRTCHNL_OP_DEL_VLAN 438 * VF sends this message to remove one or more VLAN tag filters for receives. 439 * PF removes the filters and returns status. 440 * If a port VLAN is configured by the PF, this operation will return an 441 * error to the VF. 442 */ 443 444 struct virtchnl_vlan_filter_list { 445 u16 vsi_id; 446 u16 num_elements; 447 u16 vlan_id[1]; 448 }; 449 450 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); 451 452 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE 453 * VF sends VSI id and flags. 454 * PF returns status code in retval. 455 * Note: we assume that broadcast accept mode is always enabled. 456 */ 457 struct virtchnl_promisc_info { 458 u16 vsi_id; 459 u16 flags; 460 }; 461 462 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info); 463 464 #define FLAG_VF_UNICAST_PROMISC 0x00000001 465 #define FLAG_VF_MULTICAST_PROMISC 0x00000002 466 467 /* VIRTCHNL_OP_GET_STATS 468 * VF sends this message to request stats for the selected VSI. VF uses 469 * the virtchnl_queue_select struct to specify the VSI. The queue_id 470 * field is ignored by the PF. 471 * 472 * PF replies with struct eth_stats in an external buffer. 473 */ 474 475 /* VIRTCHNL_OP_CONFIG_RSS_KEY 476 * VIRTCHNL_OP_CONFIG_RSS_LUT 477 * VF sends these messages to configure RSS. Only supported if both PF 478 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during 479 * configuration negotiation. If this is the case, then the RSS fields in 480 * the VF resource struct are valid. 481 * Both the key and LUT are initialized to 0 by the PF, meaning that 482 * RSS is effectively disabled until set up by the VF. 483 */ 484 struct virtchnl_rss_key { 485 u16 vsi_id; 486 u16 key_len; 487 u8 key[1]; /* RSS hash key, packed bytes */ 488 }; 489 490 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); 491 492 struct virtchnl_rss_lut { 493 u16 vsi_id; 494 u16 lut_entries; 495 u8 lut[1]; /* RSS lookup table */ 496 }; 497 498 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut); 499 500 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS 501 * VIRTCHNL_OP_SET_RSS_HENA 502 * VF sends these messages to get and set the hash filter enable bits for RSS. 503 * By default, the PF sets these to all possible traffic types that the 504 * hardware supports. The VF can query this value if it wants to change the 505 * traffic types that are hashed by the hardware. 506 */ 507 struct virtchnl_rss_hena { 508 u64 hena; 509 }; 510 511 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena); 512 513 /* VIRTCHNL_OP_ENABLE_CHANNELS 514 * VIRTCHNL_OP_DISABLE_CHANNELS 515 * VF sends these messages to enable or disable channels based on 516 * the user specified queue count and queue offset for each traffic class. 517 * This struct encompasses all the information that the PF needs from 518 * VF to create a channel. 519 */ 520 struct virtchnl_channel_info { 521 u16 count; /* number of queues in a channel */ 522 u16 offset; /* queues in a channel start from 'offset' */ 523 u32 pad; 524 u64 max_tx_rate; 525 }; 526 527 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info); 528 529 struct virtchnl_tc_info { 530 u32 num_tc; 531 u32 pad; 532 struct virtchnl_channel_info list[1]; 533 }; 534 535 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info); 536 537 /* VIRTCHNL_ADD_CLOUD_FILTER 538 * VIRTCHNL_DEL_CLOUD_FILTER 539 * VF sends these messages to add or delete a cloud filter based on the 540 * user specified match and action filters. These structures encompass 541 * all the information that the PF needs from the VF to add/delete a 542 * cloud filter. 543 */ 544 545 struct virtchnl_l4_spec { 546 u8 src_mac[ETH_ALEN]; 547 u8 dst_mac[ETH_ALEN]; 548 __be16 vlan_id; 549 __be16 pad; /* reserved for future use */ 550 __be32 src_ip[4]; 551 __be32 dst_ip[4]; 552 __be16 src_port; 553 __be16 dst_port; 554 }; 555 556 VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec); 557 558 union virtchnl_flow_spec { 559 struct virtchnl_l4_spec tcp_spec; 560 u8 buffer[128]; /* reserved for future use */ 561 }; 562 563 VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec); 564 565 enum virtchnl_action { 566 /* action types */ 567 VIRTCHNL_ACTION_DROP = 0, 568 VIRTCHNL_ACTION_TC_REDIRECT, 569 VIRTCHNL_ACTION_PASSTHRU, 570 VIRTCHNL_ACTION_QUEUE, 571 VIRTCHNL_ACTION_Q_REGION, 572 VIRTCHNL_ACTION_MARK, 573 VIRTCHNL_ACTION_COUNT, 574 }; 575 576 enum virtchnl_flow_type { 577 /* flow types */ 578 VIRTCHNL_TCP_V4_FLOW = 0, 579 VIRTCHNL_TCP_V6_FLOW, 580 }; 581 582 struct virtchnl_filter { 583 union virtchnl_flow_spec data; 584 union virtchnl_flow_spec mask; 585 enum virtchnl_flow_type flow_type; 586 enum virtchnl_action action; 587 u32 action_meta; 588 u8 field_flags; 589 u8 pad[3]; 590 }; 591 592 VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter); 593 594 /* VIRTCHNL_OP_EVENT 595 * PF sends this message to inform the VF driver of events that may affect it. 596 * No direct response is expected from the VF, though it may generate other 597 * messages in response to this one. 598 */ 599 enum virtchnl_event_codes { 600 VIRTCHNL_EVENT_UNKNOWN = 0, 601 VIRTCHNL_EVENT_LINK_CHANGE, 602 VIRTCHNL_EVENT_RESET_IMPENDING, 603 VIRTCHNL_EVENT_PF_DRIVER_CLOSE, 604 }; 605 606 #define PF_EVENT_SEVERITY_INFO 0 607 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255 608 609 struct virtchnl_pf_event { 610 enum virtchnl_event_codes event; 611 union { 612 /* If the PF driver does not support the new speed reporting 613 * capabilities then use link_event else use link_event_adv to 614 * get the speed and link information. The ability to understand 615 * new speeds is indicated by setting the capability flag 616 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter 617 * in virtchnl_vf_resource struct and can be used to determine 618 * which link event struct to use below. 619 */ 620 struct { 621 enum virtchnl_link_speed link_speed; 622 bool link_status; 623 } link_event; 624 struct { 625 /* link_speed provided in Mbps */ 626 u32 link_speed; 627 u8 link_status; 628 u8 pad[3]; 629 } link_event_adv; 630 } event_data; 631 632 int severity; 633 }; 634 635 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); 636 637 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP 638 * VF uses this message to request PF to map IWARP vectors to IWARP queues. 639 * The request for this originates from the VF IWARP driver through 640 * a client interface between VF LAN and VF IWARP driver. 641 * A vector could have an AEQ and CEQ attached to it although 642 * there is a single AEQ per VF IWARP instance in which case 643 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq. 644 * There will never be a case where there will be multiple CEQs attached 645 * to a single vector. 646 * PF configures interrupt mapping and returns status. 647 */ 648 649 struct virtchnl_iwarp_qv_info { 650 u32 v_idx; /* msix_vector */ 651 u16 ceq_idx; 652 u16 aeq_idx; 653 u8 itr_idx; 654 u8 pad[3]; 655 }; 656 657 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info); 658 659 struct virtchnl_iwarp_qvlist_info { 660 u32 num_vectors; 661 struct virtchnl_iwarp_qv_info qv_info[1]; 662 }; 663 664 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info); 665 666 /* VF reset states - these are written into the RSTAT register: 667 * VFGEN_RSTAT on the VF 668 * When the PF initiates a reset, it writes 0 669 * When the reset is complete, it writes 1 670 * When the PF detects that the VF has recovered, it writes 2 671 * VF checks this register periodically to determine if a reset has occurred, 672 * then polls it to know when the reset is complete. 673 * If either the PF or VF reads the register while the hardware 674 * is in a reset state, it will return DEADBEEF, which, when masked 675 * will result in 3. 676 */ 677 enum virtchnl_vfr_states { 678 VIRTCHNL_VFR_INPROGRESS = 0, 679 VIRTCHNL_VFR_COMPLETED, 680 VIRTCHNL_VFR_VFACTIVE, 681 }; 682 683 /* Type of RSS algorithm */ 684 enum virtchnl_rss_algorithm { 685 VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC = 0, 686 VIRTCHNL_RSS_ALG_R_ASYMMETRIC = 1, 687 VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC = 2, 688 VIRTCHNL_RSS_ALG_XOR_SYMMETRIC = 3, 689 }; 690 691 #define VIRTCHNL_MAX_NUM_PROTO_HDRS 32 692 #define PROTO_HDR_SHIFT 5 693 #define PROTO_HDR_FIELD_START(proto_hdr_type) ((proto_hdr_type) << PROTO_HDR_SHIFT) 694 #define PROTO_HDR_FIELD_MASK ((1UL << PROTO_HDR_SHIFT) - 1) 695 696 /* VF use these macros to configure each protocol header. 697 * Specify which protocol headers and protocol header fields base on 698 * virtchnl_proto_hdr_type and virtchnl_proto_hdr_field. 699 * @param hdr: a struct of virtchnl_proto_hdr 700 * @param hdr_type: ETH/IPV4/TCP, etc 701 * @param field: SRC/DST/TEID/SPI, etc 702 */ 703 #define VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, field) \ 704 ((hdr)->field_selector |= BIT((field) & PROTO_HDR_FIELD_MASK)) 705 #define VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, field) \ 706 ((hdr)->field_selector &= ~BIT((field) & PROTO_HDR_FIELD_MASK)) 707 #define VIRTCHNL_TEST_PROTO_HDR_FIELD(hdr, val) \ 708 ((hdr)->field_selector & BIT((val) & PROTO_HDR_FIELD_MASK)) 709 #define VIRTCHNL_GET_PROTO_HDR_FIELD(hdr) ((hdr)->field_selector) 710 711 #define VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \ 712 (VIRTCHNL_ADD_PROTO_HDR_FIELD(hdr, \ 713 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field)) 714 #define VIRTCHNL_DEL_PROTO_HDR_FIELD_BIT(hdr, hdr_type, field) \ 715 (VIRTCHNL_DEL_PROTO_HDR_FIELD(hdr, \ 716 VIRTCHNL_PROTO_HDR_ ## hdr_type ## _ ## field)) 717 718 #define VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, hdr_type) \ 719 ((hdr)->type = VIRTCHNL_PROTO_HDR_ ## hdr_type) 720 #define VIRTCHNL_GET_PROTO_HDR_TYPE(hdr) \ 721 (((hdr)->type) >> PROTO_HDR_SHIFT) 722 #define VIRTCHNL_TEST_PROTO_HDR_TYPE(hdr, val) \ 723 ((hdr)->type == ((val) >> PROTO_HDR_SHIFT)) 724 #define VIRTCHNL_TEST_PROTO_HDR(hdr, val) \ 725 (VIRTCHNL_TEST_PROTO_HDR_TYPE((hdr), (val)) && \ 726 VIRTCHNL_TEST_PROTO_HDR_FIELD((hdr), (val))) 727 728 /* Protocol header type within a packet segment. A segment consists of one or 729 * more protocol headers that make up a logical group of protocol headers. Each 730 * logical group of protocol headers encapsulates or is encapsulated using/by 731 * tunneling or encapsulation protocols for network virtualization. 732 */ 733 enum virtchnl_proto_hdr_type { 734 VIRTCHNL_PROTO_HDR_NONE, 735 VIRTCHNL_PROTO_HDR_ETH, 736 VIRTCHNL_PROTO_HDR_S_VLAN, 737 VIRTCHNL_PROTO_HDR_C_VLAN, 738 VIRTCHNL_PROTO_HDR_IPV4, 739 VIRTCHNL_PROTO_HDR_IPV6, 740 VIRTCHNL_PROTO_HDR_TCP, 741 VIRTCHNL_PROTO_HDR_UDP, 742 VIRTCHNL_PROTO_HDR_SCTP, 743 VIRTCHNL_PROTO_HDR_GTPU_IP, 744 VIRTCHNL_PROTO_HDR_GTPU_EH, 745 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN, 746 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP, 747 VIRTCHNL_PROTO_HDR_PPPOE, 748 VIRTCHNL_PROTO_HDR_L2TPV3, 749 VIRTCHNL_PROTO_HDR_ESP, 750 VIRTCHNL_PROTO_HDR_AH, 751 VIRTCHNL_PROTO_HDR_PFCP, 752 }; 753 754 /* Protocol header field within a protocol header. */ 755 enum virtchnl_proto_hdr_field { 756 /* ETHER */ 757 VIRTCHNL_PROTO_HDR_ETH_SRC = 758 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ETH), 759 VIRTCHNL_PROTO_HDR_ETH_DST, 760 VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE, 761 /* S-VLAN */ 762 VIRTCHNL_PROTO_HDR_S_VLAN_ID = 763 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_S_VLAN), 764 /* C-VLAN */ 765 VIRTCHNL_PROTO_HDR_C_VLAN_ID = 766 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_C_VLAN), 767 /* IPV4 */ 768 VIRTCHNL_PROTO_HDR_IPV4_SRC = 769 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV4), 770 VIRTCHNL_PROTO_HDR_IPV4_DST, 771 VIRTCHNL_PROTO_HDR_IPV4_DSCP, 772 VIRTCHNL_PROTO_HDR_IPV4_TTL, 773 VIRTCHNL_PROTO_HDR_IPV4_PROT, 774 /* IPV6 */ 775 VIRTCHNL_PROTO_HDR_IPV6_SRC = 776 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_IPV6), 777 VIRTCHNL_PROTO_HDR_IPV6_DST, 778 VIRTCHNL_PROTO_HDR_IPV6_TC, 779 VIRTCHNL_PROTO_HDR_IPV6_HOP_LIMIT, 780 VIRTCHNL_PROTO_HDR_IPV6_PROT, 781 /* TCP */ 782 VIRTCHNL_PROTO_HDR_TCP_SRC_PORT = 783 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_TCP), 784 VIRTCHNL_PROTO_HDR_TCP_DST_PORT, 785 /* UDP */ 786 VIRTCHNL_PROTO_HDR_UDP_SRC_PORT = 787 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_UDP), 788 VIRTCHNL_PROTO_HDR_UDP_DST_PORT, 789 /* SCTP */ 790 VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT = 791 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_SCTP), 792 VIRTCHNL_PROTO_HDR_SCTP_DST_PORT, 793 /* GTPU_IP */ 794 VIRTCHNL_PROTO_HDR_GTPU_IP_TEID = 795 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_IP), 796 /* GTPU_EH */ 797 VIRTCHNL_PROTO_HDR_GTPU_EH_PDU = 798 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_GTPU_EH), 799 VIRTCHNL_PROTO_HDR_GTPU_EH_QFI, 800 /* PPPOE */ 801 VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID = 802 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PPPOE), 803 /* L2TPV3 */ 804 VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID = 805 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_L2TPV3), 806 /* ESP */ 807 VIRTCHNL_PROTO_HDR_ESP_SPI = 808 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_ESP), 809 /* AH */ 810 VIRTCHNL_PROTO_HDR_AH_SPI = 811 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_AH), 812 /* PFCP */ 813 VIRTCHNL_PROTO_HDR_PFCP_S_FIELD = 814 PROTO_HDR_FIELD_START(VIRTCHNL_PROTO_HDR_PFCP), 815 VIRTCHNL_PROTO_HDR_PFCP_SEID, 816 }; 817 818 struct virtchnl_proto_hdr { 819 enum virtchnl_proto_hdr_type type; 820 u32 field_selector; /* a bit mask to select field for header type */ 821 u8 buffer[64]; 822 /** 823 * binary buffer in network order for specific header type. 824 * For example, if type = VIRTCHNL_PROTO_HDR_IPV4, a IPv4 825 * header is expected to be copied into the buffer. 826 */ 827 }; 828 829 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr); 830 831 struct virtchnl_proto_hdrs { 832 u8 tunnel_level; 833 /** 834 * specify where protocol header start from. 835 * 0 - from the outer layer 836 * 1 - from the first inner layer 837 * 2 - from the second inner layer 838 * .... 839 **/ 840 int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */ 841 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS]; 842 }; 843 844 VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs); 845 846 struct virtchnl_rss_cfg { 847 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */ 848 enum virtchnl_rss_algorithm rss_algorithm; /* RSS algorithm type */ 849 u8 reserved[128]; /* reserve for future */ 850 }; 851 852 VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg); 853 854 /* action configuration for FDIR */ 855 struct virtchnl_filter_action { 856 enum virtchnl_action type; 857 union { 858 /* used for queue and qgroup action */ 859 struct { 860 u16 index; 861 u8 region; 862 } queue; 863 /* used for count action */ 864 struct { 865 /* share counter ID with other flow rules */ 866 u8 shared; 867 u32 id; /* counter ID */ 868 } count; 869 /* used for mark action */ 870 u32 mark_id; 871 u8 reserve[32]; 872 } act_conf; 873 }; 874 875 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action); 876 877 #define VIRTCHNL_MAX_NUM_ACTIONS 8 878 879 struct virtchnl_filter_action_set { 880 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */ 881 int count; 882 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS]; 883 }; 884 885 VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set); 886 887 /* pattern and action for FDIR rule */ 888 struct virtchnl_fdir_rule { 889 struct virtchnl_proto_hdrs proto_hdrs; 890 struct virtchnl_filter_action_set action_set; 891 }; 892 893 VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule); 894 895 /* Status returned to VF after VF requests FDIR commands 896 * VIRTCHNL_FDIR_SUCCESS 897 * VF FDIR related request is successfully done by PF 898 * The request can be OP_ADD/DEL. 899 * 900 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE 901 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource. 902 * 903 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST 904 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed. 905 * 906 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT 907 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule. 908 * 909 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST 910 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist. 911 * 912 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID 913 * OP_ADD_FDIR_FILTER request is failed due to parameters validation 914 * or HW doesn't support. 915 * 916 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT 917 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out 918 * for programming. 919 */ 920 enum virtchnl_fdir_prgm_status { 921 VIRTCHNL_FDIR_SUCCESS = 0, 922 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE, 923 VIRTCHNL_FDIR_FAILURE_RULE_EXIST, 924 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT, 925 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST, 926 VIRTCHNL_FDIR_FAILURE_RULE_INVALID, 927 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT, 928 }; 929 930 /* VIRTCHNL_OP_ADD_FDIR_FILTER 931 * VF sends this request to PF by filling out vsi_id, 932 * validate_only and rule_cfg. PF will return flow_id 933 * if the request is successfully done and return add_status to VF. 934 */ 935 struct virtchnl_fdir_add { 936 u16 vsi_id; /* INPUT */ 937 /* 938 * 1 for validating a fdir rule, 0 for creating a fdir rule. 939 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER. 940 */ 941 u16 validate_only; /* INPUT */ 942 u32 flow_id; /* OUTPUT */ 943 struct virtchnl_fdir_rule rule_cfg; /* INPUT */ 944 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 945 }; 946 947 VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add); 948 949 /* VIRTCHNL_OP_DEL_FDIR_FILTER 950 * VF sends this request to PF by filling out vsi_id 951 * and flow_id. PF will return del_status to VF. 952 */ 953 struct virtchnl_fdir_del { 954 u16 vsi_id; /* INPUT */ 955 u16 pad; 956 u32 flow_id; /* INPUT */ 957 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 958 }; 959 960 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del); 961 962 /** 963 * virtchnl_vc_validate_vf_msg 964 * @ver: Virtchnl version info 965 * @v_opcode: Opcode for the message 966 * @msg: pointer to the msg buffer 967 * @msglen: msg length 968 * 969 * validate msg format against struct for each opcode 970 */ 971 static inline int 972 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, 973 u8 *msg, u16 msglen) 974 { 975 bool err_msg_format = false; 976 int valid_len = 0; 977 978 /* Validate message length. */ 979 switch (v_opcode) { 980 case VIRTCHNL_OP_VERSION: 981 valid_len = sizeof(struct virtchnl_version_info); 982 break; 983 case VIRTCHNL_OP_RESET_VF: 984 break; 985 case VIRTCHNL_OP_GET_VF_RESOURCES: 986 if (VF_IS_V11(ver)) 987 valid_len = sizeof(u32); 988 break; 989 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 990 valid_len = sizeof(struct virtchnl_txq_info); 991 break; 992 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 993 valid_len = sizeof(struct virtchnl_rxq_info); 994 break; 995 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 996 valid_len = sizeof(struct virtchnl_vsi_queue_config_info); 997 if (msglen >= valid_len) { 998 struct virtchnl_vsi_queue_config_info *vqc = 999 (struct virtchnl_vsi_queue_config_info *)msg; 1000 valid_len += (vqc->num_queue_pairs * 1001 sizeof(struct 1002 virtchnl_queue_pair_info)); 1003 if (vqc->num_queue_pairs == 0) 1004 err_msg_format = true; 1005 } 1006 break; 1007 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1008 valid_len = sizeof(struct virtchnl_irq_map_info); 1009 if (msglen >= valid_len) { 1010 struct virtchnl_irq_map_info *vimi = 1011 (struct virtchnl_irq_map_info *)msg; 1012 valid_len += (vimi->num_vectors * 1013 sizeof(struct virtchnl_vector_map)); 1014 if (vimi->num_vectors == 0) 1015 err_msg_format = true; 1016 } 1017 break; 1018 case VIRTCHNL_OP_ENABLE_QUEUES: 1019 case VIRTCHNL_OP_DISABLE_QUEUES: 1020 valid_len = sizeof(struct virtchnl_queue_select); 1021 break; 1022 case VIRTCHNL_OP_ADD_ETH_ADDR: 1023 case VIRTCHNL_OP_DEL_ETH_ADDR: 1024 valid_len = sizeof(struct virtchnl_ether_addr_list); 1025 if (msglen >= valid_len) { 1026 struct virtchnl_ether_addr_list *veal = 1027 (struct virtchnl_ether_addr_list *)msg; 1028 valid_len += veal->num_elements * 1029 sizeof(struct virtchnl_ether_addr); 1030 if (veal->num_elements == 0) 1031 err_msg_format = true; 1032 } 1033 break; 1034 case VIRTCHNL_OP_ADD_VLAN: 1035 case VIRTCHNL_OP_DEL_VLAN: 1036 valid_len = sizeof(struct virtchnl_vlan_filter_list); 1037 if (msglen >= valid_len) { 1038 struct virtchnl_vlan_filter_list *vfl = 1039 (struct virtchnl_vlan_filter_list *)msg; 1040 valid_len += vfl->num_elements * sizeof(u16); 1041 if (vfl->num_elements == 0) 1042 err_msg_format = true; 1043 } 1044 break; 1045 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 1046 valid_len = sizeof(struct virtchnl_promisc_info); 1047 break; 1048 case VIRTCHNL_OP_GET_STATS: 1049 valid_len = sizeof(struct virtchnl_queue_select); 1050 break; 1051 case VIRTCHNL_OP_IWARP: 1052 /* These messages are opaque to us and will be validated in 1053 * the RDMA client code. We just need to check for nonzero 1054 * length. The firmware will enforce max length restrictions. 1055 */ 1056 if (msglen) 1057 valid_len = msglen; 1058 else 1059 err_msg_format = true; 1060 break; 1061 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP: 1062 break; 1063 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 1064 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info); 1065 if (msglen >= valid_len) { 1066 struct virtchnl_iwarp_qvlist_info *qv = 1067 (struct virtchnl_iwarp_qvlist_info *)msg; 1068 if (qv->num_vectors == 0) { 1069 err_msg_format = true; 1070 break; 1071 } 1072 valid_len += ((qv->num_vectors - 1) * 1073 sizeof(struct virtchnl_iwarp_qv_info)); 1074 } 1075 break; 1076 case VIRTCHNL_OP_CONFIG_RSS_KEY: 1077 valid_len = sizeof(struct virtchnl_rss_key); 1078 if (msglen >= valid_len) { 1079 struct virtchnl_rss_key *vrk = 1080 (struct virtchnl_rss_key *)msg; 1081 valid_len += vrk->key_len - 1; 1082 } 1083 break; 1084 case VIRTCHNL_OP_CONFIG_RSS_LUT: 1085 valid_len = sizeof(struct virtchnl_rss_lut); 1086 if (msglen >= valid_len) { 1087 struct virtchnl_rss_lut *vrl = 1088 (struct virtchnl_rss_lut *)msg; 1089 valid_len += vrl->lut_entries - 1; 1090 } 1091 break; 1092 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 1093 break; 1094 case VIRTCHNL_OP_SET_RSS_HENA: 1095 valid_len = sizeof(struct virtchnl_rss_hena); 1096 break; 1097 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 1098 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 1099 break; 1100 case VIRTCHNL_OP_REQUEST_QUEUES: 1101 valid_len = sizeof(struct virtchnl_vf_res_request); 1102 break; 1103 case VIRTCHNL_OP_ENABLE_CHANNELS: 1104 valid_len = sizeof(struct virtchnl_tc_info); 1105 if (msglen >= valid_len) { 1106 struct virtchnl_tc_info *vti = 1107 (struct virtchnl_tc_info *)msg; 1108 valid_len += (vti->num_tc - 1) * 1109 sizeof(struct virtchnl_channel_info); 1110 if (vti->num_tc == 0) 1111 err_msg_format = true; 1112 } 1113 break; 1114 case VIRTCHNL_OP_DISABLE_CHANNELS: 1115 break; 1116 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 1117 valid_len = sizeof(struct virtchnl_filter); 1118 break; 1119 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 1120 valid_len = sizeof(struct virtchnl_filter); 1121 break; 1122 case VIRTCHNL_OP_ADD_RSS_CFG: 1123 case VIRTCHNL_OP_DEL_RSS_CFG: 1124 valid_len = sizeof(struct virtchnl_rss_cfg); 1125 break; 1126 case VIRTCHNL_OP_ADD_FDIR_FILTER: 1127 valid_len = sizeof(struct virtchnl_fdir_add); 1128 break; 1129 case VIRTCHNL_OP_DEL_FDIR_FILTER: 1130 valid_len = sizeof(struct virtchnl_fdir_del); 1131 break; 1132 /* These are always errors coming from the VF. */ 1133 case VIRTCHNL_OP_EVENT: 1134 case VIRTCHNL_OP_UNKNOWN: 1135 default: 1136 return VIRTCHNL_STATUS_ERR_PARAM; 1137 } 1138 /* few more checks */ 1139 if (err_msg_format || valid_len != msglen) 1140 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH; 1141 1142 return 0; 1143 } 1144 #endif /* _VIRTCHNL_H_ */ 1145