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,
55 PFVF_STATUS_MALICIOUS,
58 struct ecore_mcp_link_params;
59 struct ecore_mcp_link_state;
60 struct ecore_mcp_link_capabilities;
62 /* These defines are used by the hw-channel; should never change order */
63 #define VFPF_ACQUIRE_OS_LINUX (0)
64 #define VFPF_ACQUIRE_OS_WINDOWS (1)
65 #define VFPF_ACQUIRE_OS_ESX (2)
66 #define VFPF_ACQUIRE_OS_SOLARIS (3)
67 #define VFPF_ACQUIRE_OS_LINUX_USERSPACE (4)
69 struct ecore_vf_acquire_sw_info {
73 /* We have several close releases that all use ~same FW with different
74 * versions [making it incompatible as the versioning scheme is still
75 * tied directly to FW version], allow to override the checking. Only
76 * those versions would actually support this feature [so it would not
77 * break forward compatibility with newer HV drivers that are no longer
80 bool override_fw_version;
83 struct ecore_public_vf_info {
84 /* These copies will later be reflected in the bulletin board,
85 * but this copy should be newer.
87 u8 forced_mac[ETH_ALEN];
91 struct ecore_iov_vf_init_params {
94 /* Number of requested Queues; Currently, don't support different
95 * number of Rx/Tx queues.
97 /* TODO - remove this limitation */
100 /* Allow the client to choose which qzones to use for Rx/Tx,
101 * and which queue_base to use for Tx queues on a per-queue basis.
102 * Notice values should be relative to the PF resources.
104 u16 req_rx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
105 u16 req_tx_queue[ECORE_MAX_VF_CHAINS_PER_PF];
109 /* Should be set in case RSS is going to be used for VF */
113 #ifdef CONFIG_ECORE_SW_CHANNEL
114 /* This is SW channel related only... */
116 VF_PF_UNKNOWN_STATE = 0,
117 VF_PF_WAIT_FOR_START_REQUEST = 1,
118 VF_PF_WAIT_FOR_NEXT_CHUNK_OF_REQUEST = 2,
119 VF_PF_REQUEST_IN_PROCESSING = 3,
120 VF_PF_RESPONSE_READY = 4,
123 struct ecore_iov_sw_mbx {
124 enum mbx_state mbx_state;
134 * @brief Get the vf sw mailbox params
139 * @return struct ecore_iov_sw_mbx*
141 struct ecore_iov_sw_mbx*
142 ecore_iov_get_vf_sw_mbx(struct ecore_hwfn *p_hwfn,
146 /* This struct is part of ecore_dev and contains data relevant to all hwfns;
147 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
149 struct ecore_hw_sriov_info {
150 /* standard SRIOV capability fields, mostly for debugging */
151 int pos; /* capability position */
152 int nres; /* number of resources */
153 u32 cap; /* SR-IOV Capabilities */
154 u16 ctrl; /* SR-IOV Control */
155 u16 total_vfs; /* total VFs associated with the PF */
156 u16 num_vfs; /* number of vfs that have been started */
157 u16 initial_vfs; /* initial VFs associated with the PF */
158 u16 nr_virtfn; /* number of VFs available */
159 u16 offset; /* first VF Routing ID offset */
160 u16 stride; /* following VF stride */
161 u16 vf_device_id; /* VF device id */
162 u32 pgsz; /* page size for BAR alignment */
163 u8 link; /* Function Dependency Link */
168 #ifdef CONFIG_ECORE_SRIOV
171 * @brief mark/clear all VFs before/after an incoming PCIe sriov
177 void ecore_iov_set_vfs_to_disable(struct ecore_dev *p_dev,
181 * @brief mark/clear chosen VF before/after an incoming PCIe
188 void ecore_iov_set_vf_to_disable(struct ecore_dev *p_dev,
193 * @brief ecore_iov_init_hw_for_vf - initialize the HW for
194 * enabling access of a VF. Also includes preparing the
195 * IGU for VF access. This needs to be called AFTER hw is
196 * initialized and BEFORE VF is loaded inside the VM.
202 * @return enum _ecore_status_t
204 enum _ecore_status_t ecore_iov_init_hw_for_vf(struct ecore_hwfn *p_hwfn,
205 struct ecore_ptt *p_ptt,
206 struct ecore_iov_vf_init_params
210 * @brief ecore_iov_process_mbx_req - process a request received
217 void ecore_iov_process_mbx_req(struct ecore_hwfn *p_hwfn,
218 struct ecore_ptt *p_ptt,
222 * @brief ecore_iov_release_hw_for_vf - called once upper layer
223 * knows VF is done with - can release any resources
224 * allocated for VF at this point. this must be done once
225 * we know VF is no longer loaded in VM.
231 * @return enum _ecore_status_t
233 enum _ecore_status_t ecore_iov_release_hw_for_vf(struct ecore_hwfn *p_hwfn,
234 struct ecore_ptt *p_ptt,
238 * @brief ecore_iov_set_vf_ctx - set a context for a given VF
244 * @return enum _ecore_status_t
246 enum _ecore_status_t ecore_iov_set_vf_ctx(struct ecore_hwfn *p_hwfn,
251 * @brief FLR cleanup for all VFs
256 * @return enum _ecore_status_t
258 enum _ecore_status_t ecore_iov_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
259 struct ecore_ptt *p_ptt);
262 * @brief FLR cleanup for single VF
268 * @return enum _ecore_status_t
271 ecore_iov_single_vf_flr_cleanup(struct ecore_hwfn *p_hwfn,
272 struct ecore_ptt *p_ptt,
276 * @brief Update the bulletin with link information. Notice this does NOT
277 * send a bulletin update, only updates the PF's bulletin.
281 * @param params - the link params to use for the VF link configuration
282 * @param link - the link output to use for the VF link configuration
283 * @param p_caps - the link default capabilities.
285 void ecore_iov_set_link(struct ecore_hwfn *p_hwfn,
287 struct ecore_mcp_link_params *params,
288 struct ecore_mcp_link_state *link,
289 struct ecore_mcp_link_capabilities *p_caps);
292 * @brief Returns link information as perceived by VF.
296 * @param p_params - the link params visible to vf.
297 * @param p_link - the link state visible to vf.
298 * @param p_caps - the link default capabilities visible to vf.
300 void ecore_iov_get_link(struct ecore_hwfn *p_hwfn,
302 struct ecore_mcp_link_params *params,
303 struct ecore_mcp_link_state *link,
304 struct ecore_mcp_link_capabilities *p_caps);
307 * @brief return if the VF is pending FLR
314 bool ecore_iov_is_vf_pending_flr(struct ecore_hwfn *p_hwfn,
318 * @brief Check if given VF ID @vfid is valid
319 * w.r.t. @b_enabled_only value
320 * if b_enabled_only = true - only enabled VF id is valid
321 * else any VF id less than max_vfs is valid
324 * @param rel_vf_id - Relative VF ID
325 * @param b_enabled_only - consider only enabled VF
326 * @param b_non_malicious - true iff we want to validate vf isn't malicious.
328 * @return bool - true for valid VF ID
330 bool ecore_iov_is_valid_vfid(struct ecore_hwfn *p_hwfn,
332 bool b_enabled_only, bool b_non_malicious);
335 * @brief Get VF's public info structure
338 * @param vfid - Relative VF ID
339 * @param b_enabled_only - false if want to access even if vf is disabled
341 * @return struct ecore_public_vf_info *
343 struct ecore_public_vf_info*
344 ecore_iov_get_public_vf_info(struct ecore_hwfn *p_hwfn,
345 u16 vfid, bool b_enabled_only);
348 * @brief fills a bitmask of all VFs which have pending unhandled
353 void ecore_iov_pf_get_pending_events(struct ecore_hwfn *p_hwfn,
357 * @brief Copy VF's message to PF's buffer
363 * @return enum _ecore_status_t
365 enum _ecore_status_t ecore_iov_copy_vf_msg(struct ecore_hwfn *p_hwfn,
366 struct ecore_ptt *ptt,
369 * @brief Set forced MAC address in PFs copy of bulletin board
370 * and configures FW/HW to support the configuration.
376 void ecore_iov_bulletin_set_forced_mac(struct ecore_hwfn *p_hwfn,
380 * @brief Set MAC address in PFs copy of bulletin board without
387 enum _ecore_status_t ecore_iov_bulletin_set_mac(struct ecore_hwfn *p_hwfn,
391 * @brief Set default behaviour of VF in case no vlans are configured for it
392 * whether to accept only untagged traffic or all.
393 * Must be called prior to the VF vport-start.
396 * @param b_untagged_only
399 * @return ECORE_SUCCESS if configuration would stick.
402 ecore_iov_bulletin_set_forced_untagged_default(struct ecore_hwfn *p_hwfn,
403 bool b_untagged_only,
407 * @brief Get VFs opaque fid.
413 void ecore_iov_get_vfs_opaque_fid(struct ecore_hwfn *p_hwfn, int vfid,
417 * @brief Set forced VLAN [pvid] in PFs copy of bulletin board
418 * and configures FW/HW to support the configuration.
419 * Setting of pvid 0 would clear the feature.
424 void ecore_iov_bulletin_set_forced_vlan(struct ecore_hwfn *p_hwfn,
428 * @brief Check if VF has VPORT instance. This can be used
429 * to check if VPORT is active.
433 bool ecore_iov_vf_has_vport_instance(struct ecore_hwfn *p_hwfn, int vfid);
436 * @brief PF posts the bulletin to the VF
442 * @return enum _ecore_status_t
444 enum _ecore_status_t ecore_iov_post_vf_bulletin(struct ecore_hwfn *p_hwfn,
446 struct ecore_ptt *p_ptt);
449 * @brief Check if given VF (@vfid) is marked as stopped
454 * @return bool : true if stopped
456 bool ecore_iov_is_vf_stopped(struct ecore_hwfn *p_hwfn, int vfid);
459 * @brief Configure VF anti spoofing
463 * @param val - spoofchk value - true/false
465 * @return enum _ecore_status_t
467 enum _ecore_status_t ecore_iov_spoofchk_set(struct ecore_hwfn *p_hwfn,
471 * @brief Get VF's configured spoof value.
476 * @return bool - spoofchk value - true/false
478 bool ecore_iov_spoofchk_get(struct ecore_hwfn *p_hwfn, int vfid);
481 * @brief Check for SRIOV sanity by PF.
486 * @return bool - true if sanity checks passes, else false
488 bool ecore_iov_pf_sanity_check(struct ecore_hwfn *p_hwfn, int vfid);
491 * @brief Get the num of VF chains.
497 u8 ecore_iov_vf_chains_per_pf(struct ecore_hwfn *p_hwfn);
500 * @brief Get vf request mailbox params
504 * @param pp_req_virt_addr
505 * @param p_req_virt_size
507 void ecore_iov_get_vf_req_virt_mbx_params(struct ecore_hwfn *p_hwfn,
509 void **pp_req_virt_addr,
510 u16 *p_req_virt_size);
513 * @brief Get vf mailbox params
517 * @param pp_reply_virt_addr
518 * @param p_reply_virt_size
520 void ecore_iov_get_vf_reply_virt_mbx_params(struct ecore_hwfn *p_hwfn,
522 void **pp_reply_virt_addr,
523 u16 *p_reply_virt_size);
526 * @brief Validate if the given length is a valid vfpf message
533 bool ecore_iov_is_valid_vfpf_msg_length(u32 length);
536 * @brief Return the max pfvf message length
540 u32 ecore_iov_pfvf_msg_length(void);
543 * @brief Returns MAC address if one is configured
548 * @return OSAL_NULL if mac isn't set; Otherwise, returns MAC.
550 u8 *ecore_iov_bulletin_get_mac(struct ecore_hwfn *p_hwfn,
554 * @brief Returns forced MAC address if one is configured
559 * @return OSAL_NULL if mac isn't forced; Otherwise, returns MAC.
561 u8 *ecore_iov_bulletin_get_forced_mac(struct ecore_hwfn *p_hwfn,
565 * @brief Returns pvid if one is configured
570 * @return 0 if no pvid is configured, otherwise the pvid.
572 u16 ecore_iov_bulletin_get_forced_vlan(struct ecore_hwfn *p_hwfn,
575 * @brief Configure VFs tx rate
580 * @param val - tx rate value in Mb/sec.
582 * @return enum _ecore_status_t
584 enum _ecore_status_t ecore_iov_configure_tx_rate(struct ecore_hwfn *p_hwfn,
585 struct ecore_ptt *p_ptt,
589 * @brief - Retrieves the statistics associated with a VF
594 * @param p_stats - this will be filled with the VF statistics
596 * @return ECORE_SUCCESS iff statistics were retrieved. Error otherwise.
598 enum _ecore_status_t ecore_iov_get_vf_stats(struct ecore_hwfn *p_hwfn,
599 struct ecore_ptt *p_ptt,
601 struct ecore_eth_stats *p_stats);
604 * @brief - Retrieves num of rxqs chains
609 * @return num of rxqs chains.
611 u8 ecore_iov_get_vf_num_rxqs(struct ecore_hwfn *p_hwfn,
615 * @brief - Retrieves num of active rxqs chains
622 u8 ecore_iov_get_vf_num_active_rxqs(struct ecore_hwfn *p_hwfn,
626 * @brief - Retrieves ctx pointer
633 void *ecore_iov_get_vf_ctx(struct ecore_hwfn *p_hwfn,
637 * @brief - Retrieves VF`s num sbs
644 u8 ecore_iov_get_vf_num_sbs(struct ecore_hwfn *p_hwfn,
648 * @brief - Returm true if VF is waiting for acquire
655 bool ecore_iov_is_vf_wait_for_acquire(struct ecore_hwfn *p_hwfn,
659 * @brief - Returm true if VF is acquired but not initialized
666 bool ecore_iov_is_vf_acquired_not_initialized(struct ecore_hwfn *p_hwfn,
670 * @brief - Returm true if VF is acquired and initialized
677 bool ecore_iov_is_vf_initialized(struct ecore_hwfn *p_hwfn,
681 * @brief - Returm true if VF has started in FW
688 bool ecore_iov_is_vf_started(struct ecore_hwfn *p_hwfn,
692 * @brief - Get VF's vport min rate configured.
696 * @return - rate in Mbps
698 int ecore_iov_get_vf_min_rate(struct ecore_hwfn *p_hwfn, int vfid);
703 * @brief ecore_pf_configure_vf_queue_coalesce - PF configure coalesce
704 * parameters of VFs for Rx and Tx queue.
705 * While the API allows setting coalescing per-qid, all queues sharing a SB
706 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff]
707 * otherwise configuration would break.
710 * @param rx_coal - Rx Coalesce value in micro seconds.
711 * @param tx_coal - TX Coalesce value in micro seconds.
718 ecore_iov_pf_configure_vf_queue_coalesce(struct ecore_hwfn *p_hwfn,
719 u16 rx_coal, u16 tx_coal,
723 * @brief - Given a VF index, return index of next [including that] active VF.
728 * @return MAX_NUM_VFS_E4 in case no further active VFs, otherwise index.
730 u16 ecore_iov_get_next_active_vf(struct ecore_hwfn *p_hwfn, u16 rel_vf_id);
732 void ecore_iov_bulletin_set_udp_ports(struct ecore_hwfn *p_hwfn, int vfid,
733 u16 vxlan_port, u16 geneve_port);
735 #ifdef CONFIG_ECORE_SW_CHANNEL
737 * @brief Set whether PF should communicate with VF using SW/HW channel
738 * Needs to be called for an enabled VF before acquire is over
739 * [latest good point for doing that is OSAL_IOV_VF_ACQUIRE()]
742 * @param vfid - relative vf index
743 * @param b_is_hw - true iff PF is to use HW channel for communication
745 void ecore_iov_set_vf_hw_channel(struct ecore_hwfn *p_hwfn, int vfid,
748 #endif /* CONFIG_ECORE_SRIOV */
750 #define ecore_for_each_vf(_p_hwfn, _i) \
751 for (_i = ecore_iov_get_next_active_vf(_p_hwfn, 0); \
752 _i < MAX_NUM_VFS_E4; \
753 _i = ecore_iov_get_next_active_vf(_p_hwfn, _i + 1))