blob: 0f5689b1b45e06ffd471d0abe1a232ee0741af59 [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 Mintzdacd88d2016-05-11 16:36:16 +030027enum qed_iov_vport_update_flag {
28 QED_IOV_VP_UPDATE_ACTIVATE,
29 QED_IOV_VP_UPDATE_MCAST,
30 QED_IOV_VP_UPDATE_ACCEPT_PARAM,
31 QED_IOV_VP_UPDATE_RSS,
32 QED_IOV_VP_UPDATE_MAX,
33};
34
Yuval Mintz0b55e272016-05-11 16:36:15 +030035struct qed_public_vf_info {
36 /* These copies will later be reflected in the bulletin board,
37 * but this copy should be newer.
38 */
39 u8 mac[ETH_ALEN];
40};
41
Yuval Mintz32a47e72016-05-11 16:36:12 +030042/* This struct is part of qed_dev and contains data relevant to all hwfns;
43 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
44 */
45struct qed_hw_sriov_info {
46 int pos; /* capability position */
47 int nres; /* number of resources */
48 u32 cap; /* SR-IOV Capabilities */
49 u16 ctrl; /* SR-IOV Control */
50 u16 total_vfs; /* total VFs associated with the PF */
51 u16 num_vfs; /* number of vfs that have been started */
52 u16 initial_vfs; /* initial VFs associated with the PF */
53 u16 nr_virtfn; /* number of VFs available */
54 u16 offset; /* first VF Routing ID offset */
55 u16 stride; /* following VF stride */
56 u16 vf_device_id; /* VF device id */
57 u32 pgsz; /* page size for BAR alignment */
58 u8 link; /* Function Dependency Link */
59
60 u32 first_vf_in_pf;
61};
62
63/* This mailbox is maintained per VF in its PF contains all information
64 * required for sending / receiving a message.
65 */
66struct qed_iov_vf_mbx {
67 union vfpf_tlvs *req_virt;
68 dma_addr_t req_phys;
69 union pfvf_tlvs *reply_virt;
70 dma_addr_t reply_phys;
Yuval Mintz37bff2b2016-05-11 16:36:13 +030071
72 /* Address in VF where a pending message is located */
73 dma_addr_t pending_req;
74
75 u8 *offset;
76
77 /* saved VF request header */
78 struct vfpf_first_tlv first_tlv;
Yuval Mintz32a47e72016-05-11 16:36:12 +030079};
80
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030081struct qed_vf_q_info {
82 u16 fw_rx_qid;
83 u16 fw_tx_qid;
84 u8 fw_cid;
85 u8 rxq_active;
86 u8 txq_active;
87};
88
Yuval Mintz32a47e72016-05-11 16:36:12 +030089enum vf_state {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030090 VF_FREE = 0, /* VF ready to be acquired holds no resc */
91 VF_ACQUIRED, /* VF, acquired, but not initalized */
Yuval Mintzdacd88d2016-05-11 16:36:16 +030092 VF_ENABLED, /* VF, Enabled */
Yuval Mintz0b55e272016-05-11 16:36:15 +030093 VF_RESET, /* VF, FLR'd, pending cleanup */
Yuval Mintz32a47e72016-05-11 16:36:12 +030094 VF_STOPPED /* VF, Stopped */
95};
96
97/* PFs maintain an array of this structure, per VF */
98struct qed_vf_info {
99 struct qed_iov_vf_mbx vf_mbx;
100 enum vf_state state;
101 bool b_init;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300102 u8 to_disable;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300103
104 struct qed_bulletin bulletin;
105 dma_addr_t vf_bulletin;
106
107 u32 concrete_fid;
108 u16 opaque_fid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300109 u16 mtu;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300110
111 u8 vport_id;
112 u8 relative_vf_id;
113 u8 abs_vf_id;
114#define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
115 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
116 (p_vf)->abs_vf_id)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300117
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300118 u8 vport_instance;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300119 u8 num_rxqs;
120 u8 num_txqs;
121
122 u8 num_sbs;
123
124 u8 num_mac_filters;
125 u8 num_vlan_filters;
126 struct qed_vf_q_info vf_queues[QED_MAX_VF_CHAINS_PER_PF];
127 u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300128 u8 num_active_rxqs;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300129 struct qed_public_vf_info p_vf_info;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300130};
131
132/* This structure is part of qed_hwfn and used only for PFs that have sriov
133 * capability enabled.
134 */
135struct qed_pf_iov {
136 struct qed_vf_info vfs_array[MAX_NUM_VFS];
137 u64 pending_events[QED_VF_ARRAY_LENGTH];
138 u64 pending_flr[QED_VF_ARRAY_LENGTH];
139
140 /* Allocate message address continuosuly and split to each VF */
141 void *mbx_msg_virt_addr;
142 dma_addr_t mbx_msg_phys_addr;
143 u32 mbx_msg_size;
144 void *mbx_reply_virt_addr;
145 dma_addr_t mbx_reply_phys_addr;
146 u32 mbx_reply_size;
147 void *p_bulletins;
148 dma_addr_t bulletins_phys;
149 u32 bulletins_size;
150};
151
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300152enum qed_iov_wq_flag {
153 QED_IOV_WQ_MSG_FLAG,
154 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
155 QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
156 QED_IOV_WQ_STOP_WQ_FLAG,
157 QED_IOV_WQ_FLR_FLAG,
158};
159
Yuval Mintz32a47e72016-05-11 16:36:12 +0300160#ifdef CONFIG_QED_SRIOV
161/**
162 * @brief - Given a VF index, return index of next [including that] active VF.
163 *
164 * @param p_hwfn
165 * @param rel_vf_id
166 *
167 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
168 */
169u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
170
171/**
172 * @brief Read sriov related information and allocated resources
173 * reads from configuraiton space, shmem, etc.
174 *
175 * @param p_hwfn
176 *
177 * @return int
178 */
179int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
180
181/**
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300182 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
183 *
184 * @param p_hwfn
185 * @param p_iov
186 * @param type
187 * @param length
188 *
189 * @return pointer to the newly placed tlv
190 */
191void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
192
193/**
194 * @brief list the types and lengths of the tlvs on the buffer
195 *
196 * @param p_hwfn
197 * @param tlvs_list
198 */
199void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
200
201/**
Yuval Mintz32a47e72016-05-11 16:36:12 +0300202 * @brief qed_iov_alloc - allocate sriov related resources
203 *
204 * @param p_hwfn
205 *
206 * @return int
207 */
208int qed_iov_alloc(struct qed_hwfn *p_hwfn);
209
210/**
211 * @brief qed_iov_setup - setup sriov related resources
212 *
213 * @param p_hwfn
214 * @param p_ptt
215 */
216void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
217
218/**
219 * @brief qed_iov_free - free sriov related resources
220 *
221 * @param p_hwfn
222 */
223void qed_iov_free(struct qed_hwfn *p_hwfn);
224
225/**
226 * @brief free sriov related memory that was allocated during hw_prepare
227 *
228 * @param cdev
229 */
230void qed_iov_free_hw_info(struct qed_dev *cdev);
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300231
232/**
233 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
234 *
235 * @param p_hwfn
236 * @param opcode
237 * @param echo
238 * @param data
239 */
240int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
241 u8 opcode, __le16 echo, union event_ring_data *data);
242
Yuval Mintz0b55e272016-05-11 16:36:15 +0300243/**
244 * @brief Mark structs of vfs that have been FLR-ed.
245 *
246 * @param p_hwfn
247 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
248 *
249 * @return 1 iff one of the PF's vfs got FLRed. 0 otherwise.
250 */
251int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
252
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300253/**
254 * @brief Search extended TLVs in request/reply buffer.
255 *
256 * @param p_hwfn
257 * @param p_tlvs_list - Pointer to tlvs list
258 * @param req_type - Type of TLV
259 *
260 * @return pointer to tlv type if found, otherwise returns NULL.
261 */
262void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
263 void *p_tlvs_list, u16 req_type);
264
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300265void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
266int qed_iov_wq_start(struct qed_dev *cdev);
267
268void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300269void qed_vf_start_iov_wq(struct qed_dev *cdev);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300270int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
Yuval Mintz36558c32016-05-11 16:36:17 +0300271void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300272#else
273static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
274 u16 rel_vf_id)
275{
276 return MAX_NUM_VFS;
277}
278
279static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
280{
281 return 0;
282}
283
284static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
285{
286 return 0;
287}
288
289static inline void qed_iov_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
290{
291}
292
293static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
294{
295}
296
297static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
298{
299}
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300300
301static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
302 u8 opcode,
303 __le16 echo, union event_ring_data *data)
304{
305 return -EINVAL;
306}
307
Yuval Mintz0b55e272016-05-11 16:36:15 +0300308static inline int qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
309 u32 *disabled_vfs)
310{
311 return 0;
312}
313
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300314static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
315{
316}
317
318static inline int qed_iov_wq_start(struct qed_dev *cdev)
319{
320 return 0;
321}
322
323static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
324 enum qed_iov_wq_flag flag)
325{
326}
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300327
328static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
329{
330}
Yuval Mintz0b55e272016-05-11 16:36:15 +0300331
332static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
333{
334 return 0;
335}
Yuval Mintz36558c32016-05-11 16:36:17 +0300336
337static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
338{
339}
Yuval Mintz32a47e72016-05-11 16:36:12 +0300340#endif
341
342#define qed_for_each_vf(_p_hwfn, _i) \
343 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
344 _i < MAX_NUM_VFS; \
345 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))
346
347#endif