7eca169470fa9fc9acdf756ef5da0739c5e3acfb
[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
17 #define ECORE_ETH_VF_NUM_VLAN_FILTERS 2
18
19 #define ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS \
20         (MAX_NUM_VFS * ECORE_ETH_VF_NUM_VLAN_FILTERS)
21
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
29  * it to the VF.
30  */
31 struct ecore_vf_mbx_msg {
32         union vfpf_tlvs req;
33         union pfvf_tlvs resp;
34 };
35
36 /* This data is held in the ecore_hwfn structure for VFs only. */
37 struct ecore_vf_iov {
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;
42
43         /* Should be taken whenever the mailbox buffers are accessed */
44         osal_mutex_t mutex;
45         u8 *offset;
46
47         /* Bulletin Board */
48         struct ecore_bulletin bulletin;
49         struct ecore_bulletin_content bulletin_shadow;
50
51         /* we set aside a copy of the acquire response */
52         struct pfvf_acquire_resp_tlv acquire_resp;
53 };
54
55 /* This mailbox is maintained per VF in its PF
56  * contains all information required for sending / receiving
57  * a message
58  */
59 struct ecore_iov_vf_mbx {
60         union vfpf_tlvs         *req_virt;
61         dma_addr_t              req_phys;
62         union pfvf_tlvs         *reply_virt;
63         dma_addr_t              reply_phys;
64
65         /* Address in VF where a pending message is located */
66         dma_addr_t              pending_req;
67
68         u8 *offset;
69
70 #ifdef CONFIG_ECORE_SW_CHANNEL
71         struct ecore_iov_sw_mbx sw_mbx;
72 #endif
73
74         /* VF GPA address */
75         u32                     vf_addr_lo;
76         u32                     vf_addr_hi;
77
78         struct vfpf_first_tlv   first_tlv;      /* saved VF request header */
79
80         u8                      flags;
81 #define VF_MSG_INPROCESS        0x1     /* failsafe - the FW should prevent
82                                          * more then one pending msg
83                                          */
84 };
85
86 struct ecore_vf_q_info {
87         u16 fw_rx_qid;
88         u16 fw_tx_qid;
89         u8 fw_cid;
90         u8 rxq_active;
91         u8 txq_active;
92 };
93
94 enum int_mod {
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
101 };
102
103 enum vf_state {
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 */
109 };
110
111 struct ecore_vf_vlan_shadow {
112         bool used;
113         u16 vid;
114 };
115
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];
119
120         u8 inner_vlan_removal;
121 };
122
123 /* PFs maintain an array of this structure, per VF */
124 struct ecore_vf_info {
125         struct ecore_iov_vf_mbx vf_mbx;
126         enum vf_state state;
127         u8                      to_disable;
128
129         struct ecore_bulletin   bulletin;
130         dma_addr_t              vf_bulletin;
131
132         u32                     concrete_fid;
133         u16                     opaque_fid;
134         u16                     mtu;
135
136         u8                      vport_id;
137         u8                      relative_vf_id;
138         u8                      abs_vf_id;
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 : \
141                                          (p_vf)->abs_vf_id)
142
143         u8                      vport_instance; /* Number of active vports */
144         u8                      num_rxqs;
145         u8                      num_txqs;
146
147         u8                      num_sbs;
148
149         u8                      num_mac_filters;
150         u8                      num_vlan_filters;
151         u8 num_mc_filters;
152
153         struct ecore_vf_q_info  vf_queues[ECORE_MAX_VF_CHAINS_PER_PF];
154         u16                     igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF];
155
156         /* TODO - Only windows is using it - should be removed */
157         u8 was_malicious;
158         u8 num_active_rxqs;
159         void *ctx;
160         struct ecore_public_vf_info p_vf_info;
161         bool spoof_chk;         /* Current configured on HW */
162         bool req_spoofchk_val;  /* Requested value */
163
164         /* Stores the configuration requested by VF */
165         struct ecore_vf_shadow_config shadow_config;
166
167         /* A bitfield using bulletin's valid-map bits, used to indicate
168          * which of the bulletin board features have been configured.
169          */
170         u64 configured_features;
171 #define ECORE_IOV_CONFIGURED_FEATURES_MASK      ((1 << MAC_ADDR_FORCED) | \
172                                                  (1 << VLAN_ADDR_FORCED))
173 };
174
175 /* This structure is part of ecore_hwfn and used only for PFs that have sriov
176  * capability enabled.
177  */
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];
182         u16                     base_vport_id;
183
184         /* Allocate message address continuosuly and split to each VF */
185         void                    *mbx_msg_virt_addr;
186         dma_addr_t              mbx_msg_phys_addr;
187         u32                     mbx_msg_size;
188         void                    *mbx_reply_virt_addr;
189         dma_addr_t              mbx_reply_phys_addr;
190         u32                     mbx_reply_size;
191         void                    *p_bulletins;
192         dma_addr_t              bulletins_phys;
193         u32                     bulletins_size;
194 };
195
196 #ifdef CONFIG_ECORE_SRIOV
197 /**
198  * @brief Read sriov related information and allocated resources
199  *  reads from configuraiton space, shmem, and allocates the VF
200  *  database in the PF.
201  *
202  * @param p_hwfn
203  * @param p_ptt
204  *
205  * @return enum _ecore_status_t
206  */
207 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn,
208                                        struct ecore_ptt *p_ptt);
209
210 /**
211  * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset
212  *
213  * @param p_hwfn
214  * @param p_iov
215  * @param type
216  * @param length
217  *
218  * @return pointer to the newly placed tlv
219  */
220 void *ecore_add_tlv(struct ecore_hwfn   *p_hwfn,
221                     u8 **offset, u16 type, u16 length);
222
223 /**
224  * @brief list the types and lengths of the tlvs on the buffer
225  *
226  * @param p_hwfn
227  * @param tlvs_list
228  */
229 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn, void *tlvs_list);
230
231 /**
232  * @brief ecore_iov_alloc - allocate sriov related resources
233  *
234  * @param p_hwfn
235  *
236  * @return enum _ecore_status_t
237  */
238 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn);
239
240 /**
241  * @brief ecore_iov_setup - setup sriov related resources
242  *
243  * @param p_hwfn
244  * @param p_ptt
245  */
246 void ecore_iov_setup(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt);
247
248 /**
249  * @brief ecore_iov_free - free sriov related resources
250  *
251  * @param p_hwfn
252  */
253 void ecore_iov_free(struct ecore_hwfn *p_hwfn);
254
255 /**
256  * @brief ecore_sriov_eqe_event - handle async sriov event arrived on eqe.
257  *
258  * @param p_hwfn
259  * @param opcode
260  * @param echo
261  * @param data
262  */
263 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn     *p_hwfn,
264                                            u8                    opcode,
265                                            __le16                echo,
266                                            union event_ring_data *data);
267
268 /**
269  * @brief calculate CRC for bulletin board validation
270  *
271  * @param basic crc seed
272  * @param ptr to beginning of buffer
273  * @length in bytes of buffer
274  *
275  * @return calculated crc over buffer [with respect to seed].
276  */
277 u32 ecore_crc32(u32 crc, u8 *ptr, 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 int ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn, u32 *disabled_vfs);
288
289 /**
290  * @brief Search extended TLVs in request/reply buffer.
291  *
292  * @param p_hwfn
293  * @param p_tlvs_list - Pointer to tlvs list
294  * @param req_type - Type of TLV
295  *
296  * @return pointer to tlv type if found, otherwise returns NULL.
297  */
298 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
299                                  void *p_tlvs_list, u16 req_type);
300
301 /**
302  * @brief ecore_iov_get_vf_info - return the database of a
303  *        specific VF
304  *
305  * @param p_hwfn
306  * @param relative_vf_id - relative id of the VF for which info
307  *                       is requested
308  * @param b_enabled_only - false iff want to access even if vf is disabled
309  *
310  * @return struct ecore_vf_info*
311  */
312 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
313                                             u16 relative_vf_id,
314                                             bool b_enabled_only);
315 #else
316 static OSAL_INLINE enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn
317                                                           *p_hwfn,
318                                                           struct ecore_ptt
319                                                           *p_ptt)
320 {
321         return ECORE_SUCCESS;
322 }
323
324 static OSAL_INLINE void *ecore_add_tlv(struct ecore_hwfn *p_hwfn, u8 **offset,
325                                        u16 type, u16 length)
326 {
327         return OSAL_NULL;
328 }
329
330 static OSAL_INLINE void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn,
331                                           void *tlvs_list)
332 {
333 }
334
335 static OSAL_INLINE enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn
336                                                         *p_hwfn)
337 {
338         return ECORE_SUCCESS;
339 }
340
341 static OSAL_INLINE void ecore_iov_setup(struct ecore_hwfn *p_hwfn,
342                                         struct ecore_ptt *p_ptt)
343 {
344 }
345
346 static OSAL_INLINE void ecore_iov_free(struct ecore_hwfn *p_hwfn)
347 {
348 }
349
350 static OSAL_INLINE enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn
351                                                               *p_hwfn,
352                                                               u8 opcode,
353                                                               __le16 echo,
354                                                               union
355                                                               event_ring_data
356                                                               * data)
357 {
358         return ECORE_INVAL;
359 }
360
361 static OSAL_INLINE u32 ecore_crc32(u32 crc, u8 *ptr, u32 length)
362 {
363         return 0;
364 }
365
366 static OSAL_INLINE int ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn,
367                                              u32 *disabled_vfs)
368 {
369         return 0;
370 }
371
372 static OSAL_INLINE void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
373                                                     void *p_tlvs_list,
374                                                     u16 req_type)
375 {
376         return OSAL_NULL;
377 }
378
379 static OSAL_INLINE struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn
380                                                                *p_hwfn,
381                                                                u16
382                                                                relative_vf_id,
383                                                                bool
384                                                                b_enabled_only)
385 {
386         return OSAL_NULL;
387 }
388
389 #endif
390 #endif /* __ECORE_SRIOV_H__ */