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 "common_hsi.h"
13 #include "ecore_status.h"
15 #define ECORE_ETH_VF_NUM_MAC_FILTERS 1
16 #define ECORE_ETH_VF_NUM_VLAN_FILTERS 2
17 #define ECORE_VF_ARRAY_LENGTH (3)
19 #define IS_VF(p_dev) ((p_dev)->b_is_vf)
20 #define IS_PF(p_dev) (!((p_dev)->b_is_vf))
21 #ifdef CONFIG_ECORE_SRIOV
22 #define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->p_dev->p_iov_info))
24 #define IS_PF_SRIOV(p_hwfn) (0)
26 #define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
27 #define IS_PF_PDA(p_hwfn) 0 /* @@TBD Michalk */
29 /* @@@ TBD MichalK - what should this number be*/
30 #define ECORE_MAX_VF_CHAINS_PER_PF 16
32 /* vport update extended feature tlvs flags */
33 enum ecore_iov_vport_update_flag {
34 ECORE_IOV_VP_UPDATE_ACTIVATE = 0,
35 ECORE_IOV_VP_UPDATE_VLAN_STRIP = 1,
36 ECORE_IOV_VP_UPDATE_TX_SWITCH = 2,
37 ECORE_IOV_VP_UPDATE_MCAST = 3,
38 ECORE_IOV_VP_UPDATE_ACCEPT_PARAM = 4,
39 ECORE_IOV_VP_UPDATE_RSS = 5,
40 ECORE_IOV_VP_UPDATE_ACCEPT_ANY_VLAN = 6,
41 ECORE_IOV_VP_UPDATE_SGE_TPA = 7,
42 ECORE_IOV_VP_UPDATE_MAX = 8,
45 /* PF to VF STATUS is part of vfpf-channel API
46 * and must be forward compatible
48 enum ecore_iov_pf_to_vf_status {
49 PFVF_STATUS_WAITING = 0,
52 PFVF_STATUS_NOT_SUPPORTED,
53 PFVF_STATUS_NO_RESOURCE,
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];
90 #ifdef CONFIG_ECORE_SW_CHANNEL
91 /* This is SW channel related only... */
93 VF_PF_UNKNOWN_STATE = 0,
94 VF_PF_WAIT_FOR_START_REQUEST = 1,
95 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
96 VF_PF_REQUEST_IN_PROCESSING = 3,
97 VF_PF_RESPONSE_READY = 4,
100 struct ecore_iov_sw_mbx {
101 enum mbx_state mbx_state;
111 * @brief Get the vf sw mailbox params
116 * @return struct ecore_iov_sw_mbx*
118 struct ecore_iov_sw_mbx*
119 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
123 /* This struct is part of ecore_dev and contains data relevant to all hwfns;
124 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
126 struct ecore_hw_sriov_info {
127 /* standard SRIOV capability fields, mostly for debugging */
128 int pos; /* capability position */
129 int nres; /* number of resources */
130 u32 cap; /* SR-IOV Capabilities */
131 u16 ctrl; /* SR-IOV Control */
132 u16 total_vfs; /* total VFs associated with the PF */
133 u16 num_vfs; /* number of vfs that have been started */
134 u16 initial_vfs; /* initial VFs associated with the PF */
135 u16 nr_virtfn; /* number of VFs available */
136 u16 offset; /* first VF Routing ID offset */
137 u16 stride; /* following VF stride */
138 u16 vf_device_id; /* VF device id */
139 u32 pgsz; /* page size for BAR alignment */
140 u8 link; /* Function Dependency Link */
145 #ifdef CONFIG_ECORE_SRIOV
148 * @brief mark/clear all VFs before/after an incoming PCIe sriov
154 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
158 * @brief mark/clear chosen VF before/after an incoming PCIe
165 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
170 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
171 * enabling access of a VF. Also includes preparing the
172 * IGU for VF access. This needs to be called AFTER hw is
173 * initialized and BEFORE VF is loaded inside the VM.
178 * @param num_rx_queues
180 * @return enum _ecore_status_t
182 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
183 struct ecore_ptt *p_ptt,
188 * @brief ecore_iov_process_mbx_req - process a request received
195 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
196 struct ecore_ptt *p_ptt,
200 * @brief ecore_iov_release_hw_for_vf - called once upper layer
201 * knows VF is done with - can release any resources
202 * allocated for VF at this point. this must be done once
203 * we know VF is no longer loaded in VM.
209 * @return enum _ecore_status_t
211 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
212 struct ecore_ptt *p_ptt,
216 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
222 * @return enum _ecore_status_t
224 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
229 * @brief FLR cleanup for all VFs
234 * @return enum _ecore_status_t
236 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
237 struct ecore_ptt *p_ptt);
240 * @brief FLR cleanup for single VF
246 * @return enum _ecore_status_t
249 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
250 struct ecore_ptt *p_ptt,
254 * @brief Update the bulletin with link information. Notice this does NOT
255 * send a bulletin update, only updates the PF's bulletin.
259 * @param params - the link params to use for the VF link configuration
260 * @param link - the link output to use for the VF link configuration
261 * @param p_caps - the link default capabilities.
263 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
265 struct ecore_mcp_link_params *params,
266 struct ecore_mcp_link_state *link,
267 struct ecore_mcp_link_capabilities *p_caps);
270 * @brief Returns link information as perceived by VF.
274 * @param p_params - the link params visible to vf.
275 * @param p_link - the link state visible to vf.
276 * @param p_caps - the link default capabilities visible to vf.
278 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
280 struct ecore_mcp_link_params *params,
281 struct ecore_mcp_link_state *link,
282 struct ecore_mcp_link_capabilities *p_caps);
285 * @brief return if the VF is pending FLR
292 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
296 * @brief Check if given VF ID @vfid is valid
297 * w.r.t. @b_enabled_only value
298 * if b_enabled_only = true - only enabled VF id is valid
299 * else any VF id less than max_vfs is valid
302 * @param rel_vf_id - Relative VF ID
303 * @param b_enabled_only - consider only enabled VF
305 * @return bool - true for valid VF ID
307 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
309 bool b_enabled_only);
312 * @brief Get VF's public info structure
315 * @param vfid - Relative VF ID
316 * @param b_enabled_only - false if want to access even if vf is disabled
318 * @return struct ecore_public_vf_info *
320 struct ecore_public_vf_info*
321 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
322 u16 vfid, bool b_enabled_only);
325 * @brief Set pending events bitmap for given @vfid
330 void ecore_iov_pf_add_pending_events(struct ecore_hwfn *p_hwfn, u8 vfid);
333 * @brief Copy pending events bitmap in @events and clear
334 * original copy of events
338 void ecore_iov_pf_get_and_clear_pending_events(struct ecore_hwfn *p_hwfn,
342 * @brief Copy VF's message to PF's buffer
348 * @return enum _ecore_status_t
350 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
351 struct ecore_ptt *ptt,
354 * @brief Set forced MAC address in PFs copy of bulletin board
355 * and configures FW/HW to support the configuration.
361 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
365 * @brief Set MAC address in PFs copy of bulletin board without
372 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
376 * @brief Set default behaviour of VF in case no vlans are configured for it
377 * whether to accept only untagged traffic or all.
378 * Must be called prior to the VF vport-start.
381 * @param b_untagged_only
384 * @return ECORE_SUCCESS if configuration would stick.
387 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
388 bool b_untagged_only,
392 * @brief Get VFs opaque fid.
398 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
402 * @brief Get VFs VPORT id.
408 void ecore_iov_get_vfs_vport_id(struct ecore_hwfn *p_hwfn, int vfid,
412 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
413 * and configures FW/HW to support the configuration.
414 * Setting of pvid 0 would clear the feature.
419 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
423 * @brief Check if VF has VPORT instance. This can be used
424 * to check if VPORT is active.
428 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
431 * @brief PF posts the bulletin to the VF
437 * @return enum _ecore_status_t
439 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
441 struct ecore_ptt *p_ptt);
444 * @brief Check if given VF (@vfid) is marked as stopped
449 * @return bool : true if stopped
451 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
454 * @brief Configure VF anti spoofing
458 * @param val - spoofchk value - true/false
460 * @return enum _ecore_status_t
462 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
466 * @brief Get VF's configured spoof value.
471 * @return bool - spoofchk value - true/false
473 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
476 * @brief Check for SRIOV sanity by PF.
481 * @return bool - true if sanity checks passes, else false
483 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
486 * @brief Get the num of VF chains.
492 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
495 * @brief Get vf request mailbox params
499 * @param pp_req_virt_addr
500 * @param p_req_virt_size
502 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
504 void **pp_req_virt_addr,
505 u16 *p_req_virt_size);
508 * @brief Get vf mailbox params
512 * @param pp_reply_virt_addr
513 * @param p_reply_virt_size
515 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
517 void **pp_reply_virt_addr,
518 u16 *p_reply_virt_size);
521 * @brief Validate if the given length is a valid vfpf message
528 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
531 * @brief Return the max pfvf message length
535 u32 ecore_iov_pfvf_msg_length(void);
538 * @brief Returns forced MAC address if one is configured
543 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
545 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
549 * @brief Returns pvid if one is configured
554 * @return 0 if no pvid is configured, otherwise the pvid.
556 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
559 * @brief Configure VFs tx rate
564 * @param val - tx rate value in Mb/sec.
566 * @return enum _ecore_status_t
568 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
569 struct ecore_ptt *p_ptt,
573 * @brief - Retrieves the statistics associated with a VF
578 * @param p_stats - this will be filled with the VF statistics
580 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
582 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
583 struct ecore_ptt *p_ptt,
585 struct ecore_eth_stats *p_stats);
588 * @brief - Retrieves num of rxqs chains
593 * @return num of rxqs chains.
595 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
599 * @brief - Retrieves num of active rxqs chains
606 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
610 * @brief - Retrieves ctx pointer
617 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
621 * @brief - Retrieves VF`s num sbs
628 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
632 * @brief - Returm true if VF is waiting for acquire
639 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
643 * @brief - Returm true if VF is acquired but not initialized
650 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
654 * @brief - Returm true if VF is acquired and initialized
661 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
665 * @brief - Get VF's vport min rate configured.
669 * @return - rate in Mbps
671 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
674 * @brief - Configure min rate for VF's vport.
677 * @param - rate in Mbps
681 enum _ecore_status_t ecore_iov_configure_min_tx_rate(struct ecore_dev *p_dev,
686 * @brief - Given a VF index, return index of next [including that] active VF.
691 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
693 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
695 #endif /* CONFIG_ECORE_SRIOV */
697 #define ecore_for_each_vf(_p_hwfn, _i) \
698 for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0); \
700 _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1))