at v5.13 36 kB view raw
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 <e1000-devel@lists.sourceforge.net> 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 */ 49enum 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 73enum 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 */ 87enum 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 */ 100enum 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 161struct 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 168VIRTCHNL_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 188struct virtchnl_version_info { 189 u32 major; 190 u32 minor; 191}; 192 193VIRTCHNL_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 */ 214enum 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 227struct 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 235VIRTCHNL_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 266struct 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 279VIRTCHNL_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 */ 288struct 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 297VIRTCHNL_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 */ 306struct 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 320VIRTCHNL_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 */ 329struct 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 335VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); 336 337struct 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 344VIRTCHNL_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 */ 357struct 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 */ 368struct 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 377VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); 378 379struct virtchnl_irq_map_info { 380 u16 num_vectors; 381 struct virtchnl_vector_map vecmap[1]; 382}; 383 384VIRTCHNL_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 */ 394struct virtchnl_queue_select { 395 u16 vsi_id; 396 u16 pad; 397 u32 rx_queues; 398 u32 tx_queues; 399}; 400 401VIRTCHNL_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 415struct virtchnl_ether_addr { 416 u8 addr[ETH_ALEN]; 417 u8 pad[2]; 418}; 419 420VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); 421 422struct virtchnl_ether_addr_list { 423 u16 vsi_id; 424 u16 num_elements; 425 struct virtchnl_ether_addr list[1]; 426}; 427 428VIRTCHNL_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 444struct virtchnl_vlan_filter_list { 445 u16 vsi_id; 446 u16 num_elements; 447 u16 vlan_id[1]; 448}; 449 450VIRTCHNL_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 */ 457struct virtchnl_promisc_info { 458 u16 vsi_id; 459 u16 flags; 460}; 461 462VIRTCHNL_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 */ 484struct virtchnl_rss_key { 485 u16 vsi_id; 486 u16 key_len; 487 u8 key[1]; /* RSS hash key, packed bytes */ 488}; 489 490VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); 491 492struct virtchnl_rss_lut { 493 u16 vsi_id; 494 u16 lut_entries; 495 u8 lut[1]; /* RSS lookup table */ 496}; 497 498VIRTCHNL_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 */ 507struct virtchnl_rss_hena { 508 u64 hena; 509}; 510 511VIRTCHNL_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 */ 520struct 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 527VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info); 528 529struct virtchnl_tc_info { 530 u32 num_tc; 531 u32 pad; 532 struct virtchnl_channel_info list[1]; 533}; 534 535VIRTCHNL_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 545struct 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 556VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec); 557 558union virtchnl_flow_spec { 559 struct virtchnl_l4_spec tcp_spec; 560 u8 buffer[128]; /* reserved for future use */ 561}; 562 563VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec); 564 565enum 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 576enum virtchnl_flow_type { 577 /* flow types */ 578 VIRTCHNL_TCP_V4_FLOW = 0, 579 VIRTCHNL_TCP_V6_FLOW, 580}; 581 582struct 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 592VIRTCHNL_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 */ 599enum 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 609struct 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 635VIRTCHNL_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 649struct 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 657VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info); 658 659struct virtchnl_iwarp_qvlist_info { 660 u32 num_vectors; 661 struct virtchnl_iwarp_qv_info qv_info[1]; 662}; 663 664VIRTCHNL_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 */ 677enum virtchnl_vfr_states { 678 VIRTCHNL_VFR_INPROGRESS = 0, 679 VIRTCHNL_VFR_COMPLETED, 680 VIRTCHNL_VFR_VFACTIVE, 681}; 682 683/* Type of RSS algorithm */ 684enum 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 */ 733enum 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. */ 755enum 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 818struct 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 829VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_proto_hdr); 830 831struct virtchnl_proto_hdrs { 832 u8 tunnel_level; 833 u8 pad[3]; 834 /** 835 * specify where protocol header start from. 836 * 0 - from the outer layer 837 * 1 - from the first inner layer 838 * 2 - from the second inner layer 839 * .... 840 **/ 841 int count; /* the proto layers must < VIRTCHNL_MAX_NUM_PROTO_HDRS */ 842 struct virtchnl_proto_hdr proto_hdr[VIRTCHNL_MAX_NUM_PROTO_HDRS]; 843}; 844 845VIRTCHNL_CHECK_STRUCT_LEN(2312, virtchnl_proto_hdrs); 846 847struct virtchnl_rss_cfg { 848 struct virtchnl_proto_hdrs proto_hdrs; /* protocol headers */ 849 enum virtchnl_rss_algorithm rss_algorithm; /* RSS algorithm type */ 850 u8 reserved[128]; /* reserve for future */ 851}; 852 853VIRTCHNL_CHECK_STRUCT_LEN(2444, virtchnl_rss_cfg); 854 855/* action configuration for FDIR */ 856struct virtchnl_filter_action { 857 enum virtchnl_action type; 858 union { 859 /* used for queue and qgroup action */ 860 struct { 861 u16 index; 862 u8 region; 863 } queue; 864 /* used for count action */ 865 struct { 866 /* share counter ID with other flow rules */ 867 u8 shared; 868 u32 id; /* counter ID */ 869 } count; 870 /* used for mark action */ 871 u32 mark_id; 872 u8 reserve[32]; 873 } act_conf; 874}; 875 876VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_filter_action); 877 878#define VIRTCHNL_MAX_NUM_ACTIONS 8 879 880struct virtchnl_filter_action_set { 881 /* action number must be less then VIRTCHNL_MAX_NUM_ACTIONS */ 882 int count; 883 struct virtchnl_filter_action actions[VIRTCHNL_MAX_NUM_ACTIONS]; 884}; 885 886VIRTCHNL_CHECK_STRUCT_LEN(292, virtchnl_filter_action_set); 887 888/* pattern and action for FDIR rule */ 889struct virtchnl_fdir_rule { 890 struct virtchnl_proto_hdrs proto_hdrs; 891 struct virtchnl_filter_action_set action_set; 892}; 893 894VIRTCHNL_CHECK_STRUCT_LEN(2604, virtchnl_fdir_rule); 895 896/* Status returned to VF after VF requests FDIR commands 897 * VIRTCHNL_FDIR_SUCCESS 898 * VF FDIR related request is successfully done by PF 899 * The request can be OP_ADD/DEL. 900 * 901 * VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE 902 * OP_ADD_FDIR_FILTER request is failed due to no Hardware resource. 903 * 904 * VIRTCHNL_FDIR_FAILURE_RULE_EXIST 905 * OP_ADD_FDIR_FILTER request is failed due to the rule is already existed. 906 * 907 * VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT 908 * OP_ADD_FDIR_FILTER request is failed due to conflict with existing rule. 909 * 910 * VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST 911 * OP_DEL_FDIR_FILTER request is failed due to this rule doesn't exist. 912 * 913 * VIRTCHNL_FDIR_FAILURE_RULE_INVALID 914 * OP_ADD_FDIR_FILTER request is failed due to parameters validation 915 * or HW doesn't support. 916 * 917 * VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT 918 * OP_ADD/DEL_FDIR_FILTER request is failed due to timing out 919 * for programming. 920 */ 921enum virtchnl_fdir_prgm_status { 922 VIRTCHNL_FDIR_SUCCESS = 0, 923 VIRTCHNL_FDIR_FAILURE_RULE_NORESOURCE, 924 VIRTCHNL_FDIR_FAILURE_RULE_EXIST, 925 VIRTCHNL_FDIR_FAILURE_RULE_CONFLICT, 926 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST, 927 VIRTCHNL_FDIR_FAILURE_RULE_INVALID, 928 VIRTCHNL_FDIR_FAILURE_RULE_TIMEOUT, 929}; 930 931/* VIRTCHNL_OP_ADD_FDIR_FILTER 932 * VF sends this request to PF by filling out vsi_id, 933 * validate_only and rule_cfg. PF will return flow_id 934 * if the request is successfully done and return add_status to VF. 935 */ 936struct virtchnl_fdir_add { 937 u16 vsi_id; /* INPUT */ 938 /* 939 * 1 for validating a fdir rule, 0 for creating a fdir rule. 940 * Validate and create share one ops: VIRTCHNL_OP_ADD_FDIR_FILTER. 941 */ 942 u16 validate_only; /* INPUT */ 943 u32 flow_id; /* OUTPUT */ 944 struct virtchnl_fdir_rule rule_cfg; /* INPUT */ 945 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 946}; 947 948VIRTCHNL_CHECK_STRUCT_LEN(2616, virtchnl_fdir_add); 949 950/* VIRTCHNL_OP_DEL_FDIR_FILTER 951 * VF sends this request to PF by filling out vsi_id 952 * and flow_id. PF will return del_status to VF. 953 */ 954struct virtchnl_fdir_del { 955 u16 vsi_id; /* INPUT */ 956 u16 pad; 957 u32 flow_id; /* INPUT */ 958 enum virtchnl_fdir_prgm_status status; /* OUTPUT */ 959}; 960 961VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_fdir_del); 962 963/** 964 * virtchnl_vc_validate_vf_msg 965 * @ver: Virtchnl version info 966 * @v_opcode: Opcode for the message 967 * @msg: pointer to the msg buffer 968 * @msglen: msg length 969 * 970 * validate msg format against struct for each opcode 971 */ 972static inline int 973virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, 974 u8 *msg, u16 msglen) 975{ 976 bool err_msg_format = false; 977 int valid_len = 0; 978 979 /* Validate message length. */ 980 switch (v_opcode) { 981 case VIRTCHNL_OP_VERSION: 982 valid_len = sizeof(struct virtchnl_version_info); 983 break; 984 case VIRTCHNL_OP_RESET_VF: 985 break; 986 case VIRTCHNL_OP_GET_VF_RESOURCES: 987 if (VF_IS_V11(ver)) 988 valid_len = sizeof(u32); 989 break; 990 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 991 valid_len = sizeof(struct virtchnl_txq_info); 992 break; 993 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 994 valid_len = sizeof(struct virtchnl_rxq_info); 995 break; 996 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 997 valid_len = sizeof(struct virtchnl_vsi_queue_config_info); 998 if (msglen >= valid_len) { 999 struct virtchnl_vsi_queue_config_info *vqc = 1000 (struct virtchnl_vsi_queue_config_info *)msg; 1001 valid_len += (vqc->num_queue_pairs * 1002 sizeof(struct 1003 virtchnl_queue_pair_info)); 1004 if (vqc->num_queue_pairs == 0) 1005 err_msg_format = true; 1006 } 1007 break; 1008 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 1009 valid_len = sizeof(struct virtchnl_irq_map_info); 1010 if (msglen >= valid_len) { 1011 struct virtchnl_irq_map_info *vimi = 1012 (struct virtchnl_irq_map_info *)msg; 1013 valid_len += (vimi->num_vectors * 1014 sizeof(struct virtchnl_vector_map)); 1015 if (vimi->num_vectors == 0) 1016 err_msg_format = true; 1017 } 1018 break; 1019 case VIRTCHNL_OP_ENABLE_QUEUES: 1020 case VIRTCHNL_OP_DISABLE_QUEUES: 1021 valid_len = sizeof(struct virtchnl_queue_select); 1022 break; 1023 case VIRTCHNL_OP_ADD_ETH_ADDR: 1024 case VIRTCHNL_OP_DEL_ETH_ADDR: 1025 valid_len = sizeof(struct virtchnl_ether_addr_list); 1026 if (msglen >= valid_len) { 1027 struct virtchnl_ether_addr_list *veal = 1028 (struct virtchnl_ether_addr_list *)msg; 1029 valid_len += veal->num_elements * 1030 sizeof(struct virtchnl_ether_addr); 1031 if (veal->num_elements == 0) 1032 err_msg_format = true; 1033 } 1034 break; 1035 case VIRTCHNL_OP_ADD_VLAN: 1036 case VIRTCHNL_OP_DEL_VLAN: 1037 valid_len = sizeof(struct virtchnl_vlan_filter_list); 1038 if (msglen >= valid_len) { 1039 struct virtchnl_vlan_filter_list *vfl = 1040 (struct virtchnl_vlan_filter_list *)msg; 1041 valid_len += vfl->num_elements * sizeof(u16); 1042 if (vfl->num_elements == 0) 1043 err_msg_format = true; 1044 } 1045 break; 1046 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 1047 valid_len = sizeof(struct virtchnl_promisc_info); 1048 break; 1049 case VIRTCHNL_OP_GET_STATS: 1050 valid_len = sizeof(struct virtchnl_queue_select); 1051 break; 1052 case VIRTCHNL_OP_IWARP: 1053 /* These messages are opaque to us and will be validated in 1054 * the RDMA client code. We just need to check for nonzero 1055 * length. The firmware will enforce max length restrictions. 1056 */ 1057 if (msglen) 1058 valid_len = msglen; 1059 else 1060 err_msg_format = true; 1061 break; 1062 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP: 1063 break; 1064 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 1065 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info); 1066 if (msglen >= valid_len) { 1067 struct virtchnl_iwarp_qvlist_info *qv = 1068 (struct virtchnl_iwarp_qvlist_info *)msg; 1069 if (qv->num_vectors == 0) { 1070 err_msg_format = true; 1071 break; 1072 } 1073 valid_len += ((qv->num_vectors - 1) * 1074 sizeof(struct virtchnl_iwarp_qv_info)); 1075 } 1076 break; 1077 case VIRTCHNL_OP_CONFIG_RSS_KEY: 1078 valid_len = sizeof(struct virtchnl_rss_key); 1079 if (msglen >= valid_len) { 1080 struct virtchnl_rss_key *vrk = 1081 (struct virtchnl_rss_key *)msg; 1082 valid_len += vrk->key_len - 1; 1083 } 1084 break; 1085 case VIRTCHNL_OP_CONFIG_RSS_LUT: 1086 valid_len = sizeof(struct virtchnl_rss_lut); 1087 if (msglen >= valid_len) { 1088 struct virtchnl_rss_lut *vrl = 1089 (struct virtchnl_rss_lut *)msg; 1090 valid_len += vrl->lut_entries - 1; 1091 } 1092 break; 1093 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 1094 break; 1095 case VIRTCHNL_OP_SET_RSS_HENA: 1096 valid_len = sizeof(struct virtchnl_rss_hena); 1097 break; 1098 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 1099 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 1100 break; 1101 case VIRTCHNL_OP_REQUEST_QUEUES: 1102 valid_len = sizeof(struct virtchnl_vf_res_request); 1103 break; 1104 case VIRTCHNL_OP_ENABLE_CHANNELS: 1105 valid_len = sizeof(struct virtchnl_tc_info); 1106 if (msglen >= valid_len) { 1107 struct virtchnl_tc_info *vti = 1108 (struct virtchnl_tc_info *)msg; 1109 valid_len += (vti->num_tc - 1) * 1110 sizeof(struct virtchnl_channel_info); 1111 if (vti->num_tc == 0) 1112 err_msg_format = true; 1113 } 1114 break; 1115 case VIRTCHNL_OP_DISABLE_CHANNELS: 1116 break; 1117 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 1118 valid_len = sizeof(struct virtchnl_filter); 1119 break; 1120 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 1121 valid_len = sizeof(struct virtchnl_filter); 1122 break; 1123 case VIRTCHNL_OP_ADD_RSS_CFG: 1124 case VIRTCHNL_OP_DEL_RSS_CFG: 1125 valid_len = sizeof(struct virtchnl_rss_cfg); 1126 break; 1127 case VIRTCHNL_OP_ADD_FDIR_FILTER: 1128 valid_len = sizeof(struct virtchnl_fdir_add); 1129 break; 1130 case VIRTCHNL_OP_DEL_FDIR_FILTER: 1131 valid_len = sizeof(struct virtchnl_fdir_del); 1132 break; 1133 /* These are always errors coming from the VF. */ 1134 case VIRTCHNL_OP_EVENT: 1135 case VIRTCHNL_OP_UNKNOWN: 1136 default: 1137 return VIRTCHNL_STATUS_ERR_PARAM; 1138 } 1139 /* few more checks */ 1140 if (err_msg_format || valid_len != msglen) 1141 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH; 1142 1143 return 0; 1144} 1145#endif /* _VIRTCHNL_H_ */