1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2016 - 2018 Cavium Inc.
7 #ifndef __ECORE_SRIOV_API_H__
8 #define __ECORE_SRIOV_API_H__
10 #include "common_hsi.h"
11 #include "ecore_status.h"
13 #define ECORE_ETH_VF_NUM_MAC_FILTERS 1
14 #define ECORE_ETH_VF_NUM_VLAN_FILTERS 2
15 #define ECORE_VF_ARRAY_LENGTH (3)
17 #define IS_VF(p_dev) ((p_dev)->b_is_vf)
18 #define IS_PF(p_dev) (!((p_dev)->b_is_vf))
19 #ifdef CONFIG_ECORE_SRIOV
20 #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->p_dev->p_iov_info))
22 #define IS_PF_SRIOV(p_hwfn) (0)
24 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
25 #define IS_PF_PDA(p_hwfn) 0 /* @@TBD Michalk */
27 /* @@@ TBD MichalK - what should this number be*/
28 #define ECORE_MAX_VF_CHAINS_PER_PF 16
30 /* vport update extended feature tlvs flags */
31 enum ecore_iov_vport_update_flag {
32 ECORE_IOV_VP_UPDATE_ACTIVATE = 0,
33 ECORE_IOV_VP_UPDATE_VLAN_STRIP = 1,
34 ECORE_IOV_VP_UPDATE_TX_SWITCH = 2,
35 ECORE_IOV_VP_UPDATE_MCAST = 3,
36 ECORE_IOV_VP_UPDATE_ACCEPT_PARAM = 4,
37 ECORE_IOV_VP_UPDATE_RSS = 5,
38 ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN = 6,
39 ECORE_IOV_VP_UPDATE_SGE_TPA = 7,
40 ECORE_IOV_VP_UPDATE_MAX = 8,
43 /* PF to VF STATUS is part of vfpf-channel API
44 * and must be forward compatible
46 enum ecore_iov_pf_to_vf_status {
47 PFVF_STATUS_WAITING = 0,
50 PFVF_STATUS_NOT_SUPPORTED,
51 PFVF_STATUS_NO_RESOURCE,
53 PFVF_STATUS_MALICIOUS,
57 struct ecore_mcp_link_params;
58 struct ecore_mcp_link_state;
59 struct ecore_mcp_link_capabilities;
61 /* These defines are used by the hw-channel; should never change order */
62 #define VFPF_ACQUIRE_OS_LINUX (0)
63 #define VFPF_ACQUIRE_OS_WINDOWS (1)
64 #define VFPF_ACQUIRE_OS_ESX (2)
65 #define VFPF_ACQUIRE_OS_SOLARIS (3)
66 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4)
68 struct ecore_vf_acquire_sw_info {
72 /* We have several close releases that all use ~same FW with different
73 * versions [making it incompatible as the versioning scheme is still
74 * tied directly to FW version], allow to override the checking. Only
75 * those versions would actually support this feature [so it would not
76 * break forward compatibility with newer HV drivers that are no longer
79 bool override_fw_version;
82 struct ecore_public_vf_info {
83 /* These copies will later be reflected in the bulletin board,
84 * but this copy should be newer.
86 u8 forced_mac[ETH_ALEN];
89 /* Trusted VFs can configure promiscuous mode and
90 * set MAC address inspite PF has set forced MAC.
91 * Also store shadow promisc configuration if needed.
93 bool is_trusted_configured;
94 bool is_trusted_request;
97 struct ecore_iov_vf_init_params {
100 /* Number of requested Queues; Currently, don't support different
101 * number of Rx/Tx queues.
103 /* TODO - remove this limitation */
106 /* Allow the client to choose which qzones to use for Rx/Tx,
107 * and which queue_base to use for Tx queues on a per-queue basis.
108 * Notice values should be relative to the PF resources.
110 u16 req_rx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
111 u16 req_tx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
115 /* Should be set in case RSS is going to be used for VF */
119 #ifdef CONFIG_ECORE_SW_CHANNEL
120 /* This is SW channel related only... */
122 VF_PF_UNKNOWN_STATE = 0,
123 VF_PF_WAIT_FOR_START_REQUEST = 1,
124 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
125 VF_PF_REQUEST_IN_PROCESSING = 3,
126 VF_PF_RESPONSE_READY = 4,
129 struct ecore_iov_sw_mbx {
130 enum mbx_state mbx_state;
140 * @brief Get the vf sw mailbox params
145 * @return struct ecore_iov_sw_mbx*
147 struct ecore_iov_sw_mbx*
148 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
152 /* This struct is part of ecore_dev and contains data relevant to all hwfns;
153 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
155 struct ecore_hw_sriov_info {
156 /* standard SRIOV capability fields, mostly for debugging */
157 int pos; /* capability position */
158 int nres; /* number of resources */
159 u32 cap; /* SR-IOV Capabilities */
160 u16 ctrl; /* SR-IOV Control */
161 u16 total_vfs; /* total VFs associated with the PF */
162 u16 num_vfs; /* number of vfs that have been started */
163 u16 initial_vfs; /* initial VFs associated with the PF */
164 u16 nr_virtfn; /* number of VFs available */
165 u16 offset; /* first VF Routing ID offset */
166 u16 stride; /* following VF stride */
167 u16 vf_device_id; /* VF device id */
168 u32 pgsz; /* page size for BAR alignment */
169 u8 link; /* Function Dependency Link */
174 #ifdef CONFIG_ECORE_SRIOV
177 * @brief mark/clear all VFs before/after an incoming PCIe sriov
183 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
187 * @brief mark/clear chosen VF before/after an incoming PCIe
194 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
199 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
200 * enabling access of a VF. Also includes preparing the
201 * IGU for VF access. This needs to be called AFTER hw is
202 * initialized and BEFORE VF is loaded inside the VM.
208 * @return enum _ecore_status_t
210 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
211 struct ecore_ptt *p_ptt,
212 struct ecore_iov_vf_init_params
216 * @brief ecore_iov_process_mbx_req - process a request received
223 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
224 struct ecore_ptt *p_ptt,
228 * @brief ecore_iov_release_hw_for_vf - called once upper layer
229 * knows VF is done with - can release any resources
230 * allocated for VF at this point. this must be done once
231 * we know VF is no longer loaded in VM.
237 * @return enum _ecore_status_t
239 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
240 struct ecore_ptt *p_ptt,
244 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
250 * @return enum _ecore_status_t
252 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
257 * @brief FLR cleanup for all VFs
262 * @return enum _ecore_status_t
264 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
265 struct ecore_ptt *p_ptt);
268 * @brief FLR cleanup for single VF
274 * @return enum _ecore_status_t
277 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
278 struct ecore_ptt *p_ptt,
282 * @brief Update the bulletin with link information. Notice this does NOT
283 * send a bulletin update, only updates the PF's bulletin.
287 * @param params - the link params to use for the VF link configuration
288 * @param link - the link output to use for the VF link configuration
289 * @param p_caps - the link default capabilities.
291 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
293 struct ecore_mcp_link_params *params,
294 struct ecore_mcp_link_state *link,
295 struct ecore_mcp_link_capabilities *p_caps);
298 * @brief Returns link information as perceived by VF.
302 * @param p_params - the link params visible to vf.
303 * @param p_link - the link state visible to vf.
304 * @param p_caps - the link default capabilities visible to vf.
306 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
308 struct ecore_mcp_link_params *params,
309 struct ecore_mcp_link_state *link,
310 struct ecore_mcp_link_capabilities *p_caps);
313 * @brief return if the VF is pending FLR
320 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
324 * @brief Check if given VF ID @vfid is valid
325 * w.r.t. @b_enabled_only value
326 * if b_enabled_only = true - only enabled VF id is valid
327 * else any VF id less than max_vfs is valid
330 * @param rel_vf_id - Relative VF ID
331 * @param b_enabled_only - consider only enabled VF
332 * @param b_non_malicious - true iff we want to validate vf isn't malicious.
334 * @return bool - true for valid VF ID
336 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
338 bool b_enabled_only, bool b_non_malicious);
341 * @brief Get VF's public info structure
344 * @param vfid - Relative VF ID
345 * @param b_enabled_only - false if want to access even if vf is disabled
347 * @return struct ecore_public_vf_info *
349 struct ecore_public_vf_info*
350 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
351 u16 vfid, bool b_enabled_only);
354 * @brief fills a bitmask of all VFs which have pending unhandled
359 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
363 * @brief Copy VF's message to PF's buffer
369 * @return enum _ecore_status_t
371 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
372 struct ecore_ptt *ptt,
375 * @brief Set forced MAC address in PFs copy of bulletin board
376 * and configures FW/HW to support the configuration.
382 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
386 * @brief Set MAC address in PFs copy of bulletin board without
393 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
397 * @brief Set default behaviour of VF in case no vlans are configured for it
398 * whether to accept only untagged traffic or all.
399 * Must be called prior to the VF vport-start.
402 * @param b_untagged_only
405 * @return ECORE_SUCCESS if configuration would stick.
408 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
409 bool b_untagged_only,
413 * @brief Get VFs opaque fid.
419 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
423 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
424 * and configures FW/HW to support the configuration.
425 * Setting of pvid 0 would clear the feature.
430 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
434 * @brief Check if VF has VPORT instance. This can be used
435 * to check if VPORT is active.
439 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
442 * @brief PF posts the bulletin to the VF
448 * @return enum _ecore_status_t
450 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
452 struct ecore_ptt *p_ptt);
455 * @brief Check if given VF (@vfid) is marked as stopped
460 * @return bool : true if stopped
462 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
465 * @brief Configure VF anti spoofing
469 * @param val - spoofchk value - true/false
471 * @return enum _ecore_status_t
473 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
477 * @brief Get VF's configured spoof value.
482 * @return bool - spoofchk value - true/false
484 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
487 * @brief Check for SRIOV sanity by PF.
492 * @return bool - true if sanity checks passes, else false
494 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
497 * @brief Get the num of VF chains.
503 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
506 * @brief Get vf request mailbox params
510 * @param pp_req_virt_addr
511 * @param p_req_virt_size
513 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
515 void **pp_req_virt_addr,
516 u16 *p_req_virt_size);
519 * @brief Get vf mailbox params
523 * @param pp_reply_virt_addr
524 * @param p_reply_virt_size
526 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
528 void **pp_reply_virt_addr,
529 u16 *p_reply_virt_size);
532 * @brief Validate if the given length is a valid vfpf message
539 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
542 * @brief Return the max pfvf message length
546 u32 ecore_iov_pfvf_msg_length(void);
549 * @brief Returns MAC address if one is configured
554 * @return OSAL_NULL if mac isn't set; Otherwise, returns MAC.
556 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
560 * @brief Returns forced MAC address if one is configured
565 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
567 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
571 * @brief Returns pvid if one is configured
576 * @return 0 if no pvid is configured, otherwise the pvid.
578 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
581 * @brief Configure VFs tx rate
586 * @param val - tx rate value in Mb/sec.
588 * @return enum _ecore_status_t
590 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
591 struct ecore_ptt *p_ptt,
595 * @brief - Retrieves the statistics associated with a VF
600 * @param p_stats - this will be filled with the VF statistics
602 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
604 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
605 struct ecore_ptt *p_ptt,
607 struct ecore_eth_stats *p_stats);
610 * @brief - Retrieves num of rxqs chains
615 * @return num of rxqs chains.
617 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
621 * @brief - Retrieves num of active rxqs chains
628 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
632 * @brief - Retrieves ctx pointer
639 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
643 * @brief - Retrieves VF`s num sbs
650 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
654 * @brief - Returm true if VF is waiting for acquire
661 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
665 * @brief - Returm true if VF is acquired but not initialized
672 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
676 * @brief - Returm true if VF is acquired and initialized
683 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
687 * @brief - Returm true if VF has started in FW
694 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
698 * @brief - Get VF's vport min rate configured.
702 * @return - rate in Mbps
704 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
707 * @brief - Configure min rate for VF's vport.
710 * @param - rate in Mbps
714 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
719 * @brief ecore_pf_configure_vf_queue_coalesce - PF configure coalesce
720 * parameters of VFs for Rx and Tx queue.
721 * While the API allows setting coalescing per-qid, all queues sharing a SB
722 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
723 * otherwise configuration would break.
726 * @param rx_coal - Rx Coalesce value in micro seconds.
727 * @param tx_coal - TX Coalesce value in micro seconds.
734 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
735 u16 rx_coal, u16 tx_coal,
739 * @brief - Given a VF index, return index of next [including that] active VF.
744 * @return MAX_NUM_VFS_K2 in case no further active VFs, otherwise index.
746 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
748 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn, int vfid,
749 u16 vxlan_port, u16 geneve_port);
751 #ifdef CONFIG_ECORE_SW_CHANNEL
753 * @brief Set whether PF should communicate with VF using SW/HW channel
754 * Needs to be called for an enabled VF before acquire is over
755 * [latest good point for doing that is OSAL_IOV_VF_ACQUIRE()]
758 * @param vfid - relative vf index
759 * @param b_is_hw - true iff PF is to use HW channel for communication
761 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
764 #endif /* CONFIG_ECORE_SRIOV */
766 #define ecore_for_each_vf(_p_hwfn, _i) \
767 for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0); \
768 _i < MAX_NUM_VFS_K2; \
769 _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1))