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 ECORE_VF_ARRAY_GET_VFID(arr, vfid) \
18 (((arr)[(vfid) / 64]) & (1ULL << ((vfid) % 64)))
20 #define IS_VF(p_dev) ((p_dev)->b_is_vf)
21 #define IS_PF(p_dev) (!((p_dev)->b_is_vf))
22 #ifdef CONFIG_ECORE_SRIOV
23 #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->p_dev->p_iov_info))
25 #define IS_PF_SRIOV(p_hwfn) (0)
27 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
28 #define IS_PF_PDA(p_hwfn) 0 /* @@TBD Michalk */
30 /* @@@ TBD MichalK - what should this number be*/
31 #define ECORE_MAX_VF_CHAINS_PER_PF 16
33 /* vport update extended feature tlvs flags */
34 enum ecore_iov_vport_update_flag {
35 ECORE_IOV_VP_UPDATE_ACTIVATE = 0,
36 ECORE_IOV_VP_UPDATE_VLAN_STRIP = 1,
37 ECORE_IOV_VP_UPDATE_TX_SWITCH = 2,
38 ECORE_IOV_VP_UPDATE_MCAST = 3,
39 ECORE_IOV_VP_UPDATE_ACCEPT_PARAM = 4,
40 ECORE_IOV_VP_UPDATE_RSS = 5,
41 ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN = 6,
42 ECORE_IOV_VP_UPDATE_SGE_TPA = 7,
43 ECORE_IOV_VP_UPDATE_MAX = 8,
46 /* PF to VF STATUS is part of vfpf-channel API
47 * and must be forward compatible
49 enum ecore_iov_pf_to_vf_status {
50 PFVF_STATUS_WAITING = 0,
53 PFVF_STATUS_NOT_SUPPORTED,
54 PFVF_STATUS_NO_RESOURCE,
56 PFVF_STATUS_MALICIOUS,
60 struct ecore_mcp_link_params;
61 struct ecore_mcp_link_state;
62 struct ecore_mcp_link_capabilities;
64 /* These defines are used by the hw-channel; should never change order */
65 #define VFPF_ACQUIRE_OS_LINUX (0)
66 #define VFPF_ACQUIRE_OS_WINDOWS (1)
67 #define VFPF_ACQUIRE_OS_ESX (2)
68 #define VFPF_ACQUIRE_OS_SOLARIS (3)
69 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4)
71 struct ecore_vf_acquire_sw_info {
75 /* We have several close releases that all use ~same FW with different
76 * versions [making it incompatible as the versioning scheme is still
77 * tied directly to FW version], allow to override the checking. Only
78 * those versions would actually support this feature [so it would not
79 * break forward compatibility with newer HV drivers that are no longer
82 bool override_fw_version;
85 struct ecore_public_vf_info {
86 /* These copies will later be reflected in the bulletin board,
87 * but this copy should be newer.
89 u8 forced_mac[ETH_ALEN];
92 /* Trusted VFs can configure promiscuous mode and
93 * set MAC address inspite PF has set forced MAC.
94 * Also store shadow promisc configuration if needed.
96 bool is_trusted_configured;
97 bool is_trusted_request;
100 struct ecore_iov_vf_init_params {
103 /* Number of requested Queues; Currently, don't support different
104 * number of Rx/Tx queues.
106 /* TODO - remove this limitation */
109 /* Allow the client to choose which qzones to use for Rx/Tx,
110 * and which queue_base to use for Tx queues on a per-queue basis.
111 * Notice values should be relative to the PF resources.
113 u16 req_rx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
114 u16 req_tx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
118 /* Should be set in case RSS is going to be used for VF */
122 #ifdef CONFIG_ECORE_SW_CHANNEL
123 /* This is SW channel related only... */
125 VF_PF_UNKNOWN_STATE = 0,
126 VF_PF_WAIT_FOR_START_REQUEST = 1,
127 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
128 VF_PF_REQUEST_IN_PROCESSING = 3,
129 VF_PF_RESPONSE_READY = 4,
132 struct ecore_iov_sw_mbx {
133 enum mbx_state mbx_state;
143 * @brief Get the vf sw mailbox params
148 * @return struct ecore_iov_sw_mbx*
150 struct ecore_iov_sw_mbx*
151 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
155 /* This struct is part of ecore_dev and contains data relevant to all hwfns;
156 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
158 struct ecore_hw_sriov_info {
159 /* standard SRIOV capability fields, mostly for debugging */
160 int pos; /* capability position */
161 int nres; /* number of resources */
162 u32 cap; /* SR-IOV Capabilities */
163 u16 ctrl; /* SR-IOV Control */
164 u16 total_vfs; /* total VFs associated with the PF */
165 u16 num_vfs; /* number of vfs that have been started */
166 u16 initial_vfs; /* initial VFs associated with the PF */
167 u16 nr_virtfn; /* number of VFs available */
168 u16 offset; /* first VF Routing ID offset */
169 u16 stride; /* following VF stride */
170 u16 vf_device_id; /* VF device id */
171 u32 pgsz; /* page size for BAR alignment */
172 u8 link; /* Function Dependency Link */
177 #ifdef CONFIG_ECORE_SRIOV
180 * @brief mark/clear all VFs before/after an incoming PCIe sriov
186 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
190 * @brief mark/clear chosen VF before/after an incoming PCIe
197 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
202 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
203 * enabling access of a VF. Also includes preparing the
204 * IGU for VF access. This needs to be called AFTER hw is
205 * initialized and BEFORE VF is loaded inside the VM.
211 * @return enum _ecore_status_t
213 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
214 struct ecore_ptt *p_ptt,
215 struct ecore_iov_vf_init_params
219 * @brief ecore_iov_process_mbx_req - process a request received
226 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
227 struct ecore_ptt *p_ptt,
231 * @brief ecore_iov_release_hw_for_vf - called once upper layer
232 * knows VF is done with - can release any resources
233 * allocated for VF at this point. this must be done once
234 * we know VF is no longer loaded in VM.
240 * @return enum _ecore_status_t
242 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
243 struct ecore_ptt *p_ptt,
247 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
253 * @return enum _ecore_status_t
255 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
260 * @brief FLR cleanup for all VFs
265 * @return enum _ecore_status_t
267 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
268 struct ecore_ptt *p_ptt);
271 * @brief FLR cleanup for single VF
277 * @return enum _ecore_status_t
280 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
281 struct ecore_ptt *p_ptt,
285 * @brief Update the bulletin with link information. Notice this does NOT
286 * send a bulletin update, only updates the PF's bulletin.
290 * @param params - the link params to use for the VF link configuration
291 * @param link - the link output to use for the VF link configuration
292 * @param p_caps - the link default capabilities.
294 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
296 struct ecore_mcp_link_params *params,
297 struct ecore_mcp_link_state *link,
298 struct ecore_mcp_link_capabilities *p_caps);
301 * @brief Returns link information as perceived by VF.
305 * @param p_params - the link params visible to vf.
306 * @param p_link - the link state visible to vf.
307 * @param p_caps - the link default capabilities visible to vf.
309 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
311 struct ecore_mcp_link_params *params,
312 struct ecore_mcp_link_state *link,
313 struct ecore_mcp_link_capabilities *p_caps);
316 * @brief return if the VF is pending FLR
323 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
327 * @brief Check if given VF ID @vfid is valid
328 * w.r.t. @b_enabled_only value
329 * if b_enabled_only = true - only enabled VF id is valid
330 * else any VF id less than max_vfs is valid
333 * @param rel_vf_id - Relative VF ID
334 * @param b_enabled_only - consider only enabled VF
335 * @param b_non_malicious - true iff we want to validate vf isn't malicious.
337 * @return bool - true for valid VF ID
339 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
341 bool b_enabled_only, bool b_non_malicious);
344 * @brief Get VF's public info structure
347 * @param vfid - Relative VF ID
348 * @param b_enabled_only - false if want to access even if vf is disabled
350 * @return struct ecore_public_vf_info *
352 struct ecore_public_vf_info*
353 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
354 u16 vfid, bool b_enabled_only);
357 * @brief fills a bitmask of all VFs which have pending unhandled
362 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
366 * @brief Copy VF's message to PF's buffer
372 * @return enum _ecore_status_t
374 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
375 struct ecore_ptt *ptt,
378 * @brief Set forced MAC address in PFs copy of bulletin board
379 * and configures FW/HW to support the configuration.
385 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
389 * @brief Set MAC address in PFs copy of bulletin board without
396 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
400 * @brief Set default behaviour of VF in case no vlans are configured for it
401 * whether to accept only untagged traffic or all.
402 * Must be called prior to the VF vport-start.
405 * @param b_untagged_only
408 * @return ECORE_SUCCESS if configuration would stick.
411 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
412 bool b_untagged_only,
416 * @brief Get VFs opaque fid.
422 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
426 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
427 * and configures FW/HW to support the configuration.
428 * Setting of pvid 0 would clear the feature.
433 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
437 * @brief Check if VF has VPORT instance. This can be used
438 * to check if VPORT is active.
442 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
445 * @brief PF posts the bulletin to the VF
451 * @return enum _ecore_status_t
453 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
455 struct ecore_ptt *p_ptt);
458 * @brief Check if given VF (@vfid) is marked as stopped
463 * @return bool : true if stopped
465 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
468 * @brief Configure VF anti spoofing
472 * @param val - spoofchk value - true/false
474 * @return enum _ecore_status_t
476 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
480 * @brief Get VF's configured spoof value.
485 * @return bool - spoofchk value - true/false
487 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
490 * @brief Check for SRIOV sanity by PF.
495 * @return bool - true if sanity checks passes, else false
497 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
500 * @brief Get the num of VF chains.
506 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
509 * @brief Get vf request mailbox params
513 * @param pp_req_virt_addr
514 * @param p_req_virt_size
516 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
518 void **pp_req_virt_addr,
519 u16 *p_req_virt_size);
522 * @brief Get vf mailbox params
526 * @param pp_reply_virt_addr
527 * @param p_reply_virt_size
529 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
531 void **pp_reply_virt_addr,
532 u16 *p_reply_virt_size);
535 * @brief Validate if the given length is a valid vfpf message
542 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
545 * @brief Return the max pfvf message length
549 u32 ecore_iov_pfvf_msg_length(void);
552 * @brief Returns MAC address if one is configured
557 * @return OSAL_NULL if mac isn't set; Otherwise, returns MAC.
559 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
563 * @brief Returns forced MAC address if one is configured
568 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
570 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
574 * @brief Returns pvid if one is configured
579 * @return 0 if no pvid is configured, otherwise the pvid.
581 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
584 * @brief Configure VFs tx rate
589 * @param val - tx rate value in Mb/sec.
591 * @return enum _ecore_status_t
593 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
594 struct ecore_ptt *p_ptt,
598 * @brief - Retrieves the statistics associated with a VF
603 * @param p_stats - this will be filled with the VF statistics
605 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
607 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
608 struct ecore_ptt *p_ptt,
610 struct ecore_eth_stats *p_stats);
613 * @brief - Retrieves num of rxqs chains
618 * @return num of rxqs chains.
620 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
624 * @brief - Retrieves num of active rxqs chains
631 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
635 * @brief - Retrieves ctx pointer
642 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
646 * @brief - Retrieves VF`s num sbs
653 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
657 * @brief - Returm true if VF is waiting for acquire
664 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
668 * @brief - Returm true if VF is acquired but not initialized
675 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
679 * @brief - Returm true if VF is acquired and initialized
686 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
690 * @brief - Returm true if VF has started in FW
697 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
701 * @brief - Get VF's vport min rate configured.
705 * @return - rate in Mbps
707 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
710 * @brief - Configure min rate for VF's vport.
713 * @param - rate in Mbps
717 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
722 * @brief ecore_pf_configure_vf_queue_coalesce - PF configure coalesce
723 * parameters of VFs for Rx and Tx queue.
724 * While the API allows setting coalescing per-qid, all queues sharing a SB
725 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
726 * otherwise configuration would break.
729 * @param rx_coal - Rx Coalesce value in micro seconds.
730 * @param tx_coal - TX Coalesce value in micro seconds.
737 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
738 u16 rx_coal, u16 tx_coal,
742 * @brief - Given a VF index, return index of next [including that] active VF.
747 * @return MAX_NUM_VFS_K2 in case no further active VFs, otherwise index.
749 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
751 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn, int vfid,
752 u16 vxlan_port, u16 geneve_port);
754 #ifdef CONFIG_ECORE_SW_CHANNEL
756 * @brief Set whether PF should communicate with VF using SW/HW channel
757 * Needs to be called for an enabled VF before acquire is over
758 * [latest good point for doing that is OSAL_IOV_VF_ACQUIRE()]
761 * @param vfid - relative vf index
762 * @param b_is_hw - true iff PF is to use HW channel for communication
764 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
767 #endif /* CONFIG_ECORE_SRIOV */
769 #define ecore_for_each_vf(_p_hwfn, _i) \
770 for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0); \
771 _i < MAX_NUM_VFS_K2; \
772 _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1))