2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
9 #ifndef __ECORE_SRIOV_H__
10 #define __ECORE_SRIOV_H__
12 #include "ecore_status.h"
13 #include "ecore_vfpf_if.h"
14 #include "ecore_iov_api.h"
15 #include "ecore_hsi_common.h"
17 #define ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS \
18 (E4_MAX_NUM_VFS * ECORE_ETH_VF_NUM_VLAN_FILTERS)
20 /* Represents a full message. Both the request filled by VF
21 * and the response filled by the PF. The VF needs one copy
22 * of this message, it fills the request part and sends it to
23 * the PF. The PF will copy the response to the response part for
24 * the VF to later read it. The PF needs to hold a message like this
25 * per VF, the request that is copied to the PF is placed in the
26 * request size, and the response is filled by the PF before sending
29 struct ecore_vf_mbx_msg {
34 /* This mailbox is maintained per VF in its PF
35 * contains all information required for sending / receiving
38 struct ecore_iov_vf_mbx {
39 union vfpf_tlvs *req_virt;
41 union pfvf_tlvs *reply_virt;
42 dma_addr_t reply_phys;
44 /* Address in VF where a pending message is located */
45 dma_addr_t pending_req;
49 #ifdef CONFIG_ECORE_SW_CHANNEL
50 struct ecore_iov_sw_mbx sw_mbx;
57 struct vfpf_first_tlv first_tlv; /* saved VF request header */
60 #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
61 * more then one pending msg
65 struct ecore_vf_q_info {
67 struct ecore_queue_cid *p_rx_cid;
69 struct ecore_queue_cid *p_tx_cid;
74 VF_FREE = 0, /* VF ready to be acquired holds no resc */
75 VF_ACQUIRED = 1, /* VF, acquired, but not initalized */
76 VF_ENABLED = 2, /* VF, Enabled */
77 VF_RESET = 3, /* VF, FLR'd, pending cleanup */
78 VF_STOPPED = 4 /* VF, Stopped */
81 struct ecore_vf_vlan_shadow {
86 struct ecore_vf_shadow_config {
87 /* Shadow copy of all guest vlans */
88 struct ecore_vf_vlan_shadow vlans[ECORE_ETH_VF_NUM_VLAN_FILTERS + 1];
90 /* Shadow copy of all configured MACs; Empty if forcing MACs */
91 u8 macs[ECORE_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
92 u8 inner_vlan_removal;
95 /* PFs maintain an array of this structure, per VF */
96 struct ecore_vf_info {
97 struct ecore_iov_vf_mbx vf_mbx;
103 struct ecore_bulletin bulletin;
104 dma_addr_t vf_bulletin;
106 /* PF saves a copy of the last VF acquire message */
107 struct vfpf_acquire_tlv acquire;
117 #define ECORE_VF_ABS_ID(p_hwfn, p_vf) (ECORE_PATH_ID(p_hwfn) ? \
118 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
121 u8 vport_instance; /* Number of active vports */
130 struct ecore_vf_q_info vf_queues[ECORE_MAX_VF_CHAINS_PER_PF];
131 u16 igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF];
133 /* TODO - Only windows is using it - should be removed */
137 struct ecore_public_vf_info p_vf_info;
138 bool spoof_chk; /* Current configured on HW */
139 bool req_spoofchk_val; /* Requested value */
141 /* Stores the configuration requested by VF */
142 struct ecore_vf_shadow_config shadow_config;
144 /* A bitfield using bulletin's valid-map bits, used to indicate
145 * which of the bulletin board features have been configured.
147 u64 configured_features;
148 #define ECORE_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
149 (1 << VLAN_ADDR_FORCED))
152 /* This structure is part of ecore_hwfn and used only for PFs that have sriov
153 * capability enabled.
155 struct ecore_pf_iov {
156 struct ecore_vf_info vfs_array[E4_MAX_NUM_VFS];
157 u64 pending_events[ECORE_VF_ARRAY_LENGTH];
158 u64 pending_flr[ECORE_VF_ARRAY_LENGTH];
161 /* This doesn't serve anything functionally, but it makes windows
162 * debugging of IOV related issues easier.
164 u64 active_vfs[ECORE_VF_ARRAY_LENGTH];
167 /* Allocate message address continuosuly and split to each VF */
168 void *mbx_msg_virt_addr;
169 dma_addr_t mbx_msg_phys_addr;
171 void *mbx_reply_virt_addr;
172 dma_addr_t mbx_reply_phys_addr;
175 dma_addr_t bulletins_phys;
179 #ifdef CONFIG_ECORE_SRIOV
181 * @brief Read sriov related information and allocated resources
182 * reads from configuraiton space, shmem, etc.
186 * @return enum _ecore_status_t
188 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn);
191 * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset
198 * @return pointer to the newly placed tlv
200 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
206 * @brief list the types and lengths of the tlvs on the buffer
211 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn,
215 * @brief ecore_iov_alloc - allocate sriov related resources
219 * @return enum _ecore_status_t
221 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn);
224 * @brief ecore_iov_setup - setup sriov related resources
229 void ecore_iov_setup(struct ecore_hwfn *p_hwfn,
230 struct ecore_ptt *p_ptt);
233 * @brief ecore_iov_free - free sriov related resources
237 void ecore_iov_free(struct ecore_hwfn *p_hwfn);
240 * @brief free sriov related memory that was allocated during hw_prepare
244 void ecore_iov_free_hw_info(struct ecore_dev *p_dev);
247 * @brief ecore_sriov_eqe_event - handle async sriov event arrived on eqe.
254 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
257 union event_ring_data *data);
260 * @brief calculate CRC for bulletin board validation
262 * @param basic crc seed
263 * @param ptr to beginning of buffer
264 * @length in bytes of buffer
266 * @return calculated crc over buffer [with respect to seed].
268 u32 ecore_crc32(u32 crc,
273 * @brief Mark structs of vfs that have been FLR-ed.
276 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
278 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
280 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn,
284 * @brief Search extended TLVs in request/reply buffer.
287 * @param p_tlvs_list - Pointer to tlvs list
288 * @param req_type - Type of TLV
290 * @return pointer to tlv type if found, otherwise returns NULL.
292 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
293 void *p_tlvs_list, u16 req_type);
296 * @brief ecore_iov_get_vf_info - return the database of a
300 * @param relative_vf_id - relative id of the VF for which info
302 * @param b_enabled_only - false iff want to access even if vf is disabled
304 * @return struct ecore_vf_info*
306 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
308 bool b_enabled_only);
310 #endif /* __ECORE_SRIOV_H__ */