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