1 /******************************************************************************* 2 * 3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver 4 * Copyright(c) 2013 - 2014 Intel Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 * The full GNU General Public License is included in this distribution in 19 * the file called "COPYING". 20 * 21 * Contact Information: 22 * e1000-devel Mailing List <[email protected]> 23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 24 * 25 ******************************************************************************/ 26 27 #ifndef _VIRTCHNL_H_ 28 #define _VIRTCHNL_H_ 29 30 /* Description: 31 * This header file describes the VF-PF communication protocol used 32 * by the drivers for all devices starting from our 40G product line 33 * 34 * Admin queue buffer usage: 35 * desc->opcode is always aqc_opc_send_msg_to_pf 36 * flags, retval, datalen, and data addr are all used normally. 37 * The Firmware copies the cookie fields when sending messages between the 38 * PF and VF, but uses all other fields internally. Due to this limitation, 39 * we must send all messages as "indirect", i.e. using an external buffer. 40 * 41 * All the VSI indexes are relative to the VF. Each VF can have maximum of 42 * three VSIs. All the queue indexes are relative to the VSI. Each VF can 43 * have a maximum of sixteen queues for all of its VSIs. 44 * 45 * The PF is required to return a status code in v_retval for all messages 46 * except RESET_VF, which does not require any response. The return value 47 * is of status_code type, defined in the shared type.h. 48 * 49 * In general, VF driver initialization should roughly follow the order of 50 * these opcodes. The VF driver must first validate the API version of the 51 * PF driver, then request a reset, then get resources, then configure 52 * queues and interrupts. After these operations are complete, the VF 53 * driver may start its queues, optionally add MAC and VLAN filters, and 54 * process traffic. 55 */ 56 57 /* START GENERIC DEFINES 58 * Need to ensure the following enums and defines hold the same meaning and 59 * value in current and future projects 60 */ 61 62 /* Error Codes */ 63 enum virtchnl_status_code { 64 VIRTCHNL_STATUS_SUCCESS = 0, 65 VIRTCHNL_ERR_PARAM = -5, 66 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38, 67 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39, 68 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40, 69 VIRTCHNL_STATUS_NOT_SUPPORTED = -64, 70 }; 71 72 #define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1 73 #define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2 74 #define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3 75 #define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4 76 #define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5 77 #define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6 78 79 enum virtchnl_link_speed { 80 VIRTCHNL_LINK_SPEED_UNKNOWN = 0, 81 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT), 82 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT), 83 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT), 84 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT), 85 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT), 86 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT), 87 }; 88 89 /* for hsplit_0 field of Rx HMC context */ 90 /* deprecated with AVF 1.0 */ 91 enum virtchnl_rx_hsplit { 92 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0, 93 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1, 94 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2, 95 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4, 96 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8, 97 }; 98 99 /* END GENERIC DEFINES */ 100 101 /* Opcodes for VF-PF communication. These are placed in the v_opcode field 102 * of the virtchnl_msg structure. 103 */ 104 enum virtchnl_ops { 105 /* The PF sends status change events to VFs using 106 * the VIRTCHNL_OP_EVENT opcode. 107 * VFs send requests to the PF using the other ops. 108 * Use of "advanced opcode" features must be negotiated as part of capabilities 109 * exchange and are not considered part of base mode feature set. 110 */ 111 VIRTCHNL_OP_UNKNOWN = 0, 112 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */ 113 VIRTCHNL_OP_RESET_VF = 2, 114 VIRTCHNL_OP_GET_VF_RESOURCES = 3, 115 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4, 116 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5, 117 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6, 118 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7, 119 VIRTCHNL_OP_ENABLE_QUEUES = 8, 120 VIRTCHNL_OP_DISABLE_QUEUES = 9, 121 VIRTCHNL_OP_ADD_ETH_ADDR = 10, 122 VIRTCHNL_OP_DEL_ETH_ADDR = 11, 123 VIRTCHNL_OP_ADD_VLAN = 12, 124 VIRTCHNL_OP_DEL_VLAN = 13, 125 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14, 126 VIRTCHNL_OP_GET_STATS = 15, 127 VIRTCHNL_OP_RSVD = 16, 128 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */ 129 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */ 130 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */ 131 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */ 132 VIRTCHNL_OP_CONFIG_RSS_KEY = 23, 133 VIRTCHNL_OP_CONFIG_RSS_LUT = 24, 134 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25, 135 VIRTCHNL_OP_SET_RSS_HENA = 26, 136 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27, 137 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28, 138 VIRTCHNL_OP_REQUEST_QUEUES = 29, 139 }; 140 141 /* This macro is used to generate a compilation error if a structure 142 * is not exactly the correct length. It gives a divide by zero error if the 143 * structure is not of the correct size, otherwise it creates an enum that is 144 * never used. 145 */ 146 #define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ 147 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } 148 149 /* Virtual channel message descriptor. This overlays the admin queue 150 * descriptor. All other data is passed in external buffers. 151 */ 152 153 struct virtchnl_msg { 154 u8 pad[8]; /* AQ flags/opcode/len/retval fields */ 155 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */ 156 enum virtchnl_status_code v_retval; /* ditto for desc->retval */ 157 u32 vfid; /* used by PF when sending to VF */ 158 }; 159 160 VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg); 161 162 /* Message descriptions and data structures.*/ 163 164 /* VIRTCHNL_OP_VERSION 165 * VF posts its version number to the PF. PF responds with its version number 166 * in the same format, along with a return code. 167 * Reply from PF has its major/minor versions also in param0 and param1. 168 * If there is a major version mismatch, then the VF cannot operate. 169 * If there is a minor version mismatch, then the VF can operate but should 170 * add a warning to the system log. 171 * 172 * This enum element MUST always be specified as == 1, regardless of other 173 * changes in the API. The PF must always respond to this message without 174 * error regardless of version mismatch. 175 */ 176 #define VIRTCHNL_VERSION_MAJOR 1 177 #define VIRTCHNL_VERSION_MINOR 1 178 #define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0 179 180 struct virtchnl_version_info { 181 u32 major; 182 u32 minor; 183 }; 184 185 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info); 186 187 #define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) 188 #define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) 189 190 /* VIRTCHNL_OP_RESET_VF 191 * VF sends this request to PF with no parameters 192 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register 193 * until reset completion is indicated. The admin queue must be reinitialized 194 * after this operation. 195 * 196 * When reset is complete, PF must ensure that all queues in all VSIs associated 197 * with the VF are stopped, all queue configurations in the HMC are set to 0, 198 * and all MAC and VLAN filters (except the default MAC address) on all VSIs 199 * are cleared. 200 */ 201 202 /* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV 203 * vsi_type should always be 6 for backward compatibility. Add other fields 204 * as needed. 205 */ 206 enum virtchnl_vsi_type { 207 VIRTCHNL_VSI_TYPE_INVALID = 0, 208 VIRTCHNL_VSI_SRIOV = 6, 209 }; 210 211 /* VIRTCHNL_OP_GET_VF_RESOURCES 212 * Version 1.0 VF sends this request to PF with no parameters 213 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities 214 * PF responds with an indirect message containing 215 * virtchnl_vf_resource and one or more 216 * virtchnl_vsi_resource structures. 217 */ 218 219 struct virtchnl_vsi_resource { 220 u16 vsi_id; 221 u16 num_queue_pairs; 222 enum virtchnl_vsi_type vsi_type; 223 u16 qset_handle; 224 u8 default_mac_addr[ETH_ALEN]; 225 }; 226 227 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource); 228 229 /* VF capability flags 230 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including 231 * TX/RX Checksum offloading and TSO for non-tunnelled packets. 232 */ 233 #define VIRTCHNL_VF_OFFLOAD_L2 0x00000001 234 #define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002 235 #define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004 236 #define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008 237 #define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010 238 #define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020 239 #define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040 240 #define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000 241 #define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000 242 #define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000 243 #define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000 244 #define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000 245 #define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000 246 #define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000 247 248 #define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \ 249 VIRTCHNL_VF_OFFLOAD_VLAN | \ 250 VIRTCHNL_VF_OFFLOAD_RSS_PF) 251 252 struct virtchnl_vf_resource { 253 u16 num_vsis; 254 u16 num_queue_pairs; 255 u16 max_vectors; 256 u16 max_mtu; 257 258 u32 vf_cap_flags; 259 u32 rss_key_size; 260 u32 rss_lut_size; 261 262 struct virtchnl_vsi_resource vsi_res[1]; 263 }; 264 265 VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource); 266 267 /* VIRTCHNL_OP_CONFIG_TX_QUEUE 268 * VF sends this message to set up parameters for one TX queue. 269 * External data buffer contains one instance of virtchnl_txq_info. 270 * PF configures requested queue and returns a status code. 271 */ 272 273 /* Tx queue config info */ 274 struct virtchnl_txq_info { 275 u16 vsi_id; 276 u16 queue_id; 277 u16 ring_len; /* number of descriptors, multiple of 8 */ 278 u16 headwb_enabled; /* deprecated with AVF 1.0 */ 279 u64 dma_ring_addr; 280 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ 281 }; 282 283 VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info); 284 285 /* VIRTCHNL_OP_CONFIG_RX_QUEUE 286 * VF sends this message to set up parameters for one RX queue. 287 * External data buffer contains one instance of virtchnl_rxq_info. 288 * PF configures requested queue and returns a status code. 289 */ 290 291 /* Rx queue config info */ 292 struct virtchnl_rxq_info { 293 u16 vsi_id; 294 u16 queue_id; 295 u32 ring_len; /* number of descriptors, multiple of 32 */ 296 u16 hdr_size; 297 u16 splithdr_enabled; /* deprecated with AVF 1.0 */ 298 u32 databuffer_size; 299 u32 max_pkt_size; 300 u32 pad1; 301 u64 dma_ring_addr; 302 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */ 303 u32 pad2; 304 }; 305 306 VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info); 307 308 /* VIRTCHNL_OP_CONFIG_VSI_QUEUES 309 * VF sends this message to set parameters for all active TX and RX queues 310 * associated with the specified VSI. 311 * PF configures queues and returns status. 312 * If the number of queues specified is greater than the number of queues 313 * associated with the VSI, an error is returned and no queues are configured. 314 */ 315 struct virtchnl_queue_pair_info { 316 /* NOTE: vsi_id and queue_id should be identical for both queues. */ 317 struct virtchnl_txq_info txq; 318 struct virtchnl_rxq_info rxq; 319 }; 320 321 VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); 322 323 struct virtchnl_vsi_queue_config_info { 324 u16 vsi_id; 325 u16 num_queue_pairs; 326 u32 pad; 327 struct virtchnl_queue_pair_info qpair[1]; 328 }; 329 330 /* VIRTCHNL_OP_REQUEST_QUEUES 331 * VF sends this message to request the PF to allocate additional queues to 332 * this VF. Each VF gets a guaranteed number of queues on init but asking for 333 * additional queues must be negotiated. This is a best effort request as it 334 * is possible the PF does not have enough queues left to support the request. 335 * If the PF cannot support the number requested it will respond with the 336 * maximum number it is able to support. If the request is successful, PF will 337 * then reset the VF to institute required changes. 338 */ 339 340 /* VF resource request */ 341 struct virtchnl_vf_res_request { 342 u16 num_queue_pairs; 343 }; 344 345 VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info); 346 347 /* VIRTCHNL_OP_CONFIG_IRQ_MAP 348 * VF uses this message to map vectors to queues. 349 * The rxq_map and txq_map fields are bitmaps used to indicate which queues 350 * are to be associated with the specified vector. 351 * The "other" causes are always mapped to vector 0. 352 * PF configures interrupt mapping and returns status. 353 */ 354 struct virtchnl_vector_map { 355 u16 vsi_id; 356 u16 vector_id; 357 u16 rxq_map; 358 u16 txq_map; 359 u16 rxitr_idx; 360 u16 txitr_idx; 361 }; 362 363 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); 364 365 struct virtchnl_irq_map_info { 366 u16 num_vectors; 367 struct virtchnl_vector_map vecmap[1]; 368 }; 369 370 VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info); 371 372 /* VIRTCHNL_OP_ENABLE_QUEUES 373 * VIRTCHNL_OP_DISABLE_QUEUES 374 * VF sends these message to enable or disable TX/RX queue pairs. 375 * The queues fields are bitmaps indicating which queues to act upon. 376 * (Currently, we only support 16 queues per VF, but we make the field 377 * u32 to allow for expansion.) 378 * PF performs requested action and returns status. 379 */ 380 struct virtchnl_queue_select { 381 u16 vsi_id; 382 u16 pad; 383 u32 rx_queues; 384 u32 tx_queues; 385 }; 386 387 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select); 388 389 /* VIRTCHNL_OP_ADD_ETH_ADDR 390 * VF sends this message in order to add one or more unicast or multicast 391 * address filters for the specified VSI. 392 * PF adds the filters and returns status. 393 */ 394 395 /* VIRTCHNL_OP_DEL_ETH_ADDR 396 * VF sends this message in order to remove one or more unicast or multicast 397 * filters for the specified VSI. 398 * PF removes the filters and returns status. 399 */ 400 401 struct virtchnl_ether_addr { 402 u8 addr[ETH_ALEN]; 403 u8 pad[2]; 404 }; 405 406 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); 407 408 struct virtchnl_ether_addr_list { 409 u16 vsi_id; 410 u16 num_elements; 411 struct virtchnl_ether_addr list[1]; 412 }; 413 414 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list); 415 416 /* VIRTCHNL_OP_ADD_VLAN 417 * VF sends this message to add one or more VLAN tag filters for receives. 418 * PF adds the filters and returns status. 419 * If a port VLAN is configured by the PF, this operation will return an 420 * error to the VF. 421 */ 422 423 /* VIRTCHNL_OP_DEL_VLAN 424 * VF sends this message to remove one or more VLAN tag filters for receives. 425 * PF removes the filters and returns status. 426 * If a port VLAN is configured by the PF, this operation will return an 427 * error to the VF. 428 */ 429 430 struct virtchnl_vlan_filter_list { 431 u16 vsi_id; 432 u16 num_elements; 433 u16 vlan_id[1]; 434 }; 435 436 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); 437 438 /* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE 439 * VF sends VSI id and flags. 440 * PF returns status code in retval. 441 * Note: we assume that broadcast accept mode is always enabled. 442 */ 443 struct virtchnl_promisc_info { 444 u16 vsi_id; 445 u16 flags; 446 }; 447 448 VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info); 449 450 #define FLAG_VF_UNICAST_PROMISC 0x00000001 451 #define FLAG_VF_MULTICAST_PROMISC 0x00000002 452 453 /* VIRTCHNL_OP_GET_STATS 454 * VF sends this message to request stats for the selected VSI. VF uses 455 * the virtchnl_queue_select struct to specify the VSI. The queue_id 456 * field is ignored by the PF. 457 * 458 * PF replies with struct eth_stats in an external buffer. 459 */ 460 461 /* VIRTCHNL_OP_CONFIG_RSS_KEY 462 * VIRTCHNL_OP_CONFIG_RSS_LUT 463 * VF sends these messages to configure RSS. Only supported if both PF 464 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during 465 * configuration negotiation. If this is the case, then the RSS fields in 466 * the VF resource struct are valid. 467 * Both the key and LUT are initialized to 0 by the PF, meaning that 468 * RSS is effectively disabled until set up by the VF. 469 */ 470 struct virtchnl_rss_key { 471 u16 vsi_id; 472 u16 key_len; 473 u8 key[1]; /* RSS hash key, packed bytes */ 474 }; 475 476 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); 477 478 struct virtchnl_rss_lut { 479 u16 vsi_id; 480 u16 lut_entries; 481 u8 lut[1]; /* RSS lookup table*/ 482 }; 483 484 VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut); 485 486 /* VIRTCHNL_OP_GET_RSS_HENA_CAPS 487 * VIRTCHNL_OP_SET_RSS_HENA 488 * VF sends these messages to get and set the hash filter enable bits for RSS. 489 * By default, the PF sets these to all possible traffic types that the 490 * hardware supports. The VF can query this value if it wants to change the 491 * traffic types that are hashed by the hardware. 492 */ 493 struct virtchnl_rss_hena { 494 u64 hena; 495 }; 496 497 VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena); 498 499 /* VIRTCHNL_OP_EVENT 500 * PF sends this message to inform the VF driver of events that may affect it. 501 * No direct response is expected from the VF, though it may generate other 502 * messages in response to this one. 503 */ 504 enum virtchnl_event_codes { 505 VIRTCHNL_EVENT_UNKNOWN = 0, 506 VIRTCHNL_EVENT_LINK_CHANGE, 507 VIRTCHNL_EVENT_RESET_IMPENDING, 508 VIRTCHNL_EVENT_PF_DRIVER_CLOSE, 509 }; 510 511 #define PF_EVENT_SEVERITY_INFO 0 512 #define PF_EVENT_SEVERITY_CERTAIN_DOOM 255 513 514 struct virtchnl_pf_event { 515 enum virtchnl_event_codes event; 516 union { 517 struct { 518 enum virtchnl_link_speed link_speed; 519 bool link_status; 520 } link_event; 521 } event_data; 522 523 int severity; 524 }; 525 526 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); 527 528 /* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP 529 * VF uses this message to request PF to map IWARP vectors to IWARP queues. 530 * The request for this originates from the VF IWARP driver through 531 * a client interface between VF LAN and VF IWARP driver. 532 * A vector could have an AEQ and CEQ attached to it although 533 * there is a single AEQ per VF IWARP instance in which case 534 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq. 535 * There will never be a case where there will be multiple CEQs attached 536 * to a single vector. 537 * PF configures interrupt mapping and returns status. 538 */ 539 540 struct virtchnl_iwarp_qv_info { 541 u32 v_idx; /* msix_vector */ 542 u16 ceq_idx; 543 u16 aeq_idx; 544 u8 itr_idx; 545 }; 546 547 VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info); 548 549 struct virtchnl_iwarp_qvlist_info { 550 u32 num_vectors; 551 struct virtchnl_iwarp_qv_info qv_info[1]; 552 }; 553 554 VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info); 555 556 /* VF reset states - these are written into the RSTAT register: 557 * VFGEN_RSTAT on the VF 558 * When the PF initiates a reset, it writes 0 559 * When the reset is complete, it writes 1 560 * When the PF detects that the VF has recovered, it writes 2 561 * VF checks this register periodically to determine if a reset has occurred, 562 * then polls it to know when the reset is complete. 563 * If either the PF or VF reads the register while the hardware 564 * is in a reset state, it will return DEADBEEF, which, when masked 565 * will result in 3. 566 */ 567 enum virtchnl_vfr_states { 568 VIRTCHNL_VFR_INPROGRESS = 0, 569 VIRTCHNL_VFR_COMPLETED, 570 VIRTCHNL_VFR_VFACTIVE, 571 }; 572 573 /** 574 * virtchnl_vc_validate_vf_msg 575 * @ver: Virtchnl version info 576 * @v_opcode: Opcode for the message 577 * @msg: pointer to the msg buffer 578 * @msglen: msg length 579 * 580 * validate msg format against struct for each opcode 581 */ 582 static inline int 583 virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, 584 u8 *msg, u16 msglen) 585 { 586 bool err_msg_format = false; 587 int valid_len = 0; 588 589 /* Validate message length. */ 590 switch (v_opcode) { 591 case VIRTCHNL_OP_VERSION: 592 valid_len = sizeof(struct virtchnl_version_info); 593 break; 594 case VIRTCHNL_OP_RESET_VF: 595 break; 596 case VIRTCHNL_OP_GET_VF_RESOURCES: 597 if (VF_IS_V11(ver)) 598 valid_len = sizeof(u32); 599 break; 600 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 601 valid_len = sizeof(struct virtchnl_txq_info); 602 break; 603 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 604 valid_len = sizeof(struct virtchnl_rxq_info); 605 break; 606 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 607 valid_len = sizeof(struct virtchnl_vsi_queue_config_info); 608 if (msglen >= valid_len) { 609 struct virtchnl_vsi_queue_config_info *vqc = 610 (struct virtchnl_vsi_queue_config_info *)msg; 611 valid_len += (vqc->num_queue_pairs * 612 sizeof(struct 613 virtchnl_queue_pair_info)); 614 if (vqc->num_queue_pairs == 0) 615 err_msg_format = true; 616 } 617 break; 618 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 619 valid_len = sizeof(struct virtchnl_irq_map_info); 620 if (msglen >= valid_len) { 621 struct virtchnl_irq_map_info *vimi = 622 (struct virtchnl_irq_map_info *)msg; 623 valid_len += (vimi->num_vectors * 624 sizeof(struct virtchnl_vector_map)); 625 if (vimi->num_vectors == 0) 626 err_msg_format = true; 627 } 628 break; 629 case VIRTCHNL_OP_ENABLE_QUEUES: 630 case VIRTCHNL_OP_DISABLE_QUEUES: 631 valid_len = sizeof(struct virtchnl_queue_select); 632 break; 633 case VIRTCHNL_OP_ADD_ETH_ADDR: 634 case VIRTCHNL_OP_DEL_ETH_ADDR: 635 valid_len = sizeof(struct virtchnl_ether_addr_list); 636 if (msglen >= valid_len) { 637 struct virtchnl_ether_addr_list *veal = 638 (struct virtchnl_ether_addr_list *)msg; 639 valid_len += veal->num_elements * 640 sizeof(struct virtchnl_ether_addr); 641 if (veal->num_elements == 0) 642 err_msg_format = true; 643 } 644 break; 645 case VIRTCHNL_OP_ADD_VLAN: 646 case VIRTCHNL_OP_DEL_VLAN: 647 valid_len = sizeof(struct virtchnl_vlan_filter_list); 648 if (msglen >= valid_len) { 649 struct virtchnl_vlan_filter_list *vfl = 650 (struct virtchnl_vlan_filter_list *)msg; 651 valid_len += vfl->num_elements * sizeof(u16); 652 if (vfl->num_elements == 0) 653 err_msg_format = true; 654 } 655 break; 656 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 657 valid_len = sizeof(struct virtchnl_promisc_info); 658 break; 659 case VIRTCHNL_OP_GET_STATS: 660 valid_len = sizeof(struct virtchnl_queue_select); 661 break; 662 case VIRTCHNL_OP_IWARP: 663 /* These messages are opaque to us and will be validated in 664 * the RDMA client code. We just need to check for nonzero 665 * length. The firmware will enforce max length restrictions. 666 */ 667 if (msglen) 668 valid_len = msglen; 669 else 670 err_msg_format = true; 671 break; 672 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP: 673 break; 674 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 675 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info); 676 if (msglen >= valid_len) { 677 struct virtchnl_iwarp_qvlist_info *qv = 678 (struct virtchnl_iwarp_qvlist_info *)msg; 679 if (qv->num_vectors == 0) { 680 err_msg_format = true; 681 break; 682 } 683 valid_len += ((qv->num_vectors - 1) * 684 sizeof(struct virtchnl_iwarp_qv_info)); 685 } 686 break; 687 case VIRTCHNL_OP_CONFIG_RSS_KEY: 688 valid_len = sizeof(struct virtchnl_rss_key); 689 if (msglen >= valid_len) { 690 struct virtchnl_rss_key *vrk = 691 (struct virtchnl_rss_key *)msg; 692 valid_len += vrk->key_len - 1; 693 } 694 break; 695 case VIRTCHNL_OP_CONFIG_RSS_LUT: 696 valid_len = sizeof(struct virtchnl_rss_lut); 697 if (msglen >= valid_len) { 698 struct virtchnl_rss_lut *vrl = 699 (struct virtchnl_rss_lut *)msg; 700 valid_len += vrl->lut_entries - 1; 701 } 702 break; 703 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 704 break; 705 case VIRTCHNL_OP_SET_RSS_HENA: 706 valid_len = sizeof(struct virtchnl_rss_hena); 707 break; 708 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 709 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 710 break; 711 case VIRTCHNL_OP_REQUEST_QUEUES: 712 valid_len = sizeof(struct virtchnl_vf_res_request); 713 break; 714 /* These are always errors coming from the VF. */ 715 case VIRTCHNL_OP_EVENT: 716 case VIRTCHNL_OP_UNKNOWN: 717 default: 718 return VIRTCHNL_ERR_PARAM; 719 } 720 /* few more checks */ 721 if ((valid_len != msglen) || (err_msg_format)) 722 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH; 723 724 return 0; 725 } 726 #endif /* _VIRTCHNL_H_ */ 727