blob: 480cd99c69b5c1cdf4e8afd5722b5df0b5e7d18a [file] [log] [blame]
Yuval Mintz32a47e72016-05-11 16:36:12 +03001/* QLogic qed NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
Yuval Mintz32a47e72016-05-11 16:36:12 +03003 *
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02004 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
Yuval Mintz32a47e72016-05-11 16:36:12 +030031 */
32
33#ifndef _QED_SRIOV_H
34#define _QED_SRIOV_H
35#include <linux/types.h>
36#include "qed_vf.h"
Yuval Mintz1cf2b1a2016-06-05 13:11:12 +030037
38#define QED_ETH_VF_NUM_MAC_FILTERS 1
39#define QED_ETH_VF_NUM_VLAN_FILTERS 2
Yuval Mintz32a47e72016-05-11 16:36:12 +030040#define QED_VF_ARRAY_LENGTH (3)
41
Arnd Bergmann14b84e82016-06-01 15:29:13 +020042#ifdef CONFIG_QED_SRIOV
Yuval Mintz32a47e72016-05-11 16:36:12 +030043#define IS_VF(cdev) ((cdev)->b_is_vf)
44#define IS_PF(cdev) (!((cdev)->b_is_vf))
Yuval Mintz32a47e72016-05-11 16:36:12 +030045#define IS_PF_SRIOV(p_hwfn) (!!((p_hwfn)->cdev->p_iov_info))
46#else
Arnd Bergmann14b84e82016-06-01 15:29:13 +020047#define IS_VF(cdev) (0)
48#define IS_PF(cdev) (1)
Yuval Mintz32a47e72016-05-11 16:36:12 +030049#define IS_PF_SRIOV(p_hwfn) (0)
50#endif
51#define IS_PF_SRIOV_ALLOC(p_hwfn) (!!((p_hwfn)->pf_iov_info))
52
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030053#define QED_MAX_VF_CHAINS_PER_PF 16
Yuval Mintz1408cc1f2016-05-11 16:36:14 +030054
Yuval Mintz08feecd2016-05-11 16:36:20 +030055#define QED_ETH_MAX_VF_NUM_VLAN_FILTERS \
56 (MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS)
57
Yuval Mintzdacd88d2016-05-11 16:36:16 +030058enum qed_iov_vport_update_flag {
59 QED_IOV_VP_UPDATE_ACTIVATE,
Yuval Mintz17b235c2016-05-11 16:36:18 +030060 QED_IOV_VP_UPDATE_VLAN_STRIP,
61 QED_IOV_VP_UPDATE_TX_SWITCH,
Yuval Mintzdacd88d2016-05-11 16:36:16 +030062 QED_IOV_VP_UPDATE_MCAST,
63 QED_IOV_VP_UPDATE_ACCEPT_PARAM,
64 QED_IOV_VP_UPDATE_RSS,
Yuval Mintz17b235c2016-05-11 16:36:18 +030065 QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN,
66 QED_IOV_VP_UPDATE_SGE_TPA,
Yuval Mintzdacd88d2016-05-11 16:36:16 +030067 QED_IOV_VP_UPDATE_MAX,
68};
69
Yuval Mintz0b55e272016-05-11 16:36:15 +030070struct qed_public_vf_info {
71 /* These copies will later be reflected in the bulletin board,
72 * but this copy should be newer.
73 */
Yuval Mintzeff16962016-05-11 16:36:21 +030074 u8 forced_mac[ETH_ALEN];
Yuval Mintz08feecd2016-05-11 16:36:20 +030075 u16 forced_vlan;
Yuval Mintz0b55e272016-05-11 16:36:15 +030076 u8 mac[ETH_ALEN];
Yuval Mintz733def62016-05-11 16:36:22 +030077
78 /* IFLA_VF_LINK_STATE_<X> */
79 int link_state;
80
81 /* Currently configured Tx rate in MB/sec. 0 if unconfigured */
82 int tx_rate;
Mintz, Yuvalf990c822017-01-01 13:57:08 +020083
84 /* Trusted VFs can configure promiscuous mode.
85 * Also store shadow promisc configuration if needed.
86 */
87 bool is_trusted_configured;
88 bool is_trusted_request;
89 u8 rx_accept_mode;
90 u8 tx_accept_mode;
Yuval Mintz0b55e272016-05-11 16:36:15 +030091};
92
Mintz, Yuval3da7a372016-11-29 16:47:06 +020093struct qed_iov_vf_init_params {
94 u16 rel_vf_id;
95
96 /* Number of requested Queues; Currently, don't support different
97 * number of Rx/Tx queues.
98 */
99
100 u16 num_queues;
101
102 /* Allow the client to choose which qzones to use for Rx/Tx,
103 * and which queue_base to use for Tx queues on a per-queue basis.
104 * Notice values should be relative to the PF resources.
105 */
106 u16 req_rx_queue[QED_MAX_VF_CHAINS_PER_PF];
107 u16 req_tx_queue[QED_MAX_VF_CHAINS_PER_PF];
108};
109
Yuval Mintz32a47e72016-05-11 16:36:12 +0300110/* This struct is part of qed_dev and contains data relevant to all hwfns;
111 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
112 */
113struct qed_hw_sriov_info {
114 int pos; /* capability position */
115 int nres; /* number of resources */
116 u32 cap; /* SR-IOV Capabilities */
117 u16 ctrl; /* SR-IOV Control */
118 u16 total_vfs; /* total VFs associated with the PF */
119 u16 num_vfs; /* number of vfs that have been started */
120 u16 initial_vfs; /* initial VFs associated with the PF */
121 u16 nr_virtfn; /* number of VFs available */
122 u16 offset; /* first VF Routing ID offset */
123 u16 stride; /* following VF stride */
124 u16 vf_device_id; /* VF device id */
125 u32 pgsz; /* page size for BAR alignment */
126 u8 link; /* Function Dependency Link */
127
128 u32 first_vf_in_pf;
129};
130
131/* This mailbox is maintained per VF in its PF contains all information
132 * required for sending / receiving a message.
133 */
134struct qed_iov_vf_mbx {
135 union vfpf_tlvs *req_virt;
136 dma_addr_t req_phys;
137 union pfvf_tlvs *reply_virt;
138 dma_addr_t reply_phys;
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300139
140 /* Address in VF where a pending message is located */
141 dma_addr_t pending_req;
142
Mintz, Yuvalfd3c6152017-02-27 11:06:32 +0200143 /* Message from VF awaits handling */
144 bool b_pending_msg;
145
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300146 u8 *offset;
147
148 /* saved VF request header */
149 struct vfpf_first_tlv first_tlv;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300150};
151
Mintz, Yuvalbbe3f232017-06-04 13:31:03 +0300152#define QED_IOV_LEGACY_QID_RX (0)
153#define QED_IOV_LEGACY_QID_TX (1)
154
Mintz, Yuval007bc372017-06-04 13:31:05 +0300155struct qed_vf_queue_cid {
156 bool b_is_tx;
157 struct qed_queue_cid *p_cid;
158};
159
160/* Describes a qzone associated with the VF */
161struct qed_vf_queue {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300162 u16 fw_rx_qid;
163 u16 fw_tx_qid;
Mintz, Yuval007bc372017-06-04 13:31:05 +0300164
165 struct qed_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300166};
167
Yuval Mintz32a47e72016-05-11 16:36:12 +0300168enum vf_state {
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300169 VF_FREE = 0, /* VF ready to be acquired holds no resc */
170 VF_ACQUIRED, /* VF, acquired, but not initalized */
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300171 VF_ENABLED, /* VF, Enabled */
Yuval Mintz0b55e272016-05-11 16:36:15 +0300172 VF_RESET, /* VF, FLR'd, pending cleanup */
Yuval Mintz32a47e72016-05-11 16:36:12 +0300173 VF_STOPPED /* VF, Stopped */
174};
175
Yuval Mintz08feecd2016-05-11 16:36:20 +0300176struct qed_vf_vlan_shadow {
177 bool used;
178 u16 vid;
179};
180
181struct qed_vf_shadow_config {
182 /* Shadow copy of all guest vlans */
183 struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1];
184
Yuval Mintz8246d0b2016-06-05 13:11:15 +0300185 /* Shadow copy of all configured MACs; Empty if forcing MACs */
186 u8 macs[QED_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
Yuval Mintz08feecd2016-05-11 16:36:20 +0300187 u8 inner_vlan_removal;
188};
189
Yuval Mintz32a47e72016-05-11 16:36:12 +0300190/* PFs maintain an array of this structure, per VF */
191struct qed_vf_info {
192 struct qed_iov_vf_mbx vf_mbx;
193 enum vf_state state;
194 bool b_init;
Yuval Mintz7eff82b2016-10-14 05:19:22 -0400195 bool b_malicious;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300196 u8 to_disable;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300197
198 struct qed_bulletin bulletin;
199 dma_addr_t vf_bulletin;
200
Yuval Mintz1fe614d2016-06-05 13:11:11 +0300201 /* PF saves a copy of the last VF acquire message */
202 struct vfpf_acquire_tlv acquire;
203
Yuval Mintz32a47e72016-05-11 16:36:12 +0300204 u32 concrete_fid;
205 u16 opaque_fid;
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300206 u16 mtu;
Yuval Mintz32a47e72016-05-11 16:36:12 +0300207
208 u8 vport_id;
209 u8 relative_vf_id;
210 u8 abs_vf_id;
211#define QED_VF_ABS_ID(p_hwfn, p_vf) (QED_PATH_ID(p_hwfn) ? \
212 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
213 (p_vf)->abs_vf_id)
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300214
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300215 u8 vport_instance;
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300216 u8 num_rxqs;
217 u8 num_txqs;
218
219 u8 num_sbs;
220
221 u8 num_mac_filters;
222 u8 num_vlan_filters;
Mintz, Yuval007bc372017-06-04 13:31:05 +0300223
224 struct qed_vf_queue vf_queues[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300225 u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300226 u8 num_active_rxqs;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300227 struct qed_public_vf_info p_vf_info;
Yuval Mintz6ddc7602016-05-11 16:36:23 +0300228 bool spoof_chk;
229 bool req_spoofchk_val;
Yuval Mintz08feecd2016-05-11 16:36:20 +0300230
231 /* Stores the configuration requested by VF */
232 struct qed_vf_shadow_config shadow_config;
233
234 /* A bitfield using bulletin's valid-map bits, used to indicate
235 * which of the bulletin board features have been configured.
236 */
237 u64 configured_features;
238#define QED_IOV_CONFIGURED_FEATURES_MASK ((1 << MAC_ADDR_FORCED) | \
239 (1 << VLAN_ADDR_FORCED))
Yuval Mintz32a47e72016-05-11 16:36:12 +0300240};
241
242/* This structure is part of qed_hwfn and used only for PFs that have sriov
243 * capability enabled.
244 */
245struct qed_pf_iov {
246 struct qed_vf_info vfs_array[MAX_NUM_VFS];
Yuval Mintz32a47e72016-05-11 16:36:12 +0300247 u64 pending_flr[QED_VF_ARRAY_LENGTH];
248
249 /* Allocate message address continuosuly and split to each VF */
250 void *mbx_msg_virt_addr;
251 dma_addr_t mbx_msg_phys_addr;
252 u32 mbx_msg_size;
253 void *mbx_reply_virt_addr;
254 dma_addr_t mbx_reply_phys_addr;
255 u32 mbx_reply_size;
256 void *p_bulletins;
257 dma_addr_t bulletins_phys;
258 u32 bulletins_size;
259};
260
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300261enum qed_iov_wq_flag {
262 QED_IOV_WQ_MSG_FLAG,
263 QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
264 QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
265 QED_IOV_WQ_STOP_WQ_FLAG,
266 QED_IOV_WQ_FLR_FLAG,
Mintz, Yuvalf990c822017-01-01 13:57:08 +0200267 QED_IOV_WQ_TRUST_FLAG,
Mintz, Yuval65ed2ff2017-02-20 22:43:39 +0200268 QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300269};
270
Yuval Mintz32a47e72016-05-11 16:36:12 +0300271#ifdef CONFIG_QED_SRIOV
272/**
273 * @brief - Given a VF index, return index of next [including that] active VF.
274 *
275 * @param p_hwfn
276 * @param rel_vf_id
277 *
278 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
279 */
280u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);
281
Chopra, Manish97379f12017-04-24 10:00:48 -0700282void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
283 int vfid, u16 vxlan_port, u16 geneve_port);
284
Yuval Mintz32a47e72016-05-11 16:36:12 +0300285/**
286 * @brief Read sriov related information and allocated resources
287 * reads from configuraiton space, shmem, etc.
288 *
289 * @param p_hwfn
290 *
291 * @return int
292 */
293int qed_iov_hw_info(struct qed_hwfn *p_hwfn);
294
295/**
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300296 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
297 *
298 * @param p_hwfn
299 * @param p_iov
300 * @param type
301 * @param length
302 *
303 * @return pointer to the newly placed tlv
304 */
305void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);
306
307/**
308 * @brief list the types and lengths of the tlvs on the buffer
309 *
310 * @param p_hwfn
311 * @param tlvs_list
312 */
313void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);
314
315/**
Yuval Mintz32a47e72016-05-11 16:36:12 +0300316 * @brief qed_iov_alloc - allocate sriov related resources
317 *
318 * @param p_hwfn
319 *
320 * @return int
321 */
322int qed_iov_alloc(struct qed_hwfn *p_hwfn);
323
324/**
325 * @brief qed_iov_setup - setup sriov related resources
326 *
327 * @param p_hwfn
Yuval Mintz32a47e72016-05-11 16:36:12 +0300328 */
Mintz, Yuval1ee240e2017-06-01 15:29:11 +0300329void qed_iov_setup(struct qed_hwfn *p_hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300330
331/**
332 * @brief qed_iov_free - free sriov related resources
333 *
334 * @param p_hwfn
335 */
336void qed_iov_free(struct qed_hwfn *p_hwfn);
337
338/**
339 * @brief free sriov related memory that was allocated during hw_prepare
340 *
341 * @param cdev
342 */
343void qed_iov_free_hw_info(struct qed_dev *cdev);
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300344
345/**
346 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
347 *
348 * @param p_hwfn
349 * @param opcode
350 * @param echo
351 * @param data
352 */
353int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
354 u8 opcode, __le16 echo, union event_ring_data *data);
355
Yuval Mintz0b55e272016-05-11 16:36:15 +0300356/**
357 * @brief Mark structs of vfs that have been FLR-ed.
358 *
359 * @param p_hwfn
360 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
361 *
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +0200362 * @return true iff one of the PF's vfs got FLRed. false otherwise.
Yuval Mintz0b55e272016-05-11 16:36:15 +0300363 */
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +0200364bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300365
Yuval Mintzdacd88d2016-05-11 16:36:16 +0300366/**
367 * @brief Search extended TLVs in request/reply buffer.
368 *
369 * @param p_hwfn
370 * @param p_tlvs_list - Pointer to tlvs list
371 * @param req_type - Type of TLV
372 *
373 * @return pointer to tlv type if found, otherwise returns NULL.
374 */
375void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
376 void *p_tlvs_list, u16 req_type);
377
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300378void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
379int qed_iov_wq_start(struct qed_dev *cdev);
380
381void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300382void qed_vf_start_iov_wq(struct qed_dev *cdev);
Yuval Mintz0b55e272016-05-11 16:36:15 +0300383int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
Yuval Mintz36558c32016-05-11 16:36:17 +0300384void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
Yuval Mintz32a47e72016-05-11 16:36:12 +0300385#else
386static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
387 u16 rel_vf_id)
388{
389 return MAX_NUM_VFS;
390}
391
Chopra, Manish97379f12017-04-24 10:00:48 -0700392static inline void
393qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, int vfid,
394 u16 vxlan_port, u16 geneve_port)
395{
396}
397
Yuval Mintz32a47e72016-05-11 16:36:12 +0300398static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
399{
400 return 0;
401}
402
403static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
404{
405 return 0;
406}
407
Mintz, Yuval1ee240e2017-06-01 15:29:11 +0300408static inline void qed_iov_setup(struct qed_hwfn *p_hwfn)
Yuval Mintz32a47e72016-05-11 16:36:12 +0300409{
410}
411
412static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
413{
414}
415
416static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
417{
418}
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300419
420static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
421 u8 opcode,
422 __le16 echo, union event_ring_data *data)
423{
424 return -EINVAL;
425}
426
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +0200427static inline bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
428 u32 *disabled_vfs)
Yuval Mintz0b55e272016-05-11 16:36:15 +0300429{
Mintz, Yuvalcccf6f52017-03-19 13:08:18 +0200430 return false;
Yuval Mintz0b55e272016-05-11 16:36:15 +0300431}
432
Yuval Mintz37bff2b2016-05-11 16:36:13 +0300433static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
434{
435}
436
437static inline int qed_iov_wq_start(struct qed_dev *cdev)
438{
439 return 0;
440}
441
442static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
443 enum qed_iov_wq_flag flag)
444{
445}
Yuval Mintz1408cc1f2016-05-11 16:36:14 +0300446
447static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
448{
449}
Yuval Mintz0b55e272016-05-11 16:36:15 +0300450
451static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
452{
453 return 0;
454}
Yuval Mintz36558c32016-05-11 16:36:17 +0300455
456static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
457{
458}
Yuval Mintz32a47e72016-05-11 16:36:12 +0300459#endif
460
461#define qed_for_each_vf(_p_hwfn, _i) \
462 for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
463 _i < MAX_NUM_VFS; \
464 _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))
465
466#endif