qed_l2.c 67.5 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 37 38 39 40 41 42 43 44 45 46 47 48 49
 */

#include <linux/types.h>
#include <asm/byteorder.h>
#include <asm/param.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/etherdevice.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/version.h>
#include <linux/workqueue.h>
#include <linux/bitops.h>
#include <linux/bug.h>
M
Mintz, Yuval 已提交
50
#include <linux/vmalloc.h>
Y
Yuval Mintz 已提交
51 52 53 54 55 56 57 58
#include "qed.h"
#include <linux/qed/qed_chain.h>
#include "qed_cxt.h"
#include "qed_dev_api.h"
#include <linux/qed/qed_eth_if.h>
#include "qed_hsi.h"
#include "qed_hw.h"
#include "qed_int.h"
Y
Yuval Mintz 已提交
59
#include "qed_l2.h"
Y
Yuval Mintz 已提交
60
#include "qed_mcp.h"
Y
Yuval Mintz 已提交
61 62
#include "qed_reg_addr.h"
#include "qed_sp.h"
Y
Yuval Mintz 已提交
63
#include "qed_sriov.h"
Y
Yuval Mintz 已提交
64

65

M
Manish Chopra 已提交
66 67 68
#define QED_MAX_SGES_NUM 16
#define CRC32_POLY 0x1edc6f41

M
Mintz, Yuval 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
void qed_eth_queue_cid_release(struct qed_hwfn *p_hwfn,
			       struct qed_queue_cid *p_cid)
{
	/* VFs' CIDs are 0-based in PF-view, and uninitialized on VF */
	if (!p_cid->is_vf && IS_PF(p_hwfn->cdev))
		qed_cxt_release_cid(p_hwfn, p_cid->cid);
	vfree(p_cid);
}

/* The internal is only meant to be directly called by PFs initializeing CIDs
 * for their VFs.
 */
struct qed_queue_cid *
_qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
		      u16 opaque_fid,
		      u32 cid,
		      u8 vf_qid,
		      struct qed_queue_start_common_params *p_params)
{
	bool b_is_same = (p_hwfn->hw_info.opaque_fid == opaque_fid);
	struct qed_queue_cid *p_cid;
	int rc;

	p_cid = vmalloc(sizeof(*p_cid));
	if (!p_cid)
		return NULL;
	memset(p_cid, 0, sizeof(*p_cid));

	p_cid->opaque_fid = opaque_fid;
	p_cid->cid = cid;
	p_cid->vf_qid = vf_qid;
	p_cid->rel = *p_params;
101
	p_cid->p_owner = p_hwfn;
M
Mintz, Yuval 已提交
102 103 104 105 106 107 108 109 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

	/* Don't try calculating the absolute indices for VFs */
	if (IS_VF(p_hwfn->cdev)) {
		p_cid->abs = p_cid->rel;
		goto out;
	}

	/* Calculate the engine-absolute indices of the resources.
	 * This would guarantee they're valid later on.
	 * In some cases [SBs] we already have the right values.
	 */
	rc = qed_fw_vport(p_hwfn, p_cid->rel.vport_id, &p_cid->abs.vport_id);
	if (rc)
		goto fail;

	rc = qed_fw_l2_queue(p_hwfn, p_cid->rel.queue_id, &p_cid->abs.queue_id);
	if (rc)
		goto fail;

	/* In case of a PF configuring its VF's queues, the stats-id is already
	 * absolute [since there's a single index that's suitable per-VF].
	 */
	if (b_is_same) {
		rc = qed_fw_vport(p_hwfn, p_cid->rel.stats_id,
				  &p_cid->abs.stats_id);
		if (rc)
			goto fail;
	} else {
		p_cid->abs.stats_id = p_cid->rel.stats_id;
	}

	/* SBs relevant information was already provided as absolute */
	p_cid->abs.sb = p_cid->rel.sb;
	p_cid->abs.sb_idx = p_cid->rel.sb_idx;

	/* This is tricky - we're actually interested in whehter this is a PF
	 * entry meant for the VF.
	 */
	if (!b_is_same)
		p_cid->is_vf = true;
out:
	DP_VERBOSE(p_hwfn,
		   QED_MSG_SP,
		   "opaque_fid: %04x CID %08x vport %02x [%02x] qzone %04x [%04x] stats %02x [%02x] SB %04x PI %02x\n",
		   p_cid->opaque_fid,
		   p_cid->cid,
		   p_cid->rel.vport_id,
		   p_cid->abs.vport_id,
		   p_cid->rel.queue_id,
		   p_cid->abs.queue_id,
		   p_cid->rel.stats_id,
		   p_cid->abs.stats_id, p_cid->abs.sb, p_cid->abs.sb_idx);

	return p_cid;

fail:
	vfree(p_cid);
	return NULL;
}

static struct qed_queue_cid *qed_eth_queue_to_cid(struct qed_hwfn *p_hwfn,
						  u16 opaque_fid, struct
						  qed_queue_start_common_params
						  *p_params)
{
	struct qed_queue_cid *p_cid;
	u32 cid = 0;

	/* Get a unique firmware CID for this queue, in case it's a PF.
	 * VF's don't need a CID as the queue configuration will be done
	 * by PF.
	 */
	if (IS_PF(p_hwfn->cdev)) {
		if (qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_ETH, &cid)) {
			DP_NOTICE(p_hwfn, "Failed to acquire cid\n");
			return NULL;
		}
	}

	p_cid = _qed_eth_queue_to_cid(p_hwfn, opaque_fid, cid, 0, p_params);
	if (!p_cid && IS_PF(p_hwfn->cdev))
		qed_cxt_release_cid(p_hwfn, cid);

	return p_cid;
}

Y
Yuval Mintz 已提交
188 189
int qed_sp_eth_vport_start(struct qed_hwfn *p_hwfn,
			   struct qed_sp_vport_start_params *p_params)
M
Manish Chopra 已提交
190 191 192
{
	struct vport_start_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent =  NULL;
193
	struct qed_sp_init_data init_data;
Y
Yuval Mintz 已提交
194
	u8 abs_vport_id = 0;
M
Manish Chopra 已提交
195 196 197
	int rc = -EINVAL;
	u16 rx_mode = 0;

198
	rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
Y
Yuval Mintz 已提交
199
	if (rc)
M
Manish Chopra 已提交
200 201
		return rc;

202 203
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = qed_spq_get_cid(p_hwfn);
204
	init_data.opaque_fid = p_params->opaque_fid;
205
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
M
Manish Chopra 已提交
206 207 208

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_VPORT_START,
209
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
210 211 212 213 214 215
	if (rc)
		return rc;

	p_ramrod		= &p_ent->ramrod.vport_start;
	p_ramrod->vport_id	= abs_vport_id;

216 217 218
	p_ramrod->mtu			= cpu_to_le16(p_params->mtu);
	p_ramrod->inner_vlan_removal_en	= p_params->remove_inner_vlan;
	p_ramrod->drop_ttl0_en		= p_params->drop_ttl0;
Y
Yuval Mintz 已提交
219
	p_ramrod->untagged		= p_params->only_untagged;
M
Manish Chopra 已提交
220 221 222 223 224 225 226

	SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_UCAST_DROP_ALL, 1);
	SET_FIELD(rx_mode, ETH_VPORT_RX_MODE_MCAST_DROP_ALL, 1);

	p_ramrod->rx_mode.state = cpu_to_le16(rx_mode);

	/* TPA related fields */
Y
Yuval Mintz 已提交
227
	memset(&p_ramrod->tpa_param, 0, sizeof(struct eth_vport_tpa_param));
M
Manish Chopra 已提交
228

229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	p_ramrod->tpa_param.max_buff_num = p_params->max_buffers_per_cqe;

	switch (p_params->tpa_mode) {
	case QED_TPA_MODE_GRO:
		p_ramrod->tpa_param.tpa_max_aggs_num = ETH_TPA_MAX_AGGS_NUM;
		p_ramrod->tpa_param.tpa_max_size = (u16)-1;
		p_ramrod->tpa_param.tpa_min_size_to_cont = p_params->mtu / 2;
		p_ramrod->tpa_param.tpa_min_size_to_start = p_params->mtu / 2;
		p_ramrod->tpa_param.tpa_ipv4_en_flg = 1;
		p_ramrod->tpa_param.tpa_ipv6_en_flg = 1;
		p_ramrod->tpa_param.tpa_pkt_split_flg = 1;
		p_ramrod->tpa_param.tpa_gro_consistent_flg = 1;
		break;
	default:
		break;
	}

Y
Yuval Mintz 已提交
246 247
	p_ramrod->tx_switching_en = p_params->tx_switching;

248 249 250
	p_ramrod->ctl_frame_mac_check_en = !!p_params->check_mac;
	p_ramrod->ctl_frame_ethtype_check_en = !!p_params->check_ethtype;

M
Manish Chopra 已提交
251 252
	/* Software Function ID in hwfn (PFs are 0 - 15, VFs are 16 - 135) */
	p_ramrod->sw_fid = qed_concrete_to_sw_fid(p_hwfn->cdev,
253
						  p_params->concrete_fid);
M
Manish Chopra 已提交
254 255 256 257

	return qed_spq_post(p_hwfn, p_ent, NULL);
}

258 259
static int qed_sp_vport_start(struct qed_hwfn *p_hwfn,
			      struct qed_sp_vport_start_params *p_params)
Y
Yuval Mintz 已提交
260 261 262 263 264 265
{
	if (IS_VF(p_hwfn->cdev)) {
		return qed_vf_pf_vport_start(p_hwfn, p_params->vport_id,
					     p_params->mtu,
					     p_params->remove_inner_vlan,
					     p_params->tpa_mode,
Y
Yuval Mintz 已提交
266 267
					     p_params->max_buffers_per_cqe,
					     p_params->only_untagged);
Y
Yuval Mintz 已提交
268 269 270 271 272
	}

	return qed_sp_eth_vport_start(p_hwfn, p_params);
}

M
Manish Chopra 已提交
273 274 275
static int
qed_sp_vport_update_rss(struct qed_hwfn *p_hwfn,
			struct vport_update_ramrod_data *p_ramrod,
276
			struct qed_rss_params *p_rss)
M
Manish Chopra 已提交
277
{
278 279 280 281
	struct eth_vport_rss_config *p_config;
	u16 capabilities = 0;
	int i, table_size;
	int rc = 0;
M
Manish Chopra 已提交
282

283
	if (!p_rss) {
M
Manish Chopra 已提交
284 285 286
		p_ramrod->common.update_rss_flg = 0;
		return rc;
	}
287
	p_config = &p_ramrod->rss_config;
M
Manish Chopra 已提交
288

289
	BUILD_BUG_ON(QED_RSS_IND_TABLE_SIZE != ETH_RSS_IND_TABLE_ENTRIES_NUM);
M
Manish Chopra 已提交
290

291
	rc = qed_fw_rss_eng(p_hwfn, p_rss->rss_eng_id, &p_config->rss_id);
M
Manish Chopra 已提交
292 293 294
	if (rc)
		return rc;

295 296 297 298
	p_ramrod->common.update_rss_flg = p_rss->update_rss_config;
	p_config->update_rss_capabilities = p_rss->update_rss_capabilities;
	p_config->update_rss_ind_table = p_rss->update_rss_ind_table;
	p_config->update_rss_key = p_rss->update_rss_key;
M
Manish Chopra 已提交
299

300 301 302
	p_config->rss_mode = p_rss->rss_enable ?
			     ETH_VPORT_RSS_MODE_REGULAR :
			     ETH_VPORT_RSS_MODE_DISABLED;
M
Manish Chopra 已提交
303 304 305

	SET_FIELD(capabilities,
		  ETH_VPORT_RSS_CONFIG_IPV4_CAPABILITY,
306
		  !!(p_rss->rss_caps & QED_RSS_IPV4));
M
Manish Chopra 已提交
307 308
	SET_FIELD(capabilities,
		  ETH_VPORT_RSS_CONFIG_IPV6_CAPABILITY,
309
		  !!(p_rss->rss_caps & QED_RSS_IPV6));
M
Manish Chopra 已提交
310 311
	SET_FIELD(capabilities,
		  ETH_VPORT_RSS_CONFIG_IPV4_TCP_CAPABILITY,
312
		  !!(p_rss->rss_caps & QED_RSS_IPV4_TCP));
M
Manish Chopra 已提交
313 314
	SET_FIELD(capabilities,
		  ETH_VPORT_RSS_CONFIG_IPV6_TCP_CAPABILITY,
315
		  !!(p_rss->rss_caps & QED_RSS_IPV6_TCP));
M
Manish Chopra 已提交
316 317
	SET_FIELD(capabilities,
		  ETH_VPORT_RSS_CONFIG_IPV4_UDP_CAPABILITY,
318
		  !!(p_rss->rss_caps & QED_RSS_IPV4_UDP));
M
Manish Chopra 已提交
319 320
	SET_FIELD(capabilities,
		  ETH_VPORT_RSS_CONFIG_IPV6_UDP_CAPABILITY,
321 322
		  !!(p_rss->rss_caps & QED_RSS_IPV6_UDP));
	p_config->tbl_size = p_rss->rss_table_size_log;
M
Manish Chopra 已提交
323

324
	p_config->capabilities = cpu_to_le16(capabilities);
M
Manish Chopra 已提交
325 326 327 328

	DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
		   "update rss flag %d, rss_mode = %d, update_caps = %d, capabilities = %d, update_ind = %d, update_rss_key = %d\n",
		   p_ramrod->common.update_rss_flg,
329 330 331 332
		   p_config->rss_mode,
		   p_config->update_rss_capabilities,
		   p_config->capabilities,
		   p_config->update_rss_ind_table, p_config->update_rss_key);
M
Manish Chopra 已提交
333

334 335 336 337
	table_size = min_t(int, QED_RSS_IND_TABLE_SIZE,
			   1 << p_config->tbl_size);
	for (i = 0; i < table_size; i++) {
		struct qed_queue_cid *p_queue = p_rss->rss_ind_table[i];
M
Manish Chopra 已提交
338

339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
		if (!p_queue)
			return -EINVAL;

		p_config->indirection_table[i] =
		    cpu_to_le16(p_queue->abs.queue_id);
	}

	DP_VERBOSE(p_hwfn, NETIF_MSG_IFUP,
		   "Configured RSS indirection table [%d entries]:\n",
		   table_size);
	for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i += 0x10) {
		DP_VERBOSE(p_hwfn,
			   NETIF_MSG_IFUP,
			   "%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x\n",
			   le16_to_cpu(p_config->indirection_table[i]),
			   le16_to_cpu(p_config->indirection_table[i + 1]),
			   le16_to_cpu(p_config->indirection_table[i + 2]),
			   le16_to_cpu(p_config->indirection_table[i + 3]),
			   le16_to_cpu(p_config->indirection_table[i + 4]),
			   le16_to_cpu(p_config->indirection_table[i + 5]),
			   le16_to_cpu(p_config->indirection_table[i + 6]),
			   le16_to_cpu(p_config->indirection_table[i + 7]),
			   le16_to_cpu(p_config->indirection_table[i + 8]),
			   le16_to_cpu(p_config->indirection_table[i + 9]),
			   le16_to_cpu(p_config->indirection_table[i + 10]),
			   le16_to_cpu(p_config->indirection_table[i + 11]),
			   le16_to_cpu(p_config->indirection_table[i + 12]),
			   le16_to_cpu(p_config->indirection_table[i + 13]),
			   le16_to_cpu(p_config->indirection_table[i + 14]),
			   le16_to_cpu(p_config->indirection_table[i + 15]));
M
Manish Chopra 已提交
369 370 371
	}

	for (i = 0; i < 10; i++)
372
		p_config->rss_key[i] = cpu_to_le32(p_rss->rss_key[i]);
M
Manish Chopra 已提交
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

	return rc;
}

static void
qed_sp_update_accept_mode(struct qed_hwfn *p_hwfn,
			  struct vport_update_ramrod_data *p_ramrod,
			  struct qed_filter_accept_flags accept_flags)
{
	p_ramrod->common.update_rx_mode_flg =
		accept_flags.update_rx_mode_config;

	p_ramrod->common.update_tx_mode_flg =
		accept_flags.update_tx_mode_config;

	/* Set Rx mode accept flags */
	if (p_ramrod->common.update_rx_mode_flg) {
		u8 accept_filter = accept_flags.rx_accept_filter;
		u16 state = 0;

		SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_DROP_ALL,
			  !(!!(accept_filter & QED_ACCEPT_UCAST_MATCHED) ||
			    !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED)));

		SET_FIELD(state, ETH_VPORT_RX_MODE_UCAST_ACCEPT_UNMATCHED,
			  !!(accept_filter & QED_ACCEPT_UCAST_UNMATCHED));

		SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_DROP_ALL,
			  !(!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) ||
			    !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));

		SET_FIELD(state, ETH_VPORT_RX_MODE_MCAST_ACCEPT_ALL,
			  (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
			   !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));

		SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
			  !!(accept_filter & QED_ACCEPT_BCAST));

		p_ramrod->rx_mode.state = cpu_to_le16(state);
		DP_VERBOSE(p_hwfn, QED_MSG_SP,
			   "p_ramrod->rx_mode.state = 0x%x\n", state);
	}

	/* Set Tx mode accept flags */
	if (p_ramrod->common.update_tx_mode_flg) {
		u8 accept_filter = accept_flags.tx_accept_filter;
		u16 state = 0;

		SET_FIELD(state, ETH_VPORT_TX_MODE_UCAST_DROP_ALL,
			  !!(accept_filter & QED_ACCEPT_NONE));

		SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_DROP_ALL,
			  !!(accept_filter & QED_ACCEPT_NONE));

		SET_FIELD(state, ETH_VPORT_TX_MODE_MCAST_ACCEPT_ALL,
			  (!!(accept_filter & QED_ACCEPT_MCAST_MATCHED) &&
			   !!(accept_filter & QED_ACCEPT_MCAST_UNMATCHED)));

		SET_FIELD(state, ETH_VPORT_TX_MODE_BCAST_ACCEPT_ALL,
			  !!(accept_filter & QED_ACCEPT_BCAST));

		p_ramrod->tx_mode.state = cpu_to_le16(state);
		DP_VERBOSE(p_hwfn, QED_MSG_SP,
			   "p_ramrod->tx_mode.state = 0x%x\n", state);
	}
}

Y
Yuval Mintz 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
static void
qed_sp_vport_update_sge_tpa(struct qed_hwfn *p_hwfn,
			    struct vport_update_ramrod_data *p_ramrod,
			    struct qed_sge_tpa_params *p_params)
{
	struct eth_vport_tpa_param *p_tpa;

	if (!p_params) {
		p_ramrod->common.update_tpa_param_flg = 0;
		p_ramrod->common.update_tpa_en_flg = 0;
		p_ramrod->common.update_tpa_param_flg = 0;
		return;
	}

	p_ramrod->common.update_tpa_en_flg = p_params->update_tpa_en_flg;
	p_tpa = &p_ramrod->tpa_param;
	p_tpa->tpa_ipv4_en_flg = p_params->tpa_ipv4_en_flg;
	p_tpa->tpa_ipv6_en_flg = p_params->tpa_ipv6_en_flg;
	p_tpa->tpa_ipv4_tunn_en_flg = p_params->tpa_ipv4_tunn_en_flg;
	p_tpa->tpa_ipv6_tunn_en_flg = p_params->tpa_ipv6_tunn_en_flg;

	p_ramrod->common.update_tpa_param_flg = p_params->update_tpa_param_flg;
	p_tpa->max_buff_num = p_params->max_buffers_per_cqe;
	p_tpa->tpa_pkt_split_flg = p_params->tpa_pkt_split_flg;
	p_tpa->tpa_hdr_data_split_flg = p_params->tpa_hdr_data_split_flg;
	p_tpa->tpa_gro_consistent_flg = p_params->tpa_gro_consistent_flg;
	p_tpa->tpa_max_aggs_num = p_params->tpa_max_aggs_num;
	p_tpa->tpa_max_size = p_params->tpa_max_size;
	p_tpa->tpa_min_size_to_start = p_params->tpa_min_size_to_start;
	p_tpa->tpa_min_size_to_cont = p_params->tpa_min_size_to_cont;
}

M
Manish Chopra 已提交
472 473 474 475 476 477 478 479 480 481
static void
qed_sp_update_mcast_bin(struct qed_hwfn *p_hwfn,
			struct vport_update_ramrod_data *p_ramrod,
			struct qed_sp_vport_update_params *p_params)
{
	int i;

	memset(&p_ramrod->approx_mcast.bins, 0,
	       sizeof(p_ramrod->approx_mcast.bins));

Y
Yuval Mintz 已提交
482 483
	if (!p_params->update_approx_mcast_flg)
		return;
M
Manish Chopra 已提交
484

Y
Yuval Mintz 已提交
485 486 487 488 489
	p_ramrod->common.update_approx_mcast_flg = 1;
	for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
		u32 *p_bins = (u32 *)p_params->bins;

		p_ramrod->approx_mcast.bins[i] = cpu_to_le32(p_bins[i]);
M
Manish Chopra 已提交
490 491 492
	}
}

Y
Yuval Mintz 已提交
493 494 495 496
int qed_sp_vport_update(struct qed_hwfn *p_hwfn,
			struct qed_sp_vport_update_params *p_params,
			enum spq_mode comp_mode,
			struct qed_spq_comp_cb *p_comp_data)
M
Manish Chopra 已提交
497 498 499
{
	struct qed_rss_params *p_rss_params = p_params->rss_params;
	struct vport_update_ramrod_data_cmn *p_cmn;
500
	struct qed_sp_init_data init_data;
M
Manish Chopra 已提交
501 502
	struct vport_update_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
Y
Yuval Mintz 已提交
503
	u8 abs_vport_id = 0, val;
M
Manish Chopra 已提交
504 505
	int rc = -EINVAL;

Y
Yuval Mintz 已提交
506 507 508 509 510
	if (IS_VF(p_hwfn->cdev)) {
		rc = qed_vf_pf_vport_update(p_hwfn, p_params);
		return rc;
	}

M
Manish Chopra 已提交
511
	rc = qed_fw_vport(p_hwfn, p_params->vport_id, &abs_vport_id);
Y
Yuval Mintz 已提交
512
	if (rc)
M
Manish Chopra 已提交
513 514
		return rc;

515 516 517 518 519
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = qed_spq_get_cid(p_hwfn);
	init_data.opaque_fid = p_params->opaque_fid;
	init_data.comp_mode = comp_mode;
	init_data.p_comp_data = p_comp_data;
M
Manish Chopra 已提交
520 521 522

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_VPORT_UPDATE,
523
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
524 525 526 527 528 529 530 531 532 533 534 535
	if (rc)
		return rc;

	/* Copy input params to ramrod according to FW struct */
	p_ramrod = &p_ent->ramrod.vport_update;
	p_cmn = &p_ramrod->common;

	p_cmn->vport_id = abs_vport_id;
	p_cmn->rx_active_flg = p_params->vport_active_rx_flg;
	p_cmn->update_rx_active_flg = p_params->update_vport_active_rx_flg;
	p_cmn->tx_active_flg = p_params->vport_active_tx_flg;
	p_cmn->update_tx_active_flg = p_params->update_vport_active_tx_flg;
536
	p_cmn->accept_any_vlan = p_params->accept_any_vlan;
Y
Yuval Mintz 已提交
537 538
	val = p_params->update_accept_any_vlan_flg;
	p_cmn->update_accept_any_vlan_flg = val;
Y
Yuval Mintz 已提交
539 540 541 542

	p_cmn->inner_vlan_removal_en = p_params->inner_vlan_removal_flg;
	val = p_params->update_inner_vlan_removal_flg;
	p_cmn->update_inner_vlan_removal_en_flg = val;
Y
Yuval Mintz 已提交
543 544 545 546 547 548 549 550 551 552

	p_cmn->default_vlan_en = p_params->default_vlan_enable_flg;
	val = p_params->update_default_vlan_enable_flg;
	p_cmn->update_default_vlan_en_flg = val;

	p_cmn->default_vlan = cpu_to_le16(p_params->default_vlan);
	p_cmn->update_default_vlan_flg = p_params->update_default_vlan_flg;

	p_cmn->silent_vlan_removal_en = p_params->silent_vlan_removal_flg;

Y
Yuval Mintz 已提交
553 554 555
	p_ramrod->common.tx_switching_en = p_params->tx_switching_flg;
	p_cmn->update_tx_switching_en_flg = p_params->update_tx_switching_flg;

Y
Yuval Mintz 已提交
556 557 558 559
	p_cmn->anti_spoofing_en = p_params->anti_spoofing_en;
	val = p_params->update_anti_spoofing_en_flg;
	p_ramrod->common.update_anti_spoofing_en_flg = val;

M
Manish Chopra 已提交
560 561 562 563 564 565 566 567 568 569 570
	rc = qed_sp_vport_update_rss(p_hwfn, p_ramrod, p_rss_params);
	if (rc) {
		/* Return spq entry which is taken in qed_sp_init_request()*/
		qed_spq_return_entry(p_hwfn, p_ent);
		return rc;
	}

	/* Update mcast bins for VFs, PF doesn't use this functionality */
	qed_sp_update_mcast_bin(p_hwfn, p_ramrod, p_params);

	qed_sp_update_accept_mode(p_hwfn, p_ramrod, p_params->accept_flags);
Y
Yuval Mintz 已提交
571
	qed_sp_vport_update_sge_tpa(p_hwfn, p_ramrod, p_params->sge_tpa_params);
M
Manish Chopra 已提交
572 573 574
	return qed_spq_post(p_hwfn, p_ent, NULL);
}

Y
Yuval Mintz 已提交
575
int qed_sp_vport_stop(struct qed_hwfn *p_hwfn, u16 opaque_fid, u8 vport_id)
M
Manish Chopra 已提交
576 577
{
	struct vport_stop_ramrod_data *p_ramrod;
578
	struct qed_sp_init_data init_data;
M
Manish Chopra 已提交
579 580 581 582
	struct qed_spq_entry *p_ent;
	u8 abs_vport_id = 0;
	int rc;

Y
Yuval Mintz 已提交
583 584 585
	if (IS_VF(p_hwfn->cdev))
		return qed_vf_pf_vport_stop(p_hwfn);

M
Manish Chopra 已提交
586
	rc = qed_fw_vport(p_hwfn, vport_id, &abs_vport_id);
Y
Yuval Mintz 已提交
587
	if (rc)
M
Manish Chopra 已提交
588 589
		return rc;

590 591 592 593
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = qed_spq_get_cid(p_hwfn);
	init_data.opaque_fid = opaque_fid;
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
M
Manish Chopra 已提交
594 595 596

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_VPORT_STOP,
597
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
598 599 600 601 602 603 604 605 606
	if (rc)
		return rc;

	p_ramrod = &p_ent->ramrod.vport_stop;
	p_ramrod->vport_id = abs_vport_id;

	return qed_spq_post(p_hwfn, p_ent, NULL);
}

Y
Yuval Mintz 已提交
607 608 609 610 611 612 613 614 615 616 617 618 619
static int
qed_vf_pf_accept_flags(struct qed_hwfn *p_hwfn,
		       struct qed_filter_accept_flags *p_accept_flags)
{
	struct qed_sp_vport_update_params s_params;

	memset(&s_params, 0, sizeof(s_params));
	memcpy(&s_params.accept_flags, p_accept_flags,
	       sizeof(struct qed_filter_accept_flags));

	return qed_vf_pf_vport_update(p_hwfn, &s_params);
}

M
Manish Chopra 已提交
620 621 622
static int qed_filter_accept_cmd(struct qed_dev *cdev,
				 u8 vport,
				 struct qed_filter_accept_flags accept_flags,
623 624
				 u8 update_accept_any_vlan,
				 u8 accept_any_vlan,
Y
Yuval Mintz 已提交
625 626
				 enum spq_mode comp_mode,
				 struct qed_spq_comp_cb *p_comp_data)
M
Manish Chopra 已提交
627 628 629 630 631 632 633 634
{
	struct qed_sp_vport_update_params vport_update_params;
	int i, rc;

	/* Prepare and send the vport rx_mode change */
	memset(&vport_update_params, 0, sizeof(vport_update_params));
	vport_update_params.vport_id = vport;
	vport_update_params.accept_flags = accept_flags;
635 636
	vport_update_params.update_accept_any_vlan_flg = update_accept_any_vlan;
	vport_update_params.accept_any_vlan = accept_any_vlan;
M
Manish Chopra 已提交
637 638 639 640 641 642

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];

		vport_update_params.opaque_fid = p_hwfn->hw_info.opaque_fid;

Y
Yuval Mintz 已提交
643 644 645 646 647 648 649
		if (IS_VF(cdev)) {
			rc = qed_vf_pf_accept_flags(p_hwfn, &accept_flags);
			if (rc)
				return rc;
			continue;
		}

M
Manish Chopra 已提交
650 651
		rc = qed_sp_vport_update(p_hwfn, &vport_update_params,
					 comp_mode, p_comp_data);
Y
Yuval Mintz 已提交
652
		if (rc) {
M
Manish Chopra 已提交
653 654 655 656 657 658 659 660
			DP_ERR(cdev, "Update rx_mode failed %d\n", rc);
			return rc;
		}

		DP_VERBOSE(p_hwfn, QED_MSG_SP,
			   "Accept filter configured, flags = [Rx]%x [Tx]%x\n",
			   accept_flags.rx_accept_filter,
			   accept_flags.tx_accept_filter);
661 662 663 664
		if (update_accept_any_vlan)
			DP_VERBOSE(p_hwfn, QED_MSG_SP,
				   "accept_any_vlan=%d configured\n",
				   accept_any_vlan);
M
Manish Chopra 已提交
665 666 667 668 669
	}

	return 0;
}

M
Mintz, Yuval 已提交
670 671 672 673 674
int qed_eth_rxq_start_ramrod(struct qed_hwfn *p_hwfn,
			     struct qed_queue_cid *p_cid,
			     u16 bd_max_bytes,
			     dma_addr_t bd_chain_phys_addr,
			     dma_addr_t cqe_pbl_addr, u16 cqe_pbl_size)
M
Manish Chopra 已提交
675 676 677
{
	struct rx_queue_start_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
678
	struct qed_sp_init_data init_data;
M
Manish Chopra 已提交
679 680 681
	int rc = -EINVAL;

	DP_VERBOSE(p_hwfn, QED_MSG_SP,
M
Mintz, Yuval 已提交
682 683 684
		   "opaque_fid=0x%x, cid=0x%x, rx_qzone=0x%x, vport_id=0x%x, sb_id=0x%x\n",
		   p_cid->opaque_fid, p_cid->cid,
		   p_cid->abs.queue_id, p_cid->abs.vport_id, p_cid->abs.sb);
M
Manish Chopra 已提交
685

686 687
	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
M
Mintz, Yuval 已提交
688 689
	init_data.cid = p_cid->cid;
	init_data.opaque_fid = p_cid->opaque_fid;
690
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
M
Manish Chopra 已提交
691 692 693

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_RX_QUEUE_START,
694
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
695 696 697 698 699
	if (rc)
		return rc;

	p_ramrod = &p_ent->ramrod.rx_queue_start;

M
Mintz, Yuval 已提交
700 701 702 703 704
	p_ramrod->sb_id = cpu_to_le16(p_cid->abs.sb);
	p_ramrod->sb_index = p_cid->abs.sb_idx;
	p_ramrod->vport_id = p_cid->abs.vport_id;
	p_ramrod->stats_counter_id = p_cid->abs.stats_id;
	p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
Y
Yuval Mintz 已提交
705 706
	p_ramrod->complete_cqe_flg = 0;
	p_ramrod->complete_event_flg = 1;
M
Manish Chopra 已提交
707

Y
Yuval Mintz 已提交
708
	p_ramrod->bd_max_bytes = cpu_to_le16(bd_max_bytes);
Y
Yuval Mintz 已提交
709
	DMA_REGPAIR_LE(p_ramrod->bd_base, bd_chain_phys_addr);
M
Manish Chopra 已提交
710

Y
Yuval Mintz 已提交
711
	p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
Y
Yuval Mintz 已提交
712
	DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr, cqe_pbl_addr);
M
Manish Chopra 已提交
713

M
Mintz, Yuval 已提交
714 715
	if (p_cid->is_vf) {
		p_ramrod->vf_rx_prod_index = p_cid->vf_qid;
Y
Yuval Mintz 已提交
716
		DP_VERBOSE(p_hwfn, QED_MSG_SP,
Y
Yuval Mintz 已提交
717
			   "Queue%s is meant for VF rxq[%02x]\n",
M
Mintz, Yuval 已提交
718 719 720
			   !!p_cid->b_legacy_vf ? " [legacy]" : "",
			   p_cid->vf_qid);
		p_ramrod->vf_rx_prod_use_zone_a = !!p_cid->b_legacy_vf;
Y
Yuval Mintz 已提交
721
	}
M
Manish Chopra 已提交
722

Y
Yuval Mintz 已提交
723
	return qed_spq_post(p_hwfn, p_ent, NULL);
M
Manish Chopra 已提交
724 725 726
}

static int
M
Mintz, Yuval 已提交
727 728
qed_eth_pf_rx_queue_start(struct qed_hwfn *p_hwfn,
			  struct qed_queue_cid *p_cid,
M
Manish Chopra 已提交
729 730 731
			  u16 bd_max_bytes,
			  dma_addr_t bd_chain_phys_addr,
			  dma_addr_t cqe_pbl_addr,
Y
Yuval Mintz 已提交
732
			  u16 cqe_pbl_size, void __iomem **pp_prod)
M
Manish Chopra 已提交
733
{
734
	u32 init_prod_val = 0;
M
Manish Chopra 已提交
735

M
Mintz, Yuval 已提交
736 737 738
	*pp_prod = p_hwfn->regview +
		   GTT_BAR0_MAP_REG_MSDM_RAM +
		    MSTORM_ETH_PF_PRODS_OFFSET(p_cid->abs.queue_id);
M
Manish Chopra 已提交
739 740

	/* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
741
	__internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
M
Manish Chopra 已提交
742 743
			  (u32 *)(&init_prod_val));

M
Mintz, Yuval 已提交
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
	return qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
					bd_max_bytes,
					bd_chain_phys_addr,
					cqe_pbl_addr, cqe_pbl_size);
}

static int
qed_eth_rx_queue_start(struct qed_hwfn *p_hwfn,
		       u16 opaque_fid,
		       struct qed_queue_start_common_params *p_params,
		       u16 bd_max_bytes,
		       dma_addr_t bd_chain_phys_addr,
		       dma_addr_t cqe_pbl_addr,
		       u16 cqe_pbl_size,
		       struct qed_rxq_start_ret_params *p_ret_params)
{
	struct qed_queue_cid *p_cid;
	int rc;

M
Manish Chopra 已提交
763
	/* Allocate a CID for the queue */
M
Mintz, Yuval 已提交
764 765 766
	p_cid = qed_eth_queue_to_cid(p_hwfn, opaque_fid, p_params);
	if (!p_cid)
		return -ENOMEM;
M
Manish Chopra 已提交
767

M
Mintz, Yuval 已提交
768 769 770 771 772 773 774 775
	if (IS_PF(p_hwfn->cdev)) {
		rc = qed_eth_pf_rx_queue_start(p_hwfn, p_cid,
					       bd_max_bytes,
					       bd_chain_phys_addr,
					       cqe_pbl_addr, cqe_pbl_size,
					       &p_ret_params->p_prod);
	} else {
		rc = qed_vf_pf_rxq_start(p_hwfn, p_cid,
M
Manish Chopra 已提交
776 777
					 bd_max_bytes,
					 bd_chain_phys_addr,
M
Mintz, Yuval 已提交
778 779 780
					 cqe_pbl_addr,
					 cqe_pbl_size, &p_ret_params->p_prod);
	}
M
Manish Chopra 已提交
781

M
Mintz, Yuval 已提交
782
	/* Provide the caller with a reference to as handler */
Y
Yuval Mintz 已提交
783
	if (rc)
M
Mintz, Yuval 已提交
784 785 786
		qed_eth_queue_cid_release(p_hwfn, p_cid);
	else
		p_ret_params->p_handle = (void *)p_cid;
M
Manish Chopra 已提交
787 788 789 790

	return rc;
}

Y
Yuval Mintz 已提交
791
int qed_sp_eth_rx_queues_update(struct qed_hwfn *p_hwfn,
M
Mintz, Yuval 已提交
792
				void **pp_rxq_handles,
Y
Yuval Mintz 已提交
793 794 795 796 797 798 799 800 801
				u8 num_rxqs,
				u8 complete_cqe_flg,
				u8 complete_event_flg,
				enum spq_mode comp_mode,
				struct qed_spq_comp_cb *p_comp_data)
{
	struct rx_queue_update_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
	struct qed_sp_init_data init_data;
M
Mintz, Yuval 已提交
802
	struct qed_queue_cid *p_cid;
Y
Yuval Mintz 已提交
803 804 805 806 807 808 809 810
	int rc = -EINVAL;
	u8 i;

	memset(&init_data, 0, sizeof(init_data));
	init_data.comp_mode = comp_mode;
	init_data.p_comp_data = p_comp_data;

	for (i = 0; i < num_rxqs; i++) {
M
Mintz, Yuval 已提交
811
		p_cid = ((struct qed_queue_cid **)pp_rxq_handles)[i];
Y
Yuval Mintz 已提交
812 813

		/* Get SPQ entry */
M
Mintz, Yuval 已提交
814 815
		init_data.cid = p_cid->cid;
		init_data.opaque_fid = p_cid->opaque_fid;
Y
Yuval Mintz 已提交
816 817 818 819 820 821 822 823

		rc = qed_sp_init_request(p_hwfn, &p_ent,
					 ETH_RAMROD_RX_QUEUE_UPDATE,
					 PROTOCOLID_ETH, &init_data);
		if (rc)
			return rc;

		p_ramrod = &p_ent->ramrod.rx_queue_update;
M
Mintz, Yuval 已提交
824
		p_ramrod->vport_id = p_cid->abs.vport_id;
Y
Yuval Mintz 已提交
825

M
Mintz, Yuval 已提交
826
		p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
Y
Yuval Mintz 已提交
827 828 829 830 831 832 833 834 835 836 837
		p_ramrod->complete_cqe_flg = complete_cqe_flg;
		p_ramrod->complete_event_flg = complete_event_flg;

		rc = qed_spq_post(p_hwfn, p_ent, NULL);
		if (rc)
			return rc;
	}

	return rc;
}

M
Mintz, Yuval 已提交
838 839 840 841
static int
qed_eth_pf_rx_queue_stop(struct qed_hwfn *p_hwfn,
			 struct qed_queue_cid *p_cid,
			 bool b_eq_completion_only, bool b_cqe_completion)
M
Manish Chopra 已提交
842 843 844
{
	struct rx_queue_stop_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
845
	struct qed_sp_init_data init_data;
M
Mintz, Yuval 已提交
846
	int rc;
Y
Yuval Mintz 已提交
847

848
	memset(&init_data, 0, sizeof(init_data));
M
Mintz, Yuval 已提交
849 850
	init_data.cid = p_cid->cid;
	init_data.opaque_fid = p_cid->opaque_fid;
851
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
M
Manish Chopra 已提交
852 853 854

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_RX_QUEUE_STOP,
855
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
856 857 858 859
	if (rc)
		return rc;

	p_ramrod = &p_ent->ramrod.rx_queue_stop;
M
Mintz, Yuval 已提交
860 861
	p_ramrod->vport_id = p_cid->abs.vport_id;
	p_ramrod->rx_queue_id = cpu_to_le16(p_cid->abs.queue_id);
M
Manish Chopra 已提交
862 863 864 865

	/* Cleaning the queue requires the completion to arrive there.
	 * In addition, VFs require the answer to come as eqe to PF.
	 */
M
Mintz, Yuval 已提交
866 867 868 869
	p_ramrod->complete_cqe_flg = (!p_cid->is_vf &&
				      !b_eq_completion_only) ||
				     b_cqe_completion;
	p_ramrod->complete_event_flg = p_cid->is_vf || b_eq_completion_only;
M
Manish Chopra 已提交
870

M
Mintz, Yuval 已提交
871 872 873 874 875 876 877 878 879
	return qed_spq_post(p_hwfn, p_ent, NULL);
}

int qed_eth_rx_queue_stop(struct qed_hwfn *p_hwfn,
			  void *p_rxq,
			  bool eq_completion_only, bool cqe_completion)
{
	struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_rxq;
	int rc = -EINVAL;
M
Manish Chopra 已提交
880

M
Mintz, Yuval 已提交
881 882 883 884 885 886 887 888 889 890
	if (IS_PF(p_hwfn->cdev))
		rc = qed_eth_pf_rx_queue_stop(p_hwfn, p_cid,
					      eq_completion_only,
					      cqe_completion);
	else
		rc = qed_vf_pf_rxq_stop(p_hwfn, p_cid, cqe_completion);

	if (!rc)
		qed_eth_queue_cid_release(p_hwfn, p_cid);
	return rc;
M
Manish Chopra 已提交
891 892
}

M
Mintz, Yuval 已提交
893 894 895 896
int
qed_eth_txq_start_ramrod(struct qed_hwfn *p_hwfn,
			 struct qed_queue_cid *p_cid,
			 dma_addr_t pbl_addr, u16 pbl_size, u16 pq_id)
M
Manish Chopra 已提交
897 898 899
{
	struct tx_queue_start_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
900
	struct qed_sp_init_data init_data;
M
Manish Chopra 已提交
901
	int rc = -EINVAL;
Y
Yuval Mintz 已提交
902

903 904
	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
M
Mintz, Yuval 已提交
905 906
	init_data.cid = p_cid->cid;
	init_data.opaque_fid = p_cid->opaque_fid;
907
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
M
Manish Chopra 已提交
908

909
	rc = qed_sp_init_request(p_hwfn, &p_ent,
M
Manish Chopra 已提交
910
				 ETH_RAMROD_TX_QUEUE_START,
911
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
912 913 914
	if (rc)
		return rc;

Y
Yuval Mintz 已提交
915
	p_ramrod = &p_ent->ramrod.tx_queue_start;
M
Mintz, Yuval 已提交
916
	p_ramrod->vport_id = p_cid->abs.vport_id;
Y
Yuval Mintz 已提交
917

M
Mintz, Yuval 已提交
918 919 920
	p_ramrod->sb_id = cpu_to_le16(p_cid->abs.sb);
	p_ramrod->sb_index = p_cid->abs.sb_idx;
	p_ramrod->stats_counter_id = p_cid->abs.stats_id;
M
Manish Chopra 已提交
921

M
Mintz, Yuval 已提交
922 923
	p_ramrod->queue_zone_id = cpu_to_le16(p_cid->abs.queue_id);
	p_ramrod->same_as_last_id = cpu_to_le16(p_cid->abs.queue_id);
M
Manish Chopra 已提交
924

Y
Yuval Mintz 已提交
925
	p_ramrod->pbl_size = cpu_to_le16(pbl_size);
Y
Yuval Mintz 已提交
926
	DMA_REGPAIR_LE(p_ramrod->pbl_base_addr, pbl_addr);
M
Manish Chopra 已提交
927

Y
Yuval Mintz 已提交
928
	p_ramrod->qm_pq_id = cpu_to_le16(pq_id);
M
Manish Chopra 已提交
929 930 931 932 933

	return qed_spq_post(p_hwfn, p_ent, NULL);
}

static int
M
Mintz, Yuval 已提交
934 935 936
qed_eth_pf_tx_queue_start(struct qed_hwfn *p_hwfn,
			  struct qed_queue_cid *p_cid,
			  u8 tc,
M
Manish Chopra 已提交
937
			  dma_addr_t pbl_addr,
Y
Yuval Mintz 已提交
938
			  u16 pbl_size, void __iomem **pp_doorbell)
M
Manish Chopra 已提交
939 940 941 942
{
	union qed_qm_pq_params pq_params;
	int rc;

M
Mintz, Yuval 已提交
943
	memset(&pq_params, 0, sizeof(pq_params));
Y
Yuval Mintz 已提交
944

M
Mintz, Yuval 已提交
945 946 947 948
	rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
				      pbl_addr, pbl_size,
				      qed_get_qm_pq(p_hwfn, PROTOCOLID_ETH,
						    &pq_params));
M
Manish Chopra 已提交
949 950 951
	if (rc)
		return rc;

M
Mintz, Yuval 已提交
952 953 954
	/* Provide the caller with the necessary return values */
	*pp_doorbell = p_hwfn->doorbells +
		       qed_db_addr(p_cid->cid, DQ_DEMS_LEGACY);
M
Manish Chopra 已提交
955

M
Mintz, Yuval 已提交
956 957
	return 0;
}
M
Manish Chopra 已提交
958

M
Mintz, Yuval 已提交
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
static int
qed_eth_tx_queue_start(struct qed_hwfn *p_hwfn,
		       u16 opaque_fid,
		       struct qed_queue_start_common_params *p_params,
		       u8 tc,
		       dma_addr_t pbl_addr,
		       u16 pbl_size,
		       struct qed_txq_start_ret_params *p_ret_params)
{
	struct qed_queue_cid *p_cid;
	int rc;

	p_cid = qed_eth_queue_to_cid(p_hwfn, opaque_fid, p_params);
	if (!p_cid)
		return -EINVAL;

	if (IS_PF(p_hwfn->cdev))
		rc = qed_eth_pf_tx_queue_start(p_hwfn, p_cid, tc,
					       pbl_addr, pbl_size,
					       &p_ret_params->p_doorbell);
	else
		rc = qed_vf_pf_txq_start(p_hwfn, p_cid,
					 pbl_addr, pbl_size,
					 &p_ret_params->p_doorbell);
M
Manish Chopra 已提交
983 984

	if (rc)
M
Mintz, Yuval 已提交
985 986 987
		qed_eth_queue_cid_release(p_hwfn, p_cid);
	else
		p_ret_params->p_handle = (void *)p_cid;
M
Manish Chopra 已提交
988 989 990 991

	return rc;
}

M
Mintz, Yuval 已提交
992 993
static int
qed_eth_pf_tx_queue_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
M
Manish Chopra 已提交
994 995
{
	struct qed_spq_entry *p_ent = NULL;
996
	struct qed_sp_init_data init_data;
M
Mintz, Yuval 已提交
997
	int rc;
Y
Yuval Mintz 已提交
998

999
	memset(&init_data, 0, sizeof(init_data));
M
Mintz, Yuval 已提交
1000 1001
	init_data.cid = p_cid->cid;
	init_data.opaque_fid = p_cid->opaque_fid;
1002
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
M
Manish Chopra 已提交
1003 1004 1005

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_TX_QUEUE_STOP,
1006
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
1007 1008 1009
	if (rc)
		return rc;

M
Mintz, Yuval 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
	return qed_spq_post(p_hwfn, p_ent, NULL);
}

int qed_eth_tx_queue_stop(struct qed_hwfn *p_hwfn, void *p_handle)
{
	struct qed_queue_cid *p_cid = (struct qed_queue_cid *)p_handle;
	int rc;

	if (IS_PF(p_hwfn->cdev))
		rc = qed_eth_pf_tx_queue_stop(p_hwfn, p_cid);
	else
		rc = qed_vf_pf_txq_stop(p_hwfn, p_cid);
M
Manish Chopra 已提交
1022

M
Mintz, Yuval 已提交
1023 1024 1025
	if (!rc)
		qed_eth_queue_cid_release(p_hwfn, p_cid);
	return rc;
M
Manish Chopra 已提交
1026 1027
}

Y
Yuval Mintz 已提交
1028
static enum eth_filter_action qed_filter_action(enum qed_filter_opcode opcode)
M
Manish Chopra 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
{
	enum eth_filter_action action = MAX_ETH_FILTER_ACTION;

	switch (opcode) {
	case QED_FILTER_ADD:
		action = ETH_FILTER_ACTION_ADD;
		break;
	case QED_FILTER_REMOVE:
		action = ETH_FILTER_ACTION_REMOVE;
		break;
	case QED_FILTER_FLUSH:
Y
Yuval Mintz 已提交
1040
		action = ETH_FILTER_ACTION_REMOVE_ALL;
M
Manish Chopra 已提交
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
		break;
	default:
		action = MAX_ETH_FILTER_ACTION;
	}

	return action;
}

static void qed_set_fw_mac_addr(__le16 *fw_msb,
				__le16 *fw_mid,
				__le16 *fw_lsb,
				u8 *mac)
{
	((u8 *)fw_msb)[0] = mac[1];
	((u8 *)fw_msb)[1] = mac[0];
	((u8 *)fw_mid)[0] = mac[3];
	((u8 *)fw_mid)[1] = mac[2];
	((u8 *)fw_lsb)[0] = mac[5];
	((u8 *)fw_lsb)[1] = mac[4];
}

static int
qed_filter_ucast_common(struct qed_hwfn *p_hwfn,
			u16 opaque_fid,
			struct qed_filter_ucast *p_filter_cmd,
			struct vport_filter_update_ramrod_data **pp_ramrod,
			struct qed_spq_entry **pp_ent,
			enum spq_mode comp_mode,
			struct qed_spq_comp_cb *p_comp_data)
{
	u8 vport_to_add_to = 0, vport_to_remove_from = 0;
	struct vport_filter_update_ramrod_data *p_ramrod;
	struct eth_filter_cmd *p_first_filter;
	struct eth_filter_cmd *p_second_filter;
1075
	struct qed_sp_init_data init_data;
M
Manish Chopra 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
	enum eth_filter_action action;
	int rc;

	rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
			  &vport_to_remove_from);
	if (rc)
		return rc;

	rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
			  &vport_to_add_to);
	if (rc)
		return rc;

1089 1090 1091 1092 1093 1094
	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = qed_spq_get_cid(p_hwfn);
	init_data.opaque_fid = opaque_fid;
	init_data.comp_mode = comp_mode;
	init_data.p_comp_data = p_comp_data;
M
Manish Chopra 已提交
1095 1096 1097

	rc = qed_sp_init_request(p_hwfn, pp_ent,
				 ETH_RAMROD_FILTERS_UPDATE,
1098
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
1099 1100 1101 1102 1103 1104 1105 1106 1107
	if (rc)
		return rc;

	*pp_ramrod = &(*pp_ent)->ramrod.vport_filter_update;
	p_ramrod = *pp_ramrod;
	p_ramrod->filter_cmd_hdr.rx = p_filter_cmd->is_rx_filter ? 1 : 0;
	p_ramrod->filter_cmd_hdr.tx = p_filter_cmd->is_tx_filter ? 1 : 0;

	switch (p_filter_cmd->opcode) {
Y
Yuval Mintz 已提交
1108
	case QED_FILTER_REPLACE:
M
Manish Chopra 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
	case QED_FILTER_MOVE:
		p_ramrod->filter_cmd_hdr.cmd_cnt = 2; break;
	default:
		p_ramrod->filter_cmd_hdr.cmd_cnt = 1; break;
	}

	p_first_filter	= &p_ramrod->filter_cmds[0];
	p_second_filter = &p_ramrod->filter_cmds[1];

	switch (p_filter_cmd->type) {
	case QED_FILTER_MAC:
		p_first_filter->type = ETH_FILTER_TYPE_MAC; break;
	case QED_FILTER_VLAN:
		p_first_filter->type = ETH_FILTER_TYPE_VLAN; break;
	case QED_FILTER_MAC_VLAN:
		p_first_filter->type = ETH_FILTER_TYPE_PAIR; break;
	case QED_FILTER_INNER_MAC:
		p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC; break;
	case QED_FILTER_INNER_VLAN:
		p_first_filter->type = ETH_FILTER_TYPE_INNER_VLAN; break;
	case QED_FILTER_INNER_PAIR:
		p_first_filter->type = ETH_FILTER_TYPE_INNER_PAIR; break;
	case QED_FILTER_INNER_MAC_VNI_PAIR:
		p_first_filter->type = ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR;
		break;
	case QED_FILTER_MAC_VNI_PAIR:
		p_first_filter->type = ETH_FILTER_TYPE_MAC_VNI_PAIR; break;
	case QED_FILTER_VNI:
		p_first_filter->type = ETH_FILTER_TYPE_VNI; break;
	}

	if ((p_first_filter->type == ETH_FILTER_TYPE_MAC) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR)) {
		qed_set_fw_mac_addr(&p_first_filter->mac_msb,
				    &p_first_filter->mac_mid,
				    &p_first_filter->mac_lsb,
				    (u8 *)p_filter_cmd->mac);
	}

	if ((p_first_filter->type == ETH_FILTER_TYPE_VLAN) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_PAIR) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_INNER_VLAN) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_INNER_PAIR))
		p_first_filter->vlan_id = cpu_to_le16(p_filter_cmd->vlan);

	if ((p_first_filter->type == ETH_FILTER_TYPE_INNER_MAC_VNI_PAIR) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_MAC_VNI_PAIR) ||
	    (p_first_filter->type == ETH_FILTER_TYPE_VNI))
		p_first_filter->vni = cpu_to_le32(p_filter_cmd->vni);

	if (p_filter_cmd->opcode == QED_FILTER_MOVE) {
Y
Yuval Mintz 已提交
1164 1165 1166 1167 1168 1169
		p_second_filter->type = p_first_filter->type;
		p_second_filter->mac_msb = p_first_filter->mac_msb;
		p_second_filter->mac_mid = p_first_filter->mac_mid;
		p_second_filter->mac_lsb = p_first_filter->mac_lsb;
		p_second_filter->vlan_id = p_first_filter->vlan_id;
		p_second_filter->vni = p_first_filter->vni;
M
Manish Chopra 已提交
1170 1171 1172 1173 1174

		p_first_filter->action = ETH_FILTER_ACTION_REMOVE;

		p_first_filter->vport_id = vport_to_remove_from;

Y
Yuval Mintz 已提交
1175 1176
		p_second_filter->action = ETH_FILTER_ACTION_ADD;
		p_second_filter->vport_id = vport_to_add_to;
Y
Yuval Mintz 已提交
1177 1178 1179 1180 1181 1182
	} else if (p_filter_cmd->opcode == QED_FILTER_REPLACE) {
		p_first_filter->vport_id = vport_to_add_to;
		memcpy(p_second_filter, p_first_filter,
		       sizeof(*p_second_filter));
		p_first_filter->action	= ETH_FILTER_ACTION_REMOVE_ALL;
		p_second_filter->action = ETH_FILTER_ACTION_ADD;
M
Manish Chopra 已提交
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
	} else {
		action = qed_filter_action(p_filter_cmd->opcode);

		if (action == MAX_ETH_FILTER_ACTION) {
			DP_NOTICE(p_hwfn,
				  "%d is not supported yet\n",
				  p_filter_cmd->opcode);
			return -EINVAL;
		}

		p_first_filter->action = action;
		p_first_filter->vport_id = (p_filter_cmd->opcode ==
					    QED_FILTER_REMOVE) ?
					   vport_to_remove_from :
					   vport_to_add_to;
	}

	return 0;
}

Y
Yuval Mintz 已提交
1203 1204 1205 1206 1207
int qed_sp_eth_filter_ucast(struct qed_hwfn *p_hwfn,
			    u16 opaque_fid,
			    struct qed_filter_ucast *p_filter_cmd,
			    enum spq_mode comp_mode,
			    struct qed_spq_comp_cb *p_comp_data)
M
Manish Chopra 已提交
1208 1209 1210 1211 1212 1213 1214 1215 1216
{
	struct vport_filter_update_ramrod_data	*p_ramrod	= NULL;
	struct qed_spq_entry			*p_ent		= NULL;
	struct eth_filter_cmd_header		*p_header;
	int					rc;

	rc = qed_filter_ucast_common(p_hwfn, opaque_fid, p_filter_cmd,
				     &p_ramrod, &p_ent,
				     comp_mode, p_comp_data);
Y
Yuval Mintz 已提交
1217
	if (rc) {
M
Manish Chopra 已提交
1218 1219 1220 1221 1222 1223 1224
		DP_ERR(p_hwfn, "Uni. filter command failed %d\n", rc);
		return rc;
	}
	p_header = &p_ramrod->filter_cmd_hdr;
	p_header->assert_on_error = p_filter_cmd->assert_on_error;

	rc = qed_spq_post(p_hwfn, p_ent, NULL);
Y
Yuval Mintz 已提交
1225 1226
	if (rc) {
		DP_ERR(p_hwfn, "Unicast filter ADD command failed %d\n", rc);
M
Manish Chopra 已提交
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
		return rc;
	}

	DP_VERBOSE(p_hwfn, QED_MSG_SP,
		   "Unicast filter configured, opcode = %s, type = %s, cmd_cnt = %d, is_rx_filter = %d, is_tx_filter = %d\n",
		   (p_filter_cmd->opcode == QED_FILTER_ADD) ? "ADD" :
		   ((p_filter_cmd->opcode == QED_FILTER_REMOVE) ?
		   "REMOVE" :
		   ((p_filter_cmd->opcode == QED_FILTER_MOVE) ?
		    "MOVE" : "REPLACE")),
		   (p_filter_cmd->type == QED_FILTER_MAC) ? "MAC" :
		   ((p_filter_cmd->type == QED_FILTER_VLAN) ?
		    "VLAN" : "MAC & VLAN"),
		   p_ramrod->filter_cmd_hdr.cmd_cnt,
		   p_filter_cmd->is_rx_filter,
		   p_filter_cmd->is_tx_filter);
	DP_VERBOSE(p_hwfn, QED_MSG_SP,
		   "vport_to_add_to = %d, vport_to_remove_from = %d, mac = %2x:%2x:%2x:%2x:%2x:%2x, vlan = %d\n",
		   p_filter_cmd->vport_to_add_to,
		   p_filter_cmd->vport_to_remove_from,
		   p_filter_cmd->mac[0],
		   p_filter_cmd->mac[1],
		   p_filter_cmd->mac[2],
		   p_filter_cmd->mac[3],
		   p_filter_cmd->mac[4],
		   p_filter_cmd->mac[5],
		   p_filter_cmd->vlan);

	return 0;
}

/*******************************************************************************
 * Description:
 *         Calculates crc 32 on a buffer
 *         Note: crc32_length MUST be aligned to 8
 * Return:
 ******************************************************************************/
static u32 qed_calc_crc32c(u8 *crc32_packet,
Y
Yuval Mintz 已提交
1265
			   u32 crc32_length, u32 crc32_seed, u8 complement)
M
Manish Chopra 已提交
1266
{
Y
Yuval Mintz 已提交
1267 1268
	u32 byte = 0, bit = 0, crc32_result = crc32_seed;
	u8 msb = 0, current_byte = 0;
M
Manish Chopra 已提交
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287

	if ((!crc32_packet) ||
	    (crc32_length == 0) ||
	    ((crc32_length % 8) != 0))
		return crc32_result;
	for (byte = 0; byte < crc32_length; byte++) {
		current_byte = crc32_packet[byte];
		for (bit = 0; bit < 8; bit++) {
			msb = (u8)(crc32_result >> 31);
			crc32_result = crc32_result << 1;
			if (msb != (0x1 & (current_byte >> bit))) {
				crc32_result = crc32_result ^ CRC32_POLY;
				crc32_result |= 1; /*crc32_result[0] = 1;*/
			}
		}
	}
	return crc32_result;
}

Y
Yuval Mintz 已提交
1288
static u32 qed_crc32c_le(u32 seed, u8 *mac, u32 len)
M
Manish Chopra 已提交
1289 1290 1291 1292 1293 1294 1295
{
	u32 packet_buf[2] = { 0 };

	memcpy((u8 *)(&packet_buf[0]), &mac[0], 6);
	return qed_calc_crc32c((u8 *)packet_buf, 8, seed, 0);
}

Y
Yuval Mintz 已提交
1296
u8 qed_mcast_bin_from_mac(u8 *mac)
M
Manish Chopra 已提交
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
{
	u32 crc = qed_crc32c_le(ETH_MULTICAST_BIN_FROM_MAC_SEED,
				mac, ETH_ALEN);

	return crc & 0xff;
}

static int
qed_sp_eth_filter_mcast(struct qed_hwfn *p_hwfn,
			u16 opaque_fid,
			struct qed_filter_mcast *p_filter_cmd,
			enum spq_mode comp_mode,
			struct qed_spq_comp_cb *p_comp_data)
{
	unsigned long bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
	struct vport_update_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
1314
	struct qed_sp_init_data init_data;
M
Manish Chopra 已提交
1315 1316 1317
	u8 abs_vport_id = 0;
	int rc, i;

Y
Yuval Mintz 已提交
1318
	if (p_filter_cmd->opcode == QED_FILTER_ADD)
M
Manish Chopra 已提交
1319 1320
		rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_add_to,
				  &abs_vport_id);
Y
Yuval Mintz 已提交
1321
	else
M
Manish Chopra 已提交
1322 1323
		rc = qed_fw_vport(p_hwfn, p_filter_cmd->vport_to_remove_from,
				  &abs_vport_id);
Y
Yuval Mintz 已提交
1324 1325
	if (rc)
		return rc;
M
Manish Chopra 已提交
1326

1327 1328 1329 1330 1331 1332
	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = qed_spq_get_cid(p_hwfn);
	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
	init_data.comp_mode = comp_mode;
	init_data.p_comp_data = p_comp_data;
M
Manish Chopra 已提交
1333 1334 1335

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 ETH_RAMROD_VPORT_UPDATE,
1336
				 PROTOCOLID_ETH, &init_data);
M
Manish Chopra 已提交
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
	if (rc) {
		DP_ERR(p_hwfn, "Multi-cast command failed %d\n", rc);
		return rc;
	}

	p_ramrod = &p_ent->ramrod.vport_update;
	p_ramrod->common.update_approx_mcast_flg = 1;

	/* explicitly clear out the entire vector */
	memset(&p_ramrod->approx_mcast.bins, 0,
	       sizeof(p_ramrod->approx_mcast.bins));
	memset(bins, 0, sizeof(unsigned long) *
	       ETH_MULTICAST_MAC_BINS_IN_REGS);
	/* filter ADD op is explicit set op and it removes
	 *  any existing filters for the vport
	 */
	if (p_filter_cmd->opcode == QED_FILTER_ADD) {
		for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
			u32 bit;

			bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
			__set_bit(bit, bins);
		}

		/* Convert to correct endianity */
		for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
Y
Yuval Mintz 已提交
1363
			struct vport_update_ramrod_mcast *p_ramrod_bins;
M
Manish Chopra 已提交
1364 1365
			u32 *p_bins = (u32 *)bins;

Y
Yuval Mintz 已提交
1366 1367
			p_ramrod_bins = &p_ramrod->approx_mcast;
			p_ramrod_bins->bins[i] = cpu_to_le32(p_bins[i]);
M
Manish Chopra 已提交
1368 1369 1370 1371 1372 1373 1374 1375
		}
	}

	p_ramrod->common.vport_id = abs_vport_id;

	return qed_spq_post(p_hwfn, p_ent, NULL);
}

Y
Yuval Mintz 已提交
1376 1377 1378 1379
static int qed_filter_mcast_cmd(struct qed_dev *cdev,
				struct qed_filter_mcast *p_filter_cmd,
				enum spq_mode comp_mode,
				struct qed_spq_comp_cb *p_comp_data)
M
Manish Chopra 已提交
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
{
	int rc = 0;
	int i;

	/* only ADD and REMOVE operations are supported for multi-cast */
	if ((p_filter_cmd->opcode != QED_FILTER_ADD &&
	     (p_filter_cmd->opcode != QED_FILTER_REMOVE)) ||
	    (p_filter_cmd->num_mc_addrs > QED_MAX_MC_ADDRS))
		return -EINVAL;

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];

		u16 opaque_fid;

Y
Yuval Mintz 已提交
1395 1396 1397 1398
		if (IS_VF(cdev)) {
			qed_vf_pf_filter_mcast(p_hwfn, p_filter_cmd);
			continue;
		}
M
Manish Chopra 已提交
1399 1400 1401 1402 1403 1404

		opaque_fid = p_hwfn->hw_info.opaque_fid;

		rc = qed_sp_eth_filter_mcast(p_hwfn,
					     opaque_fid,
					     p_filter_cmd,
Y
Yuval Mintz 已提交
1405
					     comp_mode, p_comp_data);
M
Manish Chopra 已提交
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
	}
	return rc;
}

static int qed_filter_ucast_cmd(struct qed_dev *cdev,
				struct qed_filter_ucast *p_filter_cmd,
				enum spq_mode comp_mode,
				struct qed_spq_comp_cb *p_comp_data)
{
	int rc = 0;
	int i;

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
		u16 opaque_fid;

Y
Yuval Mintz 已提交
1422 1423 1424 1425
		if (IS_VF(cdev)) {
			rc = qed_vf_pf_filter_ucast(p_hwfn, p_filter_cmd);
			continue;
		}
M
Manish Chopra 已提交
1426 1427 1428 1429 1430 1431

		opaque_fid = p_hwfn->hw_info.opaque_fid;

		rc = qed_sp_eth_filter_ucast(p_hwfn,
					     opaque_fid,
					     p_filter_cmd,
Y
Yuval Mintz 已提交
1432 1433
					     comp_mode, p_comp_data);
		if (rc)
Y
Yuval Mintz 已提交
1434
			break;
M
Manish Chopra 已提交
1435 1436 1437 1438 1439
	}

	return rc;
}

Y
Yuval Mintz 已提交
1440 1441 1442
/* Statistics related code */
static void __qed_get_vport_pstats_addrlen(struct qed_hwfn *p_hwfn,
					   u32 *p_addr,
Y
Yuval Mintz 已提交
1443
					   u32 *p_len, u16 statistics_bin)
Y
Yuval Mintz 已提交
1444
{
Y
Yuval Mintz 已提交
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455
	if (IS_PF(p_hwfn->cdev)) {
		*p_addr = BAR0_MAP_REG_PSDM_RAM +
		    PSTORM_QUEUE_STAT_OFFSET(statistics_bin);
		*p_len = sizeof(struct eth_pstorm_per_queue_stat);
	} else {
		struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
		struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;

		*p_addr = p_resp->pfdev_info.stats_info.pstats.address;
		*p_len = p_resp->pfdev_info.stats_info.pstats.len;
	}
Y
Yuval Mintz 已提交
1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
}

static void __qed_get_vport_pstats(struct qed_hwfn *p_hwfn,
				   struct qed_ptt *p_ptt,
				   struct qed_eth_stats *p_stats,
				   u16 statistics_bin)
{
	struct eth_pstorm_per_queue_stat pstats;
	u32 pstats_addr = 0, pstats_len = 0;

	__qed_get_vport_pstats_addrlen(p_hwfn, &pstats_addr, &pstats_len,
				       statistics_bin);

	memset(&pstats, 0, sizeof(pstats));
Y
Yuval Mintz 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478
	qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, pstats_len);

	p_stats->tx_ucast_bytes += HILO_64_REGPAIR(pstats.sent_ucast_bytes);
	p_stats->tx_mcast_bytes += HILO_64_REGPAIR(pstats.sent_mcast_bytes);
	p_stats->tx_bcast_bytes += HILO_64_REGPAIR(pstats.sent_bcast_bytes);
	p_stats->tx_ucast_pkts += HILO_64_REGPAIR(pstats.sent_ucast_pkts);
	p_stats->tx_mcast_pkts += HILO_64_REGPAIR(pstats.sent_mcast_pkts);
	p_stats->tx_bcast_pkts += HILO_64_REGPAIR(pstats.sent_bcast_pkts);
	p_stats->tx_err_drop_pkts += HILO_64_REGPAIR(pstats.error_drop_pkts);
Y
Yuval Mintz 已提交
1479 1480 1481 1482 1483 1484 1485 1486
}

static void __qed_get_vport_tstats(struct qed_hwfn *p_hwfn,
				   struct qed_ptt *p_ptt,
				   struct qed_eth_stats *p_stats,
				   u16 statistics_bin)
{
	struct tstorm_per_port_stat tstats;
Y
Yuval Mintz 已提交
1487
	u32 tstats_addr, tstats_len;
Y
Yuval Mintz 已提交
1488

Y
Yuval Mintz 已提交
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
	if (IS_PF(p_hwfn->cdev)) {
		tstats_addr = BAR0_MAP_REG_TSDM_RAM +
		    TSTORM_PORT_STAT_OFFSET(MFW_PORT(p_hwfn));
		tstats_len = sizeof(struct tstorm_per_port_stat);
	} else {
		struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
		struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;

		tstats_addr = p_resp->pfdev_info.stats_info.tstats.address;
		tstats_len = p_resp->pfdev_info.stats_info.tstats.len;
	}
Y
Yuval Mintz 已提交
1500 1501

	memset(&tstats, 0, sizeof(tstats));
Y
Yuval Mintz 已提交
1502
	qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, tstats_len);
Y
Yuval Mintz 已提交
1503 1504 1505 1506 1507 1508 1509 1510 1511

	p_stats->mftag_filter_discards +=
		HILO_64_REGPAIR(tstats.mftag_filter_discard);
	p_stats->mac_filter_discards +=
		HILO_64_REGPAIR(tstats.eth_mac_filter_discard);
}

static void __qed_get_vport_ustats_addrlen(struct qed_hwfn *p_hwfn,
					   u32 *p_addr,
Y
Yuval Mintz 已提交
1512
					   u32 *p_len, u16 statistics_bin)
Y
Yuval Mintz 已提交
1513
{
Y
Yuval Mintz 已提交
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
	if (IS_PF(p_hwfn->cdev)) {
		*p_addr = BAR0_MAP_REG_USDM_RAM +
		    USTORM_QUEUE_STAT_OFFSET(statistics_bin);
		*p_len = sizeof(struct eth_ustorm_per_queue_stat);
	} else {
		struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
		struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;

		*p_addr = p_resp->pfdev_info.stats_info.ustats.address;
		*p_len = p_resp->pfdev_info.stats_info.ustats.len;
	}
Y
Yuval Mintz 已提交
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
}

static void __qed_get_vport_ustats(struct qed_hwfn *p_hwfn,
				   struct qed_ptt *p_ptt,
				   struct qed_eth_stats *p_stats,
				   u16 statistics_bin)
{
	struct eth_ustorm_per_queue_stat ustats;
	u32 ustats_addr = 0, ustats_len = 0;

	__qed_get_vport_ustats_addrlen(p_hwfn, &ustats_addr, &ustats_len,
				       statistics_bin);

	memset(&ustats, 0, sizeof(ustats));
Y
Yuval Mintz 已提交
1539 1540 1541 1542 1543 1544 1545 1546
	qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, ustats_len);

	p_stats->rx_ucast_bytes += HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
	p_stats->rx_mcast_bytes += HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
	p_stats->rx_bcast_bytes += HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
	p_stats->rx_ucast_pkts += HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
	p_stats->rx_mcast_pkts += HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
	p_stats->rx_bcast_pkts += HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
Y
Yuval Mintz 已提交
1547 1548 1549 1550
}

static void __qed_get_vport_mstats_addrlen(struct qed_hwfn *p_hwfn,
					   u32 *p_addr,
Y
Yuval Mintz 已提交
1551
					   u32 *p_len, u16 statistics_bin)
Y
Yuval Mintz 已提交
1552
{
Y
Yuval Mintz 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
	if (IS_PF(p_hwfn->cdev)) {
		*p_addr = BAR0_MAP_REG_MSDM_RAM +
		    MSTORM_QUEUE_STAT_OFFSET(statistics_bin);
		*p_len = sizeof(struct eth_mstorm_per_queue_stat);
	} else {
		struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
		struct pfvf_acquire_resp_tlv *p_resp = &p_iov->acquire_resp;

		*p_addr = p_resp->pfdev_info.stats_info.mstats.address;
		*p_len = p_resp->pfdev_info.stats_info.mstats.len;
	}
Y
Yuval Mintz 已提交
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
}

static void __qed_get_vport_mstats(struct qed_hwfn *p_hwfn,
				   struct qed_ptt *p_ptt,
				   struct qed_eth_stats *p_stats,
				   u16 statistics_bin)
{
	struct eth_mstorm_per_queue_stat mstats;
	u32 mstats_addr = 0, mstats_len = 0;

	__qed_get_vport_mstats_addrlen(p_hwfn, &mstats_addr, &mstats_len,
				       statistics_bin);

	memset(&mstats, 0, sizeof(mstats));
Y
Yuval Mintz 已提交
1578
	qed_memcpy_from(p_hwfn, p_ptt, &mstats, mstats_addr, mstats_len);
Y
Yuval Mintz 已提交
1579

Y
Yuval Mintz 已提交
1580
	p_stats->no_buff_discards += HILO_64_REGPAIR(mstats.no_buff_discard);
Y
Yuval Mintz 已提交
1581 1582
	p_stats->packet_too_big_discard +=
		HILO_64_REGPAIR(mstats.packet_too_big_discard);
Y
Yuval Mintz 已提交
1583
	p_stats->ttl0_discard += HILO_64_REGPAIR(mstats.ttl0_discard);
Y
Yuval Mintz 已提交
1584 1585 1586 1587
	p_stats->tpa_coalesced_pkts +=
		HILO_64_REGPAIR(mstats.tpa_coalesced_pkts);
	p_stats->tpa_coalesced_events +=
		HILO_64_REGPAIR(mstats.tpa_coalesced_events);
Y
Yuval Mintz 已提交
1588
	p_stats->tpa_aborts_num += HILO_64_REGPAIR(mstats.tpa_aborts_num);
Y
Yuval Mintz 已提交
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
	p_stats->tpa_coalesced_bytes +=
		HILO_64_REGPAIR(mstats.tpa_coalesced_bytes);
}

static void __qed_get_vport_port_stats(struct qed_hwfn *p_hwfn,
				       struct qed_ptt *p_ptt,
				       struct qed_eth_stats *p_stats)
{
	struct port_stats port_stats;
	int j;

	memset(&port_stats, 0, sizeof(port_stats));

	qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
			p_hwfn->mcp_info->port_addr +
			offsetof(struct public_port, stats),
			sizeof(port_stats));

Y
Yuval Mintz 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
	p_stats->rx_64_byte_packets		+= port_stats.eth.r64;
	p_stats->rx_65_to_127_byte_packets	+= port_stats.eth.r127;
	p_stats->rx_128_to_255_byte_packets	+= port_stats.eth.r255;
	p_stats->rx_256_to_511_byte_packets	+= port_stats.eth.r511;
	p_stats->rx_512_to_1023_byte_packets	+= port_stats.eth.r1023;
	p_stats->rx_1024_to_1518_byte_packets	+= port_stats.eth.r1518;
	p_stats->rx_1519_to_1522_byte_packets	+= port_stats.eth.r1522;
	p_stats->rx_1519_to_2047_byte_packets	+= port_stats.eth.r2047;
	p_stats->rx_2048_to_4095_byte_packets	+= port_stats.eth.r4095;
	p_stats->rx_4096_to_9216_byte_packets	+= port_stats.eth.r9216;
	p_stats->rx_9217_to_16383_byte_packets	+= port_stats.eth.r16383;
	p_stats->rx_crc_errors			+= port_stats.eth.rfcs;
	p_stats->rx_mac_crtl_frames		+= port_stats.eth.rxcf;
	p_stats->rx_pause_frames		+= port_stats.eth.rxpf;
	p_stats->rx_pfc_frames			+= port_stats.eth.rxpp;
	p_stats->rx_align_errors		+= port_stats.eth.raln;
	p_stats->rx_carrier_errors		+= port_stats.eth.rfcr;
	p_stats->rx_oversize_packets		+= port_stats.eth.rovr;
	p_stats->rx_jabbers			+= port_stats.eth.rjbr;
	p_stats->rx_undersize_packets		+= port_stats.eth.rund;
	p_stats->rx_fragments			+= port_stats.eth.rfrg;
	p_stats->tx_64_byte_packets		+= port_stats.eth.t64;
	p_stats->tx_65_to_127_byte_packets	+= port_stats.eth.t127;
	p_stats->tx_128_to_255_byte_packets	+= port_stats.eth.t255;
	p_stats->tx_256_to_511_byte_packets	+= port_stats.eth.t511;
	p_stats->tx_512_to_1023_byte_packets	+= port_stats.eth.t1023;
	p_stats->tx_1024_to_1518_byte_packets	+= port_stats.eth.t1518;
	p_stats->tx_1519_to_2047_byte_packets	+= port_stats.eth.t2047;
	p_stats->tx_2048_to_4095_byte_packets	+= port_stats.eth.t4095;
	p_stats->tx_4096_to_9216_byte_packets	+= port_stats.eth.t9216;
	p_stats->tx_9217_to_16383_byte_packets	+= port_stats.eth.t16383;
	p_stats->tx_pause_frames		+= port_stats.eth.txpf;
	p_stats->tx_pfc_frames			+= port_stats.eth.txpp;
	p_stats->tx_lpi_entry_count		+= port_stats.eth.tlpiec;
	p_stats->tx_total_collisions		+= port_stats.eth.tncl;
	p_stats->rx_mac_bytes			+= port_stats.eth.rbyte;
	p_stats->rx_mac_uc_packets		+= port_stats.eth.rxuca;
	p_stats->rx_mac_mc_packets		+= port_stats.eth.rxmca;
	p_stats->rx_mac_bc_packets		+= port_stats.eth.rxbca;
	p_stats->rx_mac_frames_ok		+= port_stats.eth.rxpok;
	p_stats->tx_mac_bytes			+= port_stats.eth.tbyte;
	p_stats->tx_mac_uc_packets		+= port_stats.eth.txuca;
	p_stats->tx_mac_mc_packets		+= port_stats.eth.txmca;
	p_stats->tx_mac_bc_packets		+= port_stats.eth.txbca;
	p_stats->tx_mac_ctrl_frames		+= port_stats.eth.txcf;
Y
Yuval Mintz 已提交
1652 1653 1654 1655 1656 1657 1658 1659 1660
	for (j = 0; j < 8; j++) {
		p_stats->brb_truncates	+= port_stats.brb.brb_truncate[j];
		p_stats->brb_discards	+= port_stats.brb.brb_discard[j];
	}
}

static void __qed_get_vport_stats(struct qed_hwfn *p_hwfn,
				  struct qed_ptt *p_ptt,
				  struct qed_eth_stats *stats,
Y
Yuval Mintz 已提交
1661
				  u16 statistics_bin, bool b_get_port_stats)
Y
Yuval Mintz 已提交
1662 1663 1664 1665 1666 1667
{
	__qed_get_vport_mstats(p_hwfn, p_ptt, stats, statistics_bin);
	__qed_get_vport_ustats(p_hwfn, p_ptt, stats, statistics_bin);
	__qed_get_vport_tstats(p_hwfn, p_ptt, stats, statistics_bin);
	__qed_get_vport_pstats(p_hwfn, p_ptt, stats, statistics_bin);

Y
Yuval Mintz 已提交
1668
	if (b_get_port_stats && p_hwfn->mcp_info)
Y
Yuval Mintz 已提交
1669 1670 1671 1672 1673 1674
		__qed_get_vport_port_stats(p_hwfn, p_ptt, stats);
}

static void _qed_get_vport_stats(struct qed_dev *cdev,
				 struct qed_eth_stats *stats)
{
Y
Yuval Mintz 已提交
1675 1676
	u8 fw_vport = 0;
	int i;
Y
Yuval Mintz 已提交
1677 1678 1679 1680 1681

	memset(stats, 0, sizeof(*stats));

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
Y
Yuval Mintz 已提交
1682 1683 1684 1685 1686 1687 1688 1689 1690
		struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
						    :  NULL;

		if (IS_PF(cdev)) {
			/* The main vport index is relative first */
			if (qed_fw_vport(p_hwfn, 0, &fw_vport)) {
				DP_ERR(p_hwfn, "No vport available!\n");
				goto out;
			}
Y
Yuval Mintz 已提交
1691 1692
		}

Y
Yuval Mintz 已提交
1693
		if (IS_PF(cdev) && !p_ptt) {
Y
Yuval Mintz 已提交
1694 1695 1696 1697
			DP_ERR(p_hwfn, "Failed to acquire ptt\n");
			continue;
		}

Y
Yuval Mintz 已提交
1698 1699
		__qed_get_vport_stats(p_hwfn, p_ptt, stats, fw_vport,
				      IS_PF(cdev) ? true : false);
Y
Yuval Mintz 已提交
1700

Y
Yuval Mintz 已提交
1701 1702 1703
out:
		if (IS_PF(cdev) && p_ptt)
			qed_ptt_release(p_hwfn, p_ptt);
Y
Yuval Mintz 已提交
1704 1705 1706
	}
}

Y
Yuval Mintz 已提交
1707
void qed_get_vport_stats(struct qed_dev *cdev, struct qed_eth_stats *stats)
Y
Yuval Mintz 已提交
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
{
	u32 i;

	if (!cdev) {
		memset(stats, 0, sizeof(*stats));
		return;
	}

	_qed_get_vport_stats(cdev, stats);

	if (!cdev->reset_stats)
		return;

	/* Reduce the statistics baseline */
	for (i = 0; i < sizeof(struct qed_eth_stats) / sizeof(u64); i++)
		((u64 *)stats)[i] -= ((u64 *)cdev->reset_stats)[i];
}

/* zeroes V-PORT specific portion of stats (Port stats remains untouched) */
void qed_reset_vport_stats(struct qed_dev *cdev)
{
	int i;

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
		struct eth_mstorm_per_queue_stat mstats;
		struct eth_ustorm_per_queue_stat ustats;
		struct eth_pstorm_per_queue_stat pstats;
Y
Yuval Mintz 已提交
1736 1737
		struct qed_ptt *p_ptt = IS_PF(cdev) ? qed_ptt_acquire(p_hwfn)
						    : NULL;
Y
Yuval Mintz 已提交
1738 1739
		u32 addr = 0, len = 0;

Y
Yuval Mintz 已提交
1740
		if (IS_PF(cdev) && !p_ptt) {
Y
Yuval Mintz 已提交
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
			DP_ERR(p_hwfn, "Failed to acquire ptt\n");
			continue;
		}

		memset(&mstats, 0, sizeof(mstats));
		__qed_get_vport_mstats_addrlen(p_hwfn, &addr, &len, 0);
		qed_memcpy_to(p_hwfn, p_ptt, addr, &mstats, len);

		memset(&ustats, 0, sizeof(ustats));
		__qed_get_vport_ustats_addrlen(p_hwfn, &addr, &len, 0);
		qed_memcpy_to(p_hwfn, p_ptt, addr, &ustats, len);

		memset(&pstats, 0, sizeof(pstats));
		__qed_get_vport_pstats_addrlen(p_hwfn, &addr, &len, 0);
		qed_memcpy_to(p_hwfn, p_ptt, addr, &pstats, len);

Y
Yuval Mintz 已提交
1757 1758
		if (IS_PF(cdev))
			qed_ptt_release(p_hwfn, p_ptt);
Y
Yuval Mintz 已提交
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769
	}

	/* PORT statistics are not necessarily reset, so we need to
	 * read and create a baseline for future statistics.
	 */
	if (!cdev->reset_stats)
		DP_INFO(cdev, "Reset stats not allocated\n");
	else
		_qed_get_vport_stats(cdev, cdev->reset_stats);
}

Y
Yuval Mintz 已提交
1770 1771 1772 1773 1774 1775 1776 1777 1778
static int qed_fill_eth_dev_info(struct qed_dev *cdev,
				 struct qed_dev_eth_info *info)
{
	int i;

	memset(info, 0, sizeof(*info));

	info->num_tc = 1;

Y
Yuval Mintz 已提交
1779
	if (IS_PF(cdev)) {
1780
		int max_vf_vlan_filters = 0;
Y
Yuval Mintz 已提交
1781
		int max_vf_mac_filters = 0;
1782

Y
Yuval Mintz 已提交
1783
		if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
			u16 num_queues = 0;

			/* Since the feature controls only queue-zones,
			 * make sure we have the contexts [rx, tx, xdp] to
			 * match.
			 */
			for_each_hwfn(cdev, i) {
				struct qed_hwfn *hwfn = &cdev->hwfns[i];
				u16 l2_queues = (u16)FEAT_NUM(hwfn,
							      QED_PF_L2_QUE);
				u16 cids;

				cids = hwfn->pf_params.eth_pf_params.num_cons;
				num_queues += min_t(u16, l2_queues, cids / 3);
			}

			/* queues might theoretically be >256, but interrupts'
			 * upper-limit guarantes that it would fit in a u8.
			 */
			if (cdev->int_params.fp_msix_cnt) {
				u8 irqs = cdev->int_params.fp_msix_cnt;

				info->num_queues = (u8)min_t(u16,
							     num_queues, irqs);
			}
Y
Yuval Mintz 已提交
1809 1810 1811 1812
		} else {
			info->num_queues = cdev->num_hwfns;
		}

Y
Yuval Mintz 已提交
1813
		if (IS_QED_SRIOV(cdev)) {
1814 1815
			max_vf_vlan_filters = cdev->p_iov_info->total_vfs *
					      QED_ETH_VF_NUM_VLAN_FILTERS;
Y
Yuval Mintz 已提交
1816 1817 1818 1819 1820
			max_vf_mac_filters = cdev->p_iov_info->total_vfs *
					     QED_ETH_VF_NUM_MAC_FILTERS;
		}
		info->num_vlan_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
						  QED_VLAN) -
1821
					 max_vf_vlan_filters;
Y
Yuval Mintz 已提交
1822 1823 1824
		info->num_mac_filters = RESC_NUM(QED_LEADING_HWFN(cdev),
						 QED_MAC) -
					max_vf_mac_filters;
1825

Y
Yuval Mintz 已提交
1826 1827
		ether_addr_copy(info->port_mac,
				cdev->hwfns[0].hw_info.hw_mac_addr);
Y
Yuval Mintz 已提交
1828
	} else {
Y
Yuval Mintz 已提交
1829 1830 1831
		qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev), &info->num_queues);
		if (cdev->num_hwfns > 1) {
			u8 queues = 0;
Y
Yuval Mintz 已提交
1832

Y
Yuval Mintz 已提交
1833 1834 1835 1836 1837
			qed_vf_get_num_rxqs(&cdev->hwfns[1], &queues);
			info->num_queues += queues;
		}

		qed_vf_get_num_vlan_filters(&cdev->hwfns[0],
1838
					    (u8 *)&info->num_vlan_filters);
M
Mintz, Yuval 已提交
1839 1840
		qed_vf_get_num_mac_filters(&cdev->hwfns[0],
					   (u8 *)&info->num_mac_filters);
Y
Yuval Mintz 已提交
1841
		qed_vf_get_port_mac(&cdev->hwfns[0], info->port_mac);
1842 1843

		info->is_legacy = !!cdev->hwfns[0].vf_iov_info->b_pre_fp_hsi;
Y
Yuval Mintz 已提交
1844
	}
Y
Yuval Mintz 已提交
1845 1846 1847

	qed_fill_dev_info(cdev, &info->common);

Y
Yuval Mintz 已提交
1848 1849 1850
	if (IS_VF(cdev))
		memset(info->common.hw_mac, 0, ETH_ALEN);

Y
Yuval Mintz 已提交
1851 1852 1853
	return 0;
}

Y
Yuval Mintz 已提交
1854
static void qed_register_eth_ops(struct qed_dev *cdev,
Y
Yuval Mintz 已提交
1855
				 struct qed_eth_cb_ops *ops, void *cookie)
Y
Yuval Mintz 已提交
1856
{
Y
Yuval Mintz 已提交
1857 1858 1859 1860 1861 1862
	cdev->protocol_ops.eth = ops;
	cdev->ops_cookie = cookie;

	/* For VF, we start bulletin reading */
	if (IS_VF(cdev))
		qed_vf_start_iov_wq(cdev);
Y
Yuval Mintz 已提交
1863 1864
}

Y
Yuval Mintz 已提交
1865 1866 1867 1868 1869 1870 1871 1872
static bool qed_check_mac(struct qed_dev *cdev, u8 *mac)
{
	if (IS_PF(cdev))
		return true;

	return qed_vf_check_mac(&cdev->hwfns[0], mac);
}

M
Manish Chopra 已提交
1873
static int qed_start_vport(struct qed_dev *cdev,
1874
			   struct qed_start_vport_params *params)
M
Manish Chopra 已提交
1875 1876 1877 1878
{
	int rc, i;

	for_each_hwfn(cdev, i) {
1879
		struct qed_sp_vport_start_params start = { 0 };
M
Manish Chopra 已提交
1880 1881
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];

1882 1883 1884
		start.tpa_mode = params->gro_enable ? QED_TPA_MODE_GRO :
							QED_TPA_MODE_NONE;
		start.remove_inner_vlan = params->remove_inner_vlan;
Y
Yuval Mintz 已提交
1885
		start.only_untagged = true;	/* untagged only */
1886 1887 1888 1889 1890 1891 1892 1893
		start.drop_ttl0 = params->drop_ttl0;
		start.opaque_fid = p_hwfn->hw_info.opaque_fid;
		start.concrete_fid = p_hwfn->hw_info.concrete_fid;
		start.vport_id = params->vport_id;
		start.max_buffers_per_cqe = 16;
		start.mtu = params->mtu;

		rc = qed_sp_vport_start(p_hwfn, &start);
M
Manish Chopra 已提交
1894 1895 1896 1897 1898 1899 1900 1901 1902
		if (rc) {
			DP_ERR(cdev, "Failed to start VPORT\n");
			return rc;
		}

		qed_hw_start_fastpath(p_hwfn);

		DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
			   "Started V-PORT %d with MTU %d\n",
1903
			   start.vport_id, start.mtu);
M
Manish Chopra 已提交
1904 1905
	}

1906 1907
	if (params->clear_stats)
		qed_reset_vport_stats(cdev);
M
Manish Chopra 已提交
1908

M
Manish Chopra 已提交
1909 1910 1911
	return 0;
}

Y
Yuval Mintz 已提交
1912
static int qed_stop_vport(struct qed_dev *cdev, u8 vport_id)
M
Manish Chopra 已提交
1913 1914 1915 1916 1917 1918 1919
{
	int rc, i;

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];

		rc = qed_sp_vport_stop(p_hwfn,
Y
Yuval Mintz 已提交
1920
				       p_hwfn->hw_info.opaque_fid, vport_id);
M
Manish Chopra 已提交
1921 1922 1923 1924 1925 1926 1927 1928 1929

		if (rc) {
			DP_ERR(cdev, "Failed to stop VPORT\n");
			return rc;
		}
	}
	return 0;
}

1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992
static int qed_update_vport_rss(struct qed_dev *cdev,
				struct qed_update_vport_rss_params *input,
				struct qed_rss_params *rss)
{
	int i, fn;

	/* Update configuration with what's correct regardless of CMT */
	rss->update_rss_config = 1;
	rss->rss_enable = 1;
	rss->update_rss_capabilities = 1;
	rss->update_rss_ind_table = 1;
	rss->update_rss_key = 1;
	rss->rss_caps = input->rss_caps;
	memcpy(rss->rss_key, input->rss_key, QED_RSS_KEY_SIZE * sizeof(u32));

	/* In regular scenario, we'd simply need to take input handlers.
	 * But in CMT, we'd have to split the handlers according to the
	 * engine they were configured on. We'd then have to understand
	 * whether RSS is really required, since 2-queues on CMT doesn't
	 * require RSS.
	 */
	if (cdev->num_hwfns == 1) {
		memcpy(rss->rss_ind_table,
		       input->rss_ind_table,
		       QED_RSS_IND_TABLE_SIZE * sizeof(void *));
		rss->rss_table_size_log = 7;
		return 0;
	}

	/* Start by copying the non-spcific information to the 2nd copy */
	memcpy(&rss[1], &rss[0], sizeof(struct qed_rss_params));

	/* CMT should be round-robin */
	for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++) {
		struct qed_queue_cid *cid = input->rss_ind_table[i];
		struct qed_rss_params *t_rss;

		if (cid->p_owner == QED_LEADING_HWFN(cdev))
			t_rss = &rss[0];
		else
			t_rss = &rss[1];

		t_rss->rss_ind_table[i / cdev->num_hwfns] = cid;
	}

	/* Make sure RSS is actually required */
	for_each_hwfn(cdev, fn) {
		for (i = 1; i < QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns; i++) {
			if (rss[fn].rss_ind_table[i] !=
			    rss[fn].rss_ind_table[0])
				break;
		}
		if (i == QED_RSS_IND_TABLE_SIZE / cdev->num_hwfns) {
			DP_VERBOSE(cdev, NETIF_MSG_IFUP,
				   "CMT - 1 queue per-hwfn; Disabling RSS\n");
			return -EINVAL;
		}
		rss[fn].rss_table_size_log = 6;
	}

	return 0;
}

M
Manish Chopra 已提交
1993 1994 1995 1996
static int qed_update_vport(struct qed_dev *cdev,
			    struct qed_update_vport_params *params)
{
	struct qed_sp_vport_update_params sp_params;
1997 1998
	struct qed_rss_params *rss;
	int rc = 0, i;
M
Manish Chopra 已提交
1999 2000 2001 2002

	if (!cdev)
		return -ENODEV;

2003 2004 2005 2006
	rss = vzalloc(sizeof(*rss) * cdev->num_hwfns);
	if (!rss)
		return -ENOMEM;

M
Manish Chopra 已提交
2007 2008 2009 2010
	memset(&sp_params, 0, sizeof(sp_params));

	/* Translate protocol params into sp params */
	sp_params.vport_id = params->vport_id;
Y
Yuval Mintz 已提交
2011 2012
	sp_params.update_vport_active_rx_flg = params->update_vport_active_flg;
	sp_params.update_vport_active_tx_flg = params->update_vport_active_flg;
M
Manish Chopra 已提交
2013 2014
	sp_params.vport_active_rx_flg = params->vport_active_flg;
	sp_params.vport_active_tx_flg = params->vport_active_flg;
Y
Yuval Mintz 已提交
2015 2016
	sp_params.update_tx_switching_flg = params->update_tx_switching_flg;
	sp_params.tx_switching_flg = params->tx_switching_flg;
2017 2018 2019
	sp_params.accept_any_vlan = params->accept_any_vlan;
	sp_params.update_accept_any_vlan_flg =
		params->update_accept_any_vlan_flg;
M
Manish Chopra 已提交
2020

2021 2022 2023
	/* Prepare the RSS configuration */
	if (params->update_rss_flg)
		if (qed_update_vport_rss(cdev, &params->rss_params, rss))
M
Manish Chopra 已提交
2024 2025 2026 2027 2028
			params->update_rss_flg = 0;

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *p_hwfn = &cdev->hwfns[i];

2029 2030 2031
		if (params->update_rss_flg)
			sp_params.rss_params = &rss[i];

M
Manish Chopra 已提交
2032 2033 2034 2035 2036 2037
		sp_params.opaque_fid = p_hwfn->hw_info.opaque_fid;
		rc = qed_sp_vport_update(p_hwfn, &sp_params,
					 QED_SPQ_MODE_EBLOCK,
					 NULL);
		if (rc) {
			DP_ERR(cdev, "Failed to update VPORT\n");
2038
			goto out;
M
Manish Chopra 已提交
2039 2040 2041 2042 2043 2044 2045 2046
		}

		DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
			   "Updated V-PORT %d: active_flag %d [update %d]\n",
			   params->vport_id, params->vport_active_flg,
			   params->update_vport_active_flg);
	}

2047 2048 2049
out:
	vfree(rss);
	return rc;
M
Manish Chopra 已提交
2050 2051 2052
}

static int qed_start_rxq(struct qed_dev *cdev,
M
Mintz, Yuval 已提交
2053 2054
			 u8 rss_num,
			 struct qed_queue_start_common_params *p_params,
M
Manish Chopra 已提交
2055 2056 2057 2058
			 u16 bd_max_bytes,
			 dma_addr_t bd_chain_phys_addr,
			 dma_addr_t cqe_pbl_addr,
			 u16 cqe_pbl_size,
M
Mintz, Yuval 已提交
2059
			 struct qed_rxq_start_ret_params *ret_params)
M
Manish Chopra 已提交
2060 2061
{
	struct qed_hwfn *p_hwfn;
Y
Yuval Mintz 已提交
2062
	int rc, hwfn_index;
M
Manish Chopra 已提交
2063

M
Mintz, Yuval 已提交
2064
	hwfn_index = rss_num % cdev->num_hwfns;
M
Manish Chopra 已提交
2065 2066
	p_hwfn = &cdev->hwfns[hwfn_index];

M
Mintz, Yuval 已提交
2067 2068
	p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
	p_params->stats_id = p_params->vport_id;
M
Manish Chopra 已提交
2069

M
Mintz, Yuval 已提交
2070 2071 2072 2073 2074 2075
	rc = qed_eth_rx_queue_start(p_hwfn,
				    p_hwfn->hw_info.opaque_fid,
				    p_params,
				    bd_max_bytes,
				    bd_chain_phys_addr,
				    cqe_pbl_addr, cqe_pbl_size, ret_params);
M
Manish Chopra 已提交
2076
	if (rc) {
M
Mintz, Yuval 已提交
2077
		DP_ERR(cdev, "Failed to start RXQ#%d\n", p_params->queue_id);
M
Manish Chopra 已提交
2078 2079 2080 2081
		return rc;
	}

	DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
M
Mintz, Yuval 已提交
2082 2083 2084
		   "Started RX-Q %d [rss_num %d] on V-PORT %d and SB %d\n",
		   p_params->queue_id, rss_num, p_params->vport_id,
		   p_params->sb);
M
Manish Chopra 已提交
2085 2086 2087 2088

	return 0;
}

M
Mintz, Yuval 已提交
2089
static int qed_stop_rxq(struct qed_dev *cdev, u8 rss_id, void *handle)
M
Manish Chopra 已提交
2090 2091 2092 2093
{
	int rc, hwfn_index;
	struct qed_hwfn *p_hwfn;

M
Mintz, Yuval 已提交
2094 2095
	hwfn_index = rss_id % cdev->num_hwfns;
	p_hwfn = &cdev->hwfns[hwfn_index];
M
Manish Chopra 已提交
2096

M
Mintz, Yuval 已提交
2097
	rc = qed_eth_rx_queue_stop(p_hwfn, handle, false, false);
M
Manish Chopra 已提交
2098
	if (rc) {
M
Mintz, Yuval 已提交
2099
		DP_ERR(cdev, "Failed to stop RXQ#%02x\n", rss_id);
M
Manish Chopra 已提交
2100 2101 2102 2103 2104 2105 2106
		return rc;
	}

	return 0;
}

static int qed_start_txq(struct qed_dev *cdev,
M
Mintz, Yuval 已提交
2107
			 u8 rss_num,
M
Manish Chopra 已提交
2108 2109 2110
			 struct qed_queue_start_common_params *p_params,
			 dma_addr_t pbl_addr,
			 u16 pbl_size,
M
Mintz, Yuval 已提交
2111
			 struct qed_txq_start_ret_params *ret_params)
M
Manish Chopra 已提交
2112 2113 2114 2115
{
	struct qed_hwfn *p_hwfn;
	int rc, hwfn_index;

M
Mintz, Yuval 已提交
2116 2117 2118 2119
	hwfn_index = rss_num % cdev->num_hwfns;
	p_hwfn = &cdev->hwfns[hwfn_index];
	p_params->queue_id = p_params->queue_id / cdev->num_hwfns;
	p_params->stats_id = p_params->vport_id;
M
Manish Chopra 已提交
2120

M
Mintz, Yuval 已提交
2121 2122 2123 2124
	rc = qed_eth_tx_queue_start(p_hwfn,
				    p_hwfn->hw_info.opaque_fid,
				    p_params, 0,
				    pbl_addr, pbl_size, ret_params);
M
Manish Chopra 已提交
2125 2126 2127 2128 2129 2130 2131

	if (rc) {
		DP_ERR(cdev, "Failed to start TXQ#%d\n", p_params->queue_id);
		return rc;
	}

	DP_VERBOSE(cdev, (QED_MSG_SPQ | NETIF_MSG_IFUP),
M
Mintz, Yuval 已提交
2132 2133
		   "Started TX-Q %d [rss_num %d] on V-PORT %d and SB %d\n",
		   p_params->queue_id, rss_num, p_params->vport_id,
M
Manish Chopra 已提交
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146
		   p_params->sb);

	return 0;
}

#define QED_HW_STOP_RETRY_LIMIT (10)
static int qed_fastpath_stop(struct qed_dev *cdev)
{
	qed_hw_stop_fastpath(cdev);

	return 0;
}

M
Mintz, Yuval 已提交
2147
static int qed_stop_txq(struct qed_dev *cdev, u8 rss_id, void *handle)
M
Manish Chopra 已提交
2148 2149 2150 2151
{
	struct qed_hwfn *p_hwfn;
	int rc, hwfn_index;

M
Mintz, Yuval 已提交
2152 2153
	hwfn_index = rss_id % cdev->num_hwfns;
	p_hwfn = &cdev->hwfns[hwfn_index];
M
Manish Chopra 已提交
2154

M
Mintz, Yuval 已提交
2155
	rc = qed_eth_tx_queue_stop(p_hwfn, handle);
M
Manish Chopra 已提交
2156
	if (rc) {
M
Mintz, Yuval 已提交
2157
		DP_ERR(cdev, "Failed to stop TXQ#%02x\n", rss_id);
M
Manish Chopra 已提交
2158 2159 2160 2161 2162 2163
		return rc;
	}

	return 0;
}

2164 2165 2166 2167 2168 2169
static int qed_tunn_configure(struct qed_dev *cdev,
			      struct qed_tunn_params *tunn_params)
{
	struct qed_tunn_update_params tunn_info;
	int i, rc;

Y
Yuval Mintz 已提交
2170 2171 2172
	if (IS_VF(cdev))
		return 0;

2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
	memset(&tunn_info, 0, sizeof(tunn_info));
	if (tunn_params->update_vxlan_port == 1) {
		tunn_info.update_vxlan_udp_port = 1;
		tunn_info.vxlan_udp_port = tunn_params->vxlan_port;
	}

	if (tunn_params->update_geneve_port == 1) {
		tunn_info.update_geneve_udp_port = 1;
		tunn_info.geneve_udp_port = tunn_params->geneve_port;
	}

	for_each_hwfn(cdev, i) {
		struct qed_hwfn *hwfn = &cdev->hwfns[i];

		rc = qed_sp_pf_update_tunn_cfg(hwfn, &tunn_info,
					       QED_SPQ_MODE_EBLOCK, NULL);

		if (rc)
			return rc;
	}

	return 0;
}

M
Manish Chopra 已提交
2197 2198 2199 2200 2201 2202 2203
static int qed_configure_filter_rx_mode(struct qed_dev *cdev,
					enum qed_filter_rx_mode_type type)
{
	struct qed_filter_accept_flags accept_flags;

	memset(&accept_flags, 0, sizeof(accept_flags));

Y
Yuval Mintz 已提交
2204 2205 2206 2207 2208
	accept_flags.update_rx_mode_config = 1;
	accept_flags.update_tx_mode_config = 1;
	accept_flags.rx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
					QED_ACCEPT_MCAST_MATCHED |
					QED_ACCEPT_BCAST;
M
Manish Chopra 已提交
2209 2210 2211 2212
	accept_flags.tx_accept_filter = QED_ACCEPT_UCAST_MATCHED |
					QED_ACCEPT_MCAST_MATCHED |
					QED_ACCEPT_BCAST;

2213
	if (type == QED_FILTER_RX_MODE_TYPE_PROMISC) {
M
Manish Chopra 已提交
2214 2215
		accept_flags.rx_accept_filter |= QED_ACCEPT_UCAST_UNMATCHED |
						 QED_ACCEPT_MCAST_UNMATCHED;
2216 2217
		accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
	} else if (type == QED_FILTER_RX_MODE_TYPE_MULTI_PROMISC) {
M
Manish Chopra 已提交
2218
		accept_flags.rx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
2219 2220
		accept_flags.tx_accept_filter |= QED_ACCEPT_MCAST_UNMATCHED;
	}
M
Manish Chopra 已提交
2221

2222
	return qed_filter_accept_cmd(cdev, 0, accept_flags, false, false,
M
Manish Chopra 已提交
2223 2224 2225 2226 2227 2228 2229 2230 2231
				     QED_SPQ_MODE_CB, NULL);
}

static int qed_configure_filter_ucast(struct qed_dev *cdev,
				      struct qed_filter_ucast_params *params)
{
	struct qed_filter_ucast ucast;

	if (!params->vlan_valid && !params->mac_valid) {
Y
Yuval Mintz 已提交
2232 2233
		DP_NOTICE(cdev,
			  "Tried configuring a unicast filter, but both MAC and VLAN are not set\n");
M
Manish Chopra 已提交
2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293
		return -EINVAL;
	}

	memset(&ucast, 0, sizeof(ucast));
	switch (params->type) {
	case QED_FILTER_XCAST_TYPE_ADD:
		ucast.opcode = QED_FILTER_ADD;
		break;
	case QED_FILTER_XCAST_TYPE_DEL:
		ucast.opcode = QED_FILTER_REMOVE;
		break;
	case QED_FILTER_XCAST_TYPE_REPLACE:
		ucast.opcode = QED_FILTER_REPLACE;
		break;
	default:
		DP_NOTICE(cdev, "Unknown unicast filter type %d\n",
			  params->type);
	}

	if (params->vlan_valid && params->mac_valid) {
		ucast.type = QED_FILTER_MAC_VLAN;
		ether_addr_copy(ucast.mac, params->mac);
		ucast.vlan = params->vlan;
	} else if (params->mac_valid) {
		ucast.type = QED_FILTER_MAC;
		ether_addr_copy(ucast.mac, params->mac);
	} else {
		ucast.type = QED_FILTER_VLAN;
		ucast.vlan = params->vlan;
	}

	ucast.is_rx_filter = true;
	ucast.is_tx_filter = true;

	return qed_filter_ucast_cmd(cdev, &ucast, QED_SPQ_MODE_CB, NULL);
}

static int qed_configure_filter_mcast(struct qed_dev *cdev,
				      struct qed_filter_mcast_params *params)
{
	struct qed_filter_mcast mcast;
	int i;

	memset(&mcast, 0, sizeof(mcast));
	switch (params->type) {
	case QED_FILTER_XCAST_TYPE_ADD:
		mcast.opcode = QED_FILTER_ADD;
		break;
	case QED_FILTER_XCAST_TYPE_DEL:
		mcast.opcode = QED_FILTER_REMOVE;
		break;
	default:
		DP_NOTICE(cdev, "Unknown multicast filter type %d\n",
			  params->type);
	}

	mcast.num_mc_addrs = params->num;
	for (i = 0; i < mcast.num_mc_addrs; i++)
		ether_addr_copy(mcast.mac[i], params->mac[i]);

Y
Yuval Mintz 已提交
2294
	return qed_filter_mcast_cmd(cdev, &mcast, QED_SPQ_MODE_CB, NULL);
M
Manish Chopra 已提交
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
}

static int qed_configure_filter(struct qed_dev *cdev,
				struct qed_filter_params *params)
{
	enum qed_filter_rx_mode_type accept_flags;

	switch (params->type) {
	case QED_FILTER_TYPE_UCAST:
		return qed_configure_filter_ucast(cdev, &params->filter.ucast);
	case QED_FILTER_TYPE_MCAST:
		return qed_configure_filter_mcast(cdev, &params->filter.mcast);
	case QED_FILTER_TYPE_RX_MODE:
		accept_flags = params->filter.accept_flags;
		return qed_configure_filter_rx_mode(cdev, accept_flags);
	default:
Y
Yuval Mintz 已提交
2311
		DP_NOTICE(cdev, "Unknown filter type %d\n", (int)params->type);
M
Manish Chopra 已提交
2312 2313 2314 2315 2316
		return -EINVAL;
	}
}

static int qed_fp_cqe_completion(struct qed_dev *dev,
Y
Yuval Mintz 已提交
2317
				 u8 rss_id, struct eth_slow_path_rx_cqe *cqe)
M
Manish Chopra 已提交
2318 2319 2320 2321 2322
{
	return qed_eth_cqe_completion(&dev->hwfns[rss_id % dev->num_hwfns],
				      cqe);
}

Y
Yuval Mintz 已提交
2323 2324 2325 2326
#ifdef CONFIG_QED_SRIOV
extern const struct qed_iov_hv_ops qed_iov_ops_pass;
#endif

2327 2328 2329 2330
#ifdef CONFIG_DCB
extern const struct qed_eth_dcbnl_ops qed_dcbnl_ops_pass;
#endif

Y
Yuval Mintz 已提交
2331 2332
static const struct qed_eth_ops qed_eth_ops_pass = {
	.common = &qed_common_ops_pass,
Y
Yuval Mintz 已提交
2333 2334
#ifdef CONFIG_QED_SRIOV
	.iov = &qed_iov_ops_pass,
2335 2336 2337
#endif
#ifdef CONFIG_DCB
	.dcb = &qed_dcbnl_ops_pass,
Y
Yuval Mintz 已提交
2338
#endif
Y
Yuval Mintz 已提交
2339
	.fill_dev_info = &qed_fill_eth_dev_info,
Y
Yuval Mintz 已提交
2340
	.register_ops = &qed_register_eth_ops,
Y
Yuval Mintz 已提交
2341
	.check_mac = &qed_check_mac,
M
Manish Chopra 已提交
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351
	.vport_start = &qed_start_vport,
	.vport_stop = &qed_stop_vport,
	.vport_update = &qed_update_vport,
	.q_rx_start = &qed_start_rxq,
	.q_rx_stop = &qed_stop_rxq,
	.q_tx_start = &qed_start_txq,
	.q_tx_stop = &qed_stop_txq,
	.filter_config = &qed_configure_filter,
	.fastpath_stop = &qed_fastpath_stop,
	.eth_cqe_completion = &qed_fp_cqe_completion,
M
Manish Chopra 已提交
2352
	.get_vport_stats = &qed_get_vport_stats,
2353
	.tunn_config = &qed_tunn_configure,
Y
Yuval Mintz 已提交
2354 2355
};

R
Rahul Verma 已提交
2356
const struct qed_eth_ops *qed_get_eth_ops(void)
Y
Yuval Mintz 已提交
2357 2358 2359 2360 2361 2362 2363 2364 2365 2366
{
	return &qed_eth_ops_pass;
}
EXPORT_SYMBOL(qed_get_eth_ops);

void qed_put_eth_ops(void)
{
	/* TODO - reference count for module? */
}
EXPORT_SYMBOL(qed_put_eth_ops);