blob: c8667c65e685b3be8709a0daa188a1e07d389e22 [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"
13#define QED_VF_ARRAY_LENGTH (3)
14
15#define IS_VF(cdev) ((cdev)->b_is_vf)
16#define IS_PF(cdev) (!((cdev)->b_is_vf))
17#ifdef CONFIG_QED_SRIOV
18#define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info))
19#else
20#define IS_PF_SRIOV(p_hwfn) (0)
21#endif
22#define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
23
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030024#define QED_MAX_VF_CHAINS_PER_PF 16
25#define QED_ETH_VF_NUM_VLAN_FILTERS 2
26
Yuval Mintz08feecd2016-05-11 16:36:20 +030027#define QED_ETH_MAX_VF_NUM_VLAN_FILTERS \
28 (MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS)
29
Yuval Mintzdacd88d2016-05-11 16:36:16 +030030enum qed_iov_vport_update_flag {
31 QED_IOV_VP_UPDATE_ACTIVATE,
Yuval Mintz17b235c2016-05-11 16:36:18 +030032 QED_IOV_VP_UPDATE_VLAN_STRIP,
33 QED_IOV_VP_UPDATE_TX_SWITCH,
Yuval Mintzdacd88d2016-05-11 16:36:16 +030034 QED_IOV_VP_UPDATE_MCAST,
35 QED_IOV_VP_UPDATE_ACCEPT_PARAM,
36 QED_IOV_VP_UPDATE_RSS,
Yuval Mintz17b235c2016-05-11 16:36:18 +030037 QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN,
38 QED_IOV_VP_UPDATE_SGE_TPA,
Yuval Mintzdacd88d2016-05-11 16:36:16 +030039 QED_IOV_VP_UPDATE_MAX,
40};
41
Yuval Mintz0b55e272016-05-11 16:36:15 +030042struct qed_public_vf_info {
43 /* These copies will later be reflected in the bulletin board,
44 * but this copy should be newer.
45 */
Yuval Mintzeff16962016-05-11 16:36:21 +030046 u8 forced_mac[ETH_ALEN];
Yuval Mintz08feecd2016-05-11 16:36:20 +030047 u16 forced_vlan;
Yuval Mintz0b55e272016-05-11 16:36:15 +030048 u8 mac[ETH_ALEN];
Yuval Mintz733def62016-05-11 16:36:22 +030049
50 /* IFLA_VF_LINK_STATE_<X> */
51 int link_state;
52
53 /* Currently configured Tx rate in MB/sec. 0 if unconfigured */
54 int tx_rate;
Yuval Mintz0b55e272016-05-11 16:36:15 +030055};
56
Yuval Mintz32a47e72016-05-11 16:36:12 +030057/* This struct is part of qed_dev and contains data relevant to all hwfns;
58 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
59 */
60struct qed_hw_sriov_info {
61 int pos; /* capability position */
62 int nres; /* number of resources */
63 u32 cap; /* SR-IOV Capabilities */
64 u16 ctrl; /* SR-IOV Control */
65 u16 total_vfs; /* total VFs associated with the PF */
66 u16 num_vfs; /* number of vfs that have been started */
67 u16 initial_vfs; /* initial VFs associated with the PF */
68 u16 nr_virtfn; /* number of VFs available */
69 u16 offset; /* first VF Routing ID offset */
70 u16 stride; /* following VF stride */
71 u16 vf_device_id; /* VF device id */
72 u32 pgsz; /* page size for BAR alignment */
73 u8 link; /* Function Dependency Link */
74
75 u32 first_vf_in_pf;
76};
77
78/* This mailbox is maintained per VF in its PF contains all information
79 * required for sending / receiving a message.
80 */
81struct qed_iov_vf_mbx {
82 union vfpf_tlvs *req_virt;
83 dma_addr_t req_phys;
84 union pfvf_tlvs *reply_virt;
85 dma_addr_t reply_phys;
Yuval Mintz37bff2b2016-05-11 16:36:13 +030086
87 /* Address in VF where a pending message is located */
88 dma_addr_t pending_req;
89
90 u8 *offset;
91
92 /* saved VF request header */
93 struct vfpf_first_tlv first_tlv;
Yuval Mintz32a47e72016-05-11 16:36:12 +030094};
95
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030096struct qed_vf_q_info {
97 u16 fw_rx_qid;
98 u16 fw_tx_qid;
99 u8 fw_cid;
100 u8 rxq_active;
101 u8 txq_active;
102};
103
Yuval Mintz32a47e72016-05-11 16:36:12 +0300104enum vf_state {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300105 VF_FREE = 0, /* VF ready to be acquired holds no resc */
106 VF_ACQUIRED, /* VF, acquired, but not initalized */
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300107 VF_ENABLED, /* VF, Enabled */
Yuval Mintz0b55e272016-05-11 16:36:15 +0300108 VF_RESET, /* VF, FLR'd, pending cleanup */
Yuval Mintz32a47e72016-05-11 16:36:12 +0300109 VF_STOPPED /* VF, Stopped */
110};
111
Yuval Mintz08feecd2016-05-11 16:36:20 +0300112struct qed_vf_vlan_shadow {
113 bool used;
114 u16 vid;
115};
116
117struct qed_vf_shadow_config {
118 /* Shadow copy of all guest vlans */
119 struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1];
120
121 u8 inner_vlan_removal;
122};
123
Yuval Mintz32a47e72016-05-11 16:36:12 +0300124/* PFs maintain an array of this structure, per VF */
125struct qed_vf_info {
126 struct qed_iov_vf_mbx vf_mbx;
127 enum vf_state state;
128 bool b_init;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300129 u8 to_disable;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300130
131 struct qed_bulletin bulletin;
132 dma_addr_t vf_bulletin;
133
134 u32 concrete_fid;
135 u16 opaque_fid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300136 u16 mtu;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300137
138 u8 vport_id;
139 u8 relative_vf_id;
140 u8 abs_vf_id;
141#define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
142 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
143 (p_vf)->abs_vf_id)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300144
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300145 u8 vport_instance;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300146 u8 num_rxqs;
147 u8 num_txqs;
148
149 u8 num_sbs;
150
151 u8 num_mac_filters;
152 u8 num_vlan_filters;
153 struct qed_vf_q_info vf_queues[QED_MAX_VF_CHAINS_PER_PF];
154 u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300155 u8 num_active_rxqs;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300156 struct qed_public_vf_info p_vf_info;
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300157 bool spoof_chk;
158 bool req_spoofchk_val;
Yuval Mintz08feecd2016-05-11 16:36:20 +0300159
160 /* Stores the configuration requested by VF */
161 struct qed_vf_shadow_config shadow_config;
162
163 /* A bitfield using bulletin's valid-map bits, used to indicate
164 * which of the bulletin board features have been configured.
165 */
166 u64 configured_features;
167#define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
168 (1 << VLAN_ADDR_FORCED))
Yuval Mintz32a47e72016-05-11 16:36:12 +0300169};
170
171/* This structure is part of qed_hwfn and used only for PFs that have sriov
172 * capability enabled.
173 */
174struct qed_pf_iov {
175 struct qed_vf_info vfs_array[MAX_NUM_VFS];
176 u64 pending_events[QED_VF_ARRAY_LENGTH];
177 u64 pending_flr[QED_VF_ARRAY_LENGTH];
178
179 /* Allocate message address continuosuly and split to each VF */
180 void *mbx_msg_virt_addr;
181 dma_addr_t mbx_msg_phys_addr;
182 u32 mbx_msg_size;
183 void *mbx_reply_virt_addr;
184 dma_addr_t mbx_reply_phys_addr;
185 u32 mbx_reply_size;
186 void *p_bulletins;
187 dma_addr_t bulletins_phys;
188 u32 bulletins_size;
189};
190
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300191enum qed_iov_wq_flag {
192 QED_IOV_WQ_MSG_FLAG,
193 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
194 QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
195 QED_IOV_WQ_STOP_WQ_FLAG,
196 QED_IOV_WQ_FLR_FLAG,
197};
198
Yuval Mintz32a47e72016-05-11 16:36:12 +0300199#ifdef CONFIG_QED_SRIOV
200/**
201 * @brief - Given a VF index, return index of next [including that] active VF.
202 *
203 * @param p_hwfn
204 * @param rel_vf_id
205 *
206 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
207 */
208u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
209
210/**
211 * @brief Read sriov related information and allocated resources
212 * reads from configuraiton space, shmem, etc.
213 *
214 * @param p_hwfn
215 *
216 * @return int
217 */
218int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
219
220/**
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300221 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
222 *
223 * @param p_hwfn
224 * @param p_iov
225 * @param type
226 * @param length
227 *
228 * @return pointer to the newly placed tlv
229 */
230void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
231
232/**
233 * @brief list the types and lengths of the tlvs on the buffer
234 *
235 * @param p_hwfn
236 * @param tlvs_list
237 */
238void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
239
240/**
Yuval Mintz32a47e72016-05-11 16:36:12 +0300241 * @brief qed_iov_alloc - allocate sriov related resources
242 *
243 * @param p_hwfn
244 *
245 * @return int
246 */
247int qed_iov_alloc(struct qed_hwfn *p_hwfn);
248
249/**
250 * @brief qed_iov_setup - setup sriov related resources
251 *
252 * @param p_hwfn
253 * @param p_ptt
254 */
255void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
256
257/**
258 * @brief qed_iov_free - free sriov related resources
259 *
260 * @param p_hwfn
261 */
262void qed_iov_free(struct qed_hwfn *p_hwfn);
263
264/**
265 * @brief free sriov related memory that was allocated during hw_prepare
266 *
267 * @param cdev
268 */
269void qed_iov_free_hw_info(struct qed_dev *cdev);
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300270
271/**
272 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
273 *
274 * @param p_hwfn
275 * @param opcode
276 * @param echo
277 * @param data
278 */
279int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
280 u8 opcode, __le16 echo, union event_ring_data *data);
281
Yuval Mintz0b55e272016-05-11 16:36:15 +0300282/**
283 * @brief Mark structs of vfs that have been FLR-ed.
284 *
285 * @param p_hwfn
286 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
287 *
288 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
289 */
290int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
291
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300292/**
293 * @brief Search extended TLVs in request/reply buffer.
294 *
295 * @param p_hwfn
296 * @param p_tlvs_list - Pointer to tlvs list
297 * @param req_type - Type of TLV
298 *
299 * @return pointer to tlv type if found, otherwise returns NULL.
300 */
301void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
302 void *p_tlvs_list, u16 req_type);
303
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300304void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
305int qed_iov_wq_start(struct qed_dev *cdev);
306
307void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300308void qed_vf_start_iov_wq(struct qed_dev *cdev);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300309int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
Yuval Mintz36558c32016-05-11 16:36:17 +0300310void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300311#else
312static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
313 u16 rel_vf_id)
314{
315 return MAX_NUM_VFS;
316}
317
318static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
319{
320 return 0;
321}
322
323static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
324{
325 return 0;
326}
327
328static inline void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
329{
330}
331
332static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
333{
334}
335
336static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
337{
338}
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300339
340static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
341 u8 opcode,
342 __le16 echo, union event_ring_data *data)
343{
344 return -EINVAL;
345}
346
Yuval Mintz0b55e272016-05-11 16:36:15 +0300347static inline int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
348 u32 *disabled_vfs)
349{
350 return 0;
351}
352
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300353static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
354{
355}
356
357static inline int qed_iov_wq_start(struct qed_dev *cdev)
358{
359 return 0;
360}
361
362static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
363 enum qed_iov_wq_flag flag)
364{
365}
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300366
367static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
368{
369}
Yuval Mintz0b55e272016-05-11 16:36:15 +0300370
371static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
372{
373 return 0;
374}
Yuval Mintz36558c32016-05-11 16:36:17 +0300375
376static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
377{
378}
Yuval Mintz32a47e72016-05-11 16:36:12 +0300379#endif
380
381#define qed_for_each_vf(_p_hwfn, _i) \
382 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
383 _i < MAX_NUM_VFS; \
384 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))
385
386#endif