blob: 96a72737f97a870ec04b846e88b820ee6aa20e8c [file] [log] [blame]
Yuval Mintz32a47e72016-05-11 16:36:12 +03001/* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
3 *
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
6 * this source tree.
7 */
8
9#ifndef _QED_SRIOV_H
10#define _QED_SRIOV_H
11#include <linux/types.h>
12#include "qed_vf.h"
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +030013
14#define QED_ETH_VF_NUM_MAC_FILTERS 1
15#define QED_ETH_VF_NUM_VLAN_FILTERS 2
Yuval Mintz32a47e72016-05-11 16:36:12 +030016#define QED_VF_ARRAY_LENGTH (3)
17
18#define IS_VF(cdev) ((cdev)->b_is_vf)
19#define IS_PF(cdev) (!((cdev)->b_is_vf))
20#ifdef CONFIG_QED_SRIOV
21#define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info))
22#else
23#define IS_PF_SRIOV(p_hwfn) (0)
24#endif
25#define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
26
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030027#define QED_MAX_VF_CHAINS_PER_PF 16
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030028
Yuval Mintz08feecd2016-05-11 16:36:20 +030029#define QED_ETH_MAX_VF_NUM_VLAN_FILTERS \
30 (MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS)
31
Yuval Mintzdacd88d2016-05-11 16:36:16 +030032enum qed_iov_vport_update_flag {
33 QED_IOV_VP_UPDATE_ACTIVATE,
Yuval Mintz17b235c2016-05-11 16:36:18 +030034 QED_IOV_VP_UPDATE_VLAN_STRIP,
35 QED_IOV_VP_UPDATE_TX_SWITCH,
Yuval Mintzdacd88d2016-05-11 16:36:16 +030036 QED_IOV_VP_UPDATE_MCAST,
37 QED_IOV_VP_UPDATE_ACCEPT_PARAM,
38 QED_IOV_VP_UPDATE_RSS,
Yuval Mintz17b235c2016-05-11 16:36:18 +030039 QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN,
40 QED_IOV_VP_UPDATE_SGE_TPA,
Yuval Mintzdacd88d2016-05-11 16:36:16 +030041 QED_IOV_VP_UPDATE_MAX,
42};
43
Yuval Mintz0b55e272016-05-11 16:36:15 +030044struct qed_public_vf_info {
45 /* These copies will later be reflected in the bulletin board,
46 * but this copy should be newer.
47 */
Yuval Mintzeff16962016-05-11 16:36:21 +030048 u8 forced_mac[ETH_ALEN];
Yuval Mintz08feecd2016-05-11 16:36:20 +030049 u16 forced_vlan;
Yuval Mintz0b55e272016-05-11 16:36:15 +030050 u8 mac[ETH_ALEN];
Yuval Mintz733def62016-05-11 16:36:22 +030051
52 /* IFLA_VF_LINK_STATE_<X> */
53 int link_state;
54
55 /* Currently configured Tx rate in MB/sec. 0 if unconfigured */
56 int tx_rate;
Yuval Mintz0b55e272016-05-11 16:36:15 +030057};
58
Yuval Mintz32a47e72016-05-11 16:36:12 +030059/* This struct is part of qed_dev and contains data relevant to all hwfns;
60 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
61 */
62struct qed_hw_sriov_info {
63 int pos; /* capability position */
64 int nres; /* number of resources */
65 u32 cap; /* SR-IOV Capabilities */
66 u16 ctrl; /* SR-IOV Control */
67 u16 total_vfs; /* total VFs associated with the PF */
68 u16 num_vfs; /* number of vfs that have been started */
69 u16 initial_vfs; /* initial VFs associated with the PF */
70 u16 nr_virtfn; /* number of VFs available */
71 u16 offset; /* first VF Routing ID offset */
72 u16 stride; /* following VF stride */
73 u16 vf_device_id; /* VF device id */
74 u32 pgsz; /* page size for BAR alignment */
75 u8 link; /* Function Dependency Link */
76
77 u32 first_vf_in_pf;
78};
79
80/* This mailbox is maintained per VF in its PF contains all information
81 * required for sending / receiving a message.
82 */
83struct qed_iov_vf_mbx {
84 union vfpf_tlvs *req_virt;
85 dma_addr_t req_phys;
86 union pfvf_tlvs *reply_virt;
87 dma_addr_t reply_phys;
Yuval Mintz37bff2b2016-05-11 16:36:13 +030088
89 /* Address in VF where a pending message is located */
90 dma_addr_t pending_req;
91
92 u8 *offset;
93
94 /* saved VF request header */
95 struct vfpf_first_tlv first_tlv;
Yuval Mintz32a47e72016-05-11 16:36:12 +030096};
97
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030098struct qed_vf_q_info {
99 u16 fw_rx_qid;
100 u16 fw_tx_qid;
101 u8 fw_cid;
102 u8 rxq_active;
103 u8 txq_active;
104};
105
Yuval Mintz32a47e72016-05-11 16:36:12 +0300106enum vf_state {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300107 VF_FREE = 0, /* VF ready to be acquired holds no resc */
108 VF_ACQUIRED, /* VF, acquired, but not initalized */
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300109 VF_ENABLED, /* VF, Enabled */
Yuval Mintz0b55e272016-05-11 16:36:15 +0300110 VF_RESET, /* VF, FLR'd, pending cleanup */
Yuval Mintz32a47e72016-05-11 16:36:12 +0300111 VF_STOPPED /* VF, Stopped */
112};
113
Yuval Mintz08feecd2016-05-11 16:36:20 +0300114struct qed_vf_vlan_shadow {
115 bool used;
116 u16 vid;
117};
118
119struct qed_vf_shadow_config {
120 /* Shadow copy of all guest vlans */
121 struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1];
122
Yuval Mintz8246d0b2016-06-05 13:11:15 +0300123 /* Shadow copy of all configured MACs; Empty if forcing MACs */
124 u8 macs[QED_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
Yuval Mintz08feecd2016-05-11 16:36:20 +0300125 u8 inner_vlan_removal;
126};
127
Yuval Mintz32a47e72016-05-11 16:36:12 +0300128/* PFs maintain an array of this structure, per VF */
129struct qed_vf_info {
130 struct qed_iov_vf_mbx vf_mbx;
131 enum vf_state state;
132 bool b_init;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300133 u8 to_disable;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300134
135 struct qed_bulletin bulletin;
136 dma_addr_t vf_bulletin;
137
Yuval Mintz1fe614d2016-06-05 13:11:11 +0300138 /* PF saves a copy of the last VF acquire message */
139 struct vfpf_acquire_tlv acquire;
140
Yuval Mintz32a47e72016-05-11 16:36:12 +0300141 u32 concrete_fid;
142 u16 opaque_fid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300143 u16 mtu;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300144
145 u8 vport_id;
146 u8 relative_vf_id;
147 u8 abs_vf_id;
148#define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
149 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
150 (p_vf)->abs_vf_id)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300151
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300152 u8 vport_instance;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300153 u8 num_rxqs;
154 u8 num_txqs;
155
156 u8 num_sbs;
157
158 u8 num_mac_filters;
159 u8 num_vlan_filters;
160 struct qed_vf_q_info vf_queues[QED_MAX_VF_CHAINS_PER_PF];
161 u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300162 u8 num_active_rxqs;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300163 struct qed_public_vf_info p_vf_info;
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300164 bool spoof_chk;
165 bool req_spoofchk_val;
Yuval Mintz08feecd2016-05-11 16:36:20 +0300166
167 /* Stores the configuration requested by VF */
168 struct qed_vf_shadow_config shadow_config;
169
170 /* A bitfield using bulletin's valid-map bits, used to indicate
171 * which of the bulletin board features have been configured.
172 */
173 u64 configured_features;
174#define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
175 (1 << VLAN_ADDR_FORCED))
Yuval Mintz32a47e72016-05-11 16:36:12 +0300176};
177
178/* This structure is part of qed_hwfn and used only for PFs that have sriov
179 * capability enabled.
180 */
181struct qed_pf_iov {
182 struct qed_vf_info vfs_array[MAX_NUM_VFS];
183 u64 pending_events[QED_VF_ARRAY_LENGTH];
184 u64 pending_flr[QED_VF_ARRAY_LENGTH];
185
186 /* Allocate message address continuosuly and split to each VF */
187 void *mbx_msg_virt_addr;
188 dma_addr_t mbx_msg_phys_addr;
189 u32 mbx_msg_size;
190 void *mbx_reply_virt_addr;
191 dma_addr_t mbx_reply_phys_addr;
192 u32 mbx_reply_size;
193 void *p_bulletins;
194 dma_addr_t bulletins_phys;
195 u32 bulletins_size;
196};
197
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300198enum qed_iov_wq_flag {
199 QED_IOV_WQ_MSG_FLAG,
200 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
201 QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
202 QED_IOV_WQ_STOP_WQ_FLAG,
203 QED_IOV_WQ_FLR_FLAG,
204};
205
Yuval Mintz32a47e72016-05-11 16:36:12 +0300206#ifdef CONFIG_QED_SRIOV
207/**
208 * @brief - Given a VF index, return index of next [including that] active VF.
209 *
210 * @param p_hwfn
211 * @param rel_vf_id
212 *
213 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
214 */
215u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
216
217/**
218 * @brief Read sriov related information and allocated resources
219 * reads from configuraiton space, shmem, etc.
220 *
221 * @param p_hwfn
222 *
223 * @return int
224 */
225int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
226
227/**
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300228 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
229 *
230 * @param p_hwfn
231 * @param p_iov
232 * @param type
233 * @param length
234 *
235 * @return pointer to the newly placed tlv
236 */
237void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
238
239/**
240 * @brief list the types and lengths of the tlvs on the buffer
241 *
242 * @param p_hwfn
243 * @param tlvs_list
244 */
245void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
246
247/**
Yuval Mintz32a47e72016-05-11 16:36:12 +0300248 * @brief qed_iov_alloc - allocate sriov related resources
249 *
250 * @param p_hwfn
251 *
252 * @return int
253 */
254int qed_iov_alloc(struct qed_hwfn *p_hwfn);
255
256/**
257 * @brief qed_iov_setup - setup sriov related resources
258 *
259 * @param p_hwfn
260 * @param p_ptt
261 */
262void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
263
264/**
265 * @brief qed_iov_free - free sriov related resources
266 *
267 * @param p_hwfn
268 */
269void qed_iov_free(struct qed_hwfn *p_hwfn);
270
271/**
272 * @brief free sriov related memory that was allocated during hw_prepare
273 *
274 * @param cdev
275 */
276void qed_iov_free_hw_info(struct qed_dev *cdev);
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300277
278/**
279 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
280 *
281 * @param p_hwfn
282 * @param opcode
283 * @param echo
284 * @param data
285 */
286int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
287 u8 opcode, __le16 echo, union event_ring_data *data);
288
Yuval Mintz0b55e272016-05-11 16:36:15 +0300289/**
290 * @brief Mark structs of vfs that have been FLR-ed.
291 *
292 * @param p_hwfn
293 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
294 *
295 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
296 */
297int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
298
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300299/**
300 * @brief Search extended TLVs in request/reply buffer.
301 *
302 * @param p_hwfn
303 * @param p_tlvs_list - Pointer to tlvs list
304 * @param req_type - Type of TLV
305 *
306 * @return pointer to tlv type if found, otherwise returns NULL.
307 */
308void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
309 void *p_tlvs_list, u16 req_type);
310
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300311void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
312int qed_iov_wq_start(struct qed_dev *cdev);
313
314void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300315void qed_vf_start_iov_wq(struct qed_dev *cdev);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300316int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
Yuval Mintz36558c32016-05-11 16:36:17 +0300317void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300318#else
319static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
320 u16 rel_vf_id)
321{
322 return MAX_NUM_VFS;
323}
324
325static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
326{
327 return 0;
328}
329
330static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
331{
332 return 0;
333}
334
335static inline void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
336{
337}
338
339static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
340{
341}
342
343static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
344{
345}
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300346
347static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
348 u8 opcode,
349 __le16 echo, union event_ring_data *data)
350{
351 return -EINVAL;
352}
353
Yuval Mintz0b55e272016-05-11 16:36:15 +0300354static inline int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
355 u32 *disabled_vfs)
356{
357 return 0;
358}
359
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300360static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
361{
362}
363
364static inline int qed_iov_wq_start(struct qed_dev *cdev)
365{
366 return 0;
367}
368
369static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
370 enum qed_iov_wq_flag flag)
371{
372}
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300373
374static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
375{
376}
Yuval Mintz0b55e272016-05-11 16:36:15 +0300377
378static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
379{
380 return 0;
381}
Yuval Mintz36558c32016-05-11 16:36:17 +0300382
383static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
384{
385}
Yuval Mintz32a47e72016-05-11 16:36:12 +0300386#endif
387
388#define qed_for_each_vf(_p_hwfn, _i) \
389 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
390 _i < MAX_NUM_VFS; \
391 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))
392
393#endif