blob: c90b2b6ad96937feb7f04ef1a8123a73bca061d4 [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
Arnd Bergmann14b84e82016-06-01 15:29:13 +020015#ifdef CONFIG_QED_SRIOV
Yuval Mintz32a47e72016-05-11 16:36:12 +030016#define IS_VF(cdev) ((cdev)->b_is_vf)
17#define IS_PF(cdev) (!((cdev)->b_is_vf))
Yuval Mintz32a47e72016-05-11 16:36:12 +030018#define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info))
19#else
Arnd Bergmann14b84e82016-06-01 15:29:13 +020020#define IS_VF(cdev) (0)
21#define IS_PF(cdev) (1)
Yuval Mintz32a47e72016-05-11 16:36:12 +030022#define IS_PF_SRIOV(p_hwfn) (0)
23#endif
24#define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
25
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030026#define QED_MAX_VF_CHAINS_PER_PF 16
27#define QED_ETH_VF_NUM_VLAN_FILTERS 2
28
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
123 u8 inner_vlan_removal;
124};
125
Yuval Mintz32a47e72016-05-11 16:36:12 +0300126/* PFs maintain an array of this structure, per VF */
127struct qed_vf_info {
128 struct qed_iov_vf_mbx vf_mbx;
129 enum vf_state state;
130 bool b_init;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300131 u8 to_disable;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300132
133 struct qed_bulletin bulletin;
134 dma_addr_t vf_bulletin;
135
136 u32 concrete_fid;
137 u16 opaque_fid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300138 u16 mtu;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300139
140 u8 vport_id;
141 u8 relative_vf_id;
142 u8 abs_vf_id;
143#define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
144 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
145 (p_vf)->abs_vf_id)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300146
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300147 u8 vport_instance;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300148 u8 num_rxqs;
149 u8 num_txqs;
150
151 u8 num_sbs;
152
153 u8 num_mac_filters;
154 u8 num_vlan_filters;
155 struct qed_vf_q_info vf_queues[QED_MAX_VF_CHAINS_PER_PF];
156 u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300157 u8 num_active_rxqs;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300158 struct qed_public_vf_info p_vf_info;
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300159 bool spoof_chk;
160 bool req_spoofchk_val;
Yuval Mintz08feecd2016-05-11 16:36:20 +0300161
162 /* Stores the configuration requested by VF */
163 struct qed_vf_shadow_config shadow_config;
164
165 /* A bitfield using bulletin's valid-map bits, used to indicate
166 * which of the bulletin board features have been configured.
167 */
168 u64 configured_features;
169#define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
170 (1 << VLAN_ADDR_FORCED))
Yuval Mintz32a47e72016-05-11 16:36:12 +0300171};
172
173/* This structure is part of qed_hwfn and used only for PFs that have sriov
174 * capability enabled.
175 */
176struct qed_pf_iov {
177 struct qed_vf_info vfs_array[MAX_NUM_VFS];
178 u64 pending_events[QED_VF_ARRAY_LENGTH];
179 u64 pending_flr[QED_VF_ARRAY_LENGTH];
180
181 /* Allocate message address continuosuly and split to each VF */
182 void *mbx_msg_virt_addr;
183 dma_addr_t mbx_msg_phys_addr;
184 u32 mbx_msg_size;
185 void *mbx_reply_virt_addr;
186 dma_addr_t mbx_reply_phys_addr;
187 u32 mbx_reply_size;
188 void *p_bulletins;
189 dma_addr_t bulletins_phys;
190 u32 bulletins_size;
191};
192
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300193enum qed_iov_wq_flag {
194 QED_IOV_WQ_MSG_FLAG,
195 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
196 QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
197 QED_IOV_WQ_STOP_WQ_FLAG,
198 QED_IOV_WQ_FLR_FLAG,
199};
200
Yuval Mintz32a47e72016-05-11 16:36:12 +0300201#ifdef CONFIG_QED_SRIOV
202/**
203 * @brief - Given a VF index, return index of next [including that] active VF.
204 *
205 * @param p_hwfn
206 * @param rel_vf_id
207 *
208 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
209 */
210u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
211
212/**
213 * @brief Read sriov related information and allocated resources
214 * reads from configuraiton space, shmem, etc.
215 *
216 * @param p_hwfn
217 *
218 * @return int
219 */
220int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
221
222/**
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300223 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
224 *
225 * @param p_hwfn
226 * @param p_iov
227 * @param type
228 * @param length
229 *
230 * @return pointer to the newly placed tlv
231 */
232void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
233
234/**
235 * @brief list the types and lengths of the tlvs on the buffer
236 *
237 * @param p_hwfn
238 * @param tlvs_list
239 */
240void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
241
242/**
Yuval Mintz32a47e72016-05-11 16:36:12 +0300243 * @brief qed_iov_alloc - allocate sriov related resources
244 *
245 * @param p_hwfn
246 *
247 * @return int
248 */
249int qed_iov_alloc(struct qed_hwfn *p_hwfn);
250
251/**
252 * @brief qed_iov_setup - setup sriov related resources
253 *
254 * @param p_hwfn
255 * @param p_ptt
256 */
257void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
258
259/**
260 * @brief qed_iov_free - free sriov related resources
261 *
262 * @param p_hwfn
263 */
264void qed_iov_free(struct qed_hwfn *p_hwfn);
265
266/**
267 * @brief free sriov related memory that was allocated during hw_prepare
268 *
269 * @param cdev
270 */
271void qed_iov_free_hw_info(struct qed_dev *cdev);
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300272
273/**
274 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
275 *
276 * @param p_hwfn
277 * @param opcode
278 * @param echo
279 * @param data
280 */
281int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
282 u8 opcode, __le16 echo, union event_ring_data *data);
283
Yuval Mintz0b55e272016-05-11 16:36:15 +0300284/**
285 * @brief Mark structs of vfs that have been FLR-ed.
286 *
287 * @param p_hwfn
288 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
289 *
290 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
291 */
292int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
293
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300294/**
295 * @brief Search extended TLVs in request/reply buffer.
296 *
297 * @param p_hwfn
298 * @param p_tlvs_list - Pointer to tlvs list
299 * @param req_type - Type of TLV
300 *
301 * @return pointer to tlv type if found, otherwise returns NULL.
302 */
303void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
304 void *p_tlvs_list, u16 req_type);
305
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300306void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
307int qed_iov_wq_start(struct qed_dev *cdev);
308
309void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300310void qed_vf_start_iov_wq(struct qed_dev *cdev);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300311int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
Yuval Mintz36558c32016-05-11 16:36:17 +0300312void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300313#else
314static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
315 u16 rel_vf_id)
316{
317 return MAX_NUM_VFS;
318}
319
320static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
321{
322 return 0;
323}
324
325static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
326{
327 return 0;
328}
329
330static inline void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
331{
332}
333
334static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
335{
336}
337
338static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
339{
340}
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300341
342static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
343 u8 opcode,
344 __le16 echo, union event_ring_data *data)
345{
346 return -EINVAL;
347}
348
Yuval Mintz0b55e272016-05-11 16:36:15 +0300349static inline int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
350 u32 *disabled_vfs)
351{
352 return 0;
353}
354
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300355static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
356{
357}
358
359static inline int qed_iov_wq_start(struct qed_dev *cdev)
360{
361 return 0;
362}
363
364static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
365 enum qed_iov_wq_flag flag)
366{
367}
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300368
369static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
370{
371}
Yuval Mintz0b55e272016-05-11 16:36:15 +0300372
373static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
374{
375 return 0;
376}
Yuval Mintz36558c32016-05-11 16:36:17 +0300377
378static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
379{
380}
Yuval Mintz32a47e72016-05-11 16:36:12 +0300381#endif
382
383#define qed_for_each_vf(_p_hwfn, _i) \
384 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
385 _i < MAX_NUM_VFS; \
386 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))
387
388#endif