qed_init_fw_funcs.c 45.5 KB
Newer Older
1
/* QLogic qed NIC Driver
M
Mintz, Yuval 已提交
2
 * Copyright (c) 2015-2017  QLogic Corporation
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.
31 32 33
 */

#include <linux/types.h>
T
Tomer Tayar 已提交
34
#include <linux/crc8.h>
35 36 37 38 39 40 41 42 43
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/string.h>
#include "qed_hsi.h"
#include "qed_hw.h"
#include "qed_init_ops.h"
#include "qed_reg_addr.h"

T
Tomer Tayar 已提交
44 45 46 47 48 49 50 51 52 53 54 55
#define CDU_VALIDATION_DEFAULT_CFG	61

static u16 con_region_offsets[3][NUM_OF_CONNECTION_TYPES_E4] = {
	{400, 336, 352, 304, 304, 384, 416, 352},	/* region 3 offsets */
	{528, 496, 416, 448, 448, 512, 544, 480},	/* region 4 offsets */
	{608, 544, 496, 512, 576, 592, 624, 560}	/* region 5 offsets */
};

static u16 task_region_offsets[1][NUM_OF_CONNECTION_TYPES_E4] = {
	{240, 240, 112, 0, 0, 0, 0, 96}	/* region 1 offsets */
};

M
Mintz, Yuval 已提交
56
/* General constants */
57 58 59 60 61
#define QM_PQ_MEM_4KB(pq_size)	(pq_size ? DIV_ROUND_UP((pq_size + 1) *	\
							QM_PQ_ELEMENT_SIZE, \
							0x1000) : 0)
#define QM_PQ_SIZE_256B(pq_size)	(pq_size ? DIV_ROUND_UP(pq_size, \
								0x100) - 1 : 0)
62 63
#define QM_INVALID_PQ_ID		0xffff

M
Mintz, Yuval 已提交
64
/* Feature enable */
65 66 67
#define QM_BYPASS_EN	1
#define QM_BYTE_CRD_EN	1

M
Mintz, Yuval 已提交
68
/* Other PQ constants */
69 70
#define QM_OTHER_PQS_PER_PF	4

71
/* WFQ constants */
72 73 74 75 76 77 78 79

/* Upper bound in MB, 10 * burst size of 1ms in 50Gbps */
#define QM_WFQ_UPPER_BOUND	62500000

/* Bit  of VOQ in WFQ VP PQ map */
#define QM_WFQ_VP_PQ_VOQ_SHIFT	0

/* Bit  of PF in WFQ VP PQ map */
80
#define QM_WFQ_VP_PQ_PF_E4_SHIFT	5
81 82 83 84 85

/* 0x9000 = 4*9*1024 */
#define QM_WFQ_INC_VAL(weight)	((weight) * 0x9000)

/* Max WFQ increment value is 0.7 * upper bound */
T
Tomer Tayar 已提交
86
#define QM_WFQ_MAX_INC_VAL	((QM_WFQ_UPPER_BOUND * 7) / 10)
Y
Yuval Mintz 已提交
87

88
/* RL constants */
89 90 91 92 93 94 95 96

/* Period in us */
#define QM_RL_PERIOD	5

/* Period in 25MHz cycles */
#define QM_RL_PERIOD_CLK_25M	(25 * QM_RL_PERIOD)

/* RL increment value - rate is specified in mbps */
T
Tomer Tayar 已提交
97 98 99 100 101 102
#define QM_RL_INC_VAL(rate) ({ \
	typeof(rate) __rate = (rate); \
	max_t(u32, \
	      (u32)(((__rate ? __rate : 1000000) * QM_RL_PERIOD * 101) / \
		    (8 * 100)), \
	      1); })
103 104

/* PF RL Upper bound is set to 10 * burst size of 1ms in 50Gbps */
T
Tomer Tayar 已提交
105
#define QM_PF_RL_UPPER_BOUND	62500000
106 107

/* Max PF RL increment value is 0.7 * upper bound */
T
Tomer Tayar 已提交
108 109 110 111 112 113 114 115 116 117 118 119
#define QM_PF_RL_MAX_INC_VAL	((QM_PF_RL_UPPER_BOUND * 7) / 10)

/* Vport RL Upper bound, link speed is in Mpbs */
#define QM_VP_RL_UPPER_BOUND(speed)	((u32)max_t(u32, \
						    QM_RL_INC_VAL(speed), \
						    9700 + 1000))

/* Max Vport RL increment value is the Vport RL upper bound */
#define QM_VP_RL_MAX_INC_VAL(speed)	QM_VP_RL_UPPER_BOUND(speed)

/* Vport RL credit threshold in case of QM bypass */
#define QM_VP_RL_BYPASS_THRESH_SPEED	(QM_VP_RL_UPPER_BOUND(10000) - 1)
120

121
/* AFullOprtnstcCrdMask constants */
122 123 124 125
#define QM_OPPOR_LINE_VOQ_DEF	1
#define QM_OPPOR_FW_STOP_DEF	0
#define QM_OPPOR_PQ_EMPTY_DEF	1

126
/* Command Queue constants */
127 128 129 130

/* Pure LB CmdQ lines (+spare) */
#define PBF_CMDQ_PURE_LB_LINES	150

T
Tomer Tayar 已提交
131 132
#define PBF_CMDQ_LINES_E5_RSVD_RATIO	8

133 134 135 136 137 138 139 140 141 142 143 144 145
#define PBF_CMDQ_LINES_RT_OFFSET(ext_voq) \
	(PBF_REG_YCMD_QS_NUM_LINES_VOQ0_RT_OFFSET + \
	 (ext_voq) * (PBF_REG_YCMD_QS_NUM_LINES_VOQ1_RT_OFFSET - \
		PBF_REG_YCMD_QS_NUM_LINES_VOQ0_RT_OFFSET))

#define PBF_BTB_GUARANTEED_RT_OFFSET(ext_voq) \
	(PBF_REG_BTB_GUARANTEED_VOQ0_RT_OFFSET + \
	 (ext_voq) * (PBF_REG_BTB_GUARANTEED_VOQ1_RT_OFFSET - \
		PBF_REG_BTB_GUARANTEED_VOQ0_RT_OFFSET))

#define QM_VOQ_LINE_CRD(pbf_cmd_lines) \
	((((pbf_cmd_lines) - 4) * 2) | QM_LINE_CRD_REG_SIGN_BIT)

146
/* BTB: blocks constants (block size = 256B) */
147 148 149 150 151 152 153 154 155 156 157

/* 256B blocks in 9700B packet */
#define BTB_JUMBO_PKT_BLOCKS	38

/* Headroom per-port */
#define BTB_HEADROOM_BLOCKS	BTB_JUMBO_PKT_BLOCKS
#define BTB_PURE_LB_FACTOR	10

/* Factored (hence really 0.7) */
#define BTB_PURE_LB_RATIO	7

158
/* QM stop command constants */
159 160 161 162 163 164 165 166 167 168 169 170 171 172
#define QM_STOP_PQ_MASK_WIDTH		32
#define QM_STOP_CMD_ADDR		2
#define QM_STOP_CMD_STRUCT_SIZE		2
#define QM_STOP_CMD_PAUSE_MASK_OFFSET	0
#define QM_STOP_CMD_PAUSE_MASK_SHIFT	0
#define QM_STOP_CMD_PAUSE_MASK_MASK	-1
#define QM_STOP_CMD_GROUP_ID_OFFSET	1
#define QM_STOP_CMD_GROUP_ID_SHIFT	16
#define QM_STOP_CMD_GROUP_ID_MASK	15
#define QM_STOP_CMD_PQ_TYPE_OFFSET	1
#define QM_STOP_CMD_PQ_TYPE_SHIFT	24
#define QM_STOP_CMD_PQ_TYPE_MASK	1
#define QM_STOP_CMD_MAX_POLL_COUNT	100
#define QM_STOP_CMD_POLL_PERIOD_US	500
M
Mintz, Yuval 已提交
173

174
/* QM command macros */
175 176 177 178 179
#define QM_CMD_STRUCT_SIZE(cmd)	cmd ## _STRUCT_SIZE
#define QM_CMD_SET_FIELD(var, cmd, field, value) \
	SET_FIELD(var[cmd ## _ ## field ## _OFFSET], \
		  cmd ## _ ## field, \
		  value)
T
Tomer Tayar 已提交
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

#define QM_INIT_TX_PQ_MAP(p_hwfn, map, chip, pq_id, rl_valid, vp_pq_id, rl_id, \
			  ext_voq, wrr) \
	do { \
		typeof(map) __map; \
		memset(&__map, 0, sizeof(__map)); \
		SET_FIELD(__map.reg, QM_RF_PQ_MAP_ ## chip ## _PQ_VALID, 1); \
		SET_FIELD(__map.reg, QM_RF_PQ_MAP_ ## chip ## _RL_VALID, \
			  rl_valid); \
		SET_FIELD(__map.reg, QM_RF_PQ_MAP_ ## chip ## _VP_PQ_ID, \
			  vp_pq_id); \
		SET_FIELD(__map.reg, QM_RF_PQ_MAP_ ## chip ## _RL_ID, rl_id); \
		SET_FIELD(__map.reg, QM_RF_PQ_MAP_ ## chip ## _VOQ, ext_voq); \
		SET_FIELD(__map.reg, \
			  QM_RF_PQ_MAP_ ## chip ## _WRR_WEIGHT_GROUP, wrr); \
		STORE_RT_REG(p_hwfn, QM_REG_TXPQMAP_RT_OFFSET + (pq_id), \
			     *((u32 *)&__map)); \
		(map) = __map; \
	} while (0)

#define WRITE_PQ_INFO_TO_RAM	1
#define PQ_INFO_ELEMENT(vp, pf, tc, port, rl_valid, rl) \
	(((vp) << 0) | ((pf) << 12) | ((tc) << 16) | ((port) << 20) | \
	((rl_valid) << 22) | ((rl) << 24))
#define PQ_INFO_RAM_GRC_ADDRESS(pq_id) \
	(XSEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM + 21776 + (pq_id) * 4)

207
/******************** INTERNAL IMPLEMENTATION *********************/
208

T
Tomer Tayar 已提交
209 210 211 212 213 214 215 216 217 218
/* Returns the external VOQ number */
static u8 qed_get_ext_voq(struct qed_hwfn *p_hwfn,
			  u8 port_id, u8 tc, u8 max_phys_tcs_per_port)
{
	if (tc == PURE_LB_TC)
		return NUM_OF_PHYS_TCS * MAX_NUM_PORTS_BB + port_id;
	else
		return port_id * max_phys_tcs_per_port + tc;
}

219
/* Prepare PF RL enable/disable runtime init values */
Y
Yuval Mintz 已提交
220
static void qed_enable_pf_rl(struct qed_hwfn *p_hwfn, bool pf_rl_en)
221 222 223
{
	STORE_RT_REG(p_hwfn, QM_REG_RLPFENABLE_RT_OFFSET, pf_rl_en ? 1 : 0);
	if (pf_rl_en) {
T
Tomer Tayar 已提交
224 225 226
		u8 num_ext_voqs = MAX_NUM_VOQS_E4;
		u64 voq_bit_mask = ((u64)1 << num_ext_voqs) - 1;

M
Mintz, Yuval 已提交
227
		/* Enable RLs for all VOQs */
T
Tomer Tayar 已提交
228 229 230 231 232 233 234
		STORE_RT_REG(p_hwfn,
			     QM_REG_RLPFVOQENABLE_RT_OFFSET,
			     (u32)voq_bit_mask);
		if (num_ext_voqs >= 32)
			STORE_RT_REG(p_hwfn, QM_REG_RLPFVOQENABLE_MSB_RT_OFFSET,
				     (u32)(voq_bit_mask >> 32));

M
Mintz, Yuval 已提交
235
		/* Write RL period */
236
		STORE_RT_REG(p_hwfn,
Y
Yuval Mintz 已提交
237
			     QM_REG_RLPFPERIOD_RT_OFFSET, QM_RL_PERIOD_CLK_25M);
238 239 240
		STORE_RT_REG(p_hwfn,
			     QM_REG_RLPFPERIODTIMER_RT_OFFSET,
			     QM_RL_PERIOD_CLK_25M);
M
Mintz, Yuval 已提交
241 242

		/* Set credit threshold for QM bypass flow */
243 244 245
		if (QM_BYPASS_EN)
			STORE_RT_REG(p_hwfn,
				     QM_REG_AFULLQMBYPTHRPFRL_RT_OFFSET,
T
Tomer Tayar 已提交
246
				     QM_PF_RL_UPPER_BOUND);
247 248 249 250
	}
}

/* Prepare PF WFQ enable/disable runtime init values */
Y
Yuval Mintz 已提交
251
static void qed_enable_pf_wfq(struct qed_hwfn *p_hwfn, bool pf_wfq_en)
252 253
{
	STORE_RT_REG(p_hwfn, QM_REG_WFQPFENABLE_RT_OFFSET, pf_wfq_en ? 1 : 0);
M
Mintz, Yuval 已提交
254 255

	/* Set credit threshold for QM bypass flow */
256 257 258 259 260 261 262
	if (pf_wfq_en && QM_BYPASS_EN)
		STORE_RT_REG(p_hwfn,
			     QM_REG_AFULLQMBYPTHRPFWFQ_RT_OFFSET,
			     QM_WFQ_UPPER_BOUND);
}

/* Prepare VPORT RL enable/disable runtime init values */
Y
Yuval Mintz 已提交
263
static void qed_enable_vport_rl(struct qed_hwfn *p_hwfn, bool vport_rl_en)
264 265 266 267
{
	STORE_RT_REG(p_hwfn, QM_REG_RLGLBLENABLE_RT_OFFSET,
		     vport_rl_en ? 1 : 0);
	if (vport_rl_en) {
M
Mintz, Yuval 已提交
268
		/* Write RL period (use timer 0 only) */
269 270 271 272 273 274
		STORE_RT_REG(p_hwfn,
			     QM_REG_RLGLBLPERIOD_0_RT_OFFSET,
			     QM_RL_PERIOD_CLK_25M);
		STORE_RT_REG(p_hwfn,
			     QM_REG_RLGLBLPERIODTIMER_0_RT_OFFSET,
			     QM_RL_PERIOD_CLK_25M);
M
Mintz, Yuval 已提交
275 276

		/* Set credit threshold for QM bypass flow */
277 278 279
		if (QM_BYPASS_EN)
			STORE_RT_REG(p_hwfn,
				     QM_REG_AFULLQMBYPTHRGLBLRL_RT_OFFSET,
T
Tomer Tayar 已提交
280
				     QM_VP_RL_BYPASS_THRESH_SPEED);
281 282 283 284
	}
}

/* Prepare VPORT WFQ enable/disable runtime init values */
Y
Yuval Mintz 已提交
285
static void qed_enable_vport_wfq(struct qed_hwfn *p_hwfn, bool vport_wfq_en)
286 287 288
{
	STORE_RT_REG(p_hwfn, QM_REG_WFQVPENABLE_RT_OFFSET,
		     vport_wfq_en ? 1 : 0);
M
Mintz, Yuval 已提交
289 290

	/* Set credit threshold for QM bypass flow */
291 292 293 294 295 296 297
	if (vport_wfq_en && QM_BYPASS_EN)
		STORE_RT_REG(p_hwfn,
			     QM_REG_AFULLQMBYPTHRVPWFQ_RT_OFFSET,
			     QM_WFQ_UPPER_BOUND);
}

/* Prepare runtime init values to allocate PBF command queue lines for
M
Mintz, Yuval 已提交
298
 * the specified VOQ.
299 300
 */
static void qed_cmdq_lines_voq_rt_init(struct qed_hwfn *p_hwfn,
T
Tomer Tayar 已提交
301
				       u8 ext_voq, u16 cmdq_lines)
302
{
T
Tomer Tayar 已提交
303
	u32 qm_line_crd = QM_VOQ_LINE_CRD(cmdq_lines);
304

T
Tomer Tayar 已提交
305
	OVERWRITE_RT_REG(p_hwfn, PBF_CMDQ_LINES_RT_OFFSET(ext_voq),
306
			 (u32)cmdq_lines);
T
Tomer Tayar 已提交
307 308 309
	STORE_RT_REG(p_hwfn, QM_REG_VOQCRDLINE_RT_OFFSET + ext_voq,
		     qm_line_crd);
	STORE_RT_REG(p_hwfn, QM_REG_VOQINITCRDLINE_RT_OFFSET + ext_voq,
310 311 312 313 314 315 316 317 318 319
		     qm_line_crd);
}

/* Prepare runtime init values to allocate PBF command queue lines. */
static void qed_cmdq_lines_rt_init(
	struct qed_hwfn *p_hwfn,
	u8 max_ports_per_engine,
	u8 max_phys_tcs_per_port,
	struct init_qm_port_params port_params[MAX_NUM_PORTS])
{
T
Tomer Tayar 已提交
320 321 322 323 324 325
	u8 tc, ext_voq, port_id, num_tcs_in_port;
	u8 num_ext_voqs = MAX_NUM_VOQS_E4;

	/* Clear PBF lines of all VOQs */
	for (ext_voq = 0; ext_voq < num_ext_voqs; ext_voq++)
		STORE_RT_REG(p_hwfn, PBF_CMDQ_LINES_RT_OFFSET(ext_voq), 0);
326 327

	for (port_id = 0; port_id < max_ports_per_engine; port_id++) {
T
Tomer Tayar 已提交
328 329 330 331
		u16 phys_lines, phys_lines_per_tc;

		if (!port_params[port_id].active)
			continue;
Y
Yuval Mintz 已提交
332

T
Tomer Tayar 已提交
333 334 335 336 337 338
		/* Find number of command queue lines to divide between the
		 * active physical TCs. In E5, 1/8 of the lines are reserved.
		 * the lines for pure LB TC are subtracted.
		 */
		phys_lines = port_params[port_id].num_pbf_cmd_lines;
		phys_lines -= PBF_CMDQ_PURE_LB_LINES;
Y
Yuval Mintz 已提交
339

T
Tomer Tayar 已提交
340 341 342 343 344 345 346
		/* Find #lines per active physical TC */
		num_tcs_in_port = 0;
		for (tc = 0; tc < max_phys_tcs_per_port; tc++)
			if (((port_params[port_id].active_phys_tcs >>
			      tc) & 0x1) == 1)
				num_tcs_in_port++;
		phys_lines_per_tc = phys_lines / num_tcs_in_port;
Y
Yuval Mintz 已提交
347

T
Tomer Tayar 已提交
348 349 350 351 352 353 354 355 356 357
		/* Init registers per active TC */
		for (tc = 0; tc < max_phys_tcs_per_port; tc++) {
			ext_voq = qed_get_ext_voq(p_hwfn,
						  port_id,
						  tc, max_phys_tcs_per_port);
			if (((port_params[port_id].active_phys_tcs >>
			      tc) & 0x1) == 1)
				qed_cmdq_lines_voq_rt_init(p_hwfn,
							   ext_voq,
							   phys_lines_per_tc);
358
		}
T
Tomer Tayar 已提交
359 360 361 362 363 364 365

		/* Init registers for pure LB TC */
		ext_voq = qed_get_ext_voq(p_hwfn,
					  port_id,
					  PURE_LB_TC, max_phys_tcs_per_port);
		qed_cmdq_lines_voq_rt_init(p_hwfn,
					   ext_voq, PBF_CMDQ_PURE_LB_LINES);
366 367 368 369 370 371 372 373 374 375
	}
}

static void qed_btb_blocks_rt_init(
	struct qed_hwfn *p_hwfn,
	u8 max_ports_per_engine,
	u8 max_phys_tcs_per_port,
	struct init_qm_port_params port_params[MAX_NUM_PORTS])
{
	u32 usable_blocks, pure_lb_blocks, phys_blocks;
T
Tomer Tayar 已提交
376
	u8 tc, ext_voq, port_id, num_tcs_in_port;
377 378 379 380 381

	for (port_id = 0; port_id < max_ports_per_engine; port_id++) {
		if (!port_params[port_id].active)
			continue;

M
Mintz, Yuval 已提交
382
		/* Subtract headroom blocks */
383 384 385
		usable_blocks = port_params[port_id].num_btb_blocks -
				BTB_HEADROOM_BLOCKS;

T
Tomer Tayar 已提交
386 387 388
		/* Find blocks per physical TC. Use factor to avoid floating
		 * arithmethic.
		 */
Y
Yuval Mintz 已提交
389
		num_tcs_in_port = 0;
T
Tomer Tayar 已提交
390
		for (tc = 0; tc < NUM_OF_PHYS_TCS; tc++)
Y
Yuval Mintz 已提交
391 392 393 394
			if (((port_params[port_id].active_phys_tcs >>
			      tc) & 0x1) == 1)
				num_tcs_in_port++;

395
		pure_lb_blocks = (usable_blocks * BTB_PURE_LB_FACTOR) /
Y
Yuval Mintz 已提交
396
				 (num_tcs_in_port * BTB_PURE_LB_FACTOR +
397 398 399
				  BTB_PURE_LB_RATIO);
		pure_lb_blocks = max_t(u32, BTB_JUMBO_PKT_BLOCKS,
				       pure_lb_blocks / BTB_PURE_LB_FACTOR);
Y
Yuval Mintz 已提交
400 401
		phys_blocks = (usable_blocks - pure_lb_blocks) /
			      num_tcs_in_port;
402

M
Mintz, Yuval 已提交
403
		/* Init physical TCs */
Y
Yuval Mintz 已提交
404 405
		for (tc = 0; tc < NUM_OF_PHYS_TCS; tc++) {
			if (((port_params[port_id].active_phys_tcs >>
T
Tomer Tayar 已提交
406 407 408 409 410 411 412 413 414 415
			      tc) & 0x1) == 1) {
				ext_voq =
					qed_get_ext_voq(p_hwfn,
							port_id,
							tc,
							max_phys_tcs_per_port);
				STORE_RT_REG(p_hwfn,
					     PBF_BTB_GUARANTEED_RT_OFFSET
					     (ext_voq), phys_blocks);
			}
416 417
		}

M
Mintz, Yuval 已提交
418
		/* Init pure LB TC */
T
Tomer Tayar 已提交
419 420 421 422
		ext_voq = qed_get_ext_voq(p_hwfn,
					  port_id,
					  PURE_LB_TC, max_phys_tcs_per_port);
		STORE_RT_REG(p_hwfn, PBF_BTB_GUARANTEED_RT_OFFSET(ext_voq),
423 424 425 426 427
			     pure_lb_blocks);
	}
}

/* Prepare Tx PQ mapping runtime init values for the specified PF */
T
Tomer Tayar 已提交
428 429 430 431
static void qed_tx_pq_map_rt_init(struct qed_hwfn *p_hwfn,
				  struct qed_ptt *p_ptt,
				  struct qed_qm_pf_rt_init_params *p_params,
				  u32 base_mem_addr_4kb)
432 433
{
	u32 tx_pq_vf_mask[MAX_QM_TX_QUEUES / QM_PF_QUEUE_GROUP_SIZE] = { 0 };
T
Tomer Tayar 已提交
434
	struct init_qm_vport_params *vport_params = p_params->vport_params;
M
Mintz, Yuval 已提交
435
	u32 num_tx_pq_vf_masks = MAX_QM_TX_QUEUES / QM_PF_QUEUE_GROUP_SIZE;
T
Tomer Tayar 已提交
436 437 438 439 440 441 442 443 444 445 446 447 448
	u16 num_pqs, first_pq_group, last_pq_group, i, j, pq_id, pq_group;
	struct init_qm_pq_params *pq_params = p_params->pq_params;
	u32 pq_mem_4kb, vport_pq_mem_4kb, mem_addr_4kb;

	num_pqs = p_params->num_pf_pqs + p_params->num_vf_pqs;

	first_pq_group = p_params->start_pq / QM_PF_QUEUE_GROUP_SIZE;
	last_pq_group = (p_params->start_pq + num_pqs - 1) /
			QM_PF_QUEUE_GROUP_SIZE;

	pq_mem_4kb = QM_PQ_MEM_4KB(p_params->num_pf_cids);
	vport_pq_mem_4kb = QM_PQ_MEM_4KB(p_params->num_vf_cids);
	mem_addr_4kb = base_mem_addr_4kb;
449

M
Mintz, Yuval 已提交
450
	/* Set mapping from PQ group to PF */
451 452 453
	for (pq_group = first_pq_group; pq_group <= last_pq_group; pq_group++)
		STORE_RT_REG(p_hwfn, QM_REG_PQTX2PF_0_RT_OFFSET + pq_group,
			     (u32)(p_params->pf_id));
T
Tomer Tayar 已提交
454

M
Mintz, Yuval 已提交
455
	/* Set PQ sizes */
456 457 458 459 460
	STORE_RT_REG(p_hwfn, QM_REG_MAXPQSIZE_0_RT_OFFSET,
		     QM_PQ_SIZE_256B(p_params->num_pf_cids));
	STORE_RT_REG(p_hwfn, QM_REG_MAXPQSIZE_1_RT_OFFSET,
		     QM_PQ_SIZE_256B(p_params->num_vf_cids));

M
Mintz, Yuval 已提交
461
	/* Go over all Tx PQs */
462
	for (i = 0, pq_id = p_params->start_pq; i < num_pqs; i++, pq_id++) {
T
Tomer Tayar 已提交
463 464
		u8 ext_voq, vport_id_in_pf, tc_id = pq_params[i].tc_id;
		u32 max_qm_global_rls = MAX_QM_GLOBAL_RLS;
465
		struct qm_rf_pq_map_e4 tx_pq_map;
T
Tomer Tayar 已提交
466 467
		bool is_vf_pq, rl_valid;
		u16 *p_first_tx_pq_id;
468

T
Tomer Tayar 已提交
469
		ext_voq = qed_get_ext_voq(p_hwfn,
M
Michal Kalderon 已提交
470
					  pq_params[i].port_id,
T
Tomer Tayar 已提交
471 472 473
					  tc_id,
					  p_params->max_phys_tcs_per_port);
		is_vf_pq = (i >= p_params->num_pf_pqs);
M
Michal Kalderon 已提交
474
		rl_valid = pq_params[i].rl_valid > 0;
M
Mintz, Yuval 已提交
475

M
Mintz, Yuval 已提交
476
		/* Update first Tx PQ of VPORT/TC */
T
Tomer Tayar 已提交
477 478 479 480 481 482 483
		vport_id_in_pf = pq_params[i].vport_id - p_params->start_vport;
		p_first_tx_pq_id =
		    &vport_params[vport_id_in_pf].first_tx_pq_id[tc_id];
		if (*p_first_tx_pq_id == QM_INVALID_PQ_ID) {
			u32 map_val =
				(ext_voq << QM_WFQ_VP_PQ_VOQ_SHIFT) |
				(p_params->pf_id << QM_WFQ_VP_PQ_PF_E4_SHIFT);
484

M
Mintz, Yuval 已提交
485
			/* Create new VP PQ */
T
Tomer Tayar 已提交
486
			*p_first_tx_pq_id = pq_id;
M
Mintz, Yuval 已提交
487 488

			/* Map VP PQ to VOQ and PF */
489 490
			STORE_RT_REG(p_hwfn,
				     QM_REG_WFQVPMAP_RT_OFFSET +
T
Tomer Tayar 已提交
491 492
				     *p_first_tx_pq_id,
				     map_val);
493
		}
M
Mintz, Yuval 已提交
494

T
Tomer Tayar 已提交
495
		/* Check RL ID */
M
Michal Kalderon 已提交
496
		if (rl_valid && pq_params[i].vport_id >= max_qm_global_rls) {
M
Mintz, Yuval 已提交
497
			DP_NOTICE(p_hwfn,
T
Tomer Tayar 已提交
498
				  "Invalid VPORT ID for rate limiter configuration\n");
M
Michal Kalderon 已提交
499 500
			rl_valid = false;
		}
T
Tomer Tayar 已提交
501 502 503 504 505 506 507 508 509 510 511 512

		/* Prepare PQ map entry */
		QM_INIT_TX_PQ_MAP(p_hwfn,
				  tx_pq_map,
				  E4,
				  pq_id,
				  rl_valid ? 1 : 0,
				  *p_first_tx_pq_id,
				  rl_valid ? pq_params[i].vport_id : 0,
				  ext_voq, pq_params[i].wrr_group);

		/* Set PQ base address */
513 514 515
		STORE_RT_REG(p_hwfn,
			     QM_REG_BASEADDRTXPQ_RT_OFFSET + pq_id,
			     mem_addr_4kb);
M
Mintz, Yuval 已提交
516

T
Tomer Tayar 已提交
517 518 519 520 521 522 523 524 525 526 527 528 529 530
		/* Clear PQ pointer table entry (64 bit) */
		if (p_params->is_pf_loading)
			for (j = 0; j < 2; j++)
				STORE_RT_REG(p_hwfn,
					     QM_REG_PTRTBLTX_RT_OFFSET +
					     (pq_id * 2) + j, 0);

		/* Write PQ info to RAM */
		if (WRITE_PQ_INFO_TO_RAM != 0) {
			u32 pq_info = 0;

			pq_info = PQ_INFO_ELEMENT(*p_first_tx_pq_id,
						  p_params->pf_id,
						  tc_id,
M
Michal Kalderon 已提交
531
						  pq_params[i].port_id,
T
Tomer Tayar 已提交
532 533 534 535 536 537 538
						  rl_valid ? 1 : 0,
						  rl_valid ?
						  pq_params[i].vport_id : 0);
			qed_wr(p_hwfn, p_ptt, PQ_INFO_RAM_GRC_ADDRESS(pq_id),
			       pq_info);
		}

M
Mintz, Yuval 已提交
539
		/* If VF PQ, add indication to PQ VF mask */
540
		if (is_vf_pq) {
M
Mintz, Yuval 已提交
541 542 543
			tx_pq_vf_mask[pq_id /
				      QM_PF_QUEUE_GROUP_SIZE] |=
			    BIT((pq_id % QM_PF_QUEUE_GROUP_SIZE));
544 545 546 547 548 549
			mem_addr_4kb += vport_pq_mem_4kb;
		} else {
			mem_addr_4kb += pq_mem_4kb;
		}
	}

M
Mintz, Yuval 已提交
550 551 552 553 554
	/* Store Tx PQ VF mask to size select register */
	for (i = 0; i < num_tx_pq_vf_masks; i++)
		if (tx_pq_vf_mask[i])
			STORE_RT_REG(p_hwfn,
				     QM_REG_MAXPQSIZETXSEL_0_RT_OFFSET + i,
Y
Yuval Mintz 已提交
555
				     tx_pq_vf_mask[i]);
556 557 558 559 560
}

/* Prepare Other PQ mapping runtime init values for the specified PF */
static void qed_other_pq_map_rt_init(struct qed_hwfn *p_hwfn,
				     u8 pf_id,
T
Tomer Tayar 已提交
561
				     bool is_pf_loading,
562
				     u32 num_pf_cids,
Y
Yuval Mintz 已提交
563
				     u32 num_tids, u32 base_mem_addr_4kb)
564
{
M
Mintz, Yuval 已提交
565
	u32 pq_size, pq_mem_4kb, mem_addr_4kb;
T
Tomer Tayar 已提交
566
	u16 i, j, pq_id, pq_group;
567

T
Tomer Tayar 已提交
568 569
	/* A single other PQ group is used in each PF, where PQ group i is used
	 * in PF i.
570
	 */
M
Mintz, Yuval 已提交
571 572 573 574
	pq_group = pf_id;
	pq_size = num_pf_cids + num_tids;
	pq_mem_4kb = QM_PQ_MEM_4KB(pq_size);
	mem_addr_4kb = base_mem_addr_4kb;
575

M
Mintz, Yuval 已提交
576
	/* Map PQ group to PF */
577 578
	STORE_RT_REG(p_hwfn, QM_REG_PQOTHER2PF_0_RT_OFFSET + pq_group,
		     (u32)(pf_id));
T
Tomer Tayar 已提交
579

M
Mintz, Yuval 已提交
580
	/* Set PQ sizes */
581 582
	STORE_RT_REG(p_hwfn, QM_REG_MAXPQSIZE_2_RT_OFFSET,
		     QM_PQ_SIZE_256B(pq_size));
M
Mintz, Yuval 已提交
583

584 585
	for (i = 0, pq_id = pf_id * QM_PF_QUEUE_GROUP_SIZE;
	     i < QM_OTHER_PQS_PER_PF; i++, pq_id++) {
T
Tomer Tayar 已提交
586
		/* Set PQ base address */
587 588 589
		STORE_RT_REG(p_hwfn,
			     QM_REG_BASEADDROTHERPQ_RT_OFFSET + pq_id,
			     mem_addr_4kb);
T
Tomer Tayar 已提交
590 591 592 593 594 595 596 597

		/* Clear PQ pointer table entry */
		if (is_pf_loading)
			for (j = 0; j < 2; j++)
				STORE_RT_REG(p_hwfn,
					     QM_REG_PTRTBLOTHER_RT_OFFSET +
					     (pq_id * 2) + j, 0);

598 599 600 601 602 603 604 605
		mem_addr_4kb += pq_mem_4kb;
	}
}

/* Prepare PF WFQ runtime init values for the specified PF.
 * Return -1 on error.
 */
static int qed_pf_wfq_rt_init(struct qed_hwfn *p_hwfn,
M
Michal Kalderon 已提交
606

607 608 609
			      struct qed_qm_pf_rt_init_params *p_params)
{
	u16 num_tx_pqs = p_params->num_pf_pqs + p_params->num_vf_pqs;
T
Tomer Tayar 已提交
610 611 612
	struct init_qm_pq_params *pq_params = p_params->pq_params;
	u32 inc_val, crd_reg_offset;
	u8 ext_voq;
613 614 615
	u16 i;

	inc_val = QM_WFQ_INC_VAL(p_params->pf_wfq);
Y
Yuval Mintz 已提交
616
	if (!inc_val || inc_val > QM_WFQ_MAX_INC_VAL) {
M
Mintz, Yuval 已提交
617
		DP_NOTICE(p_hwfn, "Invalid PF WFQ weight configuration\n");
618 619 620 621
		return -1;
	}

	for (i = 0; i < num_tx_pqs; i++) {
T
Tomer Tayar 已提交
622
		ext_voq = qed_get_ext_voq(p_hwfn,
M
Michal Kalderon 已提交
623
					  pq_params[i].port_id,
T
Tomer Tayar 已提交
624 625 626 627 628 629 630 631
					  pq_params[i].tc_id,
					  p_params->max_phys_tcs_per_port);
		crd_reg_offset =
			(p_params->pf_id < MAX_NUM_PFS_BB ?
			 QM_REG_WFQPFCRD_RT_OFFSET :
			 QM_REG_WFQPFCRD_MSB_RT_OFFSET) +
			ext_voq * MAX_NUM_PFS_BB +
			(p_params->pf_id % MAX_NUM_PFS_BB);
632
		OVERWRITE_RT_REG(p_hwfn,
T
Tomer Tayar 已提交
633
				 crd_reg_offset, (u32)QM_WFQ_CRD_REG_SIGN_BIT);
634 635
	}

Y
Yuval Mintz 已提交
636 637
	STORE_RT_REG(p_hwfn,
		     QM_REG_WFQPFUPPERBOUND_RT_OFFSET + p_params->pf_id,
T
Tomer Tayar 已提交
638
		     QM_WFQ_UPPER_BOUND | (u32)QM_WFQ_CRD_REG_SIGN_BIT);
M
Mintz, Yuval 已提交
639 640
	STORE_RT_REG(p_hwfn, QM_REG_WFQPFWEIGHT_RT_OFFSET + p_params->pf_id,
		     inc_val);
T
Tomer Tayar 已提交
641

642 643 644 645 646 647
	return 0;
}

/* Prepare PF RL runtime init values for the specified PF.
 * Return -1 on error.
 */
Y
Yuval Mintz 已提交
648
static int qed_pf_rl_rt_init(struct qed_hwfn *p_hwfn, u8 pf_id, u32 pf_rl)
649 650 651
{
	u32 inc_val = QM_RL_INC_VAL(pf_rl);

T
Tomer Tayar 已提交
652
	if (inc_val > QM_PF_RL_MAX_INC_VAL) {
M
Mintz, Yuval 已提交
653
		DP_NOTICE(p_hwfn, "Invalid PF rate limit configuration\n");
654 655
		return -1;
	}
T
Tomer Tayar 已提交
656 657 658 659 660 661 662

	STORE_RT_REG(p_hwfn,
		     QM_REG_RLPFCRD_RT_OFFSET + pf_id,
		     (u32)QM_RL_CRD_REG_SIGN_BIT);
	STORE_RT_REG(p_hwfn,
		     QM_REG_RLPFUPPERBOUND_RT_OFFSET + pf_id,
		     QM_PF_RL_UPPER_BOUND | (u32)QM_RL_CRD_REG_SIGN_BIT);
663
	STORE_RT_REG(p_hwfn, QM_REG_RLPFINCVAL_RT_OFFSET + pf_id, inc_val);
T
Tomer Tayar 已提交
664

665 666 667 668 669 670 671 672 673 674
	return 0;
}

/* Prepare VPORT WFQ runtime init values for the specified VPORTs.
 * Return -1 on error.
 */
static int qed_vp_wfq_rt_init(struct qed_hwfn *p_hwfn,
			      u8 num_vports,
			      struct init_qm_vport_params *vport_params)
{
T
Tomer Tayar 已提交
675
	u16 vport_pq_id;
676
	u32 inc_val;
Y
Yuval Mintz 已提交
677
	u8 tc, i;
678

M
Mintz, Yuval 已提交
679
	/* Go over all PF VPORTs */
Y
Yuval Mintz 已提交
680
	for (i = 0; i < num_vports; i++) {
681 682 683 684 685 686
		if (!vport_params[i].vport_wfq)
			continue;

		inc_val = QM_WFQ_INC_VAL(vport_params[i].vport_wfq);
		if (inc_val > QM_WFQ_MAX_INC_VAL) {
			DP_NOTICE(p_hwfn,
M
Mintz, Yuval 已提交
687
				  "Invalid VPORT WFQ weight configuration\n");
688 689 690
			return -1;
		}

T
Tomer Tayar 已提交
691
		/* Each VPORT can have several VPORT PQ IDs for various TCs */
692
		for (tc = 0; tc < NUM_OF_TCS; tc++) {
T
Tomer Tayar 已提交
693
			vport_pq_id = vport_params[i].first_tx_pq_id[tc];
694 695 696 697
			if (vport_pq_id != QM_INVALID_PQ_ID) {
				STORE_RT_REG(p_hwfn,
					     QM_REG_WFQVPCRD_RT_OFFSET +
					     vport_pq_id,
T
Tomer Tayar 已提交
698
					     (u32)QM_WFQ_CRD_REG_SIGN_BIT);
Y
Yuval Mintz 已提交
699 700 701
				STORE_RT_REG(p_hwfn,
					     QM_REG_WFQVPWEIGHT_RT_OFFSET +
					     vport_pq_id, inc_val);
702 703 704 705 706 707 708
			}
		}
	}

	return 0;
}

T
Tomer Tayar 已提交
709 710 711
/* Prepare VPORT RL runtime init values for the specified VPORTs.
 * Return -1 on error.
 */
712 713 714
static int qed_vport_rl_rt_init(struct qed_hwfn *p_hwfn,
				u8 start_vport,
				u8 num_vports,
T
Tomer Tayar 已提交
715
				u32 link_speed,
716 717 718
				struct init_qm_vport_params *vport_params)
{
	u8 i, vport_id;
T
Tomer Tayar 已提交
719
	u32 inc_val;
720

M
Mintz, Yuval 已提交
721 722
	if (start_vport + num_vports >= MAX_QM_GLOBAL_RLS) {
		DP_NOTICE(p_hwfn,
M
Mintz, Yuval 已提交
723
			  "Invalid VPORT ID for rate limiter configuration\n");
M
Mintz, Yuval 已提交
724 725 726
		return -1;
	}

M
Mintz, Yuval 已提交
727
	/* Go over all PF VPORTs */
728
	for (i = 0, vport_id = start_vport; i < num_vports; i++, vport_id++) {
T
Tomer Tayar 已提交
729 730 731 732
		inc_val = QM_RL_INC_VAL(vport_params[i].vport_rl ?
			  vport_params[i].vport_rl :
			  link_speed);
		if (inc_val > QM_VP_RL_MAX_INC_VAL(link_speed)) {
733
			DP_NOTICE(p_hwfn,
M
Mintz, Yuval 已提交
734
				  "Invalid VPORT rate-limit configuration\n");
735 736 737
			return -1;
		}

T
Tomer Tayar 已提交
738 739
		STORE_RT_REG(p_hwfn, QM_REG_RLGLBLCRD_RT_OFFSET + vport_id,
			     (u32)QM_RL_CRD_REG_SIGN_BIT);
740 741
		STORE_RT_REG(p_hwfn,
			     QM_REG_RLGLBLUPPERBOUND_RT_OFFSET + vport_id,
T
Tomer Tayar 已提交
742 743 744
			     QM_VP_RL_UPPER_BOUND(link_speed) |
			     (u32)QM_RL_CRD_REG_SIGN_BIT);
		STORE_RT_REG(p_hwfn, QM_REG_RLGLBLINCVAL_RT_OFFSET + vport_id,
745 746 747 748 749 750 751 752 753 754 755
			     inc_val);
	}

	return 0;
}

static bool qed_poll_on_qm_cmd_ready(struct qed_hwfn *p_hwfn,
				     struct qed_ptt *p_ptt)
{
	u32 reg_val, i;

T
Tomer Tayar 已提交
756
	for (i = 0, reg_val = 0; i < QM_STOP_CMD_MAX_POLL_COUNT && !reg_val;
757 758 759 760 761
	     i++) {
		udelay(QM_STOP_CMD_POLL_PERIOD_US);
		reg_val = qed_rd(p_hwfn, p_ptt, QM_REG_SDMCMDREADY);
	}

M
Mintz, Yuval 已提交
762
	/* Check if timeout while waiting for SDM command ready */
763 764 765 766 767 768 769 770 771 772 773
	if (i == QM_STOP_CMD_MAX_POLL_COUNT) {
		DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
			   "Timeout when waiting for QM SDM command ready signal\n");
		return false;
	}

	return true;
}

static bool qed_send_qm_cmd(struct qed_hwfn *p_hwfn,
			    struct qed_ptt *p_ptt,
Y
Yuval Mintz 已提交
774
			    u32 cmd_addr, u32 cmd_data_lsb, u32 cmd_data_msb)
775 776 777 778 779 780 781 782 783 784 785 786 787 788
{
	if (!qed_poll_on_qm_cmd_ready(p_hwfn, p_ptt))
		return false;

	qed_wr(p_hwfn, p_ptt, QM_REG_SDMCMDADDR, cmd_addr);
	qed_wr(p_hwfn, p_ptt, QM_REG_SDMCMDDATALSB, cmd_data_lsb);
	qed_wr(p_hwfn, p_ptt, QM_REG_SDMCMDDATAMSB, cmd_data_msb);
	qed_wr(p_hwfn, p_ptt, QM_REG_SDMCMDGO, 1);
	qed_wr(p_hwfn, p_ptt, QM_REG_SDMCMDGO, 0);

	return qed_poll_on_qm_cmd_ready(p_hwfn, p_ptt);
}

/******************** INTERFACE IMPLEMENTATION *********************/
T
Tomer Tayar 已提交
789 790

u32 qed_qm_pf_mem_size(u32 num_pf_cids,
791
		       u32 num_vf_cids,
Y
Yuval Mintz 已提交
792
		       u32 num_tids, u16 num_pf_pqs, u16 num_vf_pqs)
793 794 795 796 797 798
{
	return QM_PQ_MEM_4KB(num_pf_cids) * num_pf_pqs +
	       QM_PQ_MEM_4KB(num_vf_cids) * num_vf_pqs +
	       QM_PQ_MEM_4KB(num_pf_cids + num_tids) * QM_OTHER_PQS_PER_PF;
}

T
Tomer Tayar 已提交
799 800
int qed_qm_common_rt_init(struct qed_hwfn *p_hwfn,
			  struct qed_qm_common_rt_init_params *p_params)
801
{
T
Tomer Tayar 已提交
802
	/* Init AFullOprtnstcCrdMask */
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
	u32 mask = (QM_OPPOR_LINE_VOQ_DEF <<
		    QM_RF_OPPORTUNISTIC_MASK_LINEVOQ_SHIFT) |
		   (QM_BYTE_CRD_EN << QM_RF_OPPORTUNISTIC_MASK_BYTEVOQ_SHIFT) |
		   (p_params->pf_wfq_en <<
		    QM_RF_OPPORTUNISTIC_MASK_PFWFQ_SHIFT) |
		   (p_params->vport_wfq_en <<
		    QM_RF_OPPORTUNISTIC_MASK_VPWFQ_SHIFT) |
		   (p_params->pf_rl_en <<
		    QM_RF_OPPORTUNISTIC_MASK_PFRL_SHIFT) |
		   (p_params->vport_rl_en <<
		    QM_RF_OPPORTUNISTIC_MASK_VPQCNRL_SHIFT) |
		   (QM_OPPOR_FW_STOP_DEF <<
		    QM_RF_OPPORTUNISTIC_MASK_FWPAUSE_SHIFT) |
		   (QM_OPPOR_PQ_EMPTY_DEF <<
		    QM_RF_OPPORTUNISTIC_MASK_QUEUEEMPTY_SHIFT);

	STORE_RT_REG(p_hwfn, QM_REG_AFULLOPRTNSTCCRDMASK_RT_OFFSET, mask);
T
Tomer Tayar 已提交
820 821

	/* Enable/disable PF RL */
822
	qed_enable_pf_rl(p_hwfn, p_params->pf_rl_en);
T
Tomer Tayar 已提交
823 824

	/* Enable/disable PF WFQ */
825
	qed_enable_pf_wfq(p_hwfn, p_params->pf_wfq_en);
T
Tomer Tayar 已提交
826 827

	/* Enable/disable VPORT RL */
828
	qed_enable_vport_rl(p_hwfn, p_params->vport_rl_en);
T
Tomer Tayar 已提交
829 830

	/* Enable/disable VPORT WFQ */
831
	qed_enable_vport_wfq(p_hwfn, p_params->vport_wfq_en);
T
Tomer Tayar 已提交
832 833

	/* Init PBF CMDQ line credit */
834 835 836 837
	qed_cmdq_lines_rt_init(p_hwfn,
			       p_params->max_ports_per_engine,
			       p_params->max_phys_tcs_per_port,
			       p_params->port_params);
T
Tomer Tayar 已提交
838 839

	/* Init BTB blocks in PBF */
840 841 842 843
	qed_btb_blocks_rt_init(p_hwfn,
			       p_params->max_ports_per_engine,
			       p_params->max_phys_tcs_per_port,
			       p_params->port_params);
T
Tomer Tayar 已提交
844

845 846 847 848 849 850 851 852 853 854 855 856 857
	return 0;
}

int qed_qm_pf_rt_init(struct qed_hwfn *p_hwfn,
		      struct qed_ptt *p_ptt,
		      struct qed_qm_pf_rt_init_params *p_params)
{
	struct init_qm_vport_params *vport_params = p_params->vport_params;
	u32 other_mem_size_4kb = QM_PQ_MEM_4KB(p_params->num_pf_cids +
					       p_params->num_tids) *
				 QM_OTHER_PQS_PER_PF;
	u8 tc, i;

M
Mintz, Yuval 已提交
858
	/* Clear first Tx PQ ID array for each VPORT */
859 860 861 862
	for (i = 0; i < p_params->num_vports; i++)
		for (tc = 0; tc < NUM_OF_TCS; tc++)
			vport_params[i].first_tx_pq_id[tc] = QM_INVALID_PQ_ID;

M
Mintz, Yuval 已提交
863
	/* Map Other PQs (if any) */
T
Tomer Tayar 已提交
864 865 866 867
	qed_other_pq_map_rt_init(p_hwfn,
				 p_params->pf_id,
				 p_params->is_pf_loading, p_params->num_pf_cids,
				 p_params->num_tids, 0);
868

M
Mintz, Yuval 已提交
869
	/* Map Tx PQs */
870 871
	qed_tx_pq_map_rt_init(p_hwfn, p_ptt, p_params, other_mem_size_4kb);

T
Tomer Tayar 已提交
872
	/* Init PF WFQ */
873 874 875 876
	if (p_params->pf_wfq)
		if (qed_pf_wfq_rt_init(p_hwfn, p_params))
			return -1;

T
Tomer Tayar 已提交
877
	/* Init PF RL */
878 879 880
	if (qed_pf_rl_rt_init(p_hwfn, p_params->pf_id, p_params->pf_rl))
		return -1;

T
Tomer Tayar 已提交
881
	/* Set VPORT WFQ */
Y
Yuval Mintz 已提交
882
	if (qed_vp_wfq_rt_init(p_hwfn, p_params->num_vports, vport_params))
883 884
		return -1;

T
Tomer Tayar 已提交
885
	/* Set VPORT RL */
886
	if (qed_vport_rl_rt_init(p_hwfn, p_params->start_vport,
T
Tomer Tayar 已提交
887 888
				 p_params->num_vports, p_params->link_speed,
				 vport_params))
889 890 891 892 893
		return -1;

	return 0;
}

894
int qed_init_pf_wfq(struct qed_hwfn *p_hwfn,
Y
Yuval Mintz 已提交
895
		    struct qed_ptt *p_ptt, u8 pf_id, u16 pf_wfq)
896 897 898 899
{
	u32 inc_val = QM_WFQ_INC_VAL(pf_wfq);

	if (!inc_val || inc_val > QM_WFQ_MAX_INC_VAL) {
M
Mintz, Yuval 已提交
900
		DP_NOTICE(p_hwfn, "Invalid PF WFQ weight configuration\n");
901 902 903 904
		return -1;
	}

	qed_wr(p_hwfn, p_ptt, QM_REG_WFQPFWEIGHT + pf_id * 4, inc_val);
T
Tomer Tayar 已提交
905

906 907 908
	return 0;
}

909
int qed_init_pf_rl(struct qed_hwfn *p_hwfn,
Y
Yuval Mintz 已提交
910
		   struct qed_ptt *p_ptt, u8 pf_id, u32 pf_rl)
911 912 913
{
	u32 inc_val = QM_RL_INC_VAL(pf_rl);

T
Tomer Tayar 已提交
914
	if (inc_val > QM_PF_RL_MAX_INC_VAL) {
M
Mintz, Yuval 已提交
915
		DP_NOTICE(p_hwfn, "Invalid PF rate limit configuration\n");
916 917 918
		return -1;
	}

T
Tomer Tayar 已提交
919 920
	qed_wr(p_hwfn,
	       p_ptt, QM_REG_RLPFCRD + pf_id * 4, (u32)QM_RL_CRD_REG_SIGN_BIT);
921 922 923 924 925
	qed_wr(p_hwfn, p_ptt, QM_REG_RLPFINCVAL + pf_id * 4, inc_val);

	return 0;
}

926 927
int qed_init_vport_wfq(struct qed_hwfn *p_hwfn,
		       struct qed_ptt *p_ptt,
Y
Yuval Mintz 已提交
928
		       u16 first_tx_pq_id[NUM_OF_TCS], u16 vport_wfq)
929
{
M
Mintz, Yuval 已提交
930 931
	u16 vport_pq_id;
	u32 inc_val;
932 933
	u8 tc;

M
Mintz, Yuval 已提交
934
	inc_val = QM_WFQ_INC_VAL(vport_wfq);
935
	if (!inc_val || inc_val > QM_WFQ_MAX_INC_VAL) {
M
Mintz, Yuval 已提交
936
		DP_NOTICE(p_hwfn, "Invalid VPORT WFQ weight configuration\n");
937 938 939 940
		return -1;
	}

	for (tc = 0; tc < NUM_OF_TCS; tc++) {
M
Mintz, Yuval 已提交
941
		vport_pq_id = first_tx_pq_id[tc];
942
		if (vport_pq_id != QM_INVALID_PQ_ID)
T
Tomer Tayar 已提交
943 944 945
			qed_wr(p_hwfn,
			       p_ptt,
			       QM_REG_WFQVPWEIGHT + vport_pq_id * 4, inc_val);
946 947 948 949 950
	}

	return 0;
}

951
int qed_init_vport_rl(struct qed_hwfn *p_hwfn,
T
Tomer Tayar 已提交
952 953
		      struct qed_ptt *p_ptt,
		      u8 vport_id, u32 vport_rl, u32 link_speed)
954
{
T
Tomer Tayar 已提交
955
	u32 inc_val, max_qm_global_rls = MAX_QM_GLOBAL_RLS;
956

T
Tomer Tayar 已提交
957
	if (vport_id >= max_qm_global_rls) {
M
Mintz, Yuval 已提交
958
		DP_NOTICE(p_hwfn,
M
Mintz, Yuval 已提交
959
			  "Invalid VPORT ID for rate limiter configuration\n");
M
Mintz, Yuval 已提交
960 961 962
		return -1;
	}

T
Tomer Tayar 已提交
963 964
	inc_val = QM_RL_INC_VAL(vport_rl ? vport_rl : link_speed);
	if (inc_val > QM_VP_RL_MAX_INC_VAL(link_speed)) {
M
Mintz, Yuval 已提交
965
		DP_NOTICE(p_hwfn, "Invalid VPORT rate-limit configuration\n");
966 967 968
		return -1;
	}

T
Tomer Tayar 已提交
969 970 971
	qed_wr(p_hwfn,
	       p_ptt,
	       QM_REG_RLGLBLCRD + vport_id * 4, (u32)QM_RL_CRD_REG_SIGN_BIT);
972 973 974 975 976 977 978 979
	qed_wr(p_hwfn, p_ptt, QM_REG_RLGLBLINCVAL + vport_id * 4, inc_val);

	return 0;
}

bool qed_send_qm_stop_cmd(struct qed_hwfn *p_hwfn,
			  struct qed_ptt *p_ptt,
			  bool is_release_cmd,
Y
Yuval Mintz 已提交
980
			  bool is_tx_pq, u16 start_pq, u16 num_pqs)
981 982
{
	u32 cmd_arr[QM_CMD_STRUCT_SIZE(QM_STOP_CMD)] = { 0 };
T
Tomer Tayar 已提交
983 984 985
	u32 pq_mask = 0, last_pq, pq_id;

	last_pq = start_pq + num_pqs - 1;
986

M
Mintz, Yuval 已提交
987
	/* Set command's PQ type */
988 989
	QM_CMD_SET_FIELD(cmd_arr, QM_STOP_CMD, PQ_TYPE, is_tx_pq ? 0 : 1);

T
Tomer Tayar 已提交
990
	/* Go over requested PQs */
991
	for (pq_id = start_pq; pq_id <= last_pq; pq_id++) {
M
Mintz, Yuval 已提交
992
		/* Set PQ bit in mask (stop command only) */
993
		if (!is_release_cmd)
T
Tomer Tayar 已提交
994
			pq_mask |= BIT((pq_id % QM_STOP_PQ_MASK_WIDTH));
995

M
Mintz, Yuval 已提交
996
		/* If last PQ or end of PQ mask, write command */
997 998 999
		if ((pq_id == last_pq) ||
		    (pq_id % QM_STOP_PQ_MASK_WIDTH ==
		     (QM_STOP_PQ_MASK_WIDTH - 1))) {
T
Tomer Tayar 已提交
1000 1001 1002 1003
			QM_CMD_SET_FIELD(cmd_arr,
					 QM_STOP_CMD, PAUSE_MASK, pq_mask);
			QM_CMD_SET_FIELD(cmd_arr,
					 QM_STOP_CMD,
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
					 GROUP_ID,
					 pq_id / QM_STOP_PQ_MASK_WIDTH);
			if (!qed_send_qm_cmd(p_hwfn, p_ptt, QM_STOP_CMD_ADDR,
					     cmd_arr[0], cmd_arr[1]))
				return false;
			pq_mask = 0;
		}
	}

	return true;
}
1015 1016


T
Tomer Tayar 已提交
1017 1018 1019 1020 1021 1022 1023
#define SET_TUNNEL_TYPE_ENABLE_BIT(var, offset, enable) \
	do { \
		typeof(var) *__p_var = &(var); \
		typeof(offset) __offset = offset; \
		*__p_var = (*__p_var & ~BIT(__offset)) | \
			   ((enable) ? BIT(__offset) : 0); \
	} while (0)
M
Michal Kalderon 已提交
1024 1025
#define PRS_ETH_TUNN_OUTPUT_FORMAT        -188897008
#define PRS_ETH_OUTPUT_FORMAT             -46832
1026 1027

void qed_set_vxlan_dest_port(struct qed_hwfn *p_hwfn,
Y
Yuval Mintz 已提交
1028
			     struct qed_ptt *p_ptt, u16 dest_port)
1029
{
T
Tomer Tayar 已提交
1030
	/* Update PRS register */
1031
	qed_wr(p_hwfn, p_ptt, PRS_REG_VXLAN_PORT, dest_port);
T
Tomer Tayar 已提交
1032 1033

	/* Update NIG register */
Y
Yuval Mintz 已提交
1034
	qed_wr(p_hwfn, p_ptt, NIG_REG_VXLAN_CTRL, dest_port);
T
Tomer Tayar 已提交
1035 1036

	/* Update PBF register */
1037 1038 1039 1040
	qed_wr(p_hwfn, p_ptt, PBF_REG_VXLAN_PORT, dest_port);
}

void qed_set_vxlan_enable(struct qed_hwfn *p_hwfn,
Y
Yuval Mintz 已提交
1041
			  struct qed_ptt *p_ptt, bool vxlan_enable)
1042
{
T
Tomer Tayar 已提交
1043
	u32 reg_val;
1044 1045
	u8 shift;

T
Tomer Tayar 已提交
1046
	/* Update PRS register */
1047 1048
	reg_val = qed_rd(p_hwfn, p_ptt, PRS_REG_ENCAPSULATION_TYPE_EN);
	shift = PRS_REG_ENCAPSULATION_TYPE_EN_VXLAN_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1049
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, vxlan_enable);
1050
	qed_wr(p_hwfn, p_ptt, PRS_REG_ENCAPSULATION_TYPE_EN, reg_val);
M
Michal Kalderon 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059
	if (reg_val) {
		reg_val =
		    qed_rd(p_hwfn, p_ptt, PRS_REG_OUTPUT_FORMAT_4_0_BB_K2);

		/* Update output  only if tunnel blocks not included. */
		if (reg_val == (u32)PRS_ETH_OUTPUT_FORMAT)
			qed_wr(p_hwfn, p_ptt, PRS_REG_OUTPUT_FORMAT_4_0_BB_K2,
			       (u32)PRS_ETH_TUNN_OUTPUT_FORMAT);
	}
1060

T
Tomer Tayar 已提交
1061
	/* Update NIG register */
1062 1063
	reg_val = qed_rd(p_hwfn, p_ptt, NIG_REG_ENC_TYPE_ENABLE);
	shift = NIG_REG_ENC_TYPE_ENABLE_VXLAN_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1064
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, vxlan_enable);
1065 1066
	qed_wr(p_hwfn, p_ptt, NIG_REG_ENC_TYPE_ENABLE, reg_val);

T
Tomer Tayar 已提交
1067 1068 1069
	/* Update DORQ register */
	qed_wr(p_hwfn,
	       p_ptt, DORQ_REG_L2_EDPM_TUNNEL_VXLAN_EN, vxlan_enable ? 1 : 0);
1070 1071
}

T
Tomer Tayar 已提交
1072 1073
void qed_set_gre_enable(struct qed_hwfn *p_hwfn,
			struct qed_ptt *p_ptt,
1074 1075
			bool eth_gre_enable, bool ip_gre_enable)
{
T
Tomer Tayar 已提交
1076
	u32 reg_val;
1077 1078
	u8 shift;

T
Tomer Tayar 已提交
1079
	/* Update PRS register */
1080 1081
	reg_val = qed_rd(p_hwfn, p_ptt, PRS_REG_ENCAPSULATION_TYPE_EN);
	shift = PRS_REG_ENCAPSULATION_TYPE_EN_ETH_OVER_GRE_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1082
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, eth_gre_enable);
1083
	shift = PRS_REG_ENCAPSULATION_TYPE_EN_IP_OVER_GRE_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1084
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, ip_gre_enable);
1085
	qed_wr(p_hwfn, p_ptt, PRS_REG_ENCAPSULATION_TYPE_EN, reg_val);
M
Michal Kalderon 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094
	if (reg_val) {
		reg_val =
		    qed_rd(p_hwfn, p_ptt, PRS_REG_OUTPUT_FORMAT_4_0_BB_K2);

		/* Update output  only if tunnel blocks not included. */
		if (reg_val == (u32)PRS_ETH_OUTPUT_FORMAT)
			qed_wr(p_hwfn, p_ptt, PRS_REG_OUTPUT_FORMAT_4_0_BB_K2,
			       (u32)PRS_ETH_TUNN_OUTPUT_FORMAT);
	}
1095

T
Tomer Tayar 已提交
1096
	/* Update NIG register */
1097 1098
	reg_val = qed_rd(p_hwfn, p_ptt, NIG_REG_ENC_TYPE_ENABLE);
	shift = NIG_REG_ENC_TYPE_ENABLE_ETH_OVER_GRE_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1099
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, eth_gre_enable);
1100
	shift = NIG_REG_ENC_TYPE_ENABLE_IP_OVER_GRE_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1101
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, ip_gre_enable);
1102 1103
	qed_wr(p_hwfn, p_ptt, NIG_REG_ENC_TYPE_ENABLE, reg_val);

T
Tomer Tayar 已提交
1104 1105 1106 1107 1108 1109
	/* Update DORQ registers */
	qed_wr(p_hwfn,
	       p_ptt,
	       DORQ_REG_L2_EDPM_TUNNEL_GRE_ETH_EN, eth_gre_enable ? 1 : 0);
	qed_wr(p_hwfn,
	       p_ptt, DORQ_REG_L2_EDPM_TUNNEL_GRE_IP_EN, ip_gre_enable ? 1 : 0);
1110 1111 1112
}

void qed_set_geneve_dest_port(struct qed_hwfn *p_hwfn,
Y
Yuval Mintz 已提交
1113
			      struct qed_ptt *p_ptt, u16 dest_port)
1114
{
T
Tomer Tayar 已提交
1115
	/* Update PRS register */
1116
	qed_wr(p_hwfn, p_ptt, PRS_REG_NGE_PORT, dest_port);
T
Tomer Tayar 已提交
1117 1118

	/* Update NIG register */
1119
	qed_wr(p_hwfn, p_ptt, NIG_REG_NGE_PORT, dest_port);
T
Tomer Tayar 已提交
1120 1121

	/* Update PBF register */
1122 1123 1124 1125 1126
	qed_wr(p_hwfn, p_ptt, PBF_REG_NGE_PORT, dest_port);
}

void qed_set_geneve_enable(struct qed_hwfn *p_hwfn,
			   struct qed_ptt *p_ptt,
Y
Yuval Mintz 已提交
1127
			   bool eth_geneve_enable, bool ip_geneve_enable)
1128
{
T
Tomer Tayar 已提交
1129
	u32 reg_val;
1130 1131
	u8 shift;

T
Tomer Tayar 已提交
1132
	/* Update PRS register */
1133 1134
	reg_val = qed_rd(p_hwfn, p_ptt, PRS_REG_ENCAPSULATION_TYPE_EN);
	shift = PRS_REG_ENCAPSULATION_TYPE_EN_ETH_OVER_GENEVE_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1135
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, eth_geneve_enable);
1136
	shift = PRS_REG_ENCAPSULATION_TYPE_EN_IP_OVER_GENEVE_ENABLE_SHIFT;
T
Tomer Tayar 已提交
1137
	SET_TUNNEL_TYPE_ENABLE_BIT(reg_val, shift, ip_geneve_enable);
1138
	qed_wr(p_hwfn, p_ptt, PRS_REG_ENCAPSULATION_TYPE_EN, reg_val);
M
Michal Kalderon 已提交
1139 1140 1141 1142 1143 1144 1145 1146 1147
	if (reg_val) {
		reg_val =
		    qed_rd(p_hwfn, p_ptt, PRS_REG_OUTPUT_FORMAT_4_0_BB_K2);

		/* Update output  only if tunnel blocks not included. */
		if (reg_val == (u32)PRS_ETH_OUTPUT_FORMAT)
			qed_wr(p_hwfn, p_ptt, PRS_REG_OUTPUT_FORMAT_4_0_BB_K2,
			       (u32)PRS_ETH_TUNN_OUTPUT_FORMAT);
	}
1148

T
Tomer Tayar 已提交
1149
	/* Update NIG register */
1150 1151 1152 1153
	qed_wr(p_hwfn, p_ptt, NIG_REG_NGE_ETH_ENABLE,
	       eth_geneve_enable ? 1 : 0);
	qed_wr(p_hwfn, p_ptt, NIG_REG_NGE_IP_ENABLE, ip_geneve_enable ? 1 : 0);

T
Tomer Tayar 已提交
1154
	/* EDPM with geneve tunnel not supported in BB */
1155 1156 1157
	if (QED_IS_BB_B0(p_hwfn->cdev))
		return;

T
Tomer Tayar 已提交
1158 1159 1160 1161
	/* Update DORQ registers */
	qed_wr(p_hwfn,
	       p_ptt,
	       DORQ_REG_L2_EDPM_TUNNEL_NGE_ETH_EN_K2_E5,
1162
	       eth_geneve_enable ? 1 : 0);
T
Tomer Tayar 已提交
1163 1164 1165
	qed_wr(p_hwfn,
	       p_ptt,
	       DORQ_REG_L2_EDPM_TUNNEL_NGE_IP_EN_K2_E5,
1166 1167
	       ip_geneve_enable ? 1 : 0);
}
1168

M
Michal Kalderon 已提交
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
#define PRS_ETH_VXLAN_NO_L2_ENABLE_OFFSET   4
#define PRS_ETH_VXLAN_NO_L2_OUTPUT_FORMAT      -927094512

void qed_set_vxlan_no_l2_enable(struct qed_hwfn *p_hwfn,
				struct qed_ptt *p_ptt, bool enable)
{
	u32 reg_val, cfg_mask;

	/* read PRS config register */
	reg_val = qed_rd(p_hwfn, p_ptt, PRS_REG_MSG_INFO);

	/* set VXLAN_NO_L2_ENABLE mask */
	cfg_mask = BIT(PRS_ETH_VXLAN_NO_L2_ENABLE_OFFSET);

	if (enable) {
		/* set VXLAN_NO_L2_ENABLE flag */
		reg_val |= cfg_mask;

		/* update PRS FIC  register */
		qed_wr(p_hwfn,
		       p_ptt,
		       PRS_REG_OUTPUT_FORMAT_4_0_BB_K2,
		       (u32)PRS_ETH_VXLAN_NO_L2_OUTPUT_FORMAT);
	} else {
		/* clear VXLAN_NO_L2_ENABLE flag */
		reg_val &= ~cfg_mask;
	}

	/* write PRS config register */
	qed_wr(p_hwfn, p_ptt, PRS_REG_MSG_INFO, reg_val);
}

M
Mintz, Yuval 已提交
1201 1202
#define T_ETH_PACKET_ACTION_GFT_EVENTID  23
#define PARSER_ETH_CONN_GFT_ACTION_CM_HDR  272
1203
#define T_ETH_PACKET_MATCH_RFS_EVENTID 25
M
Mintz, Yuval 已提交
1204
#define PARSER_ETH_CONN_CM_HDR 0
1205 1206 1207 1208
#define CAM_LINE_SIZE sizeof(u32)
#define RAM_LINE_SIZE sizeof(u64)
#define REG_SIZE sizeof(u32)

T
Tomer Tayar 已提交
1209
void qed_gft_disable(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, u16 pf_id)
1210
{
T
Tomer Tayar 已提交
1211
	/* Disable gft search for PF */
1212
	qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_GFT, 0);
T
Tomer Tayar 已提交
1213 1214 1215 1216

	/* Clean ram & cam for next gft session */

	/* Zero camline */
M
Mintz, Yuval 已提交
1217
	qed_wr(p_hwfn, p_ptt, PRS_REG_GFT_CAM + CAM_LINE_SIZE * pf_id, 0);
T
Tomer Tayar 已提交
1218 1219 1220 1221 1222 1223 1224 1225

	/* Zero ramline */
	qed_wr(p_hwfn,
	       p_ptt, PRS_REG_GFT_PROFILE_MASK_RAM + RAM_LINE_SIZE * pf_id, 0);
	qed_wr(p_hwfn,
	       p_ptt,
	       PRS_REG_GFT_PROFILE_MASK_RAM + RAM_LINE_SIZE * pf_id + REG_SIZE,
	       0);
1226 1227
}

T
Tomer Tayar 已提交
1228 1229 1230 1231 1232 1233 1234
void qed_gft_config(struct qed_hwfn *p_hwfn,
		    struct qed_ptt *p_ptt,
		    u16 pf_id,
		    bool tcp,
		    bool udp,
		    bool ipv4, bool ipv6, enum gft_profile_type profile_type)
{
M
Michal Kalderon 已提交
1235
	u32 reg_val, cam_line, ram_line_lo, ram_line_hi, search_non_ip_as_gft;
1236 1237 1238

	if (!ipv6 && !ipv4)
		DP_NOTICE(p_hwfn,
T
Tomer Tayar 已提交
1239
			  "gft_config: must accept at least on of - ipv4 or ipv6'\n");
1240 1241
	if (!tcp && !udp)
		DP_NOTICE(p_hwfn,
T
Tomer Tayar 已提交
1242 1243 1244
			  "gft_config: must accept at least on of - udp or tcp\n");
	if (profile_type >= MAX_GFT_PROFILE_TYPE)
		DP_NOTICE(p_hwfn, "gft_config: unsupported gft_profile_type\n");
1245

T
Tomer Tayar 已提交
1246 1247 1248 1249 1250
	/* Set RFS event ID to be awakened i Tstorm By Prs */
	reg_val = T_ETH_PACKET_MATCH_RFS_EVENTID <<
		  PRS_REG_CM_HDR_GFT_EVENT_ID_SHIFT;
	reg_val |= PARSER_ETH_CONN_CM_HDR << PRS_REG_CM_HDR_GFT_CM_HDR_SHIFT;
	qed_wr(p_hwfn, p_ptt, PRS_REG_CM_HDR_GFT, reg_val);
1251

T
Tomer Tayar 已提交
1252
	/* Do not load context only cid in PRS on match. */
1253 1254
	qed_wr(p_hwfn, p_ptt, PRS_REG_LOAD_L2_FILTER, 0);

T
Tomer Tayar 已提交
1255 1256 1257 1258 1259 1260
	/* Do not use tenant ID exist bit for gft search */
	qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TENANT_ID, 0);

	/* Set Cam */
	cam_line = 0;
	SET_FIELD(cam_line, GFT_CAM_LINE_MAPPED_VALID, 1);
1261

T
Tomer Tayar 已提交
1262 1263
	/* Filters are per PF!! */
	SET_FIELD(cam_line,
M
Mintz, Yuval 已提交
1264 1265
		  GFT_CAM_LINE_MAPPED_PF_ID_MASK,
		  GFT_CAM_LINE_MAPPED_PF_ID_MASK_MASK);
T
Tomer Tayar 已提交
1266 1267
	SET_FIELD(cam_line, GFT_CAM_LINE_MAPPED_PF_ID, pf_id);

1268
	if (!(tcp && udp)) {
T
Tomer Tayar 已提交
1269
		SET_FIELD(cam_line,
M
Mintz, Yuval 已提交
1270 1271
			  GFT_CAM_LINE_MAPPED_UPPER_PROTOCOL_TYPE_MASK,
			  GFT_CAM_LINE_MAPPED_UPPER_PROTOCOL_TYPE_MASK_MASK);
1272
		if (tcp)
T
Tomer Tayar 已提交
1273
			SET_FIELD(cam_line,
1274 1275 1276
				  GFT_CAM_LINE_MAPPED_UPPER_PROTOCOL_TYPE,
				  GFT_PROFILE_TCP_PROTOCOL);
		else
T
Tomer Tayar 已提交
1277
			SET_FIELD(cam_line,
1278 1279 1280 1281 1282
				  GFT_CAM_LINE_MAPPED_UPPER_PROTOCOL_TYPE,
				  GFT_PROFILE_UDP_PROTOCOL);
	}

	if (!(ipv4 && ipv6)) {
T
Tomer Tayar 已提交
1283
		SET_FIELD(cam_line, GFT_CAM_LINE_MAPPED_IP_VERSION_MASK, 1);
1284
		if (ipv4)
T
Tomer Tayar 已提交
1285
			SET_FIELD(cam_line,
1286 1287 1288
				  GFT_CAM_LINE_MAPPED_IP_VERSION,
				  GFT_PROFILE_IPV4);
		else
T
Tomer Tayar 已提交
1289
			SET_FIELD(cam_line,
1290 1291 1292 1293
				  GFT_CAM_LINE_MAPPED_IP_VERSION,
				  GFT_PROFILE_IPV6);
	}

M
Mintz, Yuval 已提交
1294
	/* Write characteristics to cam */
1295
	qed_wr(p_hwfn, p_ptt, PRS_REG_GFT_CAM + CAM_LINE_SIZE * pf_id,
T
Tomer Tayar 已提交
1296 1297 1298
	       cam_line);
	cam_line =
	    qed_rd(p_hwfn, p_ptt, PRS_REG_GFT_CAM + CAM_LINE_SIZE * pf_id);
1299

M
Mintz, Yuval 已提交
1300
	/* Write line to RAM - compare to filter 4 tuple */
T
Tomer Tayar 已提交
1301 1302 1303
	ram_line_lo = 0;
	ram_line_hi = 0;

M
Michal Kalderon 已提交
1304 1305 1306
	/* Search no IP as GFT */
	search_non_ip_as_gft = 0;

M
Michal Kalderon 已提交
1307 1308 1309 1310
	/* Tunnel type */
	SET_FIELD(ram_line_lo, GFT_RAM_LINE_TUNNEL_DST_PORT, 1);
	SET_FIELD(ram_line_lo, GFT_RAM_LINE_TUNNEL_OVER_IP_PROTOCOL, 1);

T
Tomer Tayar 已提交
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
	if (profile_type == GFT_PROFILE_TYPE_4_TUPLE) {
		SET_FIELD(ram_line_hi, GFT_RAM_LINE_DST_IP, 1);
		SET_FIELD(ram_line_hi, GFT_RAM_LINE_SRC_IP, 1);
		SET_FIELD(ram_line_hi, GFT_RAM_LINE_OVER_IP_PROTOCOL, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_ETHERTYPE, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_SRC_PORT, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_DST_PORT, 1);
	} else if (profile_type == GFT_PROFILE_TYPE_L4_DST_PORT) {
		SET_FIELD(ram_line_hi, GFT_RAM_LINE_OVER_IP_PROTOCOL, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_ETHERTYPE, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_DST_PORT, 1);
M
Michal Kalderon 已提交
1322
	} else if (profile_type == GFT_PROFILE_TYPE_IP_DST_ADDR) {
T
Tomer Tayar 已提交
1323 1324
		SET_FIELD(ram_line_hi, GFT_RAM_LINE_DST_IP, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_ETHERTYPE, 1);
M
Michal Kalderon 已提交
1325 1326 1327 1328 1329
	} else if (profile_type == GFT_PROFILE_TYPE_IP_SRC_ADDR) {
		SET_FIELD(ram_line_hi, GFT_RAM_LINE_SRC_IP, 1);
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_ETHERTYPE, 1);
	} else if (profile_type == GFT_PROFILE_TYPE_TUNNEL_TYPE) {
		SET_FIELD(ram_line_lo, GFT_RAM_LINE_TUNNEL_ETHERTYPE, 1);
M
Michal Kalderon 已提交
1330 1331 1332

		/* Allow tunneled traffic without inner IP */
		search_non_ip_as_gft = 1;
T
Tomer Tayar 已提交
1333 1334
	}

M
Michal Kalderon 已提交
1335 1336
	qed_wr(p_hwfn,
	       p_ptt, PRS_REG_SEARCH_NON_IP_AS_GFT, search_non_ip_as_gft);
T
Tomer Tayar 已提交
1337 1338
	qed_wr(p_hwfn,
	       p_ptt,
M
Mintz, Yuval 已提交
1339
	       PRS_REG_GFT_PROFILE_MASK_RAM + RAM_LINE_SIZE * pf_id,
T
Tomer Tayar 已提交
1340 1341 1342 1343 1344
	       ram_line_lo);
	qed_wr(p_hwfn,
	       p_ptt,
	       PRS_REG_GFT_PROFILE_MASK_RAM + RAM_LINE_SIZE * pf_id + REG_SIZE,
	       ram_line_hi);
M
Mintz, Yuval 已提交
1345 1346

	/* Set default profile so that no filter match will happen */
T
Tomer Tayar 已提交
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
	qed_wr(p_hwfn,
	       p_ptt,
	       PRS_REG_GFT_PROFILE_MASK_RAM + RAM_LINE_SIZE *
	       PRS_GFT_CAM_LINES_NO_MATCH, 0xffffffff);
	qed_wr(p_hwfn,
	       p_ptt,
	       PRS_REG_GFT_PROFILE_MASK_RAM + RAM_LINE_SIZE *
	       PRS_GFT_CAM_LINES_NO_MATCH + REG_SIZE, 0x3ff);

	/* Enable gft search */
	qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_GFT, 1);
}

DECLARE_CRC8_TABLE(cdu_crc8_table);

/* Calculate and return CDU validation byte per connection type/region/cid */
static u8 qed_calc_cdu_validation_byte(u8 conn_type, u8 region, u32 cid)
{
	const u8 validation_cfg = CDU_VALIDATION_DEFAULT_CFG;
	u8 crc, validation_byte = 0;
	static u8 crc8_table_valid; /* automatically initialized to 0 */
	u32 validation_string = 0;
	u32 data_to_crc;

	if (!crc8_table_valid) {
		crc8_populate_msb(cdu_crc8_table, 0x07);
		crc8_table_valid = 1;
	}

	/* The CRC is calculated on the String-to-compress:
	 * [31:8]  = {CID[31:20],CID[11:0]}
	 * [7:4]   = Region
	 * [3:0]   = Type
	 */
	if ((validation_cfg >> CDU_CONTEXT_VALIDATION_CFG_USE_CID) & 1)
		validation_string |= (cid & 0xFFF00000) | ((cid & 0xFFF) << 8);

	if ((validation_cfg >> CDU_CONTEXT_VALIDATION_CFG_USE_REGION) & 1)
		validation_string |= ((region & 0xF) << 4);

	if ((validation_cfg >> CDU_CONTEXT_VALIDATION_CFG_USE_TYPE) & 1)
		validation_string |= (conn_type & 0xF);

	/* Convert to big-endian and calculate CRC8 */
	data_to_crc = be32_to_cpu(validation_string);

	crc = crc8(cdu_crc8_table,
		   (u8 *)&data_to_crc, sizeof(data_to_crc), CRC8_INIT_VALUE);

	/* The validation byte [7:0] is composed:
	 * for type A validation
	 * [7]          = active configuration bit
	 * [6:0]        = crc[6:0]
	 *
	 * for type B validation
	 * [7]          = active configuration bit
	 * [6:3]        = connection_type[3:0]
	 * [2:0]        = crc[2:0]
	 */
	validation_byte |=
	    ((validation_cfg >>
	      CDU_CONTEXT_VALIDATION_CFG_USE_ACTIVE) & 1) << 7;

	if ((validation_cfg >>
	     CDU_CONTEXT_VALIDATION_CFG_VALIDATION_TYPE_SHIFT) & 1)
		validation_byte |= ((conn_type & 0xF) << 3) | (crc & 0x7);
	else
		validation_byte |= crc & 0x7F;

	return validation_byte;
}

/* Calcualte and set validation bytes for session context */
void qed_calc_session_ctx_validation(void *p_ctx_mem,
				     u16 ctx_size, u8 ctx_type, u32 cid)
{
	u8 *x_val_ptr, *t_val_ptr, *u_val_ptr, *p_ctx;

	p_ctx = (u8 * const)p_ctx_mem;
	x_val_ptr = &p_ctx[con_region_offsets[0][ctx_type]];
	t_val_ptr = &p_ctx[con_region_offsets[1][ctx_type]];
	u_val_ptr = &p_ctx[con_region_offsets[2][ctx_type]];

	memset(p_ctx, 0, ctx_size);

	*x_val_ptr = qed_calc_cdu_validation_byte(ctx_type, 3, cid);
	*t_val_ptr = qed_calc_cdu_validation_byte(ctx_type, 4, cid);
	*u_val_ptr = qed_calc_cdu_validation_byte(ctx_type, 5, cid);
}

/* Calcualte and set validation bytes for task context */
void qed_calc_task_ctx_validation(void *p_ctx_mem,
				  u16 ctx_size, u8 ctx_type, u32 tid)
{
	u8 *p_ctx, *region1_val_ptr;

	p_ctx = (u8 * const)p_ctx_mem;
	region1_val_ptr = &p_ctx[task_region_offsets[0][ctx_type]];

	memset(p_ctx, 0, ctx_size);

	*region1_val_ptr = qed_calc_cdu_validation_byte(ctx_type, 1, tid);
}

/* Memset session context to 0 while preserving validation bytes */
void qed_memset_session_ctx(void *p_ctx_mem, u32 ctx_size, u8 ctx_type)
{
	u8 *x_val_ptr, *t_val_ptr, *u_val_ptr, *p_ctx;
	u8 x_val, t_val, u_val;

	p_ctx = (u8 * const)p_ctx_mem;
	x_val_ptr = &p_ctx[con_region_offsets[0][ctx_type]];
	t_val_ptr = &p_ctx[con_region_offsets[1][ctx_type]];
	u_val_ptr = &p_ctx[con_region_offsets[2][ctx_type]];

	x_val = *x_val_ptr;
	t_val = *t_val_ptr;
	u_val = *u_val_ptr;

	memset(p_ctx, 0, ctx_size);

	*x_val_ptr = x_val;
	*t_val_ptr = t_val;
	*u_val_ptr = u_val;
}

/* Memset task context to 0 while preserving validation bytes */
void qed_memset_task_ctx(void *p_ctx_mem, u32 ctx_size, u8 ctx_type)
{
	u8 *p_ctx, *region1_val_ptr;
	u8 region1_val;

	p_ctx = (u8 * const)p_ctx_mem;
	region1_val_ptr = &p_ctx[task_region_offsets[0][ctx_type]];

	region1_val = *region1_val_ptr;

	memset(p_ctx, 0, ctx_size);

	*region1_val_ptr = region1_val;
}

/* Enable and configure context validation */
void qed_enable_context_validation(struct qed_hwfn *p_hwfn,
				   struct qed_ptt *p_ptt)
{
	u32 ctx_validation;

	/* Enable validation for connection region 3: CCFC_CTX_VALID0[31:24] */
	ctx_validation = CDU_VALIDATION_DEFAULT_CFG << 24;
	qed_wr(p_hwfn, p_ptt, CDU_REG_CCFC_CTX_VALID0, ctx_validation);

	/* Enable validation for connection region 5: CCFC_CTX_VALID1[15:8] */
	ctx_validation = CDU_VALIDATION_DEFAULT_CFG << 8;
	qed_wr(p_hwfn, p_ptt, CDU_REG_CCFC_CTX_VALID1, ctx_validation);

	/* Enable validation for connection region 1: TCFC_CTX_VALID0[15:8] */
	ctx_validation = CDU_VALIDATION_DEFAULT_CFG << 8;
	qed_wr(p_hwfn, p_ptt, CDU_REG_TCFC_CTX_VALID0, ctx_validation);
1506
}
M
Michal Kalderon 已提交
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546

static u32 qed_get_rdma_assert_ram_addr(struct qed_hwfn *p_hwfn, u8 storm_id)
{
	switch (storm_id) {
	case 0:
		return TSEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM +
		    TSTORM_RDMA_ASSERT_LEVEL_OFFSET(p_hwfn->rel_pf_id);
	case 1:
		return MSEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM +
		    MSTORM_RDMA_ASSERT_LEVEL_OFFSET(p_hwfn->rel_pf_id);
	case 2:
		return USEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM +
		    USTORM_RDMA_ASSERT_LEVEL_OFFSET(p_hwfn->rel_pf_id);
	case 3:
		return XSEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM +
		    XSTORM_RDMA_ASSERT_LEVEL_OFFSET(p_hwfn->rel_pf_id);
	case 4:
		return YSEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM +
		    YSTORM_RDMA_ASSERT_LEVEL_OFFSET(p_hwfn->rel_pf_id);
	case 5:
		return PSEM_REG_FAST_MEMORY + SEM_FAST_REG_INT_RAM +
		    PSTORM_RDMA_ASSERT_LEVEL_OFFSET(p_hwfn->rel_pf_id);

	default:
		return 0;
	}
}

void qed_set_rdma_error_level(struct qed_hwfn *p_hwfn,
			      struct qed_ptt *p_ptt,
			      u8 assert_level[NUM_STORMS])
{
	u8 storm_id;

	for (storm_id = 0; storm_id < NUM_STORMS; storm_id++) {
		u32 ram_addr = qed_get_rdma_assert_ram_addr(p_hwfn, storm_id);

		qed_wr(p_hwfn, p_ptt, ram_addr, assert_level[storm_id]);
	}
}