net/qede/base: changes for VF queue zone
[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 #define ECORE_IOV_LEGACY_QID_RX (0)
67 #define ECORE_IOV_LEGACY_QID_TX (1)
68 #define ECORE_IOV_QID_INVALID (0xFE)
69
70 struct ecore_vf_queue_cid {
71         bool b_is_tx;
72         struct ecore_queue_cid *p_cid;
73 };
74
75 /* Describes a qzone associated with the VF */
76 struct ecore_vf_queue {
77         /* Input from upper-layer, mapping relateive queue to queue-zone */
78         u16 fw_rx_qid;
79         u16 fw_tx_qid;
80
81         struct ecore_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
82 };
83
84 enum vf_state {
85         VF_FREE         = 0,    /* VF ready to be acquired holds no resc */
86         VF_ACQUIRED     = 1,    /* VF, acquired, but not initalized */
87         VF_ENABLED      = 2,    /* VF, Enabled */
88         VF_RESET        = 3,    /* VF, FLR'd, pending cleanup */
89         VF_STOPPED      = 4     /* VF, Stopped */
90 };
91
92 struct ecore_vf_vlan_shadow {
93         bool used;
94         u16 vid;
95 };
96
97 struct ecore_vf_shadow_config {
98         /* Shadow copy of all guest vlans */
99         struct ecore_vf_vlan_shadow vlans[ECORE_ETH_VF_NUM_VLAN_FILTERS + 1];
100
101         /* Shadow copy of all configured MACs; Empty if forcing MACs */
102         u8 macs[ECORE_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
103         u8 inner_vlan_removal;
104 };
105
106 /* PFs maintain an array of this structure, per VF */
107 struct ecore_vf_info {
108         struct ecore_iov_vf_mbx vf_mbx;
109         enum vf_state state;
110         bool b_init;
111         bool b_malicious;
112         u8                      to_disable;
113
114         struct ecore_bulletin   bulletin;
115         dma_addr_t              vf_bulletin;
116
117         /* PF saves a copy of the last VF acquire message */
118         struct vfpf_acquire_tlv acquire;
119
120         u32                     concrete_fid;
121         u16                     opaque_fid;
122         u16                     mtu;
123
124         u8                      vport_id;
125         u8                      rss_eng_id;
126         u8                      relative_vf_id;
127         u8                      abs_vf_id;
128 #define ECORE_VF_ABS_ID(p_hwfn, p_vf)   (ECORE_PATH_ID(p_hwfn) ? \
129                                          (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
130                                          (p_vf)->abs_vf_id)
131
132         u8                      vport_instance; /* Number of active vports */
133         u8                      num_rxqs;
134         u8                      num_txqs;
135
136         u8                      num_sbs;
137
138         u8                      num_mac_filters;
139         u8                      num_vlan_filters;
140
141         struct ecore_vf_queue   vf_queues[ECORE_MAX_VF_CHAINS_PER_PF];
142         u16                     igu_sbs[ECORE_MAX_VF_CHAINS_PER_PF];
143
144         /* TODO - Only windows is using it - should be removed */
145         u8 was_malicious;
146         u8 num_active_rxqs;
147         void *ctx;
148         struct ecore_public_vf_info p_vf_info;
149         bool spoof_chk;         /* Current configured on HW */
150         bool req_spoofchk_val;  /* Requested value */
151
152         /* Stores the configuration requested by VF */
153         struct ecore_vf_shadow_config shadow_config;
154
155         /* A bitfield using bulletin's valid-map bits, used to indicate
156          * which of the bulletin board features have been configured.
157          */
158         u64 configured_features;
159 #define ECORE_IOV_CONFIGURED_FEATURES_MASK      ((1 << MAC_ADDR_FORCED) | \
160                                                  (1 << VLAN_ADDR_FORCED))
161 };
162
163 /* This structure is part of ecore_hwfn and used only for PFs that have sriov
164  * capability enabled.
165  */
166 struct ecore_pf_iov {
167         struct ecore_vf_info    vfs_array[E4_MAX_NUM_VFS];
168         u64                     pending_events[ECORE_VF_ARRAY_LENGTH];
169         u64                     pending_flr[ECORE_VF_ARRAY_LENGTH];
170
171 #ifndef REMOVE_DBG
172         /* This doesn't serve anything functionally, but it makes windows
173          * debugging of IOV related issues easier.
174          */
175         u64                     active_vfs[ECORE_VF_ARRAY_LENGTH];
176 #endif
177
178         /* Allocate message address continuosuly and split to each VF */
179         void                    *mbx_msg_virt_addr;
180         dma_addr_t              mbx_msg_phys_addr;
181         u32                     mbx_msg_size;
182         void                    *mbx_reply_virt_addr;
183         dma_addr_t              mbx_reply_phys_addr;
184         u32                     mbx_reply_size;
185         void                    *p_bulletins;
186         dma_addr_t              bulletins_phys;
187         u32                     bulletins_size;
188 };
189
190 #ifdef CONFIG_ECORE_SRIOV
191 /**
192  * @brief Read sriov related information and allocated resources
193  *  reads from configuraiton space, shmem, etc.
194  *
195  * @param p_hwfn
196  *
197  * @return enum _ecore_status_t
198  */
199 enum _ecore_status_t ecore_iov_hw_info(struct ecore_hwfn *p_hwfn);
200
201 /**
202  * @brief ecore_add_tlv - place a given tlv on the tlv buffer at next offset
203  *
204  * @param p_hwfn
205  * @param p_iov
206  * @param type
207  * @param length
208  *
209  * @return pointer to the newly placed tlv
210  */
211 void *ecore_add_tlv(struct ecore_hwfn   *p_hwfn,
212                     u8                  **offset,
213                     u16                 type,
214                     u16                 length);
215
216 /**
217  * @brief list the types and lengths of the tlvs on the buffer
218  *
219  * @param p_hwfn
220  * @param tlvs_list
221  */
222 void ecore_dp_tlv_list(struct ecore_hwfn *p_hwfn,
223                        void *tlvs_list);
224
225 /**
226  * @brief ecore_iov_alloc - allocate sriov related resources
227  *
228  * @param p_hwfn
229  *
230  * @return enum _ecore_status_t
231  */
232 enum _ecore_status_t ecore_iov_alloc(struct ecore_hwfn *p_hwfn);
233
234 /**
235  * @brief ecore_iov_setup - setup sriov related resources
236  *
237  * @param p_hwfn
238  * @param p_ptt
239  */
240 void ecore_iov_setup(struct ecore_hwfn  *p_hwfn,
241                      struct ecore_ptt   *p_ptt);
242
243 /**
244  * @brief ecore_iov_free - free sriov related resources
245  *
246  * @param p_hwfn
247  */
248 void ecore_iov_free(struct ecore_hwfn *p_hwfn);
249
250 /**
251  * @brief free sriov related memory that was allocated during hw_prepare
252  *
253  * @param p_dev
254  */
255 void ecore_iov_free_hw_info(struct ecore_dev *p_dev);
256
257 /**
258  * @brief ecore_sriov_eqe_event - handle async sriov event arrived on eqe.
259  *
260  * @param p_hwfn
261  * @param opcode
262  * @param echo
263  * @param data
264  */
265 enum _ecore_status_t ecore_sriov_eqe_event(struct ecore_hwfn     *p_hwfn,
266                                            u8                    opcode,
267                                            __le16                echo,
268                                            union event_ring_data *data);
269
270 /**
271  * @brief Mark structs of vfs that have been FLR-ed.
272  *
273  * @param p_hwfn
274  * @param disabled_vfs - bitmask of all VFs on path that were FLRed
275  *
276  * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
277  */
278 bool ecore_iov_mark_vf_flr(struct ecore_hwfn *p_hwfn,
279                            u32 *disabled_vfs);
280
281 /**
282  * @brief Search extended TLVs in request/reply buffer.
283  *
284  * @param p_hwfn
285  * @param p_tlvs_list - Pointer to tlvs list
286  * @param req_type - Type of TLV
287  *
288  * @return pointer to tlv type if found, otherwise returns NULL.
289  */
290 void *ecore_iov_search_list_tlvs(struct ecore_hwfn *p_hwfn,
291                                  void *p_tlvs_list, u16 req_type);
292
293 /**
294  * @brief ecore_iov_get_vf_info - return the database of a
295  *        specific VF
296  *
297  * @param p_hwfn
298  * @param relative_vf_id - relative id of the VF for which info
299  *                       is requested
300  * @param b_enabled_only - false iff want to access even if vf is disabled
301  *
302  * @return struct ecore_vf_info*
303  */
304 struct ecore_vf_info *ecore_iov_get_vf_info(struct ecore_hwfn *p_hwfn,
305                                             u16 relative_vf_id,
306                                             bool b_enabled_only);
307 #endif
308 #endif /* __ECORE_SRIOV_H__ */