1 /* 2 * Copyright (c) 2016 QLogic Corporation. 3 * All rights reserved. 4 * www.qlogic.com 5 * 6 * See LICENSE.qede_pmd for copyright and licensing details. 7 */ 8 9 #ifndef __ECORE_SRIOV_API_H__ 10 #define __ECORE_SRIOV_API_H__ 11 12 #include "common_hsi.h" 13 #include "ecore_status.h" 14 15 #define ECORE_ETH_VF_NUM_MAC_FILTERS 1 16 #define ECORE_ETH_VF_NUM_VLAN_FILTERS 2 17 #define ECORE_VF_ARRAY_LENGTH (3) 18 19 #define IS_VF(p_dev) ((p_dev)->b_is_vf) 20 #define IS_PF(p_dev) (!((p_dev)->b_is_vf)) 21 #ifdef CONFIG_ECORE_SRIOV 22 #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->p_dev->p_iov_info)) 23 #else 24 #define IS_PF_SRIOV(p_hwfn) (0) 25 #endif 26 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info)) 27 #define IS_PF_PDA(p_hwfn) 0 /* @@TBD Michalk */ 28 29 /* @@@ TBD MichalK - what should this number be*/ 30 #define ECORE_MAX_VF_CHAINS_PER_PF 16 31 32 /* vport update extended feature tlvs flags */ 33 enum ecore_iov_vport_update_flag { 34 ECORE_IOV_VP_UPDATE_ACTIVATE = 0, 35 ECORE_IOV_VP_UPDATE_VLAN_STRIP = 1, 36 ECORE_IOV_VP_UPDATE_TX_SWITCH = 2, 37 ECORE_IOV_VP_UPDATE_MCAST = 3, 38 ECORE_IOV_VP_UPDATE_ACCEPT_PARAM = 4, 39 ECORE_IOV_VP_UPDATE_RSS = 5, 40 ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN = 6, 41 ECORE_IOV_VP_UPDATE_SGE_TPA = 7, 42 ECORE_IOV_VP_UPDATE_MAX = 8, 43 }; 44 45 /* PF to VF STATUS is part of vfpf-channel API 46 * and must be forward compatible 47 */ 48 enum ecore_iov_pf_to_vf_status { 49 PFVF_STATUS_WAITING = 0, 50 PFVF_STATUS_SUCCESS, 51 PFVF_STATUS_FAILURE, 52 PFVF_STATUS_NOT_SUPPORTED, 53 PFVF_STATUS_NO_RESOURCE, 54 PFVF_STATUS_FORCED, 55 PFVF_STATUS_MALICIOUS, 56 }; 57 58 struct ecore_mcp_link_params; 59 struct ecore_mcp_link_state; 60 struct ecore_mcp_link_capabilities; 61 62 /* These defines are used by the hw-channel; should never change order */ 63 #define VFPF_ACQUIRE_OS_LINUX (0) 64 #define VFPF_ACQUIRE_OS_WINDOWS (1) 65 #define VFPF_ACQUIRE_OS_ESX (2) 66 #define VFPF_ACQUIRE_OS_SOLARIS (3) 67 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4) 68 69 struct ecore_vf_acquire_sw_info { 70 u32 driver_version; 71 u8 os_type; 72 73 /* We have several close releases that all use ~same FW with different 74 * versions [making it incompatible as the versioning scheme is still 75 * tied directly to FW version], allow to override the checking. Only 76 * those versions would actually support this feature [so it would not 77 * break forward compatibility with newer HV drivers that are no longer 78 * suited]. 79 */ 80 bool override_fw_version; 81 }; 82 83 struct ecore_public_vf_info { 84 /* These copies will later be reflected in the bulletin board, 85 * but this copy should be newer. 86 */ 87 u8 forced_mac[ETH_ALEN]; 88 u16 forced_vlan; 89 }; 90 91 #ifdef CONFIG_ECORE_SW_CHANNEL 92 /* This is SW channel related only... */ 93 enum mbx_state { 94 VF_PF_UNKNOWN_STATE = 0, 95 VF_PF_WAIT_FOR_START_REQUEST = 1, 96 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2, 97 VF_PF_REQUEST_IN_PROCESSING = 3, 98 VF_PF_RESPONSE_READY = 4, 99 }; 100 101 struct ecore_iov_sw_mbx { 102 enum mbx_state mbx_state; 103 104 u32 request_size; 105 u32 request_offset; 106 107 u32 response_size; 108 u32 response_offset; 109 }; 110 111 /** 112 * @brief Get the vf sw mailbox params 113 * 114 * @param p_hwfn 115 * @param rel_vf_id 116 * 117 * @return struct ecore_iov_sw_mbx* 118 */ 119 struct ecore_iov_sw_mbx* 120 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn, 121 u16 rel_vf_id); 122 #endif 123 124 /* This struct is part of ecore_dev and contains data relevant to all hwfns; 125 * Initialized only if SR-IOV cpabability is exposed in PCIe config space. 126 */ 127 struct ecore_hw_sriov_info { 128 /* standard SRIOV capability fields, mostly for debugging */ 129 int pos; /* capability position */ 130 int nres; /* number of resources */ 131 u32 cap; /* SR-IOV Capabilities */ 132 u16 ctrl; /* SR-IOV Control */ 133 u16 total_vfs; /* total VFs associated with the PF */ 134 u16 num_vfs; /* number of vfs that have been started */ 135 u16 initial_vfs; /* initial VFs associated with the PF */ 136 u16 nr_virtfn; /* number of VFs available */ 137 u16 offset; /* first VF Routing ID offset */ 138 u16 stride; /* following VF stride */ 139 u16 vf_device_id; /* VF device id */ 140 u32 pgsz; /* page size for BAR alignment */ 141 u8 link; /* Function Dependency Link */ 142 143 u32 first_vf_in_pf; 144 }; 145 146 #ifdef CONFIG_ECORE_SRIOV 147 #ifndef LINUX_REMOVE 148 /** 149 * @brief mark/clear all VFs before/after an incoming PCIe sriov 150 * disable. 151 * 152 * @param p_dev 153 * @param to_disable 154 */ 155 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev, 156 u8 to_disable); 157 158 /** 159 * @brief mark/clear chosen VF before/after an incoming PCIe 160 * sriov disable. 161 * 162 * @param p_dev 163 * @param rel_vf_id 164 * @param to_disable 165 */ 166 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev, 167 u16 rel_vf_id, 168 u8 to_disable); 169 170 /** 171 * @brief ecore_iov_init_hw_for_vf - initialize the HW for 172 * enabling access of a VF. Also includes preparing the 173 * IGU for VF access. This needs to be called AFTER hw is 174 * initialized and BEFORE VF is loaded inside the VM. 175 * 176 * @param p_hwfn 177 * @param p_ptt 178 * @param rel_vf_id 179 * @param num_rx_queues 180 * 181 * @return enum _ecore_status_t 182 */ 183 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn, 184 struct ecore_ptt *p_ptt, 185 u16 rel_vf_id, 186 u16 num_rx_queues); 187 188 /** 189 * @brief ecore_iov_process_mbx_req - process a request received 190 * from the VF 191 * 192 * @param p_hwfn 193 * @param p_ptt 194 * @param vfid 195 */ 196 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn, 197 struct ecore_ptt *p_ptt, 198 int vfid); 199 200 /** 201 * @brief ecore_iov_release_hw_for_vf - called once upper layer 202 * knows VF is done with - can release any resources 203 * allocated for VF at this point. this must be done once 204 * we know VF is no longer loaded in VM. 205 * 206 * @param p_hwfn 207 * @param p_ptt 208 * @param rel_vf_id 209 * 210 * @return enum _ecore_status_t 211 */ 212 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn, 213 struct ecore_ptt *p_ptt, 214 u16 rel_vf_id); 215 216 /** 217 * @brief ecore_iov_set_vf_ctx - set a context for a given VF 218 * 219 * @param p_hwfn 220 * @param vf_id 221 * @param ctx 222 * 223 * @return enum _ecore_status_t 224 */ 225 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn, 226 u16 vf_id, 227 void *ctx); 228 229 /** 230 * @brief FLR cleanup for all VFs 231 * 232 * @param p_hwfn 233 * @param p_ptt 234 * 235 * @return enum _ecore_status_t 236 */ 237 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn, 238 struct ecore_ptt *p_ptt); 239 240 /** 241 * @brief FLR cleanup for single VF 242 * 243 * @param p_hwfn 244 * @param p_ptt 245 * @param rel_vf_id 246 * 247 * @return enum _ecore_status_t 248 */ 249 enum _ecore_status_t 250 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn, 251 struct ecore_ptt *p_ptt, 252 u16 rel_vf_id); 253 254 /** 255 * @brief Update the bulletin with link information. Notice this does NOT 256 * send a bulletin update, only updates the PF's bulletin. 257 * 258 * @param p_hwfn 259 * @param p_vf 260 * @param params - the link params to use for the VF link configuration 261 * @param link - the link output to use for the VF link configuration 262 * @param p_caps - the link default capabilities. 263 */ 264 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn, 265 u16 vfid, 266 struct ecore_mcp_link_params *params, 267 struct ecore_mcp_link_state *link, 268 struct ecore_mcp_link_capabilities *p_caps); 269 270 /** 271 * @brief Returns link information as perceived by VF. 272 * 273 * @param p_hwfn 274 * @param p_vf 275 * @param p_params - the link params visible to vf. 276 * @param p_link - the link state visible to vf. 277 * @param p_caps - the link default capabilities visible to vf. 278 */ 279 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn, 280 u16 vfid, 281 struct ecore_mcp_link_params *params, 282 struct ecore_mcp_link_state *link, 283 struct ecore_mcp_link_capabilities *p_caps); 284 285 /** 286 * @brief return if the VF is pending FLR 287 * 288 * @param p_hwfn 289 * @param rel_vf_id 290 * 291 * @return bool 292 */ 293 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, 294 u16 rel_vf_id); 295 296 /** 297 * @brief Check if given VF ID @vfid is valid 298 * w.r.t. @b_enabled_only value 299 * if b_enabled_only = true - only enabled VF id is valid 300 * else any VF id less than max_vfs is valid 301 * 302 * @param p_hwfn 303 * @param rel_vf_id - Relative VF ID 304 * @param b_enabled_only - consider only enabled VF 305 * @param b_non_malicious - true iff we want to validate vf isn't malicious. 306 * 307 * @return bool - true for valid VF ID 308 */ 309 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn, 310 int rel_vf_id, 311 bool b_enabled_only, bool b_non_malicious); 312 313 /** 314 * @brief Get VF's public info structure 315 * 316 * @param p_hwfn 317 * @param vfid - Relative VF ID 318 * @param b_enabled_only - false if want to access even if vf is disabled 319 * 320 * @return struct ecore_public_vf_info * 321 */ 322 struct ecore_public_vf_info* 323 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn, 324 u16 vfid, bool b_enabled_only); 325 326 /** 327 * @brief Set pending events bitmap for given @vfid 328 * 329 * @param p_hwfn 330 * @param vfid 331 */ 332 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid); 333 334 /** 335 * @brief Copy pending events bitmap in @events and clear 336 * original copy of events 337 * 338 * @param p_hwfn 339 */ 340 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn, 341 u64 *events); 342 343 /** 344 * @brief Copy VF's message to PF's buffer 345 * 346 * @param p_hwfn 347 * @param ptt 348 * @param vfid 349 * 350 * @return enum _ecore_status_t 351 */ 352 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn, 353 struct ecore_ptt *ptt, 354 int vfid); 355 /** 356 * @brief Set forced MAC address in PFs copy of bulletin board 357 * and configures FW/HW to support the configuration. 358 * 359 * @param p_hwfn 360 * @param mac 361 * @param vfid 362 */ 363 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn, 364 u8 *mac, int vfid); 365 366 /** 367 * @brief Set MAC address in PFs copy of bulletin board without 368 * configuring FW/HW. 369 * 370 * @param p_hwfn 371 * @param mac 372 * @param vfid 373 */ 374 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn, 375 u8 *mac, int vfid); 376 377 /** 378 * @brief Set default behaviour of VF in case no vlans are configured for it 379 * whether to accept only untagged traffic or all. 380 * Must be called prior to the VF vport-start. 381 * 382 * @param p_hwfn 383 * @param b_untagged_only 384 * @param vfid 385 * 386 * @return ECORE_SUCCESS if configuration would stick. 387 */ 388 enum _ecore_status_t 389 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn, 390 bool b_untagged_only, 391 int vfid); 392 393 /** 394 * @brief Get VFs opaque fid. 395 * 396 * @param p_hwfn 397 * @param vfid 398 * @param opaque_fid 399 */ 400 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid, 401 u16 *opaque_fid); 402 403 /** 404 * @brief Get VFs VPORT id. 405 * 406 * @param p_hwfn 407 * @param vfid 408 * @param vport id 409 */ 410 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid, 411 u8 *p_vport_id); 412 413 /** 414 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board 415 * and configures FW/HW to support the configuration. 416 * Setting of pvid 0 would clear the feature. 417 * @param p_hwfn 418 * @param pvid 419 * @param vfid 420 */ 421 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn, 422 u16 pvid, int vfid); 423 424 /** 425 * @brief Check if VF has VPORT instance. This can be used 426 * to check if VPORT is active. 427 * 428 * @param p_hwfn 429 */ 430 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid); 431 432 /** 433 * @brief PF posts the bulletin to the VF 434 * 435 * @param p_hwfn 436 * @param p_vf 437 * @param p_ptt 438 * 439 * @return enum _ecore_status_t 440 */ 441 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn, 442 int vfid, 443 struct ecore_ptt *p_ptt); 444 445 /** 446 * @brief Check if given VF (@vfid) is marked as stopped 447 * 448 * @param p_hwfn 449 * @param vfid 450 * 451 * @return bool : true if stopped 452 */ 453 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid); 454 455 /** 456 * @brief Configure VF anti spoofing 457 * 458 * @param p_hwfn 459 * @param vfid 460 * @param val - spoofchk value - true/false 461 * 462 * @return enum _ecore_status_t 463 */ 464 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn, 465 int vfid, bool val); 466 467 /** 468 * @brief Get VF's configured spoof value. 469 * 470 * @param p_hwfn 471 * @param vfid 472 * 473 * @return bool - spoofchk value - true/false 474 */ 475 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid); 476 477 /** 478 * @brief Check for SRIOV sanity by PF. 479 * 480 * @param p_hwfn 481 * @param vfid 482 * 483 * @return bool - true if sanity checks passes, else false 484 */ 485 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid); 486 487 /** 488 * @brief Get the num of VF chains. 489 * 490 * @param p_hwfn 491 * 492 * @return u8 493 */ 494 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn); 495 496 /** 497 * @brief Get vf request mailbox params 498 * 499 * @param p_hwfn 500 * @param rel_vf_id 501 * @param pp_req_virt_addr 502 * @param p_req_virt_size 503 */ 504 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn, 505 u16 rel_vf_id, 506 void **pp_req_virt_addr, 507 u16 *p_req_virt_size); 508 509 /** 510 * @brief Get vf mailbox params 511 * 512 * @param p_hwfn 513 * @param rel_vf_id 514 * @param pp_reply_virt_addr 515 * @param p_reply_virt_size 516 */ 517 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn, 518 u16 rel_vf_id, 519 void **pp_reply_virt_addr, 520 u16 *p_reply_virt_size); 521 522 /** 523 * @brief Validate if the given length is a valid vfpf message 524 * length 525 * 526 * @param length 527 * 528 * @return bool 529 */ 530 bool ecore_iov_is_valid_vfpf_msg_length(u32 length); 531 532 /** 533 * @brief Return the max pfvf message length 534 * 535 * @return u32 536 */ 537 u32 ecore_iov_pfvf_msg_length(void); 538 539 /** 540 * @brief Returns forced MAC address if one is configured 541 * 542 * @parm p_hwfn 543 * @parm rel_vf_id 544 * 545 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC. 546 */ 547 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, 548 u16 rel_vf_id); 549 550 /** 551 * @brief Returns pvid if one is configured 552 * 553 * @parm p_hwfn 554 * @parm rel_vf_id 555 * 556 * @return 0 if no pvid is configured, otherwise the pvid. 557 */ 558 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn, 559 u16 rel_vf_id); 560 /** 561 * @brief Configure VFs tx rate 562 * 563 * @param p_hwfn 564 * @param p_ptt 565 * @param vfid 566 * @param val - tx rate value in Mb/sec. 567 * 568 * @return enum _ecore_status_t 569 */ 570 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn, 571 struct ecore_ptt *p_ptt, 572 int vfid, int val); 573 574 /** 575 * @brief - Retrieves the statistics associated with a VF 576 * 577 * @param p_hwfn 578 * @param p_ptt 579 * @param vfid 580 * @param p_stats - this will be filled with the VF statistics 581 * 582 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise. 583 */ 584 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn, 585 struct ecore_ptt *p_ptt, 586 int vfid, 587 struct ecore_eth_stats *p_stats); 588 589 /** 590 * @brief - Retrieves num of rxqs chains 591 * 592 * @param p_hwfn 593 * @param rel_vf_id 594 * 595 * @return num of rxqs chains. 596 */ 597 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, 598 u16 rel_vf_id); 599 600 /** 601 * @brief - Retrieves num of active rxqs chains 602 * 603 * @param p_hwfn 604 * @param rel_vf_id 605 * 606 * @return 607 */ 608 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, 609 u16 rel_vf_id); 610 611 /** 612 * @brief - Retrieves ctx pointer 613 * 614 * @param p_hwfn 615 * @param rel_vf_id 616 * 617 * @return 618 */ 619 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, 620 u16 rel_vf_id); 621 622 /** 623 * @brief - Retrieves VF`s num sbs 624 * 625 * @param p_hwfn 626 * @param rel_vf_id 627 * 628 * @return 629 */ 630 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, 631 u16 rel_vf_id); 632 633 /** 634 * @brief - Returm true if VF is waiting for acquire 635 * 636 * @param p_hwfn 637 * @param rel_vf_id 638 * 639 * @return 640 */ 641 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, 642 u16 rel_vf_id); 643 644 /** 645 * @brief - Returm true if VF is acquired but not initialized 646 * 647 * @param p_hwfn 648 * @param rel_vf_id 649 * 650 * @return 651 */ 652 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn, 653 u16 rel_vf_id); 654 655 /** 656 * @brief - Returm true if VF is acquired and initialized 657 * 658 * @param p_hwfn 659 * @param rel_vf_id 660 * 661 * @return 662 */ 663 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, 664 u16 rel_vf_id); 665 666 /** 667 * @brief - Returm true if VF has started in FW 668 * 669 * @param p_hwfn 670 * @param rel_vf_id 671 * 672 * @return 673 */ 674 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn, 675 u16 rel_vf_id); 676 677 /** 678 * @brief - Get VF's vport min rate configured. 679 * @param p_hwfn 680 * @param rel_vf_id 681 * 682 * @return - rate in Mbps 683 */ 684 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid); 685 686 /** 687 * @brief - Configure min rate for VF's vport. 688 * @param p_dev 689 * @param vfid 690 * @param - rate in Mbps 691 * 692 * @return 693 */ 694 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev, 695 int vfid, u32 rate); 696 #endif 697 698 /** 699 * @brief - Given a VF index, return index of next [including that] active VF. 700 * 701 * @param p_hwfn 702 * @param rel_vf_id 703 * 704 * @return MAX_NUM_VFS in case no further active VFs, otherwise index. 705 */ 706 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id); 707 708 #endif /* CONFIG_ECORE_SRIOV */ 709 710 #define ecore_for_each_vf(_p_hwfn, _i) \ 711 for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0); \ 712 _i < MAX_NUM_VFS; \ 713 _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1)) 714 715 #endif 716