at v4.20 848 lines 27 kB view raw
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 <e1000-devel@lists.sourceforge.net> 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 */ 63enum virtchnl_status_code { 64 VIRTCHNL_STATUS_SUCCESS = 0, 65 VIRTCHNL_STATUS_ERR_PARAM = -5, 66 VIRTCHNL_STATUS_ERR_NO_MEMORY = -18, 67 VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH = -38, 68 VIRTCHNL_STATUS_ERR_CQP_COMPL_ERROR = -39, 69 VIRTCHNL_STATUS_ERR_INVALID_VF_ID = -40, 70 VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR = -53, 71 VIRTCHNL_STATUS_ERR_NOT_SUPPORTED = -64, 72}; 73 74/* Backward compatibility */ 75#define VIRTCHNL_ERR_PARAM VIRTCHNL_STATUS_ERR_PARAM 76#define VIRTCHNL_STATUS_NOT_SUPPORTED VIRTCHNL_STATUS_ERR_NOT_SUPPORTED 77 78#define VIRTCHNL_LINK_SPEED_100MB_SHIFT 0x1 79#define VIRTCHNL_LINK_SPEED_1000MB_SHIFT 0x2 80#define VIRTCHNL_LINK_SPEED_10GB_SHIFT 0x3 81#define VIRTCHNL_LINK_SPEED_40GB_SHIFT 0x4 82#define VIRTCHNL_LINK_SPEED_20GB_SHIFT 0x5 83#define VIRTCHNL_LINK_SPEED_25GB_SHIFT 0x6 84 85enum virtchnl_link_speed { 86 VIRTCHNL_LINK_SPEED_UNKNOWN = 0, 87 VIRTCHNL_LINK_SPEED_100MB = BIT(VIRTCHNL_LINK_SPEED_100MB_SHIFT), 88 VIRTCHNL_LINK_SPEED_1GB = BIT(VIRTCHNL_LINK_SPEED_1000MB_SHIFT), 89 VIRTCHNL_LINK_SPEED_10GB = BIT(VIRTCHNL_LINK_SPEED_10GB_SHIFT), 90 VIRTCHNL_LINK_SPEED_40GB = BIT(VIRTCHNL_LINK_SPEED_40GB_SHIFT), 91 VIRTCHNL_LINK_SPEED_20GB = BIT(VIRTCHNL_LINK_SPEED_20GB_SHIFT), 92 VIRTCHNL_LINK_SPEED_25GB = BIT(VIRTCHNL_LINK_SPEED_25GB_SHIFT), 93}; 94 95/* for hsplit_0 field of Rx HMC context */ 96/* deprecated with AVF 1.0 */ 97enum virtchnl_rx_hsplit { 98 VIRTCHNL_RX_HSPLIT_NO_SPLIT = 0, 99 VIRTCHNL_RX_HSPLIT_SPLIT_L2 = 1, 100 VIRTCHNL_RX_HSPLIT_SPLIT_IP = 2, 101 VIRTCHNL_RX_HSPLIT_SPLIT_TCP_UDP = 4, 102 VIRTCHNL_RX_HSPLIT_SPLIT_SCTP = 8, 103}; 104 105/* END GENERIC DEFINES */ 106 107/* Opcodes for VF-PF communication. These are placed in the v_opcode field 108 * of the virtchnl_msg structure. 109 */ 110enum virtchnl_ops { 111/* The PF sends status change events to VFs using 112 * the VIRTCHNL_OP_EVENT opcode. 113 * VFs send requests to the PF using the other ops. 114 * Use of "advanced opcode" features must be negotiated as part of capabilities 115 * exchange and are not considered part of base mode feature set. 116 */ 117 VIRTCHNL_OP_UNKNOWN = 0, 118 VIRTCHNL_OP_VERSION = 1, /* must ALWAYS be 1 */ 119 VIRTCHNL_OP_RESET_VF = 2, 120 VIRTCHNL_OP_GET_VF_RESOURCES = 3, 121 VIRTCHNL_OP_CONFIG_TX_QUEUE = 4, 122 VIRTCHNL_OP_CONFIG_RX_QUEUE = 5, 123 VIRTCHNL_OP_CONFIG_VSI_QUEUES = 6, 124 VIRTCHNL_OP_CONFIG_IRQ_MAP = 7, 125 VIRTCHNL_OP_ENABLE_QUEUES = 8, 126 VIRTCHNL_OP_DISABLE_QUEUES = 9, 127 VIRTCHNL_OP_ADD_ETH_ADDR = 10, 128 VIRTCHNL_OP_DEL_ETH_ADDR = 11, 129 VIRTCHNL_OP_ADD_VLAN = 12, 130 VIRTCHNL_OP_DEL_VLAN = 13, 131 VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE = 14, 132 VIRTCHNL_OP_GET_STATS = 15, 133 VIRTCHNL_OP_RSVD = 16, 134 VIRTCHNL_OP_EVENT = 17, /* must ALWAYS be 17 */ 135 VIRTCHNL_OP_IWARP = 20, /* advanced opcode */ 136 VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP = 21, /* advanced opcode */ 137 VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP = 22, /* advanced opcode */ 138 VIRTCHNL_OP_CONFIG_RSS_KEY = 23, 139 VIRTCHNL_OP_CONFIG_RSS_LUT = 24, 140 VIRTCHNL_OP_GET_RSS_HENA_CAPS = 25, 141 VIRTCHNL_OP_SET_RSS_HENA = 26, 142 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING = 27, 143 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING = 28, 144 VIRTCHNL_OP_REQUEST_QUEUES = 29, 145 VIRTCHNL_OP_ENABLE_CHANNELS = 30, 146 VIRTCHNL_OP_DISABLE_CHANNELS = 31, 147 VIRTCHNL_OP_ADD_CLOUD_FILTER = 32, 148 VIRTCHNL_OP_DEL_CLOUD_FILTER = 33, 149}; 150 151/* These macros are used to generate compilation errors if a structure/union 152 * is not exactly the correct length. It gives a divide by zero error if the 153 * structure/union is not of the correct size, otherwise it creates an enum 154 * that is never used. 155 */ 156#define VIRTCHNL_CHECK_STRUCT_LEN(n, X) enum virtchnl_static_assert_enum_##X \ 157 { virtchnl_static_assert_##X = (n)/((sizeof(struct X) == (n)) ? 1 : 0) } 158#define VIRTCHNL_CHECK_UNION_LEN(n, X) enum virtchnl_static_asset_enum_##X \ 159 { virtchnl_static_assert_##X = (n)/((sizeof(union X) == (n)) ? 1 : 0) } 160 161/* Virtual channel message descriptor. This overlays the admin queue 162 * descriptor. All other data is passed in external buffers. 163 */ 164 165struct virtchnl_msg { 166 u8 pad[8]; /* AQ flags/opcode/len/retval fields */ 167 enum virtchnl_ops v_opcode; /* avoid confusion with desc->opcode */ 168 enum virtchnl_status_code v_retval; /* ditto for desc->retval */ 169 u32 vfid; /* used by PF when sending to VF */ 170}; 171 172VIRTCHNL_CHECK_STRUCT_LEN(20, virtchnl_msg); 173 174/* Message descriptions and data structures.*/ 175 176/* VIRTCHNL_OP_VERSION 177 * VF posts its version number to the PF. PF responds with its version number 178 * in the same format, along with a return code. 179 * Reply from PF has its major/minor versions also in param0 and param1. 180 * If there is a major version mismatch, then the VF cannot operate. 181 * If there is a minor version mismatch, then the VF can operate but should 182 * add a warning to the system log. 183 * 184 * This enum element MUST always be specified as == 1, regardless of other 185 * changes in the API. The PF must always respond to this message without 186 * error regardless of version mismatch. 187 */ 188#define VIRTCHNL_VERSION_MAJOR 1 189#define VIRTCHNL_VERSION_MINOR 1 190#define VIRTCHNL_VERSION_MINOR_NO_VF_CAPS 0 191 192struct virtchnl_version_info { 193 u32 major; 194 u32 minor; 195}; 196 197VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_version_info); 198 199#define VF_IS_V10(_v) (((_v)->major == 1) && ((_v)->minor == 0)) 200#define VF_IS_V11(_ver) (((_ver)->major == 1) && ((_ver)->minor == 1)) 201 202/* VIRTCHNL_OP_RESET_VF 203 * VF sends this request to PF with no parameters 204 * PF does NOT respond! VF driver must delay then poll VFGEN_RSTAT register 205 * until reset completion is indicated. The admin queue must be reinitialized 206 * after this operation. 207 * 208 * When reset is complete, PF must ensure that all queues in all VSIs associated 209 * with the VF are stopped, all queue configurations in the HMC are set to 0, 210 * and all MAC and VLAN filters (except the default MAC address) on all VSIs 211 * are cleared. 212 */ 213 214/* VSI types that use VIRTCHNL interface for VF-PF communication. VSI_SRIOV 215 * vsi_type should always be 6 for backward compatibility. Add other fields 216 * as needed. 217 */ 218enum virtchnl_vsi_type { 219 VIRTCHNL_VSI_TYPE_INVALID = 0, 220 VIRTCHNL_VSI_SRIOV = 6, 221}; 222 223/* VIRTCHNL_OP_GET_VF_RESOURCES 224 * Version 1.0 VF sends this request to PF with no parameters 225 * Version 1.1 VF sends this request to PF with u32 bitmap of its capabilities 226 * PF responds with an indirect message containing 227 * virtchnl_vf_resource and one or more 228 * virtchnl_vsi_resource structures. 229 */ 230 231struct virtchnl_vsi_resource { 232 u16 vsi_id; 233 u16 num_queue_pairs; 234 enum virtchnl_vsi_type vsi_type; 235 u16 qset_handle; 236 u8 default_mac_addr[ETH_ALEN]; 237}; 238 239VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_vsi_resource); 240 241/* VF capability flags 242 * VIRTCHNL_VF_OFFLOAD_L2 flag is inclusive of base mode L2 offloads including 243 * TX/RX Checksum offloading and TSO for non-tunnelled packets. 244 */ 245#define VIRTCHNL_VF_OFFLOAD_L2 0x00000001 246#define VIRTCHNL_VF_OFFLOAD_IWARP 0x00000002 247#define VIRTCHNL_VF_OFFLOAD_RSVD 0x00000004 248#define VIRTCHNL_VF_OFFLOAD_RSS_AQ 0x00000008 249#define VIRTCHNL_VF_OFFLOAD_RSS_REG 0x00000010 250#define VIRTCHNL_VF_OFFLOAD_WB_ON_ITR 0x00000020 251#define VIRTCHNL_VF_OFFLOAD_REQ_QUEUES 0x00000040 252#define VIRTCHNL_VF_OFFLOAD_VLAN 0x00010000 253#define VIRTCHNL_VF_OFFLOAD_RX_POLLING 0x00020000 254#define VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 0x00040000 255#define VIRTCHNL_VF_OFFLOAD_RSS_PF 0X00080000 256#define VIRTCHNL_VF_OFFLOAD_ENCAP 0X00100000 257#define VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM 0X00200000 258#define VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM 0X00400000 259#define VIRTCHNL_VF_OFFLOAD_ADQ 0X00800000 260 261/* Define below the capability flags that are not offloads */ 262#define VIRTCHNL_VF_CAP_ADV_LINK_SPEED 0x00000080 263#define VF_BASE_MODE_OFFLOADS (VIRTCHNL_VF_OFFLOAD_L2 | \ 264 VIRTCHNL_VF_OFFLOAD_VLAN | \ 265 VIRTCHNL_VF_OFFLOAD_RSS_PF) 266 267struct virtchnl_vf_resource { 268 u16 num_vsis; 269 u16 num_queue_pairs; 270 u16 max_vectors; 271 u16 max_mtu; 272 273 u32 vf_cap_flags; 274 u32 rss_key_size; 275 u32 rss_lut_size; 276 277 struct virtchnl_vsi_resource vsi_res[1]; 278}; 279 280VIRTCHNL_CHECK_STRUCT_LEN(36, virtchnl_vf_resource); 281 282/* VIRTCHNL_OP_CONFIG_TX_QUEUE 283 * VF sends this message to set up parameters for one TX queue. 284 * External data buffer contains one instance of virtchnl_txq_info. 285 * PF configures requested queue and returns a status code. 286 */ 287 288/* Tx queue config info */ 289struct virtchnl_txq_info { 290 u16 vsi_id; 291 u16 queue_id; 292 u16 ring_len; /* number of descriptors, multiple of 8 */ 293 u16 headwb_enabled; /* deprecated with AVF 1.0 */ 294 u64 dma_ring_addr; 295 u64 dma_headwb_addr; /* deprecated with AVF 1.0 */ 296}; 297 298VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_txq_info); 299 300/* VIRTCHNL_OP_CONFIG_RX_QUEUE 301 * VF sends this message to set up parameters for one RX queue. 302 * External data buffer contains one instance of virtchnl_rxq_info. 303 * PF configures requested queue and returns a status code. 304 */ 305 306/* Rx queue config info */ 307struct virtchnl_rxq_info { 308 u16 vsi_id; 309 u16 queue_id; 310 u32 ring_len; /* number of descriptors, multiple of 32 */ 311 u16 hdr_size; 312 u16 splithdr_enabled; /* deprecated with AVF 1.0 */ 313 u32 databuffer_size; 314 u32 max_pkt_size; 315 u32 pad1; 316 u64 dma_ring_addr; 317 enum virtchnl_rx_hsplit rx_split_pos; /* deprecated with AVF 1.0 */ 318 u32 pad2; 319}; 320 321VIRTCHNL_CHECK_STRUCT_LEN(40, virtchnl_rxq_info); 322 323/* VIRTCHNL_OP_CONFIG_VSI_QUEUES 324 * VF sends this message to set parameters for all active TX and RX queues 325 * associated with the specified VSI. 326 * PF configures queues and returns status. 327 * If the number of queues specified is greater than the number of queues 328 * associated with the VSI, an error is returned and no queues are configured. 329 */ 330struct virtchnl_queue_pair_info { 331 /* NOTE: vsi_id and queue_id should be identical for both queues. */ 332 struct virtchnl_txq_info txq; 333 struct virtchnl_rxq_info rxq; 334}; 335 336VIRTCHNL_CHECK_STRUCT_LEN(64, virtchnl_queue_pair_info); 337 338struct virtchnl_vsi_queue_config_info { 339 u16 vsi_id; 340 u16 num_queue_pairs; 341 u32 pad; 342 struct virtchnl_queue_pair_info qpair[1]; 343}; 344 345/* VIRTCHNL_OP_REQUEST_QUEUES 346 * VF sends this message to request the PF to allocate additional queues to 347 * this VF. Each VF gets a guaranteed number of queues on init but asking for 348 * additional queues must be negotiated. This is a best effort request as it 349 * is possible the PF does not have enough queues left to support the request. 350 * If the PF cannot support the number requested it will respond with the 351 * maximum number it is able to support. If the request is successful, PF will 352 * then reset the VF to institute required changes. 353 */ 354 355/* VF resource request */ 356struct virtchnl_vf_res_request { 357 u16 num_queue_pairs; 358}; 359 360VIRTCHNL_CHECK_STRUCT_LEN(72, virtchnl_vsi_queue_config_info); 361 362/* VIRTCHNL_OP_CONFIG_IRQ_MAP 363 * VF uses this message to map vectors to queues. 364 * The rxq_map and txq_map fields are bitmaps used to indicate which queues 365 * are to be associated with the specified vector. 366 * The "other" causes are always mapped to vector 0. 367 * PF configures interrupt mapping and returns status. 368 */ 369struct virtchnl_vector_map { 370 u16 vsi_id; 371 u16 vector_id; 372 u16 rxq_map; 373 u16 txq_map; 374 u16 rxitr_idx; 375 u16 txitr_idx; 376}; 377 378VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_vector_map); 379 380struct virtchnl_irq_map_info { 381 u16 num_vectors; 382 struct virtchnl_vector_map vecmap[1]; 383}; 384 385VIRTCHNL_CHECK_STRUCT_LEN(14, virtchnl_irq_map_info); 386 387/* VIRTCHNL_OP_ENABLE_QUEUES 388 * VIRTCHNL_OP_DISABLE_QUEUES 389 * VF sends these message to enable or disable TX/RX queue pairs. 390 * The queues fields are bitmaps indicating which queues to act upon. 391 * (Currently, we only support 16 queues per VF, but we make the field 392 * u32 to allow for expansion.) 393 * PF performs requested action and returns status. 394 */ 395struct virtchnl_queue_select { 396 u16 vsi_id; 397 u16 pad; 398 u32 rx_queues; 399 u32 tx_queues; 400}; 401 402VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_queue_select); 403 404/* VIRTCHNL_OP_ADD_ETH_ADDR 405 * VF sends this message in order to add one or more unicast or multicast 406 * address filters for the specified VSI. 407 * PF adds the filters and returns status. 408 */ 409 410/* VIRTCHNL_OP_DEL_ETH_ADDR 411 * VF sends this message in order to remove one or more unicast or multicast 412 * filters for the specified VSI. 413 * PF removes the filters and returns status. 414 */ 415 416struct virtchnl_ether_addr { 417 u8 addr[ETH_ALEN]; 418 u8 pad[2]; 419}; 420 421VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_ether_addr); 422 423struct virtchnl_ether_addr_list { 424 u16 vsi_id; 425 u16 num_elements; 426 struct virtchnl_ether_addr list[1]; 427}; 428 429VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_ether_addr_list); 430 431/* VIRTCHNL_OP_ADD_VLAN 432 * VF sends this message to add one or more VLAN tag filters for receives. 433 * PF adds the filters and returns status. 434 * If a port VLAN is configured by the PF, this operation will return an 435 * error to the VF. 436 */ 437 438/* VIRTCHNL_OP_DEL_VLAN 439 * VF sends this message to remove one or more VLAN tag filters for receives. 440 * PF removes the filters and returns status. 441 * If a port VLAN is configured by the PF, this operation will return an 442 * error to the VF. 443 */ 444 445struct virtchnl_vlan_filter_list { 446 u16 vsi_id; 447 u16 num_elements; 448 u16 vlan_id[1]; 449}; 450 451VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_vlan_filter_list); 452 453/* VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE 454 * VF sends VSI id and flags. 455 * PF returns status code in retval. 456 * Note: we assume that broadcast accept mode is always enabled. 457 */ 458struct virtchnl_promisc_info { 459 u16 vsi_id; 460 u16 flags; 461}; 462 463VIRTCHNL_CHECK_STRUCT_LEN(4, virtchnl_promisc_info); 464 465#define FLAG_VF_UNICAST_PROMISC 0x00000001 466#define FLAG_VF_MULTICAST_PROMISC 0x00000002 467 468/* VIRTCHNL_OP_GET_STATS 469 * VF sends this message to request stats for the selected VSI. VF uses 470 * the virtchnl_queue_select struct to specify the VSI. The queue_id 471 * field is ignored by the PF. 472 * 473 * PF replies with struct eth_stats in an external buffer. 474 */ 475 476/* VIRTCHNL_OP_CONFIG_RSS_KEY 477 * VIRTCHNL_OP_CONFIG_RSS_LUT 478 * VF sends these messages to configure RSS. Only supported if both PF 479 * and VF drivers set the VIRTCHNL_VF_OFFLOAD_RSS_PF bit during 480 * configuration negotiation. If this is the case, then the RSS fields in 481 * the VF resource struct are valid. 482 * Both the key and LUT are initialized to 0 by the PF, meaning that 483 * RSS is effectively disabled until set up by the VF. 484 */ 485struct virtchnl_rss_key { 486 u16 vsi_id; 487 u16 key_len; 488 u8 key[1]; /* RSS hash key, packed bytes */ 489}; 490 491VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); 492 493struct virtchnl_rss_lut { 494 u16 vsi_id; 495 u16 lut_entries; 496 u8 lut[1]; /* RSS lookup table */ 497}; 498 499VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_lut); 500 501/* VIRTCHNL_OP_GET_RSS_HENA_CAPS 502 * VIRTCHNL_OP_SET_RSS_HENA 503 * VF sends these messages to get and set the hash filter enable bits for RSS. 504 * By default, the PF sets these to all possible traffic types that the 505 * hardware supports. The VF can query this value if it wants to change the 506 * traffic types that are hashed by the hardware. 507 */ 508struct virtchnl_rss_hena { 509 u64 hena; 510}; 511 512VIRTCHNL_CHECK_STRUCT_LEN(8, virtchnl_rss_hena); 513 514/* VIRTCHNL_OP_ENABLE_CHANNELS 515 * VIRTCHNL_OP_DISABLE_CHANNELS 516 * VF sends these messages to enable or disable channels based on 517 * the user specified queue count and queue offset for each traffic class. 518 * This struct encompasses all the information that the PF needs from 519 * VF to create a channel. 520 */ 521struct virtchnl_channel_info { 522 u16 count; /* number of queues in a channel */ 523 u16 offset; /* queues in a channel start from 'offset' */ 524 u32 pad; 525 u64 max_tx_rate; 526}; 527 528VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_channel_info); 529 530struct virtchnl_tc_info { 531 u32 num_tc; 532 u32 pad; 533 struct virtchnl_channel_info list[1]; 534}; 535 536VIRTCHNL_CHECK_STRUCT_LEN(24, virtchnl_tc_info); 537 538/* VIRTCHNL_ADD_CLOUD_FILTER 539 * VIRTCHNL_DEL_CLOUD_FILTER 540 * VF sends these messages to add or delete a cloud filter based on the 541 * user specified match and action filters. These structures encompass 542 * all the information that the PF needs from the VF to add/delete a 543 * cloud filter. 544 */ 545 546struct virtchnl_l4_spec { 547 u8 src_mac[ETH_ALEN]; 548 u8 dst_mac[ETH_ALEN]; 549 __be16 vlan_id; 550 __be16 pad; /* reserved for future use */ 551 __be32 src_ip[4]; 552 __be32 dst_ip[4]; 553 __be16 src_port; 554 __be16 dst_port; 555}; 556 557VIRTCHNL_CHECK_STRUCT_LEN(52, virtchnl_l4_spec); 558 559union virtchnl_flow_spec { 560 struct virtchnl_l4_spec tcp_spec; 561 u8 buffer[128]; /* reserved for future use */ 562}; 563 564VIRTCHNL_CHECK_UNION_LEN(128, virtchnl_flow_spec); 565 566enum virtchnl_action { 567 /* action types */ 568 VIRTCHNL_ACTION_DROP = 0, 569 VIRTCHNL_ACTION_TC_REDIRECT, 570}; 571 572enum virtchnl_flow_type { 573 /* flow types */ 574 VIRTCHNL_TCP_V4_FLOW = 0, 575 VIRTCHNL_TCP_V6_FLOW, 576}; 577 578struct virtchnl_filter { 579 union virtchnl_flow_spec data; 580 union virtchnl_flow_spec mask; 581 enum virtchnl_flow_type flow_type; 582 enum virtchnl_action action; 583 u32 action_meta; 584 u8 field_flags; 585}; 586 587VIRTCHNL_CHECK_STRUCT_LEN(272, virtchnl_filter); 588 589/* VIRTCHNL_OP_EVENT 590 * PF sends this message to inform the VF driver of events that may affect it. 591 * No direct response is expected from the VF, though it may generate other 592 * messages in response to this one. 593 */ 594enum virtchnl_event_codes { 595 VIRTCHNL_EVENT_UNKNOWN = 0, 596 VIRTCHNL_EVENT_LINK_CHANGE, 597 VIRTCHNL_EVENT_RESET_IMPENDING, 598 VIRTCHNL_EVENT_PF_DRIVER_CLOSE, 599}; 600 601#define PF_EVENT_SEVERITY_INFO 0 602#define PF_EVENT_SEVERITY_CERTAIN_DOOM 255 603 604struct virtchnl_pf_event { 605 enum virtchnl_event_codes event; 606 union { 607 /* If the PF driver does not support the new speed reporting 608 * capabilities then use link_event else use link_event_adv to 609 * get the speed and link information. The ability to understand 610 * new speeds is indicated by setting the capability flag 611 * VIRTCHNL_VF_CAP_ADV_LINK_SPEED in vf_cap_flags parameter 612 * in virtchnl_vf_resource struct and can be used to determine 613 * which link event struct to use below. 614 */ 615 struct { 616 enum virtchnl_link_speed link_speed; 617 bool link_status; 618 } link_event; 619 struct { 620 /* link_speed provided in Mbps */ 621 u32 link_speed; 622 u8 link_status; 623 } link_event_adv; 624 } event_data; 625 626 int severity; 627}; 628 629VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_pf_event); 630 631/* VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP 632 * VF uses this message to request PF to map IWARP vectors to IWARP queues. 633 * The request for this originates from the VF IWARP driver through 634 * a client interface between VF LAN and VF IWARP driver. 635 * A vector could have an AEQ and CEQ attached to it although 636 * there is a single AEQ per VF IWARP instance in which case 637 * most vectors will have an INVALID_IDX for aeq and valid idx for ceq. 638 * There will never be a case where there will be multiple CEQs attached 639 * to a single vector. 640 * PF configures interrupt mapping and returns status. 641 */ 642 643struct virtchnl_iwarp_qv_info { 644 u32 v_idx; /* msix_vector */ 645 u16 ceq_idx; 646 u16 aeq_idx; 647 u8 itr_idx; 648}; 649 650VIRTCHNL_CHECK_STRUCT_LEN(12, virtchnl_iwarp_qv_info); 651 652struct virtchnl_iwarp_qvlist_info { 653 u32 num_vectors; 654 struct virtchnl_iwarp_qv_info qv_info[1]; 655}; 656 657VIRTCHNL_CHECK_STRUCT_LEN(16, virtchnl_iwarp_qvlist_info); 658 659/* VF reset states - these are written into the RSTAT register: 660 * VFGEN_RSTAT on the VF 661 * When the PF initiates a reset, it writes 0 662 * When the reset is complete, it writes 1 663 * When the PF detects that the VF has recovered, it writes 2 664 * VF checks this register periodically to determine if a reset has occurred, 665 * then polls it to know when the reset is complete. 666 * If either the PF or VF reads the register while the hardware 667 * is in a reset state, it will return DEADBEEF, which, when masked 668 * will result in 3. 669 */ 670enum virtchnl_vfr_states { 671 VIRTCHNL_VFR_INPROGRESS = 0, 672 VIRTCHNL_VFR_COMPLETED, 673 VIRTCHNL_VFR_VFACTIVE, 674}; 675 676/** 677 * virtchnl_vc_validate_vf_msg 678 * @ver: Virtchnl version info 679 * @v_opcode: Opcode for the message 680 * @msg: pointer to the msg buffer 681 * @msglen: msg length 682 * 683 * validate msg format against struct for each opcode 684 */ 685static inline int 686virtchnl_vc_validate_vf_msg(struct virtchnl_version_info *ver, u32 v_opcode, 687 u8 *msg, u16 msglen) 688{ 689 bool err_msg_format = false; 690 int valid_len = 0; 691 692 /* Validate message length. */ 693 switch (v_opcode) { 694 case VIRTCHNL_OP_VERSION: 695 valid_len = sizeof(struct virtchnl_version_info); 696 break; 697 case VIRTCHNL_OP_RESET_VF: 698 break; 699 case VIRTCHNL_OP_GET_VF_RESOURCES: 700 if (VF_IS_V11(ver)) 701 valid_len = sizeof(u32); 702 break; 703 case VIRTCHNL_OP_CONFIG_TX_QUEUE: 704 valid_len = sizeof(struct virtchnl_txq_info); 705 break; 706 case VIRTCHNL_OP_CONFIG_RX_QUEUE: 707 valid_len = sizeof(struct virtchnl_rxq_info); 708 break; 709 case VIRTCHNL_OP_CONFIG_VSI_QUEUES: 710 valid_len = sizeof(struct virtchnl_vsi_queue_config_info); 711 if (msglen >= valid_len) { 712 struct virtchnl_vsi_queue_config_info *vqc = 713 (struct virtchnl_vsi_queue_config_info *)msg; 714 valid_len += (vqc->num_queue_pairs * 715 sizeof(struct 716 virtchnl_queue_pair_info)); 717 if (vqc->num_queue_pairs == 0) 718 err_msg_format = true; 719 } 720 break; 721 case VIRTCHNL_OP_CONFIG_IRQ_MAP: 722 valid_len = sizeof(struct virtchnl_irq_map_info); 723 if (msglen >= valid_len) { 724 struct virtchnl_irq_map_info *vimi = 725 (struct virtchnl_irq_map_info *)msg; 726 valid_len += (vimi->num_vectors * 727 sizeof(struct virtchnl_vector_map)); 728 if (vimi->num_vectors == 0) 729 err_msg_format = true; 730 } 731 break; 732 case VIRTCHNL_OP_ENABLE_QUEUES: 733 case VIRTCHNL_OP_DISABLE_QUEUES: 734 valid_len = sizeof(struct virtchnl_queue_select); 735 break; 736 case VIRTCHNL_OP_ADD_ETH_ADDR: 737 case VIRTCHNL_OP_DEL_ETH_ADDR: 738 valid_len = sizeof(struct virtchnl_ether_addr_list); 739 if (msglen >= valid_len) { 740 struct virtchnl_ether_addr_list *veal = 741 (struct virtchnl_ether_addr_list *)msg; 742 valid_len += veal->num_elements * 743 sizeof(struct virtchnl_ether_addr); 744 if (veal->num_elements == 0) 745 err_msg_format = true; 746 } 747 break; 748 case VIRTCHNL_OP_ADD_VLAN: 749 case VIRTCHNL_OP_DEL_VLAN: 750 valid_len = sizeof(struct virtchnl_vlan_filter_list); 751 if (msglen >= valid_len) { 752 struct virtchnl_vlan_filter_list *vfl = 753 (struct virtchnl_vlan_filter_list *)msg; 754 valid_len += vfl->num_elements * sizeof(u16); 755 if (vfl->num_elements == 0) 756 err_msg_format = true; 757 } 758 break; 759 case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE: 760 valid_len = sizeof(struct virtchnl_promisc_info); 761 break; 762 case VIRTCHNL_OP_GET_STATS: 763 valid_len = sizeof(struct virtchnl_queue_select); 764 break; 765 case VIRTCHNL_OP_IWARP: 766 /* These messages are opaque to us and will be validated in 767 * the RDMA client code. We just need to check for nonzero 768 * length. The firmware will enforce max length restrictions. 769 */ 770 if (msglen) 771 valid_len = msglen; 772 else 773 err_msg_format = true; 774 break; 775 case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP: 776 break; 777 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP: 778 valid_len = sizeof(struct virtchnl_iwarp_qvlist_info); 779 if (msglen >= valid_len) { 780 struct virtchnl_iwarp_qvlist_info *qv = 781 (struct virtchnl_iwarp_qvlist_info *)msg; 782 if (qv->num_vectors == 0) { 783 err_msg_format = true; 784 break; 785 } 786 valid_len += ((qv->num_vectors - 1) * 787 sizeof(struct virtchnl_iwarp_qv_info)); 788 } 789 break; 790 case VIRTCHNL_OP_CONFIG_RSS_KEY: 791 valid_len = sizeof(struct virtchnl_rss_key); 792 if (msglen >= valid_len) { 793 struct virtchnl_rss_key *vrk = 794 (struct virtchnl_rss_key *)msg; 795 valid_len += vrk->key_len - 1; 796 } 797 break; 798 case VIRTCHNL_OP_CONFIG_RSS_LUT: 799 valid_len = sizeof(struct virtchnl_rss_lut); 800 if (msglen >= valid_len) { 801 struct virtchnl_rss_lut *vrl = 802 (struct virtchnl_rss_lut *)msg; 803 valid_len += vrl->lut_entries - 1; 804 } 805 break; 806 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: 807 break; 808 case VIRTCHNL_OP_SET_RSS_HENA: 809 valid_len = sizeof(struct virtchnl_rss_hena); 810 break; 811 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING: 812 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING: 813 break; 814 case VIRTCHNL_OP_REQUEST_QUEUES: 815 valid_len = sizeof(struct virtchnl_vf_res_request); 816 break; 817 case VIRTCHNL_OP_ENABLE_CHANNELS: 818 valid_len = sizeof(struct virtchnl_tc_info); 819 if (msglen >= valid_len) { 820 struct virtchnl_tc_info *vti = 821 (struct virtchnl_tc_info *)msg; 822 valid_len += vti->num_tc * 823 sizeof(struct virtchnl_channel_info); 824 if (vti->num_tc == 0) 825 err_msg_format = true; 826 } 827 break; 828 case VIRTCHNL_OP_DISABLE_CHANNELS: 829 break; 830 case VIRTCHNL_OP_ADD_CLOUD_FILTER: 831 valid_len = sizeof(struct virtchnl_filter); 832 break; 833 case VIRTCHNL_OP_DEL_CLOUD_FILTER: 834 valid_len = sizeof(struct virtchnl_filter); 835 break; 836 /* These are always errors coming from the VF. */ 837 case VIRTCHNL_OP_EVENT: 838 case VIRTCHNL_OP_UNKNOWN: 839 default: 840 return VIRTCHNL_STATUS_ERR_PARAM; 841 } 842 /* few more checks */ 843 if (err_msg_format || valid_len != msglen) 844 return VIRTCHNL_STATUS_ERR_OPCODE_MISMATCH; 845 846 return 0; 847} 848#endif /* _VIRTCHNL_H_ */