3c2f58bd89847dab35a665dfc6074ac607af560a
[deb_dpdk.git] / drivers / net / qede / base / ecore_sriov.h
1 /*
2  * Copyright (c) 2016 QLogic Corporation.
3  * All rights reserved.
4  * www.qlogic.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8
9 #ifndef __ECORE_SRIOV_H__
10 #define __ECORE_SRIOV_H__
11
12 #include "ecore_status.h"
13 #include "ecore_vfpf_if.h"
14 #include "ecore_iov_api.h"
15 #include "ecore_hsi_common.h"
16 #include "ecore_l2.h"
17
18 #define ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS \
19         (E4_MAX_NUM_VFS * ECORE_ETH_VF_NUM_VLAN_FILTERS)
20
21 /* Represents a full message. Both the request filled by VF
22  * and the response filled by the PF. The VF needs one copy
23  * of this message, it fills the request part and sends it to
24  * the PF. The PF will copy the response to the response part for
25  * the VF to later read it. The PF needs to hold a message like this
26  * per VF, the request that is copied to the PF is placed in the
27  * request size, and the response is filled by the PF before sending
28  * it to the VF.
29  */
30 struct ecore_vf_mbx_msg {
31         union vfpf_tlvs req;
32         union pfvf_tlvs resp;
33 };
34
35 /* This mailbox is maintained per VF in its PF
36  * contains all information required for sending / receiving
37  * a message
38  */
39 struct ecore_iov_vf_mbx {
40         union vfpf_tlvs         *req_virt;
41         dma_addr_t              req_phys;
42         union pfvf_tlvs         *reply_virt;
43         dma_addr_t              reply_phys;
44
45         /* Address in VF where a pending message is located */
46         dma_addr_t              pending_req;
47
48         u8 *offset;
49
50 #ifdef CONFIG_ECORE_SW_CHANNEL
51         struct ecore_iov_sw_mbx sw_mbx;
52 #endif
53
54         /* VF GPA address */
55         u32                     vf_addr_lo;
56         u32                     vf_addr_hi;
57
58         struct vfpf_first_tlv   first_tlv;      /* saved VF request header */
59
60         u8                      flags;
61 #define VF_MSG_INPROCESS        0x1     /* failsafe - the FW should prevent
62                                          * more then one pending msg
63                                          */
64 };
65
66 struct ecore_vf_queue_cid {
67         bool b_is_tx;
68         struct ecore_queue_cid *p_cid;
69 };
70
71 /* Describes a qzone associated with the VF */
72 struct ecore_vf_queue {
73         /* Input from upper-layer, mapping relateive queue to queue-zone */
74         u16 fw_rx_qid;
75         u16 fw_tx_qid;
76
77         struct ecore_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
78 };
79
80 enum vf_state {
81         VF_FREE         = 0,    /* VF ready to be acquired holds no resc */
82         VF_ACQUIRED     = 1,    /* VF, acquired, but not initalized */
83         VF_ENABLED      = 2,    /* VF, Enabled */
84         VF_RESET        = 3,    /* VF, FLR'd, pending cleanup */
85         VF_STOPPED      = 4     /* VF, Stopped */
86 };
87
88 struct ecore_vf_vlan_shadow {
89         bool used;
90         u16 vid;
91 };
92
93 struct ecore_vf_shadow_config {
94         /* Shadow copy of all guest vlans */
95         struct ecore_vf_vlan_shadow vlans[ECORE_ETH_VF_NUM_VLAN_FILTERS + 1];
96
97         /* Shadow copy of all configured MACs; Empty if forcing MACs */
98         u8 macs[ECORE_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
99         u8 inner_vlan_removal;
100 };
101
102 /* PFs maintain an array of this structure, per VF */
103 struct ecore_vf_info {
104         struct ecore_iov_vf_mbx vf_mbx;
105         enum vf_state state;
106         bool b_init;
107         bool b_malicious;
108         u8                      to_disable;
109
110         struct ecore_bulletin   bulletin;
111         dma_addr_t              vf_bulletin;
112
113         /* PF saves a copy of the last VF acquire message */
114         struct vfpf_acquire_tlv acquire;
115
116         u32                     concrete_fid;
117         u16                     opaque_fid;
118         u16                     mtu;
119
120         u8                      vport_id;
121         u8                      rss_eng_id;
122         u8                      relative_vf_id;
123         u8                      abs_vf_id;
124 #define ECORE_VF_ABS_ID(p_hwfn, p_vf)   (ECORE_PATH_ID(p_hwfn) ? \
125                                          (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
126                                          (p_vf)->abs_vf_id)
127
128         u8                      vport_instance; /* Number of active vports */
129         u8                      num_rxqs;
130         u8                      num_txqs;
131
132         u8                      num_sbs;
133
134         u8                      num_mac_filters;
135         u8                      num_vlan_filters;
136
137         struct ecore_vf_queue   vf_queues[ECORE_MAX_VF_CHAINS_PER_PF];
138         u16                     igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF];
139
140         /* TODO - Only windows is using it - should be removed */
141         u8 was_malicious;
142         u8 num_active_rxqs;
143         void *ctx;
144         struct ecore_public_vf_info p_vf_info;
145         bool spoof_chk;         /* Current configured on HW */
146         bool req_spoofchk_val;  /* Requested value */
147
148         /* Stores the configuration requested by VF */
149         struct ecore_vf_shadow_config shadow_config;
150
151         /* A bitfield using bulletin's valid-map bits, used to indicate
152          * which of the bulletin board features have been configured.
153          */
154         u64 configured_features;
155 #define ECORE_IOV_CONFIGURED_FEATURES_MASK      ((1 << MAC_ADDR_FORCED) | \
156                                                  (1 << VLAN_ADDR_FORCED))
157 };
158
159 /* This structure is part of ecore_hwfn and used only for PFs that have sriov
160  * capability enabled.
161  */
162 struct ecore_pf_iov {
163         struct ecore_vf_info    vfs_array[E4_MAX_NUM_VFS];
164         u64                     pending_events[ECORE_VF_ARRAY_LENGTH];
165         u64                     pending_flr[ECORE_VF_ARRAY_LENGTH];
166
167 #ifndef REMOVE_DBG
168         /* This doesn't serve anything functionally, but it makes windows
169          * debugging of IOV related issues easier.
170          */
171         u64                     active_vfs[ECORE_VF_ARRAY_LENGTH];
172 #endif
173
174         /* Allocate message address continuosuly and split to each VF */
175         void                    *mbx_msg_virt_addr;
176         dma_addr_t              mbx_msg_phys_addr;
177         u32                     mbx_msg_size;
178         void                    *mbx_reply_virt_addr;
179         dma_addr_t              mbx_reply_phys_addr;
180         u32                     mbx_reply_size;
181         void                    *p_bulletins;
182         dma_addr_t              bulletins_phys;
183         u32                     bulletins_size;
184 };
185
186 #ifdef CONFIG_ECORE_SRIOV
187 /**
188  * @brief Read sriov related information and allocated resources
189  *  reads from configuraiton space, shmem, etc.
190  *
191  * @param p_hwfn
192  *
193  * @return enum _ecore_status_t
194  */
195 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn);
196
197 /**
198  * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset
199  *
200  * @param p_hwfn
201  * @param p_iov
202  * @param type
203  * @param length
204  *
205  * @return pointer to the newly placed tlv
206  */
207 void *ecore_add_tlv(struct ecore_hwfn   *p_hwfn,
208                     u8                  **offset,
209                     u16                 type,
210                     u16                 length);
211
212 /**
213  * @brief list the types and lengths of the tlvs on the buffer
214  *
215  * @param p_hwfn
216  * @param tlvs_list
217  */
218 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn,
219                        void *tlvs_list);
220
221 /**
222  * @brief ecore_iov_alloc - allocate sriov related resources
223  *
224  * @param p_hwfn
225  *
226  * @return enum _ecore_status_t
227  */
228 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn);
229
230 /**
231  * @brief ecore_iov_setup - setup sriov related resources
232  *
233  * @param p_hwfn
234  * @param p_ptt
235  */
236 void ecore_iov_setup(struct ecore_hwfn  *p_hwfn,
237                      struct ecore_ptt   *p_ptt);
238
239 /**
240  * @brief ecore_iov_free - free sriov related resources
241  *
242  * @param p_hwfn
243  */
244 void ecore_iov_free(struct ecore_hwfn *p_hwfn);
245
246 /**
247  * @brief free sriov related memory that was allocated during hw_prepare
248  *
249  * @param p_dev
250  */
251 void ecore_iov_free_hw_info(struct ecore_dev *p_dev);
252
253 /**
254  * @brief ecore_sriov_eqe_event - handle async sriov event arrived on eqe.
255  *
256  * @param p_hwfn
257  * @param opcode
258  * @param echo
259  * @param data
260  */
261 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn     *p_hwfn,
262                                            u8                    opcode,
263                                            __le16                echo,
264                                            union event_ring_data *data);
265
266 /**
267  * @brief calculate CRC for bulletin board validation
268  *
269  * @param basic crc seed
270  * @param ptr to beginning of buffer
271  * @length in bytes of buffer
272  *
273  * @return calculated crc over buffer [with respect to seed].
274  */
275 u32 ecore_crc32(u32 crc,
276                 u8  *ptr,
277                 u32 length);
278
279 /**
280  * @brief Mark structs of vfs that have been FLR-ed.
281  *
282  * @param p_hwfn
283  * @param disabled_vfs - bitmask of all VFs on path that were FLRed
284  *
285  * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
286  */
287 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn,
288                            u32 *disabled_vfs);
289
290 /**
291  * @brief Search extended TLVs in request/reply buffer.
292  *
293  * @param p_hwfn
294  * @param p_tlvs_list - Pointer to tlvs list
295  * @param req_type - Type of TLV
296  *
297  * @return pointer to tlv type if found, otherwise returns NULL.
298  */
299 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
300                                  void *p_tlvs_list, u16 req_type);
301
302 /**
303  * @brief ecore_iov_get_vf_info - return the database of a
304  *        specific VF
305  *
306  * @param p_hwfn
307  * @param relative_vf_id - relative id of the VF for which info
308  *                       is requested
309  * @param b_enabled_only - false iff want to access even if vf is disabled
310  *
311  * @return struct ecore_vf_info*
312  */
313 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
314                                             u16 relative_vf_id,
315                                             bool b_enabled_only);
316 #endif
317 #endif /* __ECORE_SRIOV_H__ */