qed_sriov.h 11.7 KB
Newer Older
Y
Yuval Mintz 已提交
1
/* QLogic qed NIC Driver
M
Mintz, Yuval 已提交
2
 * Copyright (c) 2015-2017  QLogic Corporation
Y
Yuval Mintz 已提交
3
 *
M
Mintz, Yuval 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and /or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
Y
Yuval Mintz 已提交
31 32 33 34 35 36
 */

#ifndef _QED_SRIOV_H
#define _QED_SRIOV_H
#include <linux/types.h>
#include "qed_vf.h"
Y
Yuval Mintz 已提交
37 38 39

#define QED_ETH_VF_NUM_MAC_FILTERS 1
#define QED_ETH_VF_NUM_VLAN_FILTERS 2
Y
Yuval Mintz 已提交
40 41
#define QED_VF_ARRAY_LENGTH (3)

42
#ifdef CONFIG_QED_SRIOV
Y
Yuval Mintz 已提交
43 44 45 46
#define IS_VF(cdev)             ((cdev)->b_is_vf)
#define IS_PF(cdev)             (!((cdev)->b_is_vf))
#define IS_PF_SRIOV(p_hwfn)     (!!((p_hwfn)->cdev->p_iov_info))
#else
47 48
#define IS_VF(cdev)             (0)
#define IS_PF(cdev)             (1)
Y
Yuval Mintz 已提交
49 50 51 52
#define IS_PF_SRIOV(p_hwfn)     (0)
#endif
#define IS_PF_SRIOV_ALLOC(p_hwfn)       (!!((p_hwfn)->pf_iov_info))

Y
Yuval Mintz 已提交
53 54
#define QED_MAX_VF_CHAINS_PER_PF 16

Y
Yuval Mintz 已提交
55 56 57
#define QED_ETH_MAX_VF_NUM_VLAN_FILTERS	\
	(MAX_NUM_VFS * QED_ETH_VF_NUM_VLAN_FILTERS)

Y
Yuval Mintz 已提交
58 59
enum qed_iov_vport_update_flag {
	QED_IOV_VP_UPDATE_ACTIVATE,
Y
Yuval Mintz 已提交
60 61
	QED_IOV_VP_UPDATE_VLAN_STRIP,
	QED_IOV_VP_UPDATE_TX_SWITCH,
Y
Yuval Mintz 已提交
62 63 64
	QED_IOV_VP_UPDATE_MCAST,
	QED_IOV_VP_UPDATE_ACCEPT_PARAM,
	QED_IOV_VP_UPDATE_RSS,
Y
Yuval Mintz 已提交
65 66
	QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN,
	QED_IOV_VP_UPDATE_SGE_TPA,
Y
Yuval Mintz 已提交
67 68 69
	QED_IOV_VP_UPDATE_MAX,
};

Y
Yuval Mintz 已提交
70 71 72 73
struct qed_public_vf_info {
	/* These copies will later be reflected in the bulletin board,
	 * but this copy should be newer.
	 */
Y
Yuval Mintz 已提交
74
	u8 forced_mac[ETH_ALEN];
Y
Yuval Mintz 已提交
75
	u16 forced_vlan;
Y
Yuval Mintz 已提交
76
	u8 mac[ETH_ALEN];
Y
Yuval Mintz 已提交
77 78 79 80 81 82

	/* IFLA_VF_LINK_STATE_<X> */
	int link_state;

	/* Currently configured Tx rate in MB/sec. 0 if unconfigured */
	int tx_rate;
83 84 85 86 87 88 89 90

	/* Trusted VFs can configure promiscuous mode.
	 * Also store shadow promisc configuration if needed.
	 */
	bool is_trusted_configured;
	bool is_trusted_request;
	u8 rx_accept_mode;
	u8 tx_accept_mode;
Y
Yuval Mintz 已提交
91 92
};

M
Mintz, Yuval 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
struct qed_iov_vf_init_params {
	u16 rel_vf_id;

	/* Number of requested Queues; Currently, don't support different
	 * number of Rx/Tx queues.
	 */

	u16 num_queues;

	/* Allow the client to choose which qzones to use for Rx/Tx,
	 * and which queue_base to use for Tx queues on a per-queue basis.
	 * Notice values should be relative to the PF resources.
	 */
	u16 req_rx_queue[QED_MAX_VF_CHAINS_PER_PF];
	u16 req_tx_queue[QED_MAX_VF_CHAINS_PER_PF];
};

Y
Yuval Mintz 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
/* This struct is part of qed_dev and contains data relevant to all hwfns;
 * Initialized only if SR-IOV cpabability is exposed in PCIe config space.
 */
struct qed_hw_sriov_info {
	int pos;		/* capability position */
	int nres;		/* number of resources */
	u32 cap;		/* SR-IOV Capabilities */
	u16 ctrl;		/* SR-IOV Control */
	u16 total_vfs;		/* total VFs associated with the PF */
	u16 num_vfs;		/* number of vfs that have been started */
	u16 initial_vfs;	/* initial VFs associated with the PF */
	u16 nr_virtfn;		/* number of VFs available */
	u16 offset;		/* first VF Routing ID offset */
	u16 stride;		/* following VF stride */
	u16 vf_device_id;	/* VF device id */
	u32 pgsz;		/* page size for BAR alignment */
	u8 link;		/* Function Dependency Link */

	u32 first_vf_in_pf;
};

/* This mailbox is maintained per VF in its PF contains all information
 * required for sending / receiving a message.
 */
struct qed_iov_vf_mbx {
	union vfpf_tlvs *req_virt;
	dma_addr_t req_phys;
	union pfvf_tlvs *reply_virt;
	dma_addr_t reply_phys;
139 140 141 142

	/* Address in VF where a pending message is located */
	dma_addr_t pending_req;

M
Mintz, Yuval 已提交
143 144 145
	/* Message from VF awaits handling */
	bool b_pending_msg;

146 147 148 149
	u8 *offset;

	/* saved VF request header */
	struct vfpf_first_tlv first_tlv;
Y
Yuval Mintz 已提交
150 151
};

152 153 154
#define QED_IOV_LEGACY_QID_RX (0)
#define QED_IOV_LEGACY_QID_TX (1)

155 156 157 158 159 160 161
struct qed_vf_queue_cid {
	bool b_is_tx;
	struct qed_queue_cid *p_cid;
};

/* Describes a qzone associated with the VF */
struct qed_vf_queue {
Y
Yuval Mintz 已提交
162 163
	u16 fw_rx_qid;
	u16 fw_tx_qid;
164 165

	struct qed_vf_queue_cid cids[MAX_QUEUES_PER_QZONE];
Y
Yuval Mintz 已提交
166 167
};

Y
Yuval Mintz 已提交
168
enum vf_state {
Y
Yuval Mintz 已提交
169 170
	VF_FREE = 0,		/* VF ready to be acquired holds no resc */
	VF_ACQUIRED,		/* VF, acquired, but not initalized */
Y
Yuval Mintz 已提交
171
	VF_ENABLED,		/* VF, Enabled */
Y
Yuval Mintz 已提交
172
	VF_RESET,		/* VF, FLR'd, pending cleanup */
Y
Yuval Mintz 已提交
173 174 175
	VF_STOPPED		/* VF, Stopped */
};

Y
Yuval Mintz 已提交
176 177 178 179 180 181 182 183 184
struct qed_vf_vlan_shadow {
	bool used;
	u16 vid;
};

struct qed_vf_shadow_config {
	/* Shadow copy of all guest vlans */
	struct qed_vf_vlan_shadow vlans[QED_ETH_VF_NUM_VLAN_FILTERS + 1];

185 186
	/* Shadow copy of all configured MACs; Empty if forcing MACs */
	u8 macs[QED_ETH_VF_NUM_MAC_FILTERS][ETH_ALEN];
Y
Yuval Mintz 已提交
187 188 189
	u8 inner_vlan_removal;
};

Y
Yuval Mintz 已提交
190 191 192 193 194
/* PFs maintain an array of this structure, per VF */
struct qed_vf_info {
	struct qed_iov_vf_mbx vf_mbx;
	enum vf_state state;
	bool b_init;
Y
Yuval Mintz 已提交
195
	bool b_malicious;
Y
Yuval Mintz 已提交
196
	u8 to_disable;
Y
Yuval Mintz 已提交
197 198 199 200

	struct qed_bulletin bulletin;
	dma_addr_t vf_bulletin;

201 202 203
	/* PF saves a copy of the last VF acquire message */
	struct vfpf_acquire_tlv acquire;

Y
Yuval Mintz 已提交
204 205
	u32 concrete_fid;
	u16 opaque_fid;
Y
Yuval Mintz 已提交
206
	u16 mtu;
Y
Yuval Mintz 已提交
207 208 209 210 211 212 213

	u8 vport_id;
	u8 relative_vf_id;
	u8 abs_vf_id;
#define QED_VF_ABS_ID(p_hwfn, p_vf)	(QED_PATH_ID(p_hwfn) ?		      \
					 (p_vf)->abs_vf_id + MAX_NUM_VFS_BB : \
					 (p_vf)->abs_vf_id)
Y
Yuval Mintz 已提交
214

Y
Yuval Mintz 已提交
215
	u8 vport_instance;
Y
Yuval Mintz 已提交
216 217 218 219 220 221 222
	u8 num_rxqs;
	u8 num_txqs;

	u8 num_sbs;

	u8 num_mac_filters;
	u8 num_vlan_filters;
223 224

	struct qed_vf_queue vf_queues[QED_MAX_VF_CHAINS_PER_PF];
Y
Yuval Mintz 已提交
225
	u16 igu_sbs[QED_MAX_VF_CHAINS_PER_PF];
Y
Yuval Mintz 已提交
226
	u8 num_active_rxqs;
Y
Yuval Mintz 已提交
227
	struct qed_public_vf_info p_vf_info;
Y
Yuval Mintz 已提交
228 229
	bool spoof_chk;
	bool req_spoofchk_val;
Y
Yuval Mintz 已提交
230 231 232 233 234 235 236 237 238 239

	/* Stores the configuration requested by VF */
	struct qed_vf_shadow_config shadow_config;

	/* A bitfield using bulletin's valid-map bits, used to indicate
	 * which of the bulletin board features have been configured.
	 */
	u64 configured_features;
#define QED_IOV_CONFIGURED_FEATURES_MASK        ((1 << MAC_ADDR_FORCED) | \
						 (1 << VLAN_ADDR_FORCED))
Y
Yuval Mintz 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
};

/* This structure is part of qed_hwfn and used only for PFs that have sriov
 * capability enabled.
 */
struct qed_pf_iov {
	struct qed_vf_info vfs_array[MAX_NUM_VFS];
	u64 pending_flr[QED_VF_ARRAY_LENGTH];

	/* Allocate message address continuosuly and split to each VF */
	void *mbx_msg_virt_addr;
	dma_addr_t mbx_msg_phys_addr;
	u32 mbx_msg_size;
	void *mbx_reply_virt_addr;
	dma_addr_t mbx_reply_phys_addr;
	u32 mbx_reply_size;
	void *p_bulletins;
	dma_addr_t bulletins_phys;
	u32 bulletins_size;
};

261 262 263 264 265 266
enum qed_iov_wq_flag {
	QED_IOV_WQ_MSG_FLAG,
	QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
	QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
	QED_IOV_WQ_STOP_WQ_FLAG,
	QED_IOV_WQ_FLR_FLAG,
267
	QED_IOV_WQ_TRUST_FLAG,
M
Mintz, Yuval 已提交
268
	QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
269 270
};

Y
Yuval Mintz 已提交
271 272 273 274 275 276 277 278 279 280 281
#ifdef CONFIG_QED_SRIOV
/**
 * @brief - Given a VF index, return index of next [including that] active VF.
 *
 * @param p_hwfn
 * @param rel_vf_id
 *
 * @return MAX_NUM_VFS in case no further active VFs, otherwise index.
 */
u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id);

282 283 284
void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
				    int vfid, u16 vxlan_port, u16 geneve_port);

Y
Yuval Mintz 已提交
285 286 287 288 289 290 291 292 293 294
/**
 * @brief Read sriov related information and allocated resources
 *  reads from configuraiton space, shmem, etc.
 *
 * @param p_hwfn
 *
 * @return int
 */
int qed_iov_hw_info(struct qed_hwfn *p_hwfn);

Y
Yuval Mintz 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
/**
 * @brief qed_add_tlv - place a given tlv on the tlv buffer at next offset
 *
 * @param p_hwfn
 * @param p_iov
 * @param type
 * @param length
 *
 * @return pointer to the newly placed tlv
 */
void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length);

/**
 * @brief list the types and lengths of the tlvs on the buffer
 *
 * @param p_hwfn
 * @param tlvs_list
 */
void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list);

Y
Yuval Mintz 已提交
315 316 317 318 319 320 321 322 323 324 325 326 327 328
/**
 * @brief qed_iov_alloc - allocate sriov related resources
 *
 * @param p_hwfn
 *
 * @return int
 */
int qed_iov_alloc(struct qed_hwfn *p_hwfn);

/**
 * @brief qed_iov_setup - setup sriov related resources
 *
 * @param p_hwfn
 */
329
void qed_iov_setup(struct qed_hwfn *p_hwfn);
Y
Yuval Mintz 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343

/**
 * @brief qed_iov_free - free sriov related resources
 *
 * @param p_hwfn
 */
void qed_iov_free(struct qed_hwfn *p_hwfn);

/**
 * @brief free sriov related memory that was allocated during hw_prepare
 *
 * @param cdev
 */
void qed_iov_free_hw_info(struct qed_dev *cdev);
344 345 346 347 348 349 350 351 352 353 354 355

/**
 * @brief qed_sriov_eqe_event - handle async sriov event arrived on eqe.
 *
 * @param p_hwfn
 * @param opcode
 * @param echo
 * @param data
 */
int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
			u8 opcode, __le16 echo, union event_ring_data *data);

Y
Yuval Mintz 已提交
356 357 358 359 360 361
/**
 * @brief Mark structs of vfs that have been FLR-ed.
 *
 * @param p_hwfn
 * @param disabled_vfs - bitmask of all VFs on path that were FLRed
 *
362
 * @return true iff one of the PF's vfs got FLRed. false otherwise.
Y
Yuval Mintz 已提交
363
 */
364
bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *disabled_vfs);
Y
Yuval Mintz 已提交
365

Y
Yuval Mintz 已提交
366 367 368 369 370 371 372 373 374 375 376 377
/**
 * @brief Search extended TLVs in request/reply buffer.
 *
 * @param p_hwfn
 * @param p_tlvs_list - Pointer to tlvs list
 * @param req_type - Type of TLV
 *
 * @return pointer to tlv type if found, otherwise returns NULL.
 */
void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
			       void *p_tlvs_list, u16 req_type);

378 379 380 381
void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first);
int qed_iov_wq_start(struct qed_dev *cdev);

void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag);
Y
Yuval Mintz 已提交
382
void qed_vf_start_iov_wq(struct qed_dev *cdev);
Y
Yuval Mintz 已提交
383
int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled);
Y
Yuval Mintz 已提交
384
void qed_inform_vf_link_state(struct qed_hwfn *hwfn);
Y
Yuval Mintz 已提交
385 386 387 388 389 390 391
#else
static inline u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn,
					     u16 rel_vf_id)
{
	return MAX_NUM_VFS;
}

392 393 394 395 396 397
static inline void
qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn, int vfid,
			       u16 vxlan_port, u16 geneve_port)
{
}

Y
Yuval Mintz 已提交
398 399 400 401 402 403 404 405 406 407
static inline int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
{
	return 0;
}

static inline int qed_iov_alloc(struct qed_hwfn *p_hwfn)
{
	return 0;
}

408
static inline void qed_iov_setup(struct qed_hwfn *p_hwfn)
Y
Yuval Mintz 已提交
409 410 411 412 413 414 415 416 417 418
{
}

static inline void qed_iov_free(struct qed_hwfn *p_hwfn)
{
}

static inline void qed_iov_free_hw_info(struct qed_dev *cdev)
{
}
419 420 421 422 423 424 425 426

static inline int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
				      u8 opcode,
				      __le16 echo, union event_ring_data *data)
{
	return -EINVAL;
}

427 428
static inline bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn,
				       u32 *disabled_vfs)
Y
Yuval Mintz 已提交
429
{
430
	return false;
Y
Yuval Mintz 已提交
431 432
}

433 434 435 436 437 438 439 440 441 442 443 444 445
static inline void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
{
}

static inline int qed_iov_wq_start(struct qed_dev *cdev)
{
	return 0;
}

static inline void qed_schedule_iov(struct qed_hwfn *hwfn,
				    enum qed_iov_wq_flag flag)
{
}
Y
Yuval Mintz 已提交
446 447 448 449

static inline void qed_vf_start_iov_wq(struct qed_dev *cdev)
{
}
Y
Yuval Mintz 已提交
450 451 452 453 454

static inline int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
{
	return 0;
}
Y
Yuval Mintz 已提交
455 456 457 458

static inline void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
{
}
Y
Yuval Mintz 已提交
459 460 461 462 463 464 465 466
#endif

#define qed_for_each_vf(_p_hwfn, _i)			  \
	for (_i = qed_iov_get_next_active_vf(_p_hwfn, 0); \
	     _i < MAX_NUM_VFS;				  \
	     _i = qed_iov_get_next_active_vf(_p_hwfn, _i + 1))

#endif