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,
56 struct ecore_mcp_link_params;
57 struct ecore_mcp_link_state;
58 struct ecore_mcp_link_capabilities;
60 /* These defines are used by the hw-channel; should never change order */
61 #define VFPF_ACQUIRE_OS_LINUX (0)
62 #define VFPF_ACQUIRE_OS_WINDOWS (1)
63 #define VFPF_ACQUIRE_OS_ESX (2)
64 #define VFPF_ACQUIRE_OS_SOLARIS (3)
65 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4)
67 struct ecore_vf_acquire_sw_info {
71 /* We have several close releases that all use ~same FW with different
72 * versions [making it incompatible as the versioning scheme is still
73 * tied directly to FW version], allow to override the checking. Only
74 * those versions would actually support this feature [so it would not
75 * break forward compatibility with newer HV drivers that are no longer
78 bool override_fw_version;
81 struct ecore_public_vf_info {
82 /* These copies will later be reflected in the bulletin board,
83 * but this copy should be newer.
85 u8 forced_mac[ETH_ALEN];
88 /* Trusted VFs can configure promiscuous mode and
89 * set MAC address inspite PF has set forced MAC.
90 * Also store shadow promisc configuration if needed.
92 bool is_trusted_configured;
93 bool is_trusted_request;
96 struct ecore_iov_vf_init_params {
99 /* Number of requested Queues; Currently, don't support different
100 * number of Rx/Tx queues.
102 /* TODO - remove this limitation */
105 /* Allow the client to choose which qzones to use for Rx/Tx,
106 * and which queue_base to use for Tx queues on a per-queue basis.
107 * Notice values should be relative to the PF resources.
109 u16 req_rx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
110 u16 req_tx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
114 /* Should be set in case RSS is going to be used for VF */
118 #ifdef CONFIG_ECORE_SW_CHANNEL
119 /* This is SW channel related only... */
121 VF_PF_UNKNOWN_STATE = 0,
122 VF_PF_WAIT_FOR_START_REQUEST = 1,
123 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
124 VF_PF_REQUEST_IN_PROCESSING = 3,
125 VF_PF_RESPONSE_READY = 4,
128 struct ecore_iov_sw_mbx {
129 enum mbx_state mbx_state;
139 * @brief Get the vf sw mailbox params
144 * @return struct ecore_iov_sw_mbx*
146 struct ecore_iov_sw_mbx*
147 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
151 /* This struct is part of ecore_dev and contains data relevant to all hwfns;
152 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
154 struct ecore_hw_sriov_info {
155 /* standard SRIOV capability fields, mostly for debugging */
156 int pos; /* capability position */
157 int nres; /* number of resources */
158 u32 cap; /* SR-IOV Capabilities */
159 u16 ctrl; /* SR-IOV Control */
160 u16 total_vfs; /* total VFs associated with the PF */
161 u16 num_vfs; /* number of vfs that have been started */
162 u16 initial_vfs; /* initial VFs associated with the PF */
163 u16 nr_virtfn; /* number of VFs available */
164 u16 offset; /* first VF Routing ID offset */
165 u16 stride; /* following VF stride */
166 u16 vf_device_id; /* VF device id */
167 u32 pgsz; /* page size for BAR alignment */
168 u8 link; /* Function Dependency Link */
173 #ifdef CONFIG_ECORE_SRIOV
176 * @brief mark/clear all VFs before/after an incoming PCIe sriov
182 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
186 * @brief mark/clear chosen VF before/after an incoming PCIe
193 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
198 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
199 * enabling access of a VF. Also includes preparing the
200 * IGU for VF access. This needs to be called AFTER hw is
201 * initialized and BEFORE VF is loaded inside the VM.
207 * @return enum _ecore_status_t
209 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
210 struct ecore_ptt *p_ptt,
211 struct ecore_iov_vf_init_params
215 * @brief ecore_iov_process_mbx_req - process a request received
222 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
223 struct ecore_ptt *p_ptt,
227 * @brief ecore_iov_release_hw_for_vf - called once upper layer
228 * knows VF is done with - can release any resources
229 * allocated for VF at this point. this must be done once
230 * we know VF is no longer loaded in VM.
236 * @return enum _ecore_status_t
238 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
239 struct ecore_ptt *p_ptt,
243 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
249 * @return enum _ecore_status_t
251 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
256 * @brief FLR cleanup for all VFs
261 * @return enum _ecore_status_t
263 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
264 struct ecore_ptt *p_ptt);
267 * @brief FLR cleanup for single VF
273 * @return enum _ecore_status_t
276 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
277 struct ecore_ptt *p_ptt,
281 * @brief Update the bulletin with link information. Notice this does NOT
282 * send a bulletin update, only updates the PF's bulletin.
286 * @param params - the link params to use for the VF link configuration
287 * @param link - the link output to use for the VF link configuration
288 * @param p_caps - the link default capabilities.
290 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
292 struct ecore_mcp_link_params *params,
293 struct ecore_mcp_link_state *link,
294 struct ecore_mcp_link_capabilities *p_caps);
297 * @brief Returns link information as perceived by VF.
301 * @param p_params - the link params visible to vf.
302 * @param p_link - the link state visible to vf.
303 * @param p_caps - the link default capabilities visible to vf.
305 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
307 struct ecore_mcp_link_params *params,
308 struct ecore_mcp_link_state *link,
309 struct ecore_mcp_link_capabilities *p_caps);
312 * @brief return if the VF is pending FLR
319 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
323 * @brief Check if given VF ID @vfid is valid
324 * w.r.t. @b_enabled_only value
325 * if b_enabled_only = true - only enabled VF id is valid
326 * else any VF id less than max_vfs is valid
329 * @param rel_vf_id - Relative VF ID
330 * @param b_enabled_only - consider only enabled VF
331 * @param b_non_malicious - true iff we want to validate vf isn't malicious.
333 * @return bool - true for valid VF ID
335 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
337 bool b_enabled_only, bool b_non_malicious);
340 * @brief Get VF's public info structure
343 * @param vfid - Relative VF ID
344 * @param b_enabled_only - false if want to access even if vf is disabled
346 * @return struct ecore_public_vf_info *
348 struct ecore_public_vf_info*
349 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
350 u16 vfid, bool b_enabled_only);
353 * @brief fills a bitmask of all VFs which have pending unhandled
358 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
362 * @brief Copy VF's message to PF's buffer
368 * @return enum _ecore_status_t
370 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
371 struct ecore_ptt *ptt,
374 * @brief Set forced MAC address in PFs copy of bulletin board
375 * and configures FW/HW to support the configuration.
381 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
385 * @brief Set MAC address in PFs copy of bulletin board without
392 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
396 * @brief Set default behaviour of VF in case no vlans are configured for it
397 * whether to accept only untagged traffic or all.
398 * Must be called prior to the VF vport-start.
401 * @param b_untagged_only
404 * @return ECORE_SUCCESS if configuration would stick.
407 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
408 bool b_untagged_only,
412 * @brief Get VFs opaque fid.
418 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
422 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
423 * and configures FW/HW to support the configuration.
424 * Setting of pvid 0 would clear the feature.
429 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
433 * @brief Check if VF has VPORT instance. This can be used
434 * to check if VPORT is active.
438 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
441 * @brief PF posts the bulletin to the VF
447 * @return enum _ecore_status_t
449 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
451 struct ecore_ptt *p_ptt);
454 * @brief Check if given VF (@vfid) is marked as stopped
459 * @return bool : true if stopped
461 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
464 * @brief Configure VF anti spoofing
468 * @param val - spoofchk value - true/false
470 * @return enum _ecore_status_t
472 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
476 * @brief Get VF's configured spoof value.
481 * @return bool - spoofchk value - true/false
483 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
486 * @brief Check for SRIOV sanity by PF.
491 * @return bool - true if sanity checks passes, else false
493 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
496 * @brief Get the num of VF chains.
502 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
505 * @brief Get vf request mailbox params
509 * @param pp_req_virt_addr
510 * @param p_req_virt_size
512 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
514 void **pp_req_virt_addr,
515 u16 *p_req_virt_size);
518 * @brief Get vf mailbox params
522 * @param pp_reply_virt_addr
523 * @param p_reply_virt_size
525 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
527 void **pp_reply_virt_addr,
528 u16 *p_reply_virt_size);
531 * @brief Validate if the given length is a valid vfpf message
538 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
541 * @brief Return the max pfvf message length
545 u32 ecore_iov_pfvf_msg_length(void);
548 * @brief Returns MAC address if one is configured
553 * @return OSAL_NULL if mac isn't set; Otherwise, returns MAC.
555 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
559 * @brief Returns forced MAC address if one is configured
564 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
566 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
570 * @brief Returns pvid if one is configured
575 * @return 0 if no pvid is configured, otherwise the pvid.
577 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
580 * @brief Configure VFs tx rate
585 * @param val - tx rate value in Mb/sec.
587 * @return enum _ecore_status_t
589 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
590 struct ecore_ptt *p_ptt,
594 * @brief - Retrieves the statistics associated with a VF
599 * @param p_stats - this will be filled with the VF statistics
601 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
603 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
604 struct ecore_ptt *p_ptt,
606 struct ecore_eth_stats *p_stats);
609 * @brief - Retrieves num of rxqs chains
614 * @return num of rxqs chains.
616 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
620 * @brief - Retrieves num of active rxqs chains
627 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
631 * @brief - Retrieves ctx pointer
638 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
642 * @brief - Retrieves VF`s num sbs
649 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
653 * @brief - Returm true if VF is waiting for acquire
660 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
664 * @brief - Returm true if VF is acquired but not initialized
671 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
675 * @brief - Returm true if VF is acquired and initialized
682 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
686 * @brief - Returm true if VF has started in FW
693 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
697 * @brief - Get VF's vport min rate configured.
701 * @return - rate in Mbps
703 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
708 * @brief ecore_pf_configure_vf_queue_coalesce - PF configure coalesce
709 * parameters of VFs for Rx and Tx queue.
710 * While the API allows setting coalescing per-qid, all queues sharing a SB
711 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
712 * otherwise configuration would break.
715 * @param rx_coal - Rx Coalesce value in micro seconds.
716 * @param tx_coal - TX Coalesce value in micro seconds.
723 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
724 u16 rx_coal, u16 tx_coal,
728 * @brief - Given a VF index, return index of next [including that] active VF.
733 * @return MAX_NUM_VFS_E4 in case no further active VFs, otherwise index.
735 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
737 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn, int vfid,
738 u16 vxlan_port, u16 geneve_port);
740 #ifdef CONFIG_ECORE_SW_CHANNEL
742 * @brief Set whether PF should communicate with VF using SW/HW channel
743 * Needs to be called for an enabled VF before acquire is over
744 * [latest good point for doing that is OSAL_IOV_VF_ACQUIRE()]
747 * @param vfid - relative vf index
748 * @param b_is_hw - true iff PF is to use HW channel for communication
750 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
753 #endif /* CONFIG_ECORE_SRIOV */
755 #define ecore_for_each_vf(_p_hwfn, _i) \
756 for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0); \
757 _i < MAX_NUM_VFS_E4; \
758 _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1))