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