2 * Copyright (c) 2017-2018 Cavium, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __ECORE_SRIOV_H__
32 #define __ECORE_SRIOV_H__
34 #include "ecore_status.h"
35 #include "ecore_vfpf_if.h"
36 #include "ecore_iov_api.h"
37 #include "ecore_hsi_common.h"
40 #define ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS \
41 (E4_MAX_NUM_VFS * ECORE_ETH_VF_NUM_VLAN_FILTERS)
43 /* Represents a full message. Both the request filled by VF
44 * and the response filled by the PF. The VF needs one copy
45 * of this message, it fills the request part and sends it to
46 * the PF. The PF will copy the response to the response part for
47 * the VF to later read it. The PF needs to hold a message like this
48 * per VF, the request that is copied to the PF is placed in the
49 * request size, and the response is filled by the PF before sending
52 struct ecore_vf_mbx_msg {
57 /* This mailbox is maintained per VF in its PF
58 * contains all information required for sending / receiving
61 struct ecore_iov_vf_mbx {
62 union vfpf_tlvs *req_virt;
64 union pfvf_tlvs *reply_virt;
65 dma_addr_t reply_phys;
67 /* Address in VF where a pending message is located */
68 dma_addr_t pending_req;
70 /* Message from VF awaits handling */
75 #ifdef CONFIG_ECORE_SW_CHANNEL
76 struct ecore_iov_sw_mbx sw_mbx;
83 struct vfpf_first_tlv first_tlv; /* saved VF request header */
86 #define VF_MSG_INPROCESS 0x1 /* failsafe - the FW should prevent
87 * more then one pending msg
91 #define ECORE_IOV_LEGACY_QID_RX (0)
92 #define ECORE_IOV_LEGACY_QID_TX (1)
93 #define ECORE_IOV_QID_INVALID (0xFE)
95 struct ecore_vf_queue_cid {
97 struct ecore_queue_cid *p_cid;
100 /* Describes a qzone associated with the VF */
101 struct ecore_vf_queue {
102 /* Input from upper-layer, mapping relateive queue to queue-zone */
106 struct ecore_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
110 VF_FREE = 0, /* VF ready to be acquired holds no resc */
111 VF_ACQUIRED = 1, /* VF, acquired, but not initalized */
112 VF_ENABLED = 2, /* VF, Enabled */
113 VF_RESET = 3, /* VF, FLR'd, pending cleanup */
114 VF_STOPPED = 4 /* VF, Stopped */
117 struct ecore_vf_vlan_shadow {
122 struct ecore_vf_shadow_config {
123 /* Shadow copy of all guest vlans */
124 struct ecore_vf_vlan_shadow vlans[ECORE_ETH_VF_NUM_VLAN_FILTERS + 1];
126 /* Shadow copy of all configured MACs; Empty if forcing MACs */
127 u8 macs[ECORE_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
128 u8 inner_vlan_removal;
131 /* PFs maintain an array of this structure, per VF */
132 struct ecore_vf_info {
133 struct ecore_iov_vf_mbx vf_mbx;
139 struct ecore_bulletin bulletin;
140 dma_addr_t vf_bulletin;
142 /* PF saves a copy of the last VF acquire message */
143 struct vfpf_acquire_tlv acquire;
153 #define ECORE_VF_ABS_ID(p_hwfn, p_vf) (ECORE_PATH_ID(p_hwfn) ? \
154 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
157 u8 vport_instance; /* Number of active vports */
169 struct ecore_vf_queue vf_queues[ECORE_MAX_VF_CHAINS_PER_PF];
170 u16 igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF];
172 /* TODO - Only windows is using it - should be removed */
176 struct ecore_public_vf_info p_vf_info;
177 bool spoof_chk; /* Current configured on HW */
178 bool req_spoofchk_val; /* Requested value */
180 /* Stores the configuration requested by VF */
181 struct ecore_vf_shadow_config shadow_config;
183 /* A bitfield using bulletin's valid-map bits, used to indicate
184 * which of the bulletin board features have been configured.
186 u64 configured_features;
187 #define ECORE_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
188 (1 << VLAN_ADDR_FORCED))
191 /* This structure is part of ecore_hwfn and used only for PFs that have sriov
192 * capability enabled.
194 struct ecore_pf_iov {
195 struct ecore_vf_info vfs_array[E4_MAX_NUM_VFS];
196 u64 pending_flr[ECORE_VF_ARRAY_LENGTH];
199 /* This doesn't serve anything functionally, but it makes windows
200 * debugging of IOV related issues easier.
202 u64 active_vfs[ECORE_VF_ARRAY_LENGTH];
205 /* Allocate message address continuosuly and split to each VF */
206 void *mbx_msg_virt_addr;
207 dma_addr_t mbx_msg_phys_addr;
209 void *mbx_reply_virt_addr;
210 dma_addr_t mbx_reply_phys_addr;
213 dma_addr_t bulletins_phys;
217 #ifdef CONFIG_ECORE_SRIOV
219 * @brief Read sriov related information and allocated resources
220 * reads from configuraiton space, shmem, etc.
224 * @return enum _ecore_status_t
226 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn);
229 * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset
236 * @return pointer to the newly placed tlv
238 void *ecore_add_tlv(struct ecore_hwfn *p_hwfn,
244 * @brief list the types and lengths of the tlvs on the buffer
249 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn,
253 * @brief ecore_iov_alloc - allocate sriov related resources
257 * @return enum _ecore_status_t
259 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn);
262 * @brief ecore_iov_setup - setup sriov related resources
267 void ecore_iov_setup(struct ecore_hwfn *p_hwfn,
268 struct ecore_ptt *p_ptt);
271 * @brief ecore_iov_free - free sriov related resources
275 void ecore_iov_free(struct ecore_hwfn *p_hwfn);
278 * @brief free sriov related memory that was allocated during hw_prepare
282 void ecore_iov_free_hw_info(struct ecore_dev *p_dev);
285 * @brief ecore_sriov_eqe_event - handle async sriov event arrived on eqe.
292 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn,
295 union event_ring_data *data);
298 * @brief Mark structs of vfs that have been FLR-ed.
301 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
303 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
305 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn,
309 * @brief Search extended TLVs in request/reply buffer.
312 * @param p_tlvs_list - Pointer to tlvs list
313 * @param req_type - Type of TLV
315 * @return pointer to tlv type if found, otherwise returns NULL.
317 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
318 void *p_tlvs_list, u16 req_type);
321 * @brief ecore_iov_get_vf_info - return the database of a
325 * @param relative_vf_id - relative id of the VF for which info
327 * @param b_enabled_only - false iff want to access even if vf is disabled
329 * @return struct ecore_vf_info*
331 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
333 bool b_enabled_only);
335 static OSAL_INLINE enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn) {return ECORE_SUCCESS;}
336 static OSAL_INLINE void *ecore_add_tlv(struct ecore_hwfn *p_hwfn, u8 **offset, u16 type, u16 length) {return OSAL_NULL;}
337 static OSAL_INLINE void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list) {}
338 static OSAL_INLINE enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn) {return ECORE_SUCCESS;}
339 static OSAL_INLINE void ecore_iov_setup(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt) {}
340 static OSAL_INLINE void ecore_iov_free(struct ecore_hwfn *p_hwfn) {}
341 static OSAL_INLINE void ecore_iov_free_hw_info(struct ecore_dev *p_dev) {}
342 static OSAL_INLINE enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn *p_hwfn, u8 opcode, __le16 echo, union event_ring_data *data) {return ECORE_INVAL;}
343 static OSAL_INLINE u32 ecore_crc32(u32 crc, u8 *ptr, u32 length) {return 0;}
344 static OSAL_INLINE bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *disabled_vfs) {return 0;}
345 static OSAL_INLINE void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn, void *p_tlvs_list, u16 req_type) {return OSAL_NULL;}
346 static OSAL_INLINE struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn, u16 relative_vf_id, bool b_enabled_only) {return OSAL_NULL;}
349 #endif /* __ECORE_SRIOV_H__ */