2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
9 #ifndef __ECORE_SRIOV_API_H__
10 #define __ECORE_SRIOV_API_H__
12 #include "ecore_status.h"
14 #define ECORE_VF_ARRAY_LENGTH (3)
16 #define IS_VF(p_dev) ((p_dev)->b_is_vf)
17 #define IS_PF(p_dev) (!((p_dev)->b_is_vf))
18 #ifdef CONFIG_ECORE_SRIOV
19 #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->p_dev->sriov_info.total_vfs))
21 #define IS_PF_SRIOV(p_hwfn) (0)
23 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
24 #define IS_PF_PDA(p_hwfn) 0 /* @@TBD Michalk */
26 /* @@@ TBD MichalK - what should this number be*/
27 #define ECORE_MAX_VF_CHAINS_PER_PF 16
29 /* vport update extended feature tlvs flags */
30 enum ecore_iov_vport_update_flag {
31 ECORE_IOV_VP_UPDATE_ACTIVATE = 0,
32 ECORE_IOV_VP_UPDATE_VLAN_STRIP = 1,
33 ECORE_IOV_VP_UPDATE_TX_SWITCH = 2,
34 ECORE_IOV_VP_UPDATE_MCAST = 3,
35 ECORE_IOV_VP_UPDATE_ACCEPT_PARAM = 4,
36 ECORE_IOV_VP_UPDATE_RSS = 5,
37 ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN = 6,
38 ECORE_IOV_VP_UPDATE_SGE_TPA = 7,
39 ECORE_IOV_VP_UPDATE_MAX = 8,
42 struct ecore_mcp_link_params;
43 struct ecore_mcp_link_state;
44 struct ecore_mcp_link_capabilities;
46 /* These defines are used by the hw-channel; should never change order */
47 #define VFPF_ACQUIRE_OS_LINUX (0)
48 #define VFPF_ACQUIRE_OS_WINDOWS (1)
49 #define VFPF_ACQUIRE_OS_ESX (2)
50 #define VFPF_ACQUIRE_OS_SOLARIS (3)
51 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4)
53 struct ecore_vf_acquire_sw_info {
57 /* We have several close releases that all use ~same FW with different
58 * versions [making it incompatible as the versioning scheme is still
59 * tied directly to FW version], allow to override the checking. Only
60 * those versions would actually support this feature [so it would not
61 * break forward compatibility with newer HV drivers that are no longer
64 bool override_fw_version;
67 struct ecore_public_vf_info {
68 /* These copies will later be reflected in the bulletin board,
69 * but this copy should be newer.
71 u8 forced_mac[ETH_ALEN];
75 #ifdef CONFIG_ECORE_SW_CHANNEL
76 /* This is SW channel related only... */
78 VF_PF_UNKNOWN_STATE = 0,
79 VF_PF_WAIT_FOR_START_REQUEST = 1,
80 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
81 VF_PF_REQUEST_IN_PROCESSING = 3,
82 VF_PF_RESPONSE_READY = 4,
85 struct ecore_iov_sw_mbx {
86 enum mbx_state mbx_state;
96 * @brief Get the vf sw mailbox params
101 * @return struct ecore_iov_sw_mbx*
103 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
107 #ifdef CONFIG_ECORE_SRIOV
109 * @brief mark/clear all VFs before/after an incoming PCIe sriov
115 void ecore_iov_set_vfs_to_disable(struct ecore_hwfn *p_hwfn, u8 to_disable);
118 * @brief mark/clear chosen VFs before/after an incoming PCIe
124 void ecore_iov_set_vf_to_disable(struct ecore_hwfn *p_hwfn,
125 u16 rel_vf_id, u8 to_disable);
129 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
130 * enabling access of a VF. Also includes preparing the
131 * IGU for VF access. This needs to be called AFTER hw is
132 * initialized and BEFORE VF is loaded inside the VM.
137 * @param num_rx_queues
139 * @return enum _ecore_status_t
141 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
142 struct ecore_ptt *p_ptt,
147 * @brief ecore_iov_process_mbx_req - process a request received
154 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
155 struct ecore_ptt *p_ptt,
159 * @brief ecore_iov_release_hw_for_vf - called once upper layer
160 * knows VF is done with - can release any resources
161 * allocated for VF at this point. this must be done once
162 * we know VF is no longer loaded in VM.
168 * @return enum _ecore_status_t
170 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
171 struct ecore_ptt *p_ptt,
176 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
182 * @return enum _ecore_status_t
184 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
185 u16 vf_id, void *ctx);
189 * @brief FLR cleanup for all VFs
194 * @return enum _ecore_status_t
196 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
197 struct ecore_ptt *p_ptt);
200 * @brief FLR cleanup for single VF
206 * @return enum _ecore_status_t
209 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
210 struct ecore_ptt *p_ptt,
214 * @brief Update the bulletin with link information. Notice this does NOT
215 * send a bulletin update, only updates the PF's bulletin.
219 * @param params - the link params to use for the VF link configuration
220 * @param link - the link output to use for the VF link configuration
221 * @param p_caps - the link default capabilities.
223 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
225 struct ecore_mcp_link_params *params,
226 struct ecore_mcp_link_state *link,
227 struct ecore_mcp_link_capabilities *p_caps);
230 * @brief Returns link information as perceived by VF.
234 * @param p_params - the link params visible to vf.
235 * @param p_link - the link state visible to vf.
236 * @param p_caps - the link default capabilities visible to vf.
238 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
240 struct ecore_mcp_link_params *params,
241 struct ecore_mcp_link_state *link,
242 struct ecore_mcp_link_capabilities *p_caps);
245 * @brief return if the VF is pending FLR
252 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
256 * @brief Check if given VF ID @vfid is valid
257 * w.r.t. @b_enabled_only value
258 * if b_enabled_only = true - only enabled VF id is valid
259 * else any VF id less than max_vfs is valid
262 * @param rel_vf_id - Relative VF ID
263 * @param b_enabled_only - consider only enabled VF
265 * @return bool - true for valid VF ID
267 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
269 bool b_enabled_only);
272 * @brief Get VF's public info structure
275 * @param vfid - Relative VF ID
276 * @param b_enabled_only - false if want to access even if vf is disabled
278 * @return struct ecore_public_vf_info *
280 struct ecore_public_vf_info*
281 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
282 u16 vfid, bool b_enabled_only);
285 * @brief Set pending events bitmap for given @vfid
290 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid);
293 * @brief Copy pending events bitmap in @events and clear
294 * original copy of events
298 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
302 * @brief Copy VF's message to PF's buffer
308 * @return enum _ecore_status_t
310 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
311 struct ecore_ptt *ptt,
314 * @brief Set forced MAC address in PFs copy of bulletin board
315 * and configures FW/HW to support the configuration.
321 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
325 * @brief Set MAC address in PFs copy of bulletin board without
332 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
336 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
337 * and configures FW/HW to support the configuration.
338 * Setting of pvid 0 would clear the feature.
343 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
347 * @brief Set default behaviour of VF in case no vlans are configured for it
348 * whether to accept only untagged traffic or all.
349 * Must be called prior to the VF vport-start.
352 * @param b_untagged_only
355 * @return ECORE_SUCCESS if configuration would stick.
358 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
359 bool b_untagged_only,
363 * @brief Get VFs opaque fid.
369 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
373 * @brief Get VFs VPORT id.
379 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid,
383 * @brief Check if VF has VPORT instance. This can be used
384 * to check if VPORT is active.
388 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
391 * @brief PF posts the bulletin to the VF
397 * @return enum _ecore_status_t
399 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
401 struct ecore_ptt *p_ptt);
404 * @brief Check if given VF (@vfid) is marked as stopped
409 * @return bool : true if stopped
411 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
414 * @brief Configure VF anti spoofing
418 * @param val - spoofchk value - true/false
420 * @return enum _ecore_status_t
422 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
426 * @brief Get VF's configured spoof value.
431 * @return bool - spoofchk value - true/false
433 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
436 * @brief Check for SRIOV sanity by PF.
441 * @return bool - true if sanity checks passes, else false
443 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
446 * @brief Get the num of VF chains.
452 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
455 * @brief Get vf request mailbox params
459 * @param pp_req_virt_addr
460 * @param p_req_virt_size
462 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
464 void **pp_req_virt_addr,
465 u16 *p_req_virt_size);
468 * @brief Get vf mailbox params
472 * @param pp_reply_virt_addr
473 * @param p_reply_virt_size
475 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
477 void **pp_reply_virt_addr,
478 u16 *p_reply_virt_size);
481 * @brief Validate if the given length is a valid vfpf message
488 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
491 * @brief Return the max pfvf message length
495 u32 ecore_iov_pfvf_msg_length(void);
498 * @brief Returns forced MAC address if one is configured
503 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
505 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
509 * @brief Returns pvid if one is configured
514 * @return 0 if no pvid is configured, otherwise the pvid.
516 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
519 * @brief Configure VFs tx rate
524 * @param val - tx rate value in Mb/sec.
526 * @return enum _ecore_status_t
528 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
529 struct ecore_ptt *p_ptt,
533 * @brief - Retrieves the statistics associated with a VF
538 * @param p_stats - this will be filled with the VF statistics
540 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
542 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
543 struct ecore_ptt *p_ptt,
545 struct ecore_eth_stats *p_stats);
548 * @brief - Retrieves num of rxqs chains
553 * @return num of rxqs chains.
555 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
559 * @brief - Retrieves num of active rxqs chains
566 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
570 * @brief - Retrieves ctx pointer
577 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
581 * @brief - Retrieves VF`s num sbs
588 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
592 * @brief - Returm true if VF is waiting for acquire
599 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
603 * @brief - Returm true if VF is acquired but not initialized
610 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
614 * @brief - Returm true if VF is acquired and initialized
621 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
625 * @brief - Get VF's vport min rate configured.
629 * @return - rate in Mbps
631 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
634 * @brief - Configure min rate for VF's vport.
637 * @param - rate in Mbps
641 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
644 static OSAL_INLINE void ecore_iov_set_vfs_to_disable(struct ecore_hwfn *p_hwfn,
649 static OSAL_INLINE void ecore_iov_set_vf_to_disable(struct ecore_hwfn *p_hwfn,
655 static OSAL_INLINE enum _ecore_status_t ecore_iov_init_hw_for_vf(struct
668 static OSAL_INLINE void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
669 struct ecore_ptt *p_ptt,
674 static OSAL_INLINE enum _ecore_status_t ecore_iov_release_hw_for_vf(struct
683 return ECORE_SUCCESS;
687 static OSAL_INLINE enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn
694 static OSAL_INLINE enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct
704 static OSAL_INLINE enum _ecore_status_t ecore_iov_single_vf_flr_cleanup(
705 struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, u16 rel_vf_id)
710 static OSAL_INLINE void ecore_iov_set_link(struct ecore_hwfn *p_hwfn, u16 vfid,
711 struct ecore_mcp_link_params *params,
712 struct ecore_mcp_link_state *link,
713 struct ecore_mcp_link_capabilities
718 static OSAL_INLINE void ecore_iov_get_link(struct ecore_hwfn *p_hwfn, u16 vfid,
719 struct ecore_mcp_link_params *params,
720 struct ecore_mcp_link_state *link,
721 struct ecore_mcp_link_capabilities
726 static OSAL_INLINE bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
732 static OSAL_INLINE bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
739 static OSAL_INLINE struct ecore_public_vf_info *
740 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn, u16 vfid,
746 static OSAL_INLINE void ecore_iov_pf_add_pending_events(struct ecore_hwfn
751 static OSAL_INLINE void ecore_iov_pf_get_and_clear_pending_events(struct
758 static OSAL_INLINE enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn
766 static OSAL_INLINE void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn
772 static OSAL_INLINE enum _ecore_status_t ecore_iov_bulletin_set_mac(struct
781 static OSAL_INLINE void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn
787 static OSAL_INLINE void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn,
788 int vfid, u16 *opaque_fid)
792 static OSAL_INLINE void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn,
793 int vfid, u8 *p_vport_id)
797 static OSAL_INLINE bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn
803 static OSAL_INLINE enum _ecore_status_t ecore_iov_post_vf_bulletin(struct
814 static OSAL_INLINE bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn,
820 static OSAL_INLINE enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn
828 static OSAL_INLINE bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn,
834 static OSAL_INLINE bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn,
840 static OSAL_INLINE u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
845 static OSAL_INLINE void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn
855 static OSAL_INLINE void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn
859 **pp_reply_virt_addr,
865 static OSAL_INLINE bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
870 static OSAL_INLINE u32 ecore_iov_pfvf_msg_length(void)
875 static OSAL_INLINE u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn
876 *p_hwfn, u16 rel_vf_id)
881 static OSAL_INLINE u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn
888 static OSAL_INLINE enum _ecore_status_t ecore_iov_configure_tx_rate(struct
900 static OSAL_INLINE u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
906 static OSAL_INLINE u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn
907 *p_hwfn, u16 rel_vf_id)
912 static OSAL_INLINE void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
918 static OSAL_INLINE u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
924 static OSAL_INLINE bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn
925 *p_hwfn, u16 rel_vf_id)
930 static OSAL_INLINE bool ecore_iov_is_vf_acquired_not_initialized(struct
938 static OSAL_INLINE bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
944 static OSAL_INLINE int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn,
950 static OSAL_INLINE enum _ecore_status_t ecore_iov_configure_min_tx_rate(
951 struct ecore_dev *p_dev, int vfid, u32 rate)