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_VF_NUM_VLAN_FILTERS 2
19 #define ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS \
20 (MAX_NUM_VFS * ECORE_ETH_VF_NUM_VLAN_FILTERS)
22 /* Represents a full message. Both the request filled by VF
23 * and the response filled by the PF. The VF needs one copy
24 * of this message, it fills the request part and sends it to
25 * the PF. The PF will copy the response to the response part for
26 * the VF to later read it. The PF needs to hold a message like this
27 * per VF, the request that is copied to the PF is placed in the
28 * request size, and the response is filled by the PF before sending
31 struct ecore_vf_mbx_msg {
36 /* This data is held in the ecore_hwfn structure for VFs only. */
38 union vfpf_tlvs *vf2pf_request;
39 dma_addr_t vf2pf_request_phys;
40 union pfvf_tlvs *pf2vf_reply;
41 dma_addr_t pf2vf_reply_phys;
43 /* Should be taken whenever the mailbox buffers are accessed */
48 struct ecore_bulletin bulletin;
49 struct ecore_bulletin_content bulletin_shadow;
51 /* we set aside a copy of the acquire response */
52 struct pfvf_acquire_resp_tlv acquire_resp;
55 /* This mailbox is maintained per VF in its PF
56 * contains all information required for sending / receiving
59 struct ecore_iov_vf_mbx {
60 union vfpf_tlvs *req_virt;
62 union pfvf_tlvs *reply_virt;
63 dma_addr_t reply_phys;
65 /* Address in VF where a pending message is located */
66 dma_addr_t pending_req;
70 #ifdef CONFIG_ECORE_SW_CHANNEL
71 struct ecore_iov_sw_mbx sw_mbx;
78 struct vfpf_first_tlv first_tlv; /* saved VF request header */
81 #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
82 * more then one pending msg
86 struct ecore_vf_q_info {
95 VPORT_INT_MOD_UNDEFINED = 0,
96 VPORT_INT_MOD_ADAPTIVE = 1,
97 VPORT_INT_MOD_OFF = 2,
98 VPORT_INT_MOD_LOW = 100,
99 VPORT_INT_MOD_MEDIUM = 200,
100 VPORT_INT_MOD_HIGH = 300
104 VF_FREE = 0, /* VF ready to be acquired holds no resc */
105 VF_ACQUIRED = 1, /* VF, acquired, but not initalized */
106 VF_ENABLED = 2, /* VF, Enabled */
107 VF_RESET = 3, /* VF, FLR'd, pending cleanup */
108 VF_STOPPED = 4 /* VF, Stopped */
111 struct ecore_vf_vlan_shadow {
116 struct ecore_vf_shadow_config {
117 /* Shadow copy of all guest vlans */
118 struct ecore_vf_vlan_shadow vlans[ECORE_ETH_VF_NUM_VLAN_FILTERS + 1];
120 u8 inner_vlan_removal;
123 /* PFs maintain an array of this structure, per VF */
124 struct ecore_vf_info {
125 struct ecore_iov_vf_mbx vf_mbx;
129 struct ecore_bulletin bulletin;
130 dma_addr_t vf_bulletin;
139 #define ECORE_VF_ABS_ID(p_hwfn, p_vf) (ECORE_PATH_ID(p_hwfn) ? \
140 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
143 u8 vport_instance; /* Number of active vports */
153 struct ecore_vf_q_info vf_queues[ECORE_MAX_VF_CHAINS_PER_PF];
154 u16 igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF];
156 /* TODO - Only windows is using it - should be removed */
160 struct ecore_public_vf_info p_vf_info;
161 bool spoof_chk; /* Current configured on HW */
162 bool req_spoofchk_val; /* Requested value */
164 /* Stores the configuration requested by VF */
165 struct ecore_vf_shadow_config shadow_config;
167 /* A bitfield using bulletin's valid-map bits, used to indicate
168 * which of the bulletin board features have been configured.
170 u64 configured_features;
171 #define ECORE_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
172 (1 << VLAN_ADDR_FORCED))
175 /* This structure is part of ecore_hwfn and used only for PFs that have sriov
176 * capability enabled.
178 struct ecore_pf_iov {
179 struct ecore_vf_info vfs_array[MAX_NUM_VFS];
180 u64 pending_events[ECORE_VF_ARRAY_LENGTH];
181 u64 pending_flr[ECORE_VF_ARRAY_LENGTH];
184 /* Allocate message address continuosuly and split to each VF */
185 void *mbx_msg_virt_addr;
186 dma_addr_t mbx_msg_phys_addr;
188 void *mbx_reply_virt_addr;
189 dma_addr_t mbx_reply_phys_addr;
192 dma_addr_t bulletins_phys;
196 #ifdef CONFIG_ECORE_SRIOV
198 * @brief Read sriov related information and allocated resources
199 * reads from configuraiton space, shmem, and allocates the VF
200 * database in the PF.
205 * @return enum _ecore_status_t
207 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn,
208 struct ecore_ptt *p_ptt);
211 * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset
218 * @return pointer to the newly placed tlv
220 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
221 u8 **offset, u16 type, u16 length);
224 * @brief list the types and lengths of the tlvs on the buffer
229 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list);
232 * @brief ecore_iov_alloc - allocate sriov related resources
236 * @return enum _ecore_status_t
238 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn);
241 * @brief ecore_iov_setup - setup sriov related resources
246 void ecore_iov_setup(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
249 * @brief ecore_iov_free - free sriov related resources
253 void ecore_iov_free(struct ecore_hwfn *p_hwfn);
256 * @brief ecore_sriov_eqe_event - handle async sriov event arrived on eqe.
263 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
266 union event_ring_data *data);
269 * @brief calculate CRC for bulletin board validation
271 * @param basic crc seed
272 * @param ptr to beginning of buffer
273 * @length in bytes of buffer
275 * @return calculated crc over buffer [with respect to seed].
277 u32 ecore_crc32(u32 crc, u8 *ptr, u32 length);
280 * @brief Mark structs of vfs that have been FLR-ed.
283 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
285 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
287 int ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *disabled_vfs);
290 * @brief Search extended TLVs in request/reply buffer.
293 * @param p_tlvs_list - Pointer to tlvs list
294 * @param req_type - Type of TLV
296 * @return pointer to tlv type if found, otherwise returns NULL.
298 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
299 void *p_tlvs_list, u16 req_type);
302 * @brief ecore_iov_get_vf_info - return the database of a
306 * @param relative_vf_id - relative id of the VF for which info
308 * @param b_enabled_only - false iff want to access even if vf is disabled
310 * @return struct ecore_vf_info*
312 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
314 bool b_enabled_only);
316 static OSAL_INLINE enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn
321 return ECORE_SUCCESS;
324 static OSAL_INLINE void *ecore_add_tlv(struct ecore_hwfn *p_hwfn, u8 **offset,
325 u16 type, u16 length)
330 static OSAL_INLINE void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn,
335 static OSAL_INLINE enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn
338 return ECORE_SUCCESS;
341 static OSAL_INLINE void ecore_iov_setup(struct ecore_hwfn *p_hwfn,
342 struct ecore_ptt *p_ptt)
346 static OSAL_INLINE void ecore_iov_free(struct ecore_hwfn *p_hwfn)
350 static OSAL_INLINE enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn
361 static OSAL_INLINE u32 ecore_crc32(u32 crc, u8 *ptr, u32 length)
366 static OSAL_INLINE int ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn,
372 static OSAL_INLINE void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
379 static OSAL_INLINE struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn
390 #endif /* __ECORE_SRIOV_H__ */