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 {
56 bool override_fw_version;
59 struct ecore_public_vf_info {
60 /* These copies will later be reflected in the bulletin board,
61 * but this copy should be newer.
63 u8 forced_mac[ETH_ALEN];
67 #ifdef CONFIG_ECORE_SW_CHANNEL
68 /* This is SW channel related only... */
70 VF_PF_UNKNOWN_STATE = 0,
71 VF_PF_WAIT_FOR_START_REQUEST = 1,
72 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
73 VF_PF_REQUEST_IN_PROCESSING = 3,
74 VF_PF_RESPONSE_READY = 4,
77 struct ecore_iov_sw_mbx {
78 enum mbx_state mbx_state;
88 * @brief Get the vf sw mailbox params
93 * @return struct ecore_iov_sw_mbx*
95 struct ecore_iov_sw_mbx *ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
99 #ifdef CONFIG_ECORE_SRIOV
101 * @brief mark/clear all VFs before/after an incoming PCIe sriov
107 void ecore_iov_set_vfs_to_disable(struct ecore_hwfn *p_hwfn, u8 to_disable);
110 * @brief mark/clear chosen VFs before/after an incoming PCIe
116 void ecore_iov_set_vf_to_disable(struct ecore_hwfn *p_hwfn,
117 u16 rel_vf_id, u8 to_disable);
121 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
122 * enabling access of a VF. Also includes preparing the
123 * IGU for VF access. This needs to be called AFTER hw is
124 * initialized and BEFORE VF is loaded inside the VM.
129 * @param num_rx_queues
131 * @return enum _ecore_status_t
133 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
134 struct ecore_ptt *p_ptt,
135 u16 rel_vf_id, u16 num_rx_queues);
138 * @brief ecore_iov_process_mbx_req - process a request received
145 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
146 struct ecore_ptt *p_ptt, int vfid);
149 * @brief ecore_iov_release_hw_for_vf - called once upper layer
150 * knows VF is done with - can release any resources
151 * allocated for VF at this point. this must be done once
152 * we know VF is no longer loaded in VM.
158 * @return enum _ecore_status_t
160 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
161 struct ecore_ptt *p_ptt,
166 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
172 * @return enum _ecore_status_t
174 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
175 u16 vf_id, void *ctx);
179 * @brief FLR cleanup for all VFs
184 * @return enum _ecore_status_t
186 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
187 struct ecore_ptt *p_ptt);
190 * @brief FLR cleanup for single VF
196 * @return enum _ecore_status_t
199 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
200 struct ecore_ptt *p_ptt, u16 rel_vf_id);
203 * @brief Update the bulletin with link information. Notice this does NOT
204 * send a bulletin update, only updates the PF's bulletin.
208 * @param params - the link params to use for the VF link configuration
209 * @param link - the link output to use for the VF link configuration
210 * @param p_caps - the link default capabilities.
212 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
214 struct ecore_mcp_link_params *params,
215 struct ecore_mcp_link_state *link,
216 struct ecore_mcp_link_capabilities *p_caps);
219 * @brief Returns link information as perceived by VF.
223 * @param p_params - the link params visible to vf.
224 * @param p_link - the link state visible to vf.
225 * @param p_caps - the link default capabilities visible to vf.
227 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
229 struct ecore_mcp_link_params *params,
230 struct ecore_mcp_link_state *link,
231 struct ecore_mcp_link_capabilities *p_caps);
234 * @brief return if the VF is pending FLR
241 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
244 * @brief Check if given VF ID @vfid is valid
245 * w.r.t. @b_enabled_only value
246 * if b_enabled_only = true - only enabled VF id is valid
247 * else any VF id less than max_vfs is valid
250 * @param rel_vf_id - Relative VF ID
251 * @param b_enabled_only - consider only enabled VF
253 * @return bool - true for valid VF ID
255 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
256 int rel_vf_id, bool b_enabled_only);
259 * @brief Get VF's public info structure
262 * @param vfid - Relative VF ID
263 * @param b_enabled_only - false if want to access even if vf is disabled
265 * @return struct ecore_public_vf_info *
267 struct ecore_public_vf_info *ecore_iov_get_public_vf_info(struct ecore_hwfn
269 bool b_enabled_only);
272 * @brief Set pending events bitmap for given @vfid
277 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid);
280 * @brief Copy pending events bitmap in @events and clear
281 * original copy of events
285 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
289 * @brief Copy VF's message to PF's buffer
295 * @return enum _ecore_status_t
297 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
298 struct ecore_ptt *ptt, int vfid);
300 * @brief Set forced MAC address in PFs copy of bulletin board
301 * and configures FW/HW to support the configuration.
307 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
311 * @brief Set MAC address in PFs copy of bulletin board without
318 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
322 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
323 * and configures FW/HW to support the configuration.
324 * Setting of pvid 0 would clear the feature.
329 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
333 * @brief Set default behaviour of VF in case no vlans are configured for it
334 * whether to accept only untagged traffic or all.
335 * Must be called prior to the VF vport-start.
338 * @param b_untagged_only
341 * @return ECORE_SUCCESS if configuration would stick.
344 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
345 bool b_untagged_only, int vfid);
347 * @brief Get VFs opaque fid.
353 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
357 * @brief Get VFs VPORT id.
363 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid,
367 * @brief Check if VF has VPORT instance. This can be used
368 * to check if VPORT is active.
372 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
375 * @brief PF posts the bulletin to the VF
381 * @return enum _ecore_status_t
383 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
385 struct ecore_ptt *p_ptt);
388 * @brief Check if given VF (@vfid) is marked as stopped
393 * @return bool : true if stopped
395 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
398 * @brief Configure VF anti spoofing
402 * @param val - spoofchk value - true/false
404 * @return enum _ecore_status_t
406 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
410 * @brief Get VF's configured spoof value.
415 * @return bool - spoofchk value - true/false
417 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
420 * @brief Check for SRIOV sanity by PF.
425 * @return bool - true if sanity checks passes, else false
427 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
430 * @brief Get the num of VF chains.
436 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
439 * @brief Get vf request mailbox params
443 * @param pp_req_virt_addr
444 * @param p_req_virt_size
446 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
448 void **pp_req_virt_addr,
449 u16 *p_req_virt_size);
452 * @brief Get vf mailbox params
456 * @param pp_reply_virt_addr
457 * @param p_reply_virt_size
459 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
461 void **pp_reply_virt_addr,
462 u16 *p_reply_virt_size);
465 * @brief Validate if the given length is a valid vfpf message
472 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
475 * @brief Return the max pfvf message length
479 u32 ecore_iov_pfvf_msg_length(void);
482 * @brief Returns forced MAC address if one is configured
487 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
489 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
492 * @brief Returns pvid if one is configured
497 * @return 0 if no pvid is configured, otherwise the pvid.
499 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
502 * @brief Configure VFs tx rate
507 * @param val - tx rate value in Mb/sec.
509 * @return enum _ecore_status_t
511 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
512 struct ecore_ptt *p_ptt,
516 * @brief - Retrieves the statistics associated with a VF
521 * @param p_stats - this will be filled with the VF statistics
523 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
525 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
526 struct ecore_ptt *p_ptt,
528 struct ecore_eth_stats *p_stats);
531 * @brief - Retrieves num of rxqs chains
536 * @return num of rxqs chains.
538 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
541 * @brief - Retrieves num of active rxqs chains
548 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
551 * @brief - Retrieves ctx pointer
558 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
561 * @brief - Retrieves VF`s num sbs
568 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
571 * @brief - Returm true if VF is waiting for acquire
578 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
581 * @brief - Returm true if VF is acquired but not initialized
588 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
592 * @brief - Returm true if VF is acquired and initialized
599 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
602 * @brief - Get VF's vport min rate configured.
606 * @return - rate in Mbps
608 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
611 * @brief - Configure min rate for VF's vport.
614 * @param - rate in Mbps
618 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
621 static OSAL_INLINE void ecore_iov_set_vfs_to_disable(struct ecore_hwfn *p_hwfn,
626 static OSAL_INLINE void ecore_iov_set_vf_to_disable(struct ecore_hwfn *p_hwfn,
632 static OSAL_INLINE enum _ecore_status_t ecore_iov_init_hw_for_vf(struct
645 static OSAL_INLINE void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
646 struct ecore_ptt *p_ptt,
651 static OSAL_INLINE enum _ecore_status_t ecore_iov_release_hw_for_vf(struct
660 return ECORE_SUCCESS;
664 static OSAL_INLINE enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn
671 static OSAL_INLINE enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct
681 static OSAL_INLINE enum _ecore_status_t ecore_iov_single_vf_flr_cleanup(
682 struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt, u16 rel_vf_id)
687 static OSAL_INLINE void ecore_iov_set_link(struct ecore_hwfn *p_hwfn, u16 vfid,
688 struct ecore_mcp_link_params *params,
689 struct ecore_mcp_link_state *link,
690 struct ecore_mcp_link_capabilities
695 static OSAL_INLINE void ecore_iov_get_link(struct ecore_hwfn *p_hwfn, u16 vfid,
696 struct ecore_mcp_link_params *params,
697 struct ecore_mcp_link_state *link,
698 struct ecore_mcp_link_capabilities
703 static OSAL_INLINE bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
709 static OSAL_INLINE bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
716 static OSAL_INLINE struct ecore_public_vf_info *
717 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn, u16 vfid,
723 static OSAL_INLINE void ecore_iov_pf_add_pending_events(struct ecore_hwfn
728 static OSAL_INLINE void ecore_iov_pf_get_and_clear_pending_events(struct
735 static OSAL_INLINE enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn
743 static OSAL_INLINE void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn
749 static OSAL_INLINE enum _ecore_status_t ecore_iov_bulletin_set_mac(struct
758 static OSAL_INLINE void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn
764 static OSAL_INLINE void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn,
765 int vfid, u16 *opaque_fid)
769 static OSAL_INLINE void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn,
770 int vfid, u8 *p_vport_id)
774 static OSAL_INLINE bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn
780 static OSAL_INLINE enum _ecore_status_t ecore_iov_post_vf_bulletin(struct
791 static OSAL_INLINE bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn,
797 static OSAL_INLINE enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn
805 static OSAL_INLINE bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn,
811 static OSAL_INLINE bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn,
817 static OSAL_INLINE u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn)
822 static OSAL_INLINE void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn
832 static OSAL_INLINE void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn
836 **pp_reply_virt_addr,
842 static OSAL_INLINE bool ecore_iov_is_valid_vfpf_msg_length(u32 length)
847 static OSAL_INLINE u32 ecore_iov_pfvf_msg_length(void)
852 static OSAL_INLINE u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn
853 *p_hwfn, u16 rel_vf_id)
858 static OSAL_INLINE u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn
865 static OSAL_INLINE enum _ecore_status_t ecore_iov_configure_tx_rate(struct
877 static OSAL_INLINE u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
883 static OSAL_INLINE u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn
884 *p_hwfn, u16 rel_vf_id)
889 static OSAL_INLINE void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
895 static OSAL_INLINE u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
901 static OSAL_INLINE bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn
902 *p_hwfn, u16 rel_vf_id)
907 static OSAL_INLINE bool ecore_iov_is_vf_acquired_not_initialized(struct
915 static OSAL_INLINE bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
921 static OSAL_INLINE int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn,
927 static OSAL_INLINE enum _ecore_status_t ecore_iov_configure_min_tx_rate(
928 struct ecore_dev *p_dev, int vfid, u32 rate)