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