2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
11 #include "ecore_gtt_reg_addr.h"
13 #include "ecore_chain.h"
14 #include "ecore_status.h"
16 #include "ecore_rt_defs.h"
17 #include "ecore_init_ops.h"
18 #include "ecore_int.h"
19 #include "ecore_cxt.h"
20 #include "ecore_spq.h"
21 #include "ecore_init_fw_funcs.h"
22 #include "ecore_sp_commands.h"
23 #include "ecore_dev_api.h"
24 #include "ecore_sriov.h"
26 #include "ecore_mcp.h"
27 #include "ecore_hw_defs.h"
28 #include "mcp_public.h"
29 #include "ecore_iro.h"
31 #include "ecore_dev_api.h"
32 #include "ecore_attn_values.h"
35 #define ECORE_MIN_DPIS (4) /* The minimal number of DPIs required
36 * load the driver. The number was
41 #define ECORE_MIN_PWM_REGION ((ECORE_WID_SIZE) * (ECORE_MIN_DPIS))
44 BAR_ID_0, /* used for GRC */
45 BAR_ID_1 /* Used for doorbells */
48 static u32 ecore_hw_bar_size(struct ecore_hwfn *p_hwfn, enum BAR_ID bar_id)
50 u32 bar_reg = (bar_id == BAR_ID_0 ?
51 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
52 u32 val = ecore_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
54 /* The above registers were updated in the past only in CMT mode. Since
55 * they were found to be useful MFW started updating them from 8.7.7.0.
56 * In older MFW versions they are set to 0 which means disabled.
59 if (p_hwfn->p_dev->num_hwfns > 1) {
60 DP_NOTICE(p_hwfn, false,
61 "BAR size not configured. Assuming BAR"
62 " size of 256kB for GRC and 512kB for DB\n");
63 return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
66 DP_NOTICE(p_hwfn, false,
67 "BAR size not configured. Assuming BAR"
68 " size of 512kB for GRC and 512kB for DB\n");
72 return 1 << (val + 15);
75 void ecore_init_dp(struct ecore_dev *p_dev,
76 u32 dp_module, u8 dp_level, void *dp_ctx)
80 p_dev->dp_level = dp_level;
81 p_dev->dp_module = dp_module;
82 p_dev->dp_ctx = dp_ctx;
83 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
84 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
86 p_hwfn->dp_level = dp_level;
87 p_hwfn->dp_module = dp_module;
88 p_hwfn->dp_ctx = dp_ctx;
92 void ecore_init_struct(struct ecore_dev *p_dev)
96 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
97 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
99 p_hwfn->p_dev = p_dev;
101 p_hwfn->b_active = false;
103 OSAL_MUTEX_ALLOC(p_hwfn, &p_hwfn->dmae_info.mutex);
104 OSAL_MUTEX_INIT(&p_hwfn->dmae_info.mutex);
107 /* hwfn 0 is always active */
108 p_dev->hwfns[0].b_active = true;
110 /* set the default cache alignment to 128 (may be overridden later) */
111 p_dev->cache_shift = 7;
114 static void ecore_qm_info_free(struct ecore_hwfn *p_hwfn)
116 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
118 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_pq_params);
119 qm_info->qm_pq_params = OSAL_NULL;
120 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_vport_params);
121 qm_info->qm_vport_params = OSAL_NULL;
122 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_port_params);
123 qm_info->qm_port_params = OSAL_NULL;
124 OSAL_FREE(p_hwfn->p_dev, qm_info->wfq_data);
125 qm_info->wfq_data = OSAL_NULL;
128 void ecore_resc_free(struct ecore_dev *p_dev)
135 OSAL_FREE(p_dev, p_dev->fw_data);
136 p_dev->fw_data = OSAL_NULL;
138 OSAL_FREE(p_dev, p_dev->reset_stats);
140 for_each_hwfn(p_dev, i) {
141 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
143 OSAL_FREE(p_dev, p_hwfn->p_tx_cids);
144 p_hwfn->p_tx_cids = OSAL_NULL;
145 OSAL_FREE(p_dev, p_hwfn->p_rx_cids);
146 p_hwfn->p_rx_cids = OSAL_NULL;
149 for_each_hwfn(p_dev, i) {
150 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
152 ecore_cxt_mngr_free(p_hwfn);
153 ecore_qm_info_free(p_hwfn);
154 ecore_spq_free(p_hwfn);
155 ecore_eq_free(p_hwfn, p_hwfn->p_eq);
156 ecore_consq_free(p_hwfn, p_hwfn->p_consq);
157 ecore_int_free(p_hwfn);
158 ecore_iov_free(p_hwfn);
159 ecore_dmae_info_free(p_hwfn);
160 /* @@@TBD Flush work-queue ? */
164 static enum _ecore_status_t ecore_init_qm_info(struct ecore_hwfn *p_hwfn,
167 u8 num_vports, vf_offset = 0, i, vport_id, num_ports;
168 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
169 struct init_qm_port_params *p_qm_port;
170 u16 num_pqs, multi_cos_tcs = 1;
171 #ifdef CONFIG_ECORE_SRIOV
172 u16 num_vfs = p_hwfn->p_dev->sriov_info.total_vfs;
177 OSAL_MEM_ZERO(qm_info, sizeof(*qm_info));
180 /* @TMP - Don't allocate QM queues for VFs on emulation */
181 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
182 DP_NOTICE(p_hwfn, false,
183 "Emulation - skip configuring QM queues for VFs\n");
188 num_pqs = multi_cos_tcs + num_vfs + 1; /* The '1' is for pure-LB */
189 num_vports = (u8)RESC_NUM(p_hwfn, ECORE_VPORT);
191 /* Sanity checking that setup requires legal number of resources */
192 if (num_pqs > RESC_NUM(p_hwfn, ECORE_PQ)) {
194 "Need too many Physical queues - 0x%04x when"
195 " only %04x are available\n",
196 num_pqs, RESC_NUM(p_hwfn, ECORE_PQ));
200 /* PQs will be arranged as follows: First per-TC PQ, then pure-LB queue,
201 * then special queues, then per-VF PQ.
203 qm_info->qm_pq_params = OSAL_ZALLOC(p_hwfn->p_dev,
204 b_sleepable ? GFP_KERNEL :
206 sizeof(struct init_qm_pq_params) *
208 if (!qm_info->qm_pq_params)
211 qm_info->qm_vport_params = OSAL_ZALLOC(p_hwfn->p_dev,
212 b_sleepable ? GFP_KERNEL :
215 init_qm_vport_params) *
217 if (!qm_info->qm_vport_params)
220 qm_info->qm_port_params = OSAL_ZALLOC(p_hwfn->p_dev,
221 b_sleepable ? GFP_KERNEL :
223 sizeof(struct init_qm_port_params)
225 if (!qm_info->qm_port_params)
228 qm_info->wfq_data = OSAL_ZALLOC(p_hwfn->p_dev,
229 b_sleepable ? GFP_KERNEL :
231 sizeof(struct ecore_wfq_data) *
234 if (!qm_info->wfq_data)
237 vport_id = (u8)RESC_START(p_hwfn, ECORE_VPORT);
239 /* First init per-TC PQs */
240 for (i = 0; i < multi_cos_tcs; i++) {
241 struct init_qm_pq_params *params = &qm_info->qm_pq_params[i];
243 if (p_hwfn->hw_info.personality == ECORE_PCI_ETH) {
244 params->vport_id = vport_id;
245 params->tc_id = p_hwfn->hw_info.non_offload_tc;
246 params->wrr_group = 1; /* @@@TBD ECORE_WRR_MEDIUM */
248 params->vport_id = vport_id;
249 params->tc_id = p_hwfn->hw_info.offload_tc;
250 params->wrr_group = 1; /* @@@TBD ECORE_WRR_MEDIUM */
254 /* Then init pure-LB PQ */
255 qm_info->pure_lb_pq = i;
256 qm_info->qm_pq_params[i].vport_id =
257 (u8)RESC_START(p_hwfn, ECORE_VPORT);
258 qm_info->qm_pq_params[i].tc_id = PURE_LB_TC;
259 qm_info->qm_pq_params[i].wrr_group = 1;
262 /* Then init per-VF PQs */
264 for (i = 0; i < num_vfs; i++) {
265 /* First vport is used by the PF */
266 qm_info->qm_pq_params[vf_offset + i].vport_id = vport_id +
268 qm_info->qm_pq_params[vf_offset + i].tc_id =
269 p_hwfn->hw_info.non_offload_tc;
270 qm_info->qm_pq_params[vf_offset + i].wrr_group = 1;
273 qm_info->vf_queues_offset = vf_offset;
274 qm_info->num_pqs = num_pqs;
275 qm_info->num_vports = num_vports;
277 /* Initialize qm port parameters */
278 num_ports = p_hwfn->p_dev->num_ports_in_engines;
279 for (i = 0; i < num_ports; i++) {
280 p_qm_port = &qm_info->qm_port_params[i];
281 p_qm_port->active = 1;
283 p_qm_port->num_active_phys_tcs = 2;
285 p_qm_port->num_active_phys_tcs = 5;
286 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
287 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
290 if (ECORE_IS_AH(p_hwfn->p_dev) && (num_ports == 4))
291 qm_info->max_phys_tcs_per_port = NUM_PHYS_TCS_4PORT_K2;
293 qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
295 qm_info->start_pq = (u16)RESC_START(p_hwfn, ECORE_PQ);
297 qm_info->num_vf_pqs = num_vfs;
298 qm_info->start_vport = (u8)RESC_START(p_hwfn, ECORE_VPORT);
300 for (i = 0; i < qm_info->num_vports; i++)
301 qm_info->qm_vport_params[i].vport_wfq = 1;
305 qm_info->vport_rl_en = 1;
306 qm_info->vport_wfq_en = 1;
308 return ECORE_SUCCESS;
311 DP_NOTICE(p_hwfn, false, "Failed to allocate memory for QM params\n");
312 ecore_qm_info_free(p_hwfn);
316 /* This function reconfigures the QM pf on the fly.
317 * For this purpose we:
318 * 1. reconfigure the QM database
319 * 2. set new values to runtime arrat
320 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
321 * 4. activate init tool in QM_PF stage
322 * 5. send an sdm_qm_cmd through rbc interface to release the QM
324 enum _ecore_status_t ecore_qm_reconf(struct ecore_hwfn *p_hwfn,
325 struct ecore_ptt *p_ptt)
327 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
328 enum _ecore_status_t rc;
331 /* qm_info is allocated in ecore_init_qm_info() which is already called
332 * from ecore_resc_alloc() or previous call of ecore_qm_reconf().
333 * The allocated size may change each init, so we free it before next
336 ecore_qm_info_free(p_hwfn);
338 /* initialize ecore's qm data structure */
339 rc = ecore_init_qm_info(p_hwfn, false);
340 if (rc != ECORE_SUCCESS)
343 /* stop PF's qm queues */
344 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
345 qm_info->start_pq, qm_info->num_pqs);
349 /* clear the QM_PF runtime phase leftovers from previous init */
350 ecore_init_clear_rt_data(p_hwfn);
352 /* prepare QM portion of runtime array */
353 ecore_qm_init_pf(p_hwfn);
355 /* activate init tool on runtime array */
356 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
357 p_hwfn->hw_info.hw_mode);
358 if (rc != ECORE_SUCCESS)
361 /* start PF's qm queues */
362 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
363 qm_info->start_pq, qm_info->num_pqs);
367 return ECORE_SUCCESS;
370 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev)
372 enum _ecore_status_t rc = ECORE_SUCCESS;
373 struct ecore_consq *p_consq;
374 struct ecore_eq *p_eq;
380 p_dev->fw_data = OSAL_ZALLOC(p_dev, GFP_KERNEL,
381 sizeof(struct ecore_fw_data));
385 /* Allocate Memory for the Queue->CID mapping */
386 for_each_hwfn(p_dev, i) {
387 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
389 /* @@@TMP - resc management, change to actual required size */
390 int tx_size = sizeof(struct ecore_hw_cid_data) *
391 RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
392 int rx_size = sizeof(struct ecore_hw_cid_data) *
393 RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
395 p_hwfn->p_tx_cids = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
397 if (!p_hwfn->p_tx_cids) {
398 DP_NOTICE(p_hwfn, true,
399 "Failed to allocate memory for Tx Cids\n");
403 p_hwfn->p_rx_cids = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
405 if (!p_hwfn->p_rx_cids) {
406 DP_NOTICE(p_hwfn, true,
407 "Failed to allocate memory for Rx Cids\n");
412 for_each_hwfn(p_dev, i) {
413 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
415 /* First allocate the context manager structure */
416 rc = ecore_cxt_mngr_alloc(p_hwfn);
420 /* Set the HW cid/tid numbers (in the contest manager)
421 * Must be done prior to any further computations.
423 rc = ecore_cxt_set_pf_params(p_hwfn);
427 /* Prepare and process QM requirements */
428 rc = ecore_init_qm_info(p_hwfn, true);
432 /* Compute the ILT client partition */
433 rc = ecore_cxt_cfg_ilt_compute(p_hwfn);
437 /* CID map / ILT shadow table / T2
438 * The talbes sizes are determined by the computations above
440 rc = ecore_cxt_tables_alloc(p_hwfn);
444 /* SPQ, must follow ILT because initializes SPQ context */
445 rc = ecore_spq_alloc(p_hwfn);
449 /* SP status block allocation */
450 p_hwfn->p_dpc_ptt = ecore_get_reserved_ptt(p_hwfn,
453 rc = ecore_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
457 rc = ecore_iov_alloc(p_hwfn);
462 p_eq = ecore_eq_alloc(p_hwfn, 256);
467 p_consq = ecore_consq_alloc(p_hwfn);
470 p_hwfn->p_consq = p_consq;
472 /* DMA info initialization */
473 rc = ecore_dmae_info_alloc(p_hwfn);
475 DP_NOTICE(p_hwfn, true,
476 "Failed to allocate memory for"
477 " dmae_info structure\n");
482 p_dev->reset_stats = OSAL_ZALLOC(p_dev, GFP_KERNEL,
483 sizeof(struct ecore_eth_stats));
484 if (!p_dev->reset_stats) {
485 DP_NOTICE(p_dev, true, "Failed to allocate reset statistics\n");
489 return ECORE_SUCCESS;
494 ecore_resc_free(p_dev);
498 void ecore_resc_setup(struct ecore_dev *p_dev)
505 for_each_hwfn(p_dev, i) {
506 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
508 ecore_cxt_mngr_setup(p_hwfn);
509 ecore_spq_setup(p_hwfn);
510 ecore_eq_setup(p_hwfn, p_hwfn->p_eq);
511 ecore_consq_setup(p_hwfn, p_hwfn->p_consq);
513 /* Read shadow of current MFW mailbox */
514 ecore_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
515 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
516 p_hwfn->mcp_info->mfw_mb_cur,
517 p_hwfn->mcp_info->mfw_mb_length);
519 ecore_int_setup(p_hwfn, p_hwfn->p_main_ptt);
521 ecore_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
525 #define FINAL_CLEANUP_POLL_CNT (100)
526 #define FINAL_CLEANUP_POLL_TIME (10)
527 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
528 struct ecore_ptt *p_ptt,
531 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
532 enum _ecore_status_t rc = ECORE_TIMEOUT;
535 if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev) ||
536 CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
537 DP_INFO(p_hwfn, "Skipping final cleanup for non-ASIC\n");
538 return ECORE_SUCCESS;
542 addr = GTT_BAR0_MAP_REG_USDM_RAM +
543 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
548 command |= X_FINAL_CLEANUP_AGG_INT <<
549 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
550 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
551 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
552 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
554 /* Make sure notification is not set before initiating final cleanup */
555 if (REG_RD(p_hwfn, addr)) {
556 DP_NOTICE(p_hwfn, false,
557 "Unexpected; Found final cleanup notification "
558 "before initiating final cleanup\n");
559 REG_WR(p_hwfn, addr, 0);
562 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
563 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
564 id, OSAL_CPU_TO_LE32(command));
566 ecore_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN,
567 OSAL_CPU_TO_LE32(command));
569 /* Poll until completion */
570 while (!REG_RD(p_hwfn, addr) && count--)
571 OSAL_MSLEEP(FINAL_CLEANUP_POLL_TIME);
573 if (REG_RD(p_hwfn, addr))
576 DP_NOTICE(p_hwfn, true,
577 "Failed to receive FW final cleanup notification\n");
579 /* Cleanup afterwards */
580 REG_WR(p_hwfn, addr, 0);
585 static void ecore_calc_hw_mode(struct ecore_hwfn *p_hwfn)
589 switch (ECORE_GET_TYPE(p_hwfn->p_dev)) {
591 hw_mode |= 1 << MODE_BB_A0;
594 hw_mode |= 1 << MODE_BB_B0;
597 hw_mode |= 1 << MODE_K2;
600 DP_NOTICE(p_hwfn, true, "Can't initialize chip ID %d\n",
601 ECORE_GET_TYPE(p_hwfn->p_dev));
605 /* Ports per engine is based on the values in CNIG_REG_NW_PORT_MODE */
606 switch (p_hwfn->p_dev->num_ports_in_engines) {
608 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
611 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
614 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
617 DP_NOTICE(p_hwfn, true,
618 "num_ports_in_engine = %d not supported\n",
619 p_hwfn->p_dev->num_ports_in_engines);
623 switch (p_hwfn->p_dev->mf_mode) {
624 case ECORE_MF_DEFAULT:
626 hw_mode |= 1 << MODE_MF_SI;
629 hw_mode |= 1 << MODE_MF_SD;
632 DP_NOTICE(p_hwfn, true,
633 "Unsupported MF mode, init as DEFAULT\n");
634 hw_mode |= 1 << MODE_MF_SI;
638 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
639 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
640 hw_mode |= 1 << MODE_FPGA;
642 if (p_hwfn->p_dev->b_is_emul_full)
643 hw_mode |= 1 << MODE_EMUL_FULL;
645 hw_mode |= 1 << MODE_EMUL_REDUCED;
649 hw_mode |= 1 << MODE_ASIC;
651 if (ENABLE_EAGLE_ENG1_WORKAROUND(p_hwfn))
652 hw_mode |= 1 << MODE_EAGLE_ENG1_WORKAROUND;
654 if (p_hwfn->p_dev->num_hwfns > 1)
655 hw_mode |= 1 << MODE_100G;
657 p_hwfn->hw_info.hw_mode = hw_mode;
659 DP_VERBOSE(p_hwfn, (ECORE_MSG_PROBE | ECORE_MSG_IFUP),
660 "Configuring function for hw_mode: 0x%08x\n",
661 p_hwfn->hw_info.hw_mode);
665 /* MFW-replacement initializations for non-ASIC */
666 static void ecore_hw_init_chip(struct ecore_hwfn *p_hwfn,
667 struct ecore_ptt *p_ptt)
672 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev))
675 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV + 4, pl_hv);
677 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev))
678 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV_2, 0x3ffffff);
680 /* initialize interrupt masks */
683 attn_blocks[BLOCK_MISCS].chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].
684 num_of_int_regs; i++)
685 ecore_wr(p_hwfn, p_ptt,
686 attn_blocks[BLOCK_MISCS].
687 chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].int_regs[i]->
690 if (!CHIP_REV_IS_EMUL(p_hwfn->p_dev) || !ECORE_IS_AH(p_hwfn->p_dev))
691 ecore_wr(p_hwfn, p_ptt,
692 attn_blocks[BLOCK_CNIG].
693 chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].int_regs[0]->
695 ecore_wr(p_hwfn, p_ptt,
696 attn_blocks[BLOCK_PGLCS].
697 chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].int_regs[0]->
699 ecore_wr(p_hwfn, p_ptt,
700 attn_blocks[BLOCK_CPMU].
701 chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].int_regs[0]->
703 /* Currently A0 and B0 interrupt bits are the same in pglue_b;
704 * If this changes, need to set this according to chip type. <14/09/23>
706 ecore_wr(p_hwfn, p_ptt,
707 attn_blocks[BLOCK_PGLUE_B].
708 chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].int_regs[0]->
711 /* initialize port mode to 4x10G_E (10G with 4x10 SERDES) */
712 /* CNIG_REG_NW_PORT_MODE is same for A0 and B0 */
713 if (!CHIP_REV_IS_EMUL(p_hwfn->p_dev) || !ECORE_IS_AH(p_hwfn->p_dev))
714 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB_B0, 4);
716 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev)) {
717 /* 2 for 4-port, 1 for 2-port, 0 for 1-port */
718 ecore_wr(p_hwfn, p_ptt, MISC_REG_PORT_MODE,
719 (p_hwfn->p_dev->num_ports_in_engines >> 1));
721 ecore_wr(p_hwfn, p_ptt, MISC_REG_BLOCK_256B_EN,
722 p_hwfn->p_dev->num_ports_in_engines == 4 ? 0 : 3);
726 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_RBC_DONE, 1);
727 for (i = 0; i < 100; i++) {
729 if (ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_CFG_DONE) == 1)
733 DP_NOTICE(p_hwfn, true,
734 "RBC done failed to complete in PSWRQ2\n");
738 /* Init run time data for all PFs and their VFs on an engine.
739 * TBD - for VFs - Once we have parent PF info for each VF in
740 * shmem available as CAU requires knowledge of parent PF for each VF.
742 static void ecore_init_cau_rt_data(struct ecore_dev *p_dev)
744 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
747 for_each_hwfn(p_dev, i) {
748 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
749 struct ecore_igu_info *p_igu_info;
750 struct ecore_igu_block *p_block;
751 struct cau_sb_entry sb_entry;
753 p_igu_info = p_hwfn->hw_info.p_igu_info;
755 for (sb_id = 0; sb_id < ECORE_MAPPING_MEMORY_SIZE(p_dev);
757 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
762 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
763 p_block->function_id, 0, 0);
764 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry);
769 static enum _ecore_status_t ecore_hw_init_common(struct ecore_hwfn *p_hwfn,
770 struct ecore_ptt *p_ptt,
773 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
774 enum _ecore_status_t rc = ECORE_SUCCESS;
775 struct ecore_dev *p_dev = p_hwfn->p_dev;
776 u8 vf_id, max_num_vfs;
780 ecore_init_cau_rt_data(p_dev);
782 /* Program GTT windows */
783 ecore_gtt_init(p_hwfn);
786 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev))
787 ecore_hw_init_chip(p_hwfn, p_hwfn->p_main_ptt);
790 if (p_hwfn->mcp_info) {
791 if (p_hwfn->mcp_info->func_info.bandwidth_max)
792 qm_info->pf_rl_en = 1;
793 if (p_hwfn->mcp_info->func_info.bandwidth_min)
794 qm_info->pf_wfq_en = 1;
797 ecore_qm_common_rt_init(p_hwfn,
798 p_hwfn->p_dev->num_ports_in_engines,
799 qm_info->max_phys_tcs_per_port,
800 qm_info->pf_rl_en, qm_info->pf_wfq_en,
801 qm_info->vport_rl_en, qm_info->vport_wfq_en,
802 qm_info->qm_port_params);
804 ecore_cxt_hw_init_common(p_hwfn);
806 /* Close gate from NIG to BRB/Storm; By default they are open, but
807 * we close them to prevent NIG from passing data to reset blocks.
808 * Should have been done in the ENGINE phase, but init-tool lacks
809 * proper port-pretend capabilities.
811 ecore_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
812 ecore_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
813 ecore_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
814 ecore_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
815 ecore_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
816 ecore_port_unpretend(p_hwfn, p_ptt);
818 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
819 if (rc != ECORE_SUCCESS)
822 /* @@TBD MichalK - should add VALIDATE_VFID to init tool...
823 * need to decide with which value, maybe runtime
825 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
826 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
828 if (ECORE_IS_BB(p_hwfn->p_dev)) {
829 num_pfs = NUM_OF_ENG_PFS(p_hwfn->p_dev);
832 /* pretend to original PF */
833 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
836 /* Workaround for avoiding CCFC execution error when getting packets
837 * with CRC errors, and allowing instead the invoking of the FW error
839 * This is not done inside the init tool since it currently can't
840 * perform a pretending to VFs.
842 max_num_vfs = ECORE_IS_AH(p_hwfn->p_dev) ? MAX_NUM_VFS_K2
844 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
845 concrete_fid = ecore_vfid_to_concrete(p_hwfn, vf_id);
846 ecore_fid_pretend(p_hwfn, p_ptt, (u16)concrete_fid);
847 ecore_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
849 /* pretend to original PF */
850 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
856 #define MISC_REG_RESET_REG_2_XMAC_BIT (1 << 4)
857 #define MISC_REG_RESET_REG_2_XMAC_SOFT_BIT (1 << 5)
859 #define PMEG_IF_BYTE_COUNT 8
861 static void ecore_wr_nw_port(struct ecore_hwfn *p_hwfn,
862 struct ecore_ptt *p_ptt,
863 u32 addr, u64 data, u8 reg_type, u8 port)
865 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
866 "CMD: %08x, ADDR: 0x%08x, DATA: %08x:%08x\n",
867 ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB_B0) |
868 (8 << PMEG_IF_BYTE_COUNT),
869 (reg_type << 25) | (addr << 8) | port,
870 (u32)((data >> 32) & 0xffffffff),
871 (u32)(data & 0xffffffff));
873 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB_B0,
874 (ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB_B0) &
875 0xffff00fe) | (8 << PMEG_IF_BYTE_COUNT));
876 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_ADDR_BB_B0,
877 (reg_type << 25) | (addr << 8) | port);
878 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB_B0,
880 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB_B0,
881 (data >> 32) & 0xffffffff);
884 #define XLPORT_MODE_REG (0x20a)
885 #define XLPORT_MAC_CONTROL (0x210)
886 #define XLPORT_FLOW_CONTROL_CONFIG (0x207)
887 #define XLPORT_ENABLE_REG (0x20b)
889 #define XLMAC_CTRL (0x600)
890 #define XLMAC_MODE (0x601)
891 #define XLMAC_RX_MAX_SIZE (0x608)
892 #define XLMAC_TX_CTRL (0x604)
893 #define XLMAC_PAUSE_CTRL (0x60d)
894 #define XLMAC_PFC_CTRL (0x60e)
896 static void ecore_emul_link_init_ah(struct ecore_hwfn *p_hwfn,
897 struct ecore_ptt *p_ptt)
899 u8 port = p_hwfn->port_id;
900 u32 mac_base = NWM_REG_MAC0 + (port << 2) * NWM_REG_MAC0_SIZE;
902 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NIG_PORT0_CONF_K2 + (port << 2),
903 (1 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_ENABLE_0_SHIFT) |
904 (port << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_NWM_PORT_MAP_0_SHIFT)
905 | (0 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_RATE_0_SHIFT));
907 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_XIF_MODE,
908 1 << ETH_MAC_REG_XIF_MODE_XGMII_SHIFT);
910 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_FRM_LENGTH,
911 9018 << ETH_MAC_REG_FRM_LENGTH_FRM_LENGTH_SHIFT);
913 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_IPG_LENGTH,
914 0xc << ETH_MAC_REG_TX_IPG_LENGTH_TXIPG_SHIFT);
916 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_RX_FIFO_SECTIONS,
917 8 << ETH_MAC_REG_RX_FIFO_SECTIONS_RX_SECTION_FULL_SHIFT);
919 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_FIFO_SECTIONS,
920 (0xA << ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_EMPTY_SHIFT) |
921 (8 << ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_FULL_SHIFT));
923 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_COMMAND_CONFIG, 0xa853);
926 static void ecore_emul_link_init(struct ecore_hwfn *p_hwfn,
927 struct ecore_ptt *p_ptt)
929 u8 loopback = 0, port = p_hwfn->port_id * 2;
931 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
933 if (ECORE_IS_AH(p_hwfn->p_dev)) {
934 ecore_emul_link_init_ah(p_hwfn, p_ptt);
938 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MODE_REG, (0x4 << 4) | 0x4, 1,
940 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MAC_CONTROL, 0, 1, port);
941 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x40, 0, port);
942 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_MODE, 0x40, 0, port);
943 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_RX_MAX_SIZE, 0x3fff, 0, port);
944 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_TX_CTRL,
945 0x01000000800ULL | (0xa << 12) | ((u64)1 << 38),
947 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PAUSE_CTRL, 0x7c000, 0, port);
948 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PFC_CTRL,
949 0x30ffffc000ULL, 0, port);
950 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x3 | (loopback << 2), 0,
952 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x1003 | (loopback << 2),
954 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_FLOW_CONTROL_CONFIG, 1, 0, port);
955 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_ENABLE_REG, 0xf, 1, port);
958 static void ecore_link_init(struct ecore_hwfn *p_hwfn,
959 struct ecore_ptt *p_ptt, u8 port)
961 int port_offset = port ? 0x800 : 0;
965 /* FIXME: move to common start */
966 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
967 MISC_REG_RESET_REG_2_XMAC_BIT); /* Clear */
969 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
970 MISC_REG_RESET_REG_2_XMAC_BIT); /* Set */
972 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_CORE_PORT_MODE, 1);
974 /* Set the number of ports on the Warp Core to 10G */
975 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_PHY_PORT_MODE, 3);
977 /* Soft reset of XMAC */
978 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
979 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
981 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
982 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
984 /* FIXME: move to common end */
985 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
986 ecore_wr(p_hwfn, p_ptt, XMAC_REG_MODE + port_offset, 0x20);
988 /* Set Max packet size: initialize XMAC block register for port 0 */
989 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_MAX_SIZE + port_offset, 0x2710);
991 /* CRC append for Tx packets: init XMAC block register for port 1 */
992 ecore_wr(p_hwfn, p_ptt, XMAC_REG_TX_CTRL_LO + port_offset, 0xC800);
994 /* Enable TX and RX: initialize XMAC block register for port 1 */
995 ecore_wr(p_hwfn, p_ptt, XMAC_REG_CTRL + port_offset,
996 XMAC_REG_CTRL_TX_EN | XMAC_REG_CTRL_RX_EN);
997 xmac_rxctrl = ecore_rd(p_hwfn, p_ptt, XMAC_REG_RX_CTRL + port_offset);
998 xmac_rxctrl |= XMAC_REG_RX_CTRL_PROCESS_VARIABLE_PREAMBLE;
999 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_CTRL + port_offset, xmac_rxctrl);
1003 static enum _ecore_status_t ecore_hw_init_port(struct ecore_hwfn *p_hwfn,
1004 struct ecore_ptt *p_ptt,
1007 enum _ecore_status_t rc = ECORE_SUCCESS;
1010 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
1012 if (rc != ECORE_SUCCESS)
1016 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev))
1017 return ECORE_SUCCESS;
1019 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1020 if (ECORE_IS_AH(p_hwfn->p_dev))
1021 return ECORE_SUCCESS;
1022 ecore_link_init(p_hwfn, p_ptt, p_hwfn->port_id);
1023 } else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
1024 if (p_hwfn->p_dev->num_hwfns > 1) {
1025 /* Activate OPTE in CMT */
1028 val = ecore_rd(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV);
1030 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV, val);
1031 ecore_wr(p_hwfn, p_ptt, MISC_REG_CLK_100G_MODE, 1);
1032 ecore_wr(p_hwfn, p_ptt, MISCS_REG_CLK_100G_MODE, 1);
1033 ecore_wr(p_hwfn, p_ptt, MISC_REG_OPTE_MODE, 1);
1034 ecore_wr(p_hwfn, p_ptt,
1035 NIG_REG_LLH_ENG_CLS_TCP_4_TUPLE_SEARCH, 1);
1036 ecore_wr(p_hwfn, p_ptt,
1037 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL, 0x55555555);
1038 ecore_wr(p_hwfn, p_ptt,
1039 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL + 0x4,
1043 ecore_emul_link_init(p_hwfn, p_ptt);
1045 DP_INFO(p_hwfn->p_dev, "link is not being configured\n");
1052 static enum _ecore_status_t
1053 ecore_hw_init_pf_doorbell_bar(struct ecore_hwfn *p_hwfn,
1054 struct ecore_ptt *p_ptt)
1056 u32 pwm_regsize, norm_regsize;
1057 u32 non_pwm_conn, min_addr_reg1;
1058 u32 db_bar_size, n_cpus;
1060 int rc = ECORE_SUCCESS;
1062 db_bar_size = ecore_hw_bar_size(p_hwfn, BAR_ID_1);
1063 if (p_hwfn->p_dev->num_hwfns > 1)
1066 /* Calculate doorbell regions
1067 * -----------------------------------
1068 * The doorbell BAR is made of two regions. The first is called normal
1069 * region and the second is called PWM region. In the normal region
1070 * each ICID has its own set of addresses so that writing to that
1071 * specific address identifies the ICID. In the Process Window Mode
1072 * region the ICID is given in the data written to the doorbell. The
1073 * above per PF register denotes the offset in the doorbell BAR in which
1074 * the PWM region begins.
1075 * The normal region has ECORE_PF_DEMS_SIZE bytes per ICID, that is per
1076 * non-PWM connection. The calculation below computes the total non-PWM
1077 * connections. The DORQ_REG_PF_MIN_ADDR_REG1 register is
1078 * in units of 4,096 bytes.
1080 non_pwm_conn = ecore_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1081 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1083 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, OSAL_NULL);
1084 norm_regsize = ROUNDUP(ECORE_PF_DEMS_SIZE * non_pwm_conn, 4096);
1085 min_addr_reg1 = norm_regsize / 4096;
1086 pwm_regsize = db_bar_size - norm_regsize;
1088 /* Check that the normal and PWM sizes are valid */
1089 if (db_bar_size < norm_regsize) {
1090 DP_ERR(p_hwfn->p_dev,
1091 "Doorbell BAR size 0x%x is too"
1092 " small (normal region is 0x%0x )\n",
1093 db_bar_size, norm_regsize);
1094 return ECORE_NORESOURCES;
1096 if (pwm_regsize < ECORE_MIN_PWM_REGION) {
1097 DP_ERR(p_hwfn->p_dev,
1098 "PWM region size 0x%0x is too small."
1099 " Should be at least 0x%0x (Doorbell BAR size"
1100 " is 0x%x and normal region size is 0x%0x)\n",
1101 pwm_regsize, ECORE_MIN_PWM_REGION, db_bar_size,
1103 return ECORE_NORESOURCES;
1107 p_hwfn->dpi_start_offset = norm_regsize; /* this is later used to
1108 * calculate the doorbell
1112 /* Update registers */
1113 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1114 pf_dems_shift = OSAL_LOG2(ECORE_PF_DEMS_SIZE / 4);
1115 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1116 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1119 "Doorbell size 0x%x, Normal region 0x%x, PWM region 0x%x\n",
1120 db_bar_size, norm_regsize, pwm_regsize);
1121 DP_INFO(p_hwfn, "DPI size 0x%x, DPI count 0x%x\n", p_hwfn->dpi_size,
1124 return ECORE_SUCCESS;
1127 static enum _ecore_status_t
1128 ecore_hw_init_pf(struct ecore_hwfn *p_hwfn,
1129 struct ecore_ptt *p_ptt,
1130 struct ecore_tunn_start_params *p_tunn,
1133 enum ecore_int_mode int_mode, bool allow_npar_tx_switch)
1135 enum _ecore_status_t rc = ECORE_SUCCESS;
1136 u8 rel_pf_id = p_hwfn->rel_pf_id;
1142 if (p_hwfn->mcp_info) {
1143 struct ecore_mcp_function_info *p_info;
1145 p_info = &p_hwfn->mcp_info->func_info;
1146 if (p_info->bandwidth_min)
1147 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1149 /* Update rate limit once we'll actually have a link */
1150 p_hwfn->qm_info.pf_rl = 100;
1152 ecore_cxt_hw_init_pf(p_hwfn);
1154 ecore_int_igu_init_rt(p_hwfn); /* @@@TBD TODO MichalS multi hwfn ?? */
1156 /* Set VLAN in NIG if needed */
1157 if (hw_mode & (1 << MODE_MF_SD)) {
1158 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1159 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1160 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1161 p_hwfn->hw_info.ovlan);
1164 /* Enable classification by MAC if needed */
1165 if (hw_mode & (1 << MODE_MF_SI)) {
1166 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
1167 "Configuring TAGMAC_CLS_TYPE\n");
1168 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET,
1172 /* Protocl Configuration - @@@TBD - should we set 0 otherwise? */
1173 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET, 0);
1175 /* perform debug configuration when chip is out of reset */
1176 OSAL_BEFORE_PF_START((void *)p_hwfn->p_dev, p_hwfn->my_id);
1178 /* Cleanup chip from previous driver if such remains exist */
1179 rc = ecore_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
1180 if (rc != ECORE_SUCCESS) {
1181 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_RAMROD_FAIL);
1185 /* PF Init sequence */
1186 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1190 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1191 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1195 /* Pure runtime initializations - directly to the HW */
1196 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1198 /* PCI relaxed ordering causes a decrease in the performance on some
1199 * systems. Till a root cause is found, disable this attribute in the
1203 * pos = OSAL_PCI_FIND_CAPABILITY(p_hwfn->p_dev, PCI_CAP_ID_EXP);
1205 * DP_NOTICE(p_hwfn, true,
1206 * "Failed to find the PCI Express"
1207 * " Capability structure in the PCI config space\n");
1210 * OSAL_PCI_READ_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL,
1212 * ctrl &= ~PCI_EXP_DEVCTL_RELAX_EN;
1213 * OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL,
1218 /*@@TMP - On B0 build 1, need to mask the datapath_registers parity */
1219 if (CHIP_REV_IS_EMUL_B0(p_hwfn->p_dev) &&
1220 (p_hwfn->p_dev->chip_metal == 1)) {
1224 attn_blocks[BLOCK_PGLUE_B].
1225 chip_regs[ECORE_GET_TYPE(p_hwfn->p_dev)].prty_regs[0]->
1227 DP_NOTICE(p_hwfn, false,
1228 "Masking datapath registers parity on"
1229 " B0 emulation [build 1]\n");
1230 tmp = ecore_rd(p_hwfn, p_ptt, reg_addr);
1231 tmp |= (1 << 0); /* Was PRTY_MASK_DATAPATH_REGISTERS */
1232 ecore_wr(p_hwfn, p_ptt, reg_addr, tmp);
1236 rc = ecore_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1241 /* enable interrupts */
1242 ecore_int_igu_enable(p_hwfn, p_ptt, int_mode);
1244 /* send function start command */
1245 rc = ecore_sp_pf_start(p_hwfn, p_tunn, p_hwfn->p_dev->mf_mode,
1246 allow_npar_tx_switch);
1248 DP_NOTICE(p_hwfn, true,
1249 "Function start ramrod failed\n");
1251 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1252 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1253 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1255 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1256 "PRS_REG_SEARCH register after start PFn\n");
1257 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP);
1258 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1259 "PRS_REG_SEARCH_TCP: %x\n", prs_reg);
1260 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP);
1261 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1262 "PRS_REG_SEARCH_UDP: %x\n", prs_reg);
1263 prs_reg = ecore_rd(p_hwfn, p_ptt,
1264 PRS_REG_SEARCH_TCP_FIRST_FRAG);
1265 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1266 "PRS_REG_SEARCH_TCP_FIRST_FRAG: %x\n",
1268 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1269 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1270 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1276 static enum _ecore_status_t
1277 ecore_change_pci_hwfn(struct ecore_hwfn *p_hwfn,
1278 struct ecore_ptt *p_ptt, u8 enable)
1280 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
1282 /* Change PF in PXP */
1283 ecore_wr(p_hwfn, p_ptt,
1284 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1286 /* wait until value is set - try for 1 second every 50us */
1287 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1288 val = ecore_rd(p_hwfn, p_ptt,
1289 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1296 if (val != set_val) {
1297 DP_NOTICE(p_hwfn, true,
1298 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1299 return ECORE_UNKNOWN_ERROR;
1302 return ECORE_SUCCESS;
1305 static void ecore_reset_mb_shadow(struct ecore_hwfn *p_hwfn,
1306 struct ecore_ptt *p_main_ptt)
1308 /* Read shadow of current MFW mailbox */
1309 ecore_mcp_read_mb(p_hwfn, p_main_ptt);
1310 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1311 p_hwfn->mcp_info->mfw_mb_cur,
1312 p_hwfn->mcp_info->mfw_mb_length);
1315 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
1316 struct ecore_tunn_start_params *p_tunn,
1318 enum ecore_int_mode int_mode,
1319 bool allow_npar_tx_switch,
1320 const u8 *bin_fw_data)
1322 enum _ecore_status_t rc, mfw_rc;
1323 u32 load_code, param;
1327 rc = ecore_init_fw_data(p_dev, bin_fw_data);
1328 if (rc != ECORE_SUCCESS)
1332 for_each_hwfn(p_dev, i) {
1333 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1336 rc = ecore_vf_pf_init(p_hwfn);
1342 /* Enable DMAE in PXP */
1343 rc = ecore_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
1345 ecore_calc_hw_mode(p_hwfn);
1346 /* @@@TBD need to add here:
1347 * Check for fan failure
1350 rc = ecore_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt, &load_code);
1352 DP_NOTICE(p_hwfn, true,
1353 "Failed sending LOAD_REQ command\n");
1358 * When coming back from hiberbate state, the registers from
1359 * which shadow is read initially are not initialized. It turns
1360 * out that these registers get initialized during the call to
1361 * ecore_mcp_load_req request. So we need to reread them here
1362 * to get the proper shadow register value.
1363 * Note: This is a workaround for the missinginig MFW
1364 * initialization. It may be removed once the implementation
1367 ecore_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
1369 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1370 "Load request was sent.Resp:0x%x, Load code: 0x%x\n",
1373 /* Only relevant for recovery:
1374 * Clear the indication after the LOAD_REQ command is responded
1377 p_dev->recov_in_prog = false;
1379 p_hwfn->first_on_engine = (load_code ==
1380 FW_MSG_CODE_DRV_LOAD_ENGINE);
1382 switch (load_code) {
1383 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1384 rc = ecore_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
1385 p_hwfn->hw_info.hw_mode);
1389 case FW_MSG_CODE_DRV_LOAD_PORT:
1390 rc = ecore_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
1391 p_hwfn->hw_info.hw_mode);
1395 if (ENABLE_EAGLE_ENG1_WORKAROUND(p_hwfn)) {
1396 struct init_nig_pri_tc_map_req tc_map;
1398 OSAL_MEM_ZERO(&tc_map, sizeof(tc_map));
1400 /* remove this once flow control is
1403 for (j = 0; j < NUM_OF_VLAN_PRIORITIES; j++) {
1404 tc_map.pri[j].tc_id = 0;
1405 tc_map.pri[j].valid = 1;
1407 ecore_init_nig_pri_tc_map(p_hwfn,
1412 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1413 rc = ecore_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
1414 p_tunn, p_hwfn->hw_info.hw_mode,
1415 b_hw_start, int_mode,
1416 allow_npar_tx_switch);
1423 if (rc != ECORE_SUCCESS)
1424 DP_NOTICE(p_hwfn, true,
1425 "init phase failed loadcode 0x%x (rc %d)\n",
1428 /* ACK mfw regardless of success or failure of initialization */
1429 mfw_rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1430 DRV_MSG_CODE_LOAD_DONE,
1431 0, &load_code, ¶m);
1432 if (rc != ECORE_SUCCESS)
1434 if (mfw_rc != ECORE_SUCCESS) {
1435 DP_NOTICE(p_hwfn, true,
1436 "Failed sending LOAD_DONE command\n");
1440 p_hwfn->hw_init_done = true;
1443 return ECORE_SUCCESS;
1446 #define ECORE_HW_STOP_RETRY_LIMIT (10)
1447 static OSAL_INLINE void ecore_hw_timers_stop(struct ecore_dev *p_dev,
1448 struct ecore_hwfn *p_hwfn,
1449 struct ecore_ptt *p_ptt)
1454 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
1455 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
1456 for (i = 0; i < ECORE_HW_STOP_RETRY_LIMIT &&
1457 !p_dev->recov_in_prog; i++) {
1458 if ((!ecore_rd(p_hwfn, p_ptt,
1459 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
1460 (!ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
1463 /* Dependent on number of connection/tasks, possibly
1464 * 1ms sleep is required between polls
1468 if (i == ECORE_HW_STOP_RETRY_LIMIT)
1469 DP_NOTICE(p_hwfn, true,
1470 "Timers linear scans are not over"
1471 " [Connection %02x Tasks %02x]\n",
1472 (u8)ecore_rd(p_hwfn, p_ptt,
1473 TM_REG_PF_SCAN_ACTIVE_CONN),
1474 (u8)ecore_rd(p_hwfn, p_ptt,
1475 TM_REG_PF_SCAN_ACTIVE_TASK));
1478 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev)
1482 for_each_hwfn(p_dev, j) {
1483 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
1484 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
1486 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
1490 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev)
1492 enum _ecore_status_t rc = ECORE_SUCCESS, t_rc;
1495 for_each_hwfn(p_dev, j) {
1496 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
1497 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
1499 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Stopping hw/fw\n");
1502 ecore_vf_pf_int_cleanup(p_hwfn);
1506 /* mark the hw as uninitialized... */
1507 p_hwfn->hw_init_done = false;
1509 rc = ecore_sp_pf_stop(p_hwfn);
1511 DP_NOTICE(p_hwfn, true,
1512 "Failed to close PF against FW. Continue to"
1513 " stop HW to prevent illegal host access"
1514 " by the device\n");
1516 /* perform debug action after PF stop was sent */
1517 OSAL_AFTER_PF_STOP((void *)p_hwfn->p_dev, p_hwfn->my_id);
1519 /* close NIG to BRB gate */
1520 ecore_wr(p_hwfn, p_ptt,
1521 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1524 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1525 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1526 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1528 /* @@@TBD - clean transmission queues (5.b) */
1529 /* @@@TBD - clean BTB (5.c) */
1531 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
1533 /* @@@TBD - verify DMAE requests are done (8) */
1535 /* Disable Attention Generation */
1536 ecore_int_igu_disable_int(p_hwfn, p_ptt);
1537 ecore_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
1538 ecore_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
1539 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
1540 /* Need to wait 1ms to guarantee SBs are cleared */
1545 /* Disable DMAE in PXP - in CMT, this should only be done for
1546 * first hw-function, and only after all transactions have
1547 * stopped for all active hw-functions.
1549 t_rc = ecore_change_pci_hwfn(&p_dev->hwfns[0],
1550 p_dev->hwfns[0].p_main_ptt, false);
1551 if (t_rc != ECORE_SUCCESS)
1558 void ecore_hw_stop_fastpath(struct ecore_dev *p_dev)
1562 for_each_hwfn(p_dev, j) {
1563 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
1564 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
1567 ecore_vf_pf_int_cleanup(p_hwfn);
1571 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
1572 "Shutting down the fastpath\n");
1574 ecore_wr(p_hwfn, p_ptt,
1575 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1577 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1578 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1579 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1581 /* @@@TBD - clean transmission queues (5.b) */
1582 /* @@@TBD - clean BTB (5.c) */
1584 /* @@@TBD - verify DMAE requests are done (8) */
1586 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
1587 /* Need to wait 1ms to guarantee SBs are cleared */
1592 void ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn)
1594 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
1596 if (IS_VF(p_hwfn->p_dev))
1599 /* Re-open incoming traffic */
1600 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
1601 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
1604 static enum _ecore_status_t ecore_reg_assert(struct ecore_hwfn *p_hwfn,
1605 struct ecore_ptt *p_ptt, u32 reg,
1608 u32 assert_val = ecore_rd(p_hwfn, p_ptt, reg);
1610 if (assert_val != expected) {
1611 DP_NOTICE(p_hwfn, true, "Value at address 0x%08x != 0x%08x\n",
1613 return ECORE_UNKNOWN_ERROR;
1619 enum _ecore_status_t ecore_hw_reset(struct ecore_dev *p_dev)
1621 enum _ecore_status_t rc = ECORE_SUCCESS;
1622 u32 unload_resp, unload_param;
1625 for_each_hwfn(p_dev, i) {
1626 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1629 rc = ecore_vf_pf_reset(p_hwfn);
1635 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Resetting hw/fw\n");
1637 /* Check for incorrect states */
1638 if (!p_dev->recov_in_prog) {
1639 ecore_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
1640 QM_REG_USG_CNT_PF_TX, 0);
1641 ecore_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
1642 QM_REG_USG_CNT_PF_OTHER, 0);
1643 /* @@@TBD - assert on incorrect xCFC values (10.b) */
1646 /* Disable PF in HW blocks */
1647 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
1648 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
1649 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
1650 TCFC_REG_STRONG_ENABLE_PF, 0);
1651 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
1652 CCFC_REG_STRONG_ENABLE_PF, 0);
1654 if (p_dev->recov_in_prog) {
1655 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
1656 "Recovery is in progress -> skip "
1657 "sending unload_req/done\n");
1661 /* Send unload command to MCP */
1662 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1663 DRV_MSG_CODE_UNLOAD_REQ,
1664 DRV_MB_PARAM_UNLOAD_WOL_MCP,
1665 &unload_resp, &unload_param);
1666 if (rc != ECORE_SUCCESS) {
1667 DP_NOTICE(p_hwfn, true,
1668 "ecore_hw_reset: UNLOAD_REQ failed\n");
1669 /* @@TBD - what to do? for now, assume ENG. */
1670 unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
1673 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1674 DRV_MSG_CODE_UNLOAD_DONE,
1675 0, &unload_resp, &unload_param);
1676 if (rc != ECORE_SUCCESS) {
1678 true, "ecore_hw_reset: UNLOAD_DONE failed\n");
1679 /* @@@TBD - Should it really ASSERT here ? */
1687 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
1688 static void ecore_hw_hwfn_free(struct ecore_hwfn *p_hwfn)
1690 ecore_ptt_pool_free(p_hwfn);
1691 OSAL_FREE(p_hwfn->p_dev, p_hwfn->hw_info.p_igu_info);
1694 /* Setup bar access */
1695 static void ecore_hw_hwfn_prepare(struct ecore_hwfn *p_hwfn)
1697 /* clear indirect access */
1698 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
1699 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
1700 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
1701 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
1703 /* Clean Previous errors if such exist */
1704 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
1705 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
1707 /* enable internal target-read */
1708 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
1709 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1712 static void get_function_id(struct ecore_hwfn *p_hwfn)
1715 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn,
1716 PXP_PF_ME_OPAQUE_ADDR);
1718 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
1720 /* Bits 16-19 from the ME registers are the pf_num */
1721 /* @@ @TBD - check, may be wrong after B0 implementation for CMT */
1722 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
1723 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
1724 PXP_CONCRETE_FID_PFID);
1725 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
1726 PXP_CONCRETE_FID_PORT);
1728 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
1729 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
1730 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
1733 static void ecore_hw_set_feat(struct ecore_hwfn *p_hwfn)
1735 u32 *feat_num = p_hwfn->hw_info.feat_num;
1736 int num_features = 1;
1738 /* L2 Queues require each: 1 status block. 1 L2 queue */
1739 feat_num[ECORE_PF_L2_QUE] =
1741 RESC_NUM(p_hwfn, ECORE_SB) / num_features,
1742 RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
1744 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
1745 "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
1746 feat_num[ECORE_PF_L2_QUE],
1747 RESC_NUM(p_hwfn, ECORE_SB), num_features);
1750 /* @@@TBD MK RESC: This info is currently hard code and set as if we were MF
1751 * need to read it from shmem...
1753 static enum _ecore_status_t ecore_hw_get_resc(struct ecore_hwfn *p_hwfn)
1755 u32 *resc_start = p_hwfn->hw_info.resc_start;
1756 u8 num_funcs = p_hwfn->num_funcs_on_engine;
1757 u32 *resc_num = p_hwfn->hw_info.resc_num;
1758 int i, max_vf_vlan_filters;
1759 struct ecore_sb_cnt_info sb_cnt_info;
1760 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
1762 OSAL_MEM_ZERO(&sb_cnt_info, sizeof(sb_cnt_info));
1764 #ifdef CONFIG_ECORE_SRIOV
1765 max_vf_vlan_filters = ECORE_ETH_MAX_VF_NUM_VLAN_FILTERS;
1767 max_vf_vlan_filters = 0;
1770 ecore_int_get_num_sbs(p_hwfn, &sb_cnt_info);
1771 resc_num[ECORE_SB] = OSAL_MIN_T(u32,
1772 (MAX_SB_PER_PATH_BB / num_funcs),
1773 sb_cnt_info.sb_cnt);
1775 resc_num[ECORE_L2_QUEUE] = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
1776 MAX_NUM_L2_QUEUES_BB) / num_funcs;
1777 resc_num[ECORE_VPORT] = (b_ah ? MAX_NUM_VPORTS_K2 :
1778 MAX_NUM_VPORTS_BB) / num_funcs;
1779 resc_num[ECORE_RSS_ENG] = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
1780 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
1781 resc_num[ECORE_PQ] = (b_ah ? MAX_QM_TX_QUEUES_K2 :
1782 MAX_QM_TX_QUEUES_BB) / num_funcs;
1783 resc_num[ECORE_RL] = 8;
1784 resc_num[ECORE_MAC] = ETH_NUM_MAC_FILTERS / num_funcs;
1785 resc_num[ECORE_VLAN] = (ETH_NUM_VLAN_FILTERS -
1786 max_vf_vlan_filters +
1787 1 /*For vlan0 */) / num_funcs;
1789 /* TODO - there will be a problem in AH - there are only 11k lines */
1790 resc_num[ECORE_ILT] = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
1791 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
1794 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1795 /* Reduced build contains less PQs */
1796 if (!(p_hwfn->p_dev->b_is_emul_full))
1797 resc_num[ECORE_PQ] = 32;
1799 /* For AH emulation, since we have a possible maximal number of
1800 * 16 enabled PFs, in case there are not enough ILT lines -
1801 * allocate only first PF as RoCE and have all the other ETH
1802 * only with less ILT lines.
1804 if (!p_hwfn->rel_pf_id && p_hwfn->p_dev->b_is_emul_full)
1805 resc_num[ECORE_ILT] = resc_num[ECORE_ILT];
1809 for (i = 0; i < ECORE_MAX_RESC; i++)
1810 resc_start[i] = resc_num[i] * p_hwfn->rel_pf_id;
1813 /* Correct the common ILT calculation if PF0 has more */
1814 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev) &&
1815 p_hwfn->p_dev->b_is_emul_full &&
1816 p_hwfn->rel_pf_id && resc_num[ECORE_ILT])
1817 resc_start[ECORE_ILT] += resc_num[ECORE_ILT];
1820 /* Sanity for ILT */
1821 if ((b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
1822 (!b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
1823 DP_NOTICE(p_hwfn, true,
1824 "Can't assign ILT pages [%08x,...,%08x]\n",
1825 RESC_START(p_hwfn, ECORE_ILT), RESC_END(p_hwfn,
1831 ecore_hw_set_feat(p_hwfn);
1833 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
1834 "The numbers for each resource are:\n"
1835 "SB = %d start = %d\n"
1836 "L2_QUEUE = %d start = %d\n"
1837 "VPORT = %d start = %d\n"
1838 "PQ = %d start = %d\n"
1839 "RL = %d start = %d\n"
1840 "MAC = %d start = %d\n"
1841 "VLAN = %d start = %d\n"
1842 "ILT = %d start = %d\n"
1843 "CMDQS_CQS = %d start = %d\n",
1844 RESC_NUM(p_hwfn, ECORE_SB), RESC_START(p_hwfn, ECORE_SB),
1845 RESC_NUM(p_hwfn, ECORE_L2_QUEUE),
1846 RESC_START(p_hwfn, ECORE_L2_QUEUE),
1847 RESC_NUM(p_hwfn, ECORE_VPORT),
1848 RESC_START(p_hwfn, ECORE_VPORT),
1849 RESC_NUM(p_hwfn, ECORE_PQ), RESC_START(p_hwfn, ECORE_PQ),
1850 RESC_NUM(p_hwfn, ECORE_RL), RESC_START(p_hwfn, ECORE_RL),
1851 RESC_NUM(p_hwfn, ECORE_MAC), RESC_START(p_hwfn, ECORE_MAC),
1852 RESC_NUM(p_hwfn, ECORE_VLAN),
1853 RESC_START(p_hwfn, ECORE_VLAN),
1854 RESC_NUM(p_hwfn, ECORE_ILT), RESC_START(p_hwfn, ECORE_ILT),
1855 RESC_NUM(p_hwfn, ECORE_CMDQS_CQS),
1856 RESC_START(p_hwfn, ECORE_CMDQS_CQS));
1858 return ECORE_SUCCESS;
1861 static enum _ecore_status_t ecore_hw_get_nvm_info(struct ecore_hwfn *p_hwfn,
1862 struct ecore_ptt *p_ptt)
1864 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
1865 u32 port_cfg_addr, link_temp, device_capabilities;
1866 struct ecore_mcp_link_params *link;
1868 /* Read global nvm_cfg address */
1869 u32 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
1871 /* Verify MCP has initialized it */
1872 if (nvm_cfg_addr == 0) {
1873 DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
1877 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
1878 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
1880 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1881 OFFSETOF(struct nvm_cfg1, glob) + OFFSETOF(struct nvm_cfg1_glob,
1884 core_cfg = ecore_rd(p_hwfn, p_ptt, addr);
1886 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
1887 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
1888 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X40G:
1889 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X40G;
1891 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X50G:
1892 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X50G;
1894 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X100G:
1895 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X100G;
1897 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_F:
1898 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_F;
1900 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_E:
1901 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_E;
1903 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X20G:
1904 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X20G;
1906 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X40G:
1907 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X40G;
1909 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X25G:
1910 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X25G;
1912 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X25G:
1913 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X25G;
1916 DP_NOTICE(p_hwfn, true, "Unknown port mode in 0x%08x\n",
1921 /* Read default link configuration */
1922 link = &p_hwfn->mcp_info->link_input;
1923 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1924 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
1925 link_temp = ecore_rd(p_hwfn, p_ptt,
1927 OFFSETOF(struct nvm_cfg1_port, speed_cap_mask));
1928 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
1929 link->speed.advertised_speeds = link_temp;
1931 link_temp = link->speed.advertised_speeds;
1932 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
1934 link_temp = ecore_rd(p_hwfn, p_ptt,
1936 OFFSETOF(struct nvm_cfg1_port, link_settings));
1937 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
1938 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
1939 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
1940 link->speed.autoneg = true;
1942 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
1943 link->speed.forced_speed = 1000;
1945 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
1946 link->speed.forced_speed = 10000;
1948 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
1949 link->speed.forced_speed = 25000;
1951 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
1952 link->speed.forced_speed = 40000;
1954 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
1955 link->speed.forced_speed = 50000;
1957 case NVM_CFG1_PORT_DRV_LINK_SPEED_100G:
1958 link->speed.forced_speed = 100000;
1961 DP_NOTICE(p_hwfn, true, "Unknown Speed in 0x%08x\n", link_temp);
1964 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
1965 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
1966 link->pause.autoneg = !!(link_temp &
1967 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
1968 link->pause.forced_rx = !!(link_temp &
1969 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
1970 link->pause.forced_tx = !!(link_temp &
1971 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
1972 link->loopback_mode = 0;
1974 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1975 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x,"
1976 " AN: 0x%02x, PAUSE AN: 0x%02x\n",
1977 link->speed.forced_speed, link->speed.advertised_speeds,
1978 link->speed.autoneg, link->pause.autoneg);
1980 /* Read Multi-function information from shmem */
1981 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1982 OFFSETOF(struct nvm_cfg1, glob) +
1983 OFFSETOF(struct nvm_cfg1_glob, generic_cont0);
1985 generic_cont0 = ecore_rd(p_hwfn, p_ptt, addr);
1987 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
1988 NVM_CFG1_GLOB_MF_MODE_OFFSET;
1991 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
1992 p_hwfn->p_dev->mf_mode = ECORE_MF_OVLAN;
1994 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
1995 p_hwfn->p_dev->mf_mode = ECORE_MF_NPAR;
1997 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
1998 p_hwfn->p_dev->mf_mode = ECORE_MF_DEFAULT;
2001 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
2002 p_hwfn->p_dev->mf_mode);
2004 /* Read Multi-function information from shmem */
2005 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2006 OFFSETOF(struct nvm_cfg1, glob) +
2007 OFFSETOF(struct nvm_cfg1_glob, device_capabilities);
2009 device_capabilities = ecore_rd(p_hwfn, p_ptt, addr);
2010 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
2011 OSAL_SET_BIT(ECORE_DEV_CAP_ETH,
2012 &p_hwfn->hw_info.device_capabilities);
2014 return ecore_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
2017 static void ecore_get_num_funcs(struct ecore_hwfn *p_hwfn,
2018 struct ecore_ptt *p_ptt)
2023 num_funcs = ECORE_IS_AH(p_hwfn->p_dev) ? MAX_NUM_PFS_K2
2026 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
2027 * in the other bits are selected.
2028 * Bits 1-15 are for functions 1-15, respectively, and their value is
2029 * '0' only for enabled functions (function 0 always exists and
2031 * In case of CMT, only the "even" functions are enabled, and thus the
2032 * number of functions for both hwfns is learnt from the same bits.
2035 tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
2037 if (ECORE_PATH_ID(p_hwfn) && p_hwfn->p_dev->num_hwfns == 1) {
2045 tmp = (tmp ^ 0xffffffff) & mask;
2053 p_hwfn->num_funcs_on_engine = num_funcs;
2056 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2057 DP_NOTICE(p_hwfn, false,
2058 "FPGA: Limit number of PFs to 4 [would affect"
2059 " resource allocation, needed for IOV]\n");
2060 p_hwfn->num_funcs_on_engine = 4;
2064 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE, "num_funcs_on_engine = %d\n",
2065 p_hwfn->num_funcs_on_engine);
2068 static void ecore_hw_info_port_num_bb(struct ecore_hwfn *p_hwfn,
2069 struct ecore_ptt *p_ptt)
2074 /* Read the port mode */
2075 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
2077 else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) &&
2078 (p_hwfn->p_dev->num_hwfns > 1))
2079 /* In CMT on emulation, assume 1 port */
2083 port_mode = ecore_rd(p_hwfn, p_ptt,
2084 CNIG_REG_NW_PORT_MODE_BB_B0);
2086 if (port_mode < 3) {
2087 p_hwfn->p_dev->num_ports_in_engines = 1;
2088 } else if (port_mode <= 5) {
2089 p_hwfn->p_dev->num_ports_in_engines = 2;
2091 DP_NOTICE(p_hwfn, true, "PORT MODE: %d not supported\n",
2092 p_hwfn->p_dev->num_ports_in_engines);
2094 /* Default num_ports_in_engines to something */
2095 p_hwfn->p_dev->num_ports_in_engines = 1;
2099 static void ecore_hw_info_port_num_ah(struct ecore_hwfn *p_hwfn,
2100 struct ecore_ptt *p_ptt)
2105 p_hwfn->p_dev->num_ports_in_engines = 0;
2107 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
2108 port = ecore_rd(p_hwfn, p_ptt,
2109 CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4));
2111 p_hwfn->p_dev->num_ports_in_engines++;
2115 static void ecore_hw_info_port_num(struct ecore_hwfn *p_hwfn,
2116 struct ecore_ptt *p_ptt)
2118 if (ECORE_IS_BB(p_hwfn->p_dev))
2119 ecore_hw_info_port_num_bb(p_hwfn, p_ptt);
2121 ecore_hw_info_port_num_ah(p_hwfn, p_ptt);
2124 static enum _ecore_status_t
2125 ecore_get_hw_info(struct ecore_hwfn *p_hwfn,
2126 struct ecore_ptt *p_ptt,
2127 enum ecore_pci_personality personality)
2129 enum _ecore_status_t rc;
2131 rc = ecore_iov_hw_info(p_hwfn, p_hwfn->p_main_ptt);
2135 /* TODO In get_hw_info, amoungst others:
2136 * Get MCP FW revision and determine according to it the supported
2137 * featrues (e.g. DCB)
2139 * ecore_get_pcie_width_speed, WOL capability.
2140 * Number of global CQ-s (for storage
2142 ecore_hw_info_port_num(p_hwfn, p_ptt);
2145 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev))
2147 ecore_hw_get_nvm_info(p_hwfn, p_ptt);
2149 rc = ecore_int_igu_read_cam(p_hwfn, p_ptt);
2154 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev) && ecore_mcp_is_init(p_hwfn)) {
2156 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr,
2157 p_hwfn->mcp_info->func_info.mac, ETH_ALEN);
2160 static u8 mcp_hw_mac[6] = { 0, 2, 3, 4, 5, 6 };
2162 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr, mcp_hw_mac, ETH_ALEN);
2163 p_hwfn->hw_info.hw_mac_addr[5] = p_hwfn->abs_pf_id;
2167 if (ecore_mcp_is_init(p_hwfn)) {
2168 if (p_hwfn->mcp_info->func_info.ovlan != ECORE_MCP_VLAN_UNSET)
2169 p_hwfn->hw_info.ovlan =
2170 p_hwfn->mcp_info->func_info.ovlan;
2172 ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
2175 if (personality != ECORE_PCI_DEFAULT)
2176 p_hwfn->hw_info.personality = personality;
2177 else if (ecore_mcp_is_init(p_hwfn))
2178 p_hwfn->hw_info.personality =
2179 p_hwfn->mcp_info->func_info.protocol;
2182 /* To overcome ILT lack for emulation, until at least until we'll have
2183 * a definite answer from system about it, allow only PF0 to be RoCE.
2185 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev))
2186 p_hwfn->hw_info.personality = ECORE_PCI_ETH;
2189 ecore_get_num_funcs(p_hwfn, p_ptt);
2191 /* Feat num is dependent on personality and on the number of functions
2192 * on the engine. Therefore it should be come after personality
2193 * initialization and after getting the number of functions.
2195 return ecore_hw_get_resc(p_hwfn);
2198 /* @TMP - this should move to a proper .h */
2199 #define CHIP_NUM_AH 0x8070
2201 static enum _ecore_status_t ecore_get_dev_info(struct ecore_dev *p_dev)
2203 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
2206 /* Read Vendor Id / Device Id */
2207 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_VENDOR_ID_OFFSET,
2209 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_DEVICE_ID_OFFSET,
2212 p_dev->chip_num = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
2213 MISCS_REG_CHIP_NUM);
2214 p_dev->chip_rev = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
2215 MISCS_REG_CHIP_REV);
2217 MASK_FIELD(CHIP_REV, p_dev->chip_rev);
2219 /* Determine type */
2220 if (p_dev->device_id == CHIP_NUM_AH)
2221 p_dev->type = ECORE_DEV_TYPE_AH;
2223 p_dev->type = ECORE_DEV_TYPE_BB;
2225 /* Learn number of HW-functions */
2226 tmp = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
2227 MISCS_REG_CMT_ENABLED_FOR_PAIR);
2229 if (tmp & (1 << p_hwfn->rel_pf_id)) {
2230 DP_NOTICE(p_dev->hwfns, false, "device in CMT mode\n");
2231 p_dev->num_hwfns = 2;
2233 p_dev->num_hwfns = 1;
2237 if (CHIP_REV_IS_EMUL(p_dev)) {
2238 /* For some reason we have problems with this register
2239 * in B0 emulation; Simply assume no CMT
2241 DP_NOTICE(p_dev->hwfns, false,
2242 "device on emul - assume no CMT\n");
2243 p_dev->num_hwfns = 1;
2247 p_dev->chip_bond_id = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
2248 MISCS_REG_CHIP_TEST_REG) >> 4;
2249 MASK_FIELD(CHIP_BOND_ID, p_dev->chip_bond_id);
2250 p_dev->chip_metal = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
2251 MISCS_REG_CHIP_METAL);
2252 MASK_FIELD(CHIP_METAL, p_dev->chip_metal);
2253 DP_INFO(p_dev->hwfns,
2254 "Chip details - %s%d, Num: %04x Rev: %04x Bond id: %04x"
2256 ECORE_IS_BB(p_dev) ? "BB" : "AH",
2257 CHIP_REV_IS_A0(p_dev) ? 0 : 1,
2258 p_dev->chip_num, p_dev->chip_rev, p_dev->chip_bond_id,
2261 if (ECORE_IS_BB(p_dev) && CHIP_REV_IS_A0(p_dev)) {
2262 DP_NOTICE(p_dev->hwfns, false,
2263 "The chip type/rev (BB A0) is not supported!\n");
2264 return ECORE_ABORTED;
2267 if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_AH(p_dev))
2268 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2269 MISCS_REG_PLL_MAIN_CTRL_4, 0x1);
2271 if (CHIP_REV_IS_EMUL(p_dev)) {
2272 tmp = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
2273 MISCS_REG_ECO_RESERVED);
2274 if (tmp & (1 << 29)) {
2275 DP_NOTICE(p_hwfn, false,
2276 "Emulation: Running on a FULL build\n");
2277 p_dev->b_is_emul_full = true;
2279 DP_NOTICE(p_hwfn, false,
2280 "Emulation: Running on a REDUCED build\n");
2285 return ECORE_SUCCESS;
2288 void ecore_prepare_hibernate(struct ecore_dev *p_dev)
2295 for_each_hwfn(p_dev, j) {
2296 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2298 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
2299 "Mark hw/fw uninitialized\n");
2301 p_hwfn->hw_init_done = false;
2302 p_hwfn->first_on_engine = false;
2306 static enum _ecore_status_t
2307 ecore_hw_prepare_single(struct ecore_hwfn *p_hwfn,
2308 void OSAL_IOMEM *p_regview,
2309 void OSAL_IOMEM *p_doorbells,
2310 enum ecore_pci_personality personality)
2312 enum _ecore_status_t rc = ECORE_SUCCESS;
2314 /* Split PCI bars evenly between hwfns */
2315 p_hwfn->regview = p_regview;
2316 p_hwfn->doorbells = p_doorbells;
2318 /* Validate that chip access is feasible */
2319 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
2321 "Reading the ME register returns all Fs;"
2322 " Preventing further chip access\n");
2326 get_function_id(p_hwfn);
2328 /* Allocate PTT pool */
2329 rc = ecore_ptt_pool_alloc(p_hwfn);
2331 DP_NOTICE(p_hwfn, true, "Failed to prepare hwfn's hw\n");
2335 /* Allocate the main PTT */
2336 p_hwfn->p_main_ptt = ecore_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
2338 /* First hwfn learns basic information, e.g., number of hwfns */
2339 if (!p_hwfn->my_id) {
2340 rc = ecore_get_dev_info(p_hwfn->p_dev);
2341 if (rc != ECORE_SUCCESS)
2345 ecore_hw_hwfn_prepare(p_hwfn);
2347 /* Initialize MCP structure */
2348 rc = ecore_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
2350 DP_NOTICE(p_hwfn, true, "Failed initializing mcp command\n");
2354 /* Read the device configuration information from the HW and SHMEM */
2355 rc = ecore_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
2357 DP_NOTICE(p_hwfn, true, "Failed to get HW information\n");
2361 /* Allocate the init RT array and initialize the init-ops engine */
2362 rc = ecore_init_alloc(p_hwfn);
2364 DP_NOTICE(p_hwfn, true, "Failed to allocate the init array\n");
2368 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
2369 DP_NOTICE(p_hwfn, false,
2370 "FPGA: workaround; Prevent DMAE parities\n");
2371 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PCIE_REG_PRTY_MASK, 7);
2373 DP_NOTICE(p_hwfn, false,
2374 "FPGA: workaround: Set VF bar0 size\n");
2375 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2376 PGLUE_B_REG_VF_BAR0_SIZE, 4);
2382 ecore_mcp_free(p_hwfn);
2384 ecore_hw_hwfn_free(p_hwfn);
2389 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev, int personality)
2391 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
2392 enum _ecore_status_t rc;
2395 return ecore_vf_hw_prepare(p_dev);
2397 /* Store the precompiled init data ptrs */
2398 ecore_init_iro_array(p_dev);
2400 /* Initialize the first hwfn - will learn number of hwfns */
2401 rc = ecore_hw_prepare_single(p_hwfn,
2403 p_dev->doorbells, personality);
2404 if (rc != ECORE_SUCCESS)
2407 personality = p_hwfn->hw_info.personality;
2409 /* initialalize 2nd hwfn if necessary */
2410 if (p_dev->num_hwfns > 1) {
2411 void OSAL_IOMEM *p_regview, *p_doorbell;
2412 u8 OSAL_IOMEM *addr;
2414 /* adjust bar offset for second engine */
2415 addr = (u8 OSAL_IOMEM *)p_dev->regview +
2416 ecore_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
2417 p_regview = (void OSAL_IOMEM *)addr;
2419 addr = (u8 OSAL_IOMEM *)p_dev->doorbells +
2420 ecore_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
2421 p_doorbell = (void OSAL_IOMEM *)addr;
2423 /* prepare second hw function */
2424 rc = ecore_hw_prepare_single(&p_dev->hwfns[1], p_regview,
2425 p_doorbell, personality);
2427 /* in case of error, need to free the previously
2428 * initialiazed hwfn 0
2430 if (rc != ECORE_SUCCESS) {
2431 ecore_init_free(p_hwfn);
2432 ecore_mcp_free(p_hwfn);
2433 ecore_hw_hwfn_free(p_hwfn);
2438 return ECORE_SUCCESS;
2441 void ecore_hw_remove(struct ecore_dev *p_dev)
2445 for_each_hwfn(p_dev, i) {
2446 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
2449 ecore_vf_pf_release(p_hwfn);
2453 ecore_init_free(p_hwfn);
2454 ecore_hw_hwfn_free(p_hwfn);
2455 ecore_mcp_free(p_hwfn);
2457 OSAL_MUTEX_DEALLOC(&p_hwfn->dmae_info.mutex);
2461 static void ecore_chain_free_next_ptr(struct ecore_dev *p_dev,
2462 struct ecore_chain *p_chain)
2464 void *p_virt = p_chain->p_virt_addr, *p_virt_next = OSAL_NULL;
2465 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
2466 struct ecore_chain_next *p_next;
2472 size = p_chain->elem_size * p_chain->usable_per_page;
2474 for (i = 0; i < p_chain->page_cnt; i++) {
2478 p_next = (struct ecore_chain_next *)((u8 *)p_virt + size);
2479 p_virt_next = p_next->next_virt;
2480 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
2482 OSAL_DMA_FREE_COHERENT(p_dev, p_virt, p_phys,
2483 ECORE_CHAIN_PAGE_SIZE);
2485 p_virt = p_virt_next;
2486 p_phys = p_phys_next;
2490 static void ecore_chain_free_single(struct ecore_dev *p_dev,
2491 struct ecore_chain *p_chain)
2493 if (!p_chain->p_virt_addr)
2496 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->p_virt_addr,
2497 p_chain->p_phys_addr, ECORE_CHAIN_PAGE_SIZE);
2500 static void ecore_chain_free_pbl(struct ecore_dev *p_dev,
2501 struct ecore_chain *p_chain)
2503 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
2504 u8 *p_pbl_virt = (u8 *)p_chain->pbl.p_virt_table;
2505 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
2507 if (!pp_virt_addr_tbl)
2510 if (!p_chain->pbl.p_virt_table)
2513 for (i = 0; i < page_cnt; i++) {
2514 if (!pp_virt_addr_tbl[i])
2517 OSAL_DMA_FREE_COHERENT(p_dev, pp_virt_addr_tbl[i],
2518 *(dma_addr_t *)p_pbl_virt,
2519 ECORE_CHAIN_PAGE_SIZE);
2521 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
2524 pbl_size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
2525 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->pbl.p_virt_table,
2526 p_chain->pbl.p_phys_table, pbl_size);
2528 OSAL_VFREE(p_dev, p_chain->pbl.pp_virt_addr_tbl);
2531 void ecore_chain_free(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
2533 switch (p_chain->mode) {
2534 case ECORE_CHAIN_MODE_NEXT_PTR:
2535 ecore_chain_free_next_ptr(p_dev, p_chain);
2537 case ECORE_CHAIN_MODE_SINGLE:
2538 ecore_chain_free_single(p_dev, p_chain);
2540 case ECORE_CHAIN_MODE_PBL:
2541 ecore_chain_free_pbl(p_dev, p_chain);
2546 static enum _ecore_status_t
2547 ecore_chain_alloc_sanity_check(struct ecore_dev *p_dev,
2548 enum ecore_chain_cnt_type cnt_type,
2549 osal_size_t elem_size, u32 page_cnt)
2551 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
2553 /* The actual chain size can be larger than the maximal possible value
2554 * after rounding up the requested elements number to pages, and after
2555 * taking into acount the unusuable elements (next-ptr elements).
2556 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
2557 * size/capacity fields are of a u32 type.
2559 if ((cnt_type == ECORE_CHAIN_CNT_TYPE_U16 &&
2560 chain_size > ((u32)ECORE_U16_MAX + 1)) ||
2561 (cnt_type == ECORE_CHAIN_CNT_TYPE_U32 &&
2562 chain_size > ECORE_U32_MAX)) {
2563 DP_NOTICE(p_dev, true,
2564 "The actual chain size (0x%lx) is larger than"
2565 " the maximal possible value\n",
2566 (unsigned long)chain_size);
2570 return ECORE_SUCCESS;
2573 static enum _ecore_status_t
2574 ecore_chain_alloc_next_ptr(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
2576 void *p_virt = OSAL_NULL, *p_virt_prev = OSAL_NULL;
2577 dma_addr_t p_phys = 0;
2580 for (i = 0; i < p_chain->page_cnt; i++) {
2581 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
2582 ECORE_CHAIN_PAGE_SIZE);
2584 DP_NOTICE(p_dev, true,
2585 "Failed to allocate chain memory\n");
2590 ecore_chain_init_mem(p_chain, p_virt, p_phys);
2591 ecore_chain_reset(p_chain);
2593 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
2597 p_virt_prev = p_virt;
2599 /* Last page's next element should point to the beginning of the
2602 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
2603 p_chain->p_virt_addr,
2604 p_chain->p_phys_addr);
2606 return ECORE_SUCCESS;
2609 static enum _ecore_status_t
2610 ecore_chain_alloc_single(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
2612 void *p_virt = OSAL_NULL;
2613 dma_addr_t p_phys = 0;
2615 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys, ECORE_CHAIN_PAGE_SIZE);
2617 DP_NOTICE(p_dev, true, "Failed to allocate chain memory\n");
2621 ecore_chain_init_mem(p_chain, p_virt, p_phys);
2622 ecore_chain_reset(p_chain);
2624 return ECORE_SUCCESS;
2627 static enum _ecore_status_t ecore_chain_alloc_pbl(struct ecore_dev *p_dev,
2628 struct ecore_chain *p_chain)
2630 void *p_virt = OSAL_NULL;
2631 u8 *p_pbl_virt = OSAL_NULL;
2632 void **pp_virt_addr_tbl = OSAL_NULL;
2633 dma_addr_t p_phys = 0, p_pbl_phys = 0;
2634 u32 page_cnt = p_chain->page_cnt, size, i;
2636 size = page_cnt * sizeof(*pp_virt_addr_tbl);
2637 pp_virt_addr_tbl = (void **)OSAL_VALLOC(p_dev, size);
2638 if (!pp_virt_addr_tbl) {
2639 DP_NOTICE(p_dev, true,
2640 "Failed to allocate memory for the chain"
2641 " virtual addresses table\n");
2644 OSAL_MEM_ZERO(pp_virt_addr_tbl, size);
2646 /* The allocation of the PBL table is done with its full size, since it
2647 * is expected to be successive.
2649 size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
2650 p_pbl_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_pbl_phys, size);
2652 DP_NOTICE(p_dev, true, "Failed to allocate chain pbl memory\n");
2656 ecore_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
2659 for (i = 0; i < page_cnt; i++) {
2660 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
2661 ECORE_CHAIN_PAGE_SIZE);
2663 DP_NOTICE(p_dev, true,
2664 "Failed to allocate chain memory\n");
2669 ecore_chain_init_mem(p_chain, p_virt, p_phys);
2670 ecore_chain_reset(p_chain);
2673 /* Fill the PBL table with the physical address of the page */
2674 *(dma_addr_t *)p_pbl_virt = p_phys;
2675 /* Keep the virtual address of the page */
2676 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
2678 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
2681 return ECORE_SUCCESS;
2684 enum _ecore_status_t ecore_chain_alloc(struct ecore_dev *p_dev,
2685 enum ecore_chain_use_mode intended_use,
2686 enum ecore_chain_mode mode,
2687 enum ecore_chain_cnt_type cnt_type,
2688 u32 num_elems, osal_size_t elem_size,
2689 struct ecore_chain *p_chain)
2692 enum _ecore_status_t rc = ECORE_SUCCESS;
2694 if (mode == ECORE_CHAIN_MODE_SINGLE)
2697 page_cnt = ECORE_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
2699 rc = ecore_chain_alloc_sanity_check(p_dev, cnt_type, elem_size,
2702 DP_NOTICE(p_dev, true,
2703 "Cannot allocate a chain with the given arguments:\n"
2704 " [use_mode %d, mode %d, cnt_type %d, num_elems %d,"
2705 " elem_size %zu]\n",
2706 intended_use, mode, cnt_type, num_elems, elem_size);
2710 ecore_chain_init_params(p_chain, page_cnt, (u8)elem_size, intended_use,
2714 case ECORE_CHAIN_MODE_NEXT_PTR:
2715 rc = ecore_chain_alloc_next_ptr(p_dev, p_chain);
2717 case ECORE_CHAIN_MODE_SINGLE:
2718 rc = ecore_chain_alloc_single(p_dev, p_chain);
2720 case ECORE_CHAIN_MODE_PBL:
2721 rc = ecore_chain_alloc_pbl(p_dev, p_chain);
2727 return ECORE_SUCCESS;
2730 ecore_chain_free(p_dev, p_chain);
2734 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
2735 u16 src_id, u16 *dst_id)
2737 if (src_id >= RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
2740 min = (u16)RESC_START(p_hwfn, ECORE_L2_QUEUE);
2741 max = min + RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
2742 DP_NOTICE(p_hwfn, true,
2743 "l2_queue id [%d] is not valid, available"
2744 " indices [%d - %d]\n",
2750 *dst_id = RESC_START(p_hwfn, ECORE_L2_QUEUE) + src_id;
2752 return ECORE_SUCCESS;
2755 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
2756 u8 src_id, u8 *dst_id)
2758 if (src_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
2761 min = (u8)RESC_START(p_hwfn, ECORE_VPORT);
2762 max = min + RESC_NUM(p_hwfn, ECORE_VPORT);
2763 DP_NOTICE(p_hwfn, true,
2764 "vport id [%d] is not valid, available"
2765 " indices [%d - %d]\n",
2771 *dst_id = RESC_START(p_hwfn, ECORE_VPORT) + src_id;
2773 return ECORE_SUCCESS;
2776 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
2777 u8 src_id, u8 *dst_id)
2779 if (src_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG)) {
2782 min = (u8)RESC_START(p_hwfn, ECORE_RSS_ENG);
2783 max = min + RESC_NUM(p_hwfn, ECORE_RSS_ENG);
2784 DP_NOTICE(p_hwfn, true,
2785 "rss_eng id [%d] is not valid,avail idx [%d - %d]\n",
2791 *dst_id = RESC_START(p_hwfn, ECORE_RSS_ENG) + src_id;
2793 return ECORE_SUCCESS;
2796 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
2797 struct ecore_ptt *p_ptt,
2803 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2804 return ECORE_SUCCESS;
2806 high = p_filter[1] | (p_filter[0] << 8);
2807 low = p_filter[5] | (p_filter[4] << 8) |
2808 (p_filter[3] << 16) | (p_filter[2] << 24);
2810 /* Find a free entry and utilize it */
2811 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2812 en = ecore_rd(p_hwfn, p_ptt,
2813 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
2816 ecore_wr(p_hwfn, p_ptt,
2817 NIG_REG_LLH_FUNC_FILTER_VALUE +
2818 2 * i * sizeof(u32), low);
2819 ecore_wr(p_hwfn, p_ptt,
2820 NIG_REG_LLH_FUNC_FILTER_VALUE +
2821 (2 * i + 1) * sizeof(u32), high);
2822 ecore_wr(p_hwfn, p_ptt,
2823 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
2824 ecore_wr(p_hwfn, p_ptt,
2825 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
2826 i * sizeof(u32), 0);
2827 ecore_wr(p_hwfn, p_ptt,
2828 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
2831 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
2832 DP_NOTICE(p_hwfn, false,
2833 "Failed to find an empty LLH filter to utilize\n");
2837 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
2838 "MAC: %x:%x:%x:%x:%x:%x is added at %d\n",
2839 p_filter[0], p_filter[1], p_filter[2],
2840 p_filter[3], p_filter[4], p_filter[5], i);
2842 return ECORE_SUCCESS;
2845 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
2846 struct ecore_ptt *p_ptt, u8 *p_filter)
2851 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2854 high = p_filter[1] | (p_filter[0] << 8);
2855 low = p_filter[5] | (p_filter[4] << 8) |
2856 (p_filter[3] << 16) | (p_filter[2] << 24);
2858 /* Find the entry and clean it */
2859 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2860 if (ecore_rd(p_hwfn, p_ptt,
2861 NIG_REG_LLH_FUNC_FILTER_VALUE +
2862 2 * i * sizeof(u32)) != low)
2864 if (ecore_rd(p_hwfn, p_ptt,
2865 NIG_REG_LLH_FUNC_FILTER_VALUE +
2866 (2 * i + 1) * sizeof(u32)) != high)
2869 ecore_wr(p_hwfn, p_ptt,
2870 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
2871 ecore_wr(p_hwfn, p_ptt,
2872 NIG_REG_LLH_FUNC_FILTER_VALUE +
2873 2 * i * sizeof(u32), 0);
2874 ecore_wr(p_hwfn, p_ptt,
2875 NIG_REG_LLH_FUNC_FILTER_VALUE +
2876 (2 * i + 1) * sizeof(u32), 0);
2879 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
2880 DP_NOTICE(p_hwfn, false,
2881 "Tried to remove a non-configured filter\n");
2884 enum _ecore_status_t ecore_llh_add_ethertype_filter(struct ecore_hwfn *p_hwfn,
2885 struct ecore_ptt *p_ptt,
2891 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2892 return ECORE_SUCCESS;
2897 /* Find a free entry and utilize it */
2898 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2899 en = ecore_rd(p_hwfn, p_ptt,
2900 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
2903 ecore_wr(p_hwfn, p_ptt,
2904 NIG_REG_LLH_FUNC_FILTER_VALUE +
2905 2 * i * sizeof(u32), low);
2906 ecore_wr(p_hwfn, p_ptt,
2907 NIG_REG_LLH_FUNC_FILTER_VALUE +
2908 (2 * i + 1) * sizeof(u32), high);
2909 ecore_wr(p_hwfn, p_ptt,
2910 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1);
2911 ecore_wr(p_hwfn, p_ptt,
2912 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
2913 i * sizeof(u32), 1);
2914 ecore_wr(p_hwfn, p_ptt,
2915 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
2918 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
2919 DP_NOTICE(p_hwfn, false,
2920 "Failed to find an empty LLH filter to utilize\n");
2924 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
2925 "ETH type: %x is added at %d\n", filter, i);
2927 return ECORE_SUCCESS;
2930 void ecore_llh_remove_ethertype_filter(struct ecore_hwfn *p_hwfn,
2931 struct ecore_ptt *p_ptt, u16 filter)
2936 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2942 /* Find the entry and clean it */
2943 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2944 if (ecore_rd(p_hwfn, p_ptt,
2945 NIG_REG_LLH_FUNC_FILTER_VALUE +
2946 2 * i * sizeof(u32)) != low)
2948 if (ecore_rd(p_hwfn, p_ptt,
2949 NIG_REG_LLH_FUNC_FILTER_VALUE +
2950 (2 * i + 1) * sizeof(u32)) != high)
2953 ecore_wr(p_hwfn, p_ptt,
2954 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
2955 ecore_wr(p_hwfn, p_ptt,
2956 NIG_REG_LLH_FUNC_FILTER_VALUE +
2957 2 * i * sizeof(u32), 0);
2958 ecore_wr(p_hwfn, p_ptt,
2959 NIG_REG_LLH_FUNC_FILTER_VALUE +
2960 (2 * i + 1) * sizeof(u32), 0);
2963 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
2964 DP_NOTICE(p_hwfn, false,
2965 "Tried to remove a non-configured filter\n");
2968 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
2969 struct ecore_ptt *p_ptt)
2973 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2976 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2977 ecore_wr(p_hwfn, p_ptt,
2978 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
2979 ecore_wr(p_hwfn, p_ptt,
2980 NIG_REG_LLH_FUNC_FILTER_VALUE +
2981 2 * i * sizeof(u32), 0);
2982 ecore_wr(p_hwfn, p_ptt,
2983 NIG_REG_LLH_FUNC_FILTER_VALUE +
2984 (2 * i + 1) * sizeof(u32), 0);
2988 enum _ecore_status_t ecore_test_registers(struct ecore_hwfn *p_hwfn,
2989 struct ecore_ptt *p_ptt)
2992 BRB_REG_HEADER_SIZE,
2993 BTB_REG_HEADER_SIZE,
2994 CAU_REG_LONG_TIMEOUT_THRESHOLD,
2995 CCFC_REG_ACTIVITY_COUNTER,
2996 CDU_REG_CID_ADDR_PARAMS,
2997 DBG_REG_CLIENT_ENABLE,
3001 IGU_REG_BLOCK_CONFIGURATION,
3003 MCP2_REG_DBG_DWORD_ENABLE,
3005 MISCS_REG_CLK_100G_MODE,
3006 MSDM_REG_ENABLE_IN1,
3011 PTU_REG_ATC_INIT_ARRAY,
3013 PGLUE_B_REG_ADMIN_PER_PF_REGION,
3014 PRM_REG_DISABLE_PRM,
3016 PSDM_REG_ENABLE_IN1,
3018 PSWRQ_REG_DBG_SELECT,
3019 PSWRQ2_REG_CDUT_P_SIZE,
3020 PSWHST_REG_DISCARD_INTERNAL_WRITES,
3021 PSWHST2_REG_DBGSYN_ALMOST_FULL_THR,
3022 PSWRD_REG_DBG_SELECT,
3024 PSWWR_REG_USDM_FULL_TH,
3025 PSWWR2_REG_CDU_FULL_TH2,
3027 RSS_REG_RSS_INIT_EN,
3028 RDIF_REG_STOP_ON_ERROR,
3030 TCFC_REG_ACTIVITY_COUNTER,
3032 TM_REG_PXP_READ_DATA_FIFO_INIT,
3033 TSDM_REG_ENABLE_IN1,
3035 TDIF_REG_STOP_ON_ERROR,
3037 UMAC_REG_IPG_HD_BKP_CNTL_BB_B0,
3038 USDM_REG_ENABLE_IN1,
3041 XSDM_REG_ENABLE_IN1,
3044 YSDM_REG_ENABLE_IN1,
3046 XYLD_REG_SCBD_STRICT_PRIO,
3047 TMLD_REG_SCBD_STRICT_PRIO,
3048 MULD_REG_SCBD_STRICT_PRIO,
3049 YULD_REG_SCBD_STRICT_PRIO,
3051 u32 test_val[] = { 0x0, 0x1 };
3052 u32 val, save_val, i, j;
3054 for (i = 0; i < OSAL_ARRAY_SIZE(test_val); i++) {
3055 for (j = 0; j < OSAL_ARRAY_SIZE(reg_tbl); j++) {
3056 save_val = ecore_rd(p_hwfn, p_ptt, reg_tbl[j]);
3057 ecore_wr(p_hwfn, p_ptt, reg_tbl[j], test_val[i]);
3058 val = ecore_rd(p_hwfn, p_ptt, reg_tbl[j]);
3059 /* Restore the original register's value */
3060 ecore_wr(p_hwfn, p_ptt, reg_tbl[j], save_val);
3061 if (val != test_val[i]) {
3062 DP_INFO(p_hwfn->p_dev,
3063 "offset 0x%x: val 0x%x != 0x%x\n",
3064 reg_tbl[j], val, test_val[i]);
3069 return ECORE_SUCCESS;
3072 static enum _ecore_status_t ecore_set_coalesce(struct ecore_hwfn *p_hwfn,
3073 struct ecore_ptt *p_ptt,
3074 u32 hw_addr, void *p_qzone,
3075 osal_size_t qzone_size,
3078 struct coalescing_timeset *p_coalesce_timeset;
3080 if (IS_VF(p_hwfn->p_dev)) {
3081 DP_NOTICE(p_hwfn, true, "VF coalescing config not supported\n");
3085 if (p_hwfn->p_dev->int_coalescing_mode != ECORE_COAL_MODE_ENABLE) {
3086 DP_NOTICE(p_hwfn, true,
3087 "Coalescing configuration not enabled\n");
3091 OSAL_MEMSET(p_qzone, 0, qzone_size);
3092 p_coalesce_timeset = p_qzone;
3093 p_coalesce_timeset->timeset = timeset;
3094 p_coalesce_timeset->valid = 1;
3095 ecore_memcpy_to(p_hwfn, p_ptt, hw_addr, p_qzone, qzone_size);
3097 return ECORE_SUCCESS;
3100 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
3101 struct ecore_ptt *p_ptt,
3102 u8 coalesce, u8 qid)
3104 struct ustorm_eth_queue_zone qzone;
3108 enum _ecore_status_t rc;
3110 rc = ecore_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
3111 if (rc != ECORE_SUCCESS)
3114 address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
3115 /* Translate the coalescing time into a timeset, according to:
3116 * Timeout[Rx] = TimeSet[Rx] << (TimerRes[Rx] + 1)
3118 timeset = coalesce >> (ECORE_CAU_DEF_RX_TIMER_RES + 1);
3120 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, &qzone,
3121 sizeof(struct ustorm_eth_queue_zone), timeset);
3122 if (rc != ECORE_SUCCESS)
3125 p_hwfn->p_dev->rx_coalesce_usecs = coalesce;
3130 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
3131 struct ecore_ptt *p_ptt,
3132 u8 coalesce, u8 qid)
3134 struct ystorm_eth_queue_zone qzone;
3138 enum _ecore_status_t rc;
3140 rc = ecore_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
3141 if (rc != ECORE_SUCCESS)
3144 address = BAR0_MAP_REG_YSDM_RAM + YSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
3145 /* Translate the coalescing time into a timeset, according to:
3146 * Timeout[Tx] = TimeSet[Tx] << (TimerRes[Tx] + 1)
3148 timeset = coalesce >> (ECORE_CAU_DEF_TX_TIMER_RES + 1);
3150 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, &qzone,
3151 sizeof(struct ystorm_eth_queue_zone), timeset);
3152 if (rc != ECORE_SUCCESS)
3155 p_hwfn->p_dev->tx_coalesce_usecs = coalesce;
3160 /* Calculate final WFQ values for all vports and configure it.
3161 * After this configuration each vport must have
3162 * approx min rate = vport_wfq * min_pf_rate / ECORE_WFQ_UNIT
3164 static void ecore_configure_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
3165 struct ecore_ptt *p_ptt,
3168 struct init_qm_vport_params *vport_params;
3171 vport_params = p_hwfn->qm_info.qm_vport_params;
3172 num_vports = p_hwfn->qm_info.num_vports;
3174 for (i = 0; i < num_vports; i++) {
3175 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
3177 vport_params[i].vport_wfq =
3178 (wfq_speed * ECORE_WFQ_UNIT) / min_pf_rate;
3179 ecore_init_vport_wfq(p_hwfn, p_ptt,
3180 vport_params[i].first_tx_pq_id,
3181 vport_params[i].vport_wfq);
3186 ecore_init_wfq_default_param(struct ecore_hwfn *p_hwfn, u32 min_pf_rate)
3191 num_vports = p_hwfn->qm_info.num_vports;
3192 min_speed = min_pf_rate / num_vports;
3194 for (i = 0; i < num_vports; i++) {
3195 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
3196 p_hwfn->qm_info.wfq_data[i].default_min_speed = min_speed;
3200 static void ecore_disable_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
3201 struct ecore_ptt *p_ptt,
3204 struct init_qm_vport_params *vport_params;
3207 vport_params = p_hwfn->qm_info.qm_vport_params;
3208 num_vports = p_hwfn->qm_info.num_vports;
3210 for (i = 0; i < num_vports; i++) {
3211 ecore_init_wfq_default_param(p_hwfn, min_pf_rate);
3212 ecore_init_vport_wfq(p_hwfn, p_ptt,
3213 vport_params[i].first_tx_pq_id,
3214 vport_params[i].vport_wfq);
3218 /* validate wfq for a given vport and required min rate */
3219 static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
3220 u16 vport_id, u32 req_rate,
3223 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
3224 int non_requested_count = 0, req_count = 0, i, num_vports;
3226 num_vports = p_hwfn->qm_info.num_vports;
3228 /* Check pre-set data for some of the vports */
3229 for (i = 0; i < num_vports; i++) {
3232 if ((i != vport_id) && p_hwfn->qm_info.wfq_data[i].configured) {
3234 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
3235 total_req_min_rate += tmp_speed;
3239 /* Include current vport data as well */
3241 total_req_min_rate += req_rate;
3242 non_requested_count = p_hwfn->qm_info.num_vports - req_count;
3244 /* validate possible error cases */
3245 if (req_rate > min_pf_rate) {
3246 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3247 "Vport [%d] - Requested rate[%d Mbps] is greater"
3248 " than configured PF min rate[%d Mbps]\n",
3249 vport_id, req_rate, min_pf_rate);
3253 if (req_rate * ECORE_WFQ_UNIT / min_pf_rate < 1) {
3254 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3255 "Vport [%d] - Requested rate[%d Mbps] is less than"
3256 " one percent of configured PF min rate[%d Mbps]\n",
3257 vport_id, req_rate, min_pf_rate);
3261 /* TBD - for number of vports greater than 100 */
3262 if (ECORE_WFQ_UNIT / p_hwfn->qm_info.num_vports < 1) {
3263 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3264 "Number of vports are greater than 100\n");
3268 if (total_req_min_rate > min_pf_rate) {
3269 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3270 "Total requested min rate for all vports[%d Mbps]"
3271 "is greater than configured PF min rate[%d Mbps]\n",
3272 total_req_min_rate, min_pf_rate);
3276 /* Data left for non requested vports */
3277 total_left_rate = min_pf_rate - total_req_min_rate;
3278 left_rate_per_vp = total_left_rate / non_requested_count;
3280 /* validate if non requested get < 1% of min bw */
3281 if (left_rate_per_vp * ECORE_WFQ_UNIT / min_pf_rate < 1)
3284 /* now req_rate for given vport passes all scenarios.
3285 * assign final wfq rates to all vports.
3287 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
3288 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
3290 for (i = 0; i < num_vports; i++) {
3291 if (p_hwfn->qm_info.wfq_data[i].configured)
3294 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
3297 return ECORE_SUCCESS;
3300 static int __ecore_configure_vport_wfq(struct ecore_hwfn *p_hwfn,
3301 struct ecore_ptt *p_ptt,
3302 u16 vp_id, u32 rate)
3304 struct ecore_mcp_link_state *p_link;
3305 int rc = ECORE_SUCCESS;
3307 p_link = &p_hwfn->p_dev->hwfns[0].mcp_info->link_output;
3309 if (!p_link->min_pf_rate) {
3310 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
3311 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
3315 rc = ecore_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
3317 if (rc == ECORE_SUCCESS)
3318 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt,
3319 p_link->min_pf_rate);
3321 DP_NOTICE(p_hwfn, false,
3322 "Validation failed while configuring min rate\n");
3327 static int __ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn *p_hwfn,
3328 struct ecore_ptt *p_ptt,
3331 int rc = ECORE_SUCCESS;
3332 bool use_wfq = false;
3335 num_vports = p_hwfn->qm_info.num_vports;
3337 /* Validate all pre configured vports for wfq */
3338 for (i = 0; i < num_vports; i++) {
3339 if (p_hwfn->qm_info.wfq_data[i].configured) {
3340 u32 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
3343 rc = ecore_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
3344 if (rc == ECORE_INVAL) {
3345 DP_NOTICE(p_hwfn, false,
3346 "Validation failed while"
3347 " configuring min rate\n");
3353 if (rc == ECORE_SUCCESS && use_wfq)
3354 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
3356 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
3361 /* Main API for ecore clients to configure vport min rate.
3362 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
3363 * rate - Speed in Mbps needs to be assigned to a given vport.
3365 int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate)
3367 int i, rc = ECORE_INVAL;
3369 /* TBD - for multiple hardware functions - that is 100 gig */
3370 if (p_dev->num_hwfns > 1) {
3371 DP_NOTICE(p_dev, false,
3372 "WFQ configuration is not supported for this dev\n");
3376 for_each_hwfn(p_dev, i) {
3377 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3378 struct ecore_ptt *p_ptt;
3380 p_ptt = ecore_ptt_acquire(p_hwfn);
3382 return ECORE_TIMEOUT;
3384 rc = __ecore_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
3386 if (rc != ECORE_SUCCESS) {
3387 ecore_ptt_release(p_hwfn, p_ptt);
3391 ecore_ptt_release(p_hwfn, p_ptt);
3397 /* API to configure WFQ from mcp link change */
3398 void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
3403 /* TBD - for multiple hardware functions - that is 100 gig */
3404 if (p_dev->num_hwfns > 1) {
3405 DP_VERBOSE(p_dev, ECORE_MSG_LINK,
3406 "WFQ configuration is not supported for this dev\n");
3410 for_each_hwfn(p_dev, i) {
3411 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3413 __ecore_configure_vp_wfq_on_link_change(p_hwfn,
3419 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
3420 struct ecore_ptt *p_ptt,
3421 struct ecore_mcp_link_state *p_link,
3424 int rc = ECORE_SUCCESS;
3426 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
3428 if (!p_link->line_speed)
3431 p_link->speed = (p_link->line_speed * max_bw) / 100;
3433 rc = ecore_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id, p_link->speed);
3435 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3436 "Configured MAX bandwidth to be %08x Mb/sec\n",
3442 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
3443 int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw)
3445 int i, rc = ECORE_INVAL;
3447 if (max_bw < 1 || max_bw > 100) {
3448 DP_NOTICE(p_dev, false, "PF max bw valid range is [1-100]\n");
3452 for_each_hwfn(p_dev, i) {
3453 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3454 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
3455 struct ecore_mcp_link_state *p_link;
3456 struct ecore_ptt *p_ptt;
3458 p_link = &p_lead->mcp_info->link_output;
3460 p_ptt = ecore_ptt_acquire(p_hwfn);
3462 return ECORE_TIMEOUT;
3464 rc = __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
3466 if (rc != ECORE_SUCCESS) {
3467 ecore_ptt_release(p_hwfn, p_ptt);
3471 ecore_ptt_release(p_hwfn, p_ptt);
3477 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
3478 struct ecore_ptt *p_ptt,
3479 struct ecore_mcp_link_state *p_link,
3482 int rc = ECORE_SUCCESS;
3484 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
3486 if (!p_link->line_speed)
3489 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
3491 rc = ecore_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
3493 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3494 "Configured MIN bandwidth to be %d Mb/sec\n",
3495 p_link->min_pf_rate);
3500 /* Main API to configure PF min bandwidth where bw range is [1-100] */
3501 int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw)
3503 int i, rc = ECORE_INVAL;
3505 if (min_bw < 1 || min_bw > 100) {
3506 DP_NOTICE(p_dev, false, "PF min bw valid range is [1-100]\n");
3510 for_each_hwfn(p_dev, i) {
3511 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3512 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
3513 struct ecore_mcp_link_state *p_link;
3514 struct ecore_ptt *p_ptt;
3516 p_link = &p_lead->mcp_info->link_output;
3518 p_ptt = ecore_ptt_acquire(p_hwfn);
3520 return ECORE_TIMEOUT;
3522 rc = __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
3524 if (rc != ECORE_SUCCESS) {
3525 ecore_ptt_release(p_hwfn, p_ptt);
3529 if (p_link->min_pf_rate) {
3530 u32 min_rate = p_link->min_pf_rate;
3532 rc = __ecore_configure_vp_wfq_on_link_change(p_hwfn,
3537 ecore_ptt_release(p_hwfn, p_ptt);
3543 void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
3545 struct ecore_mcp_link_state *p_link;
3547 p_link = &p_hwfn->mcp_info->link_output;
3549 if (p_link->min_pf_rate)
3550 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt,
3551 p_link->min_pf_rate);
3553 OSAL_MEMSET(p_hwfn->qm_info.wfq_data, 0,
3554 sizeof(*p_hwfn->qm_info.wfq_data) *
3555 p_hwfn->qm_info.num_vports);
3558 int ecore_device_num_engines(struct ecore_dev *p_dev)
3560 return ECORE_IS_BB(p_dev) ? 2 : 1;
3563 int ecore_device_num_ports(struct ecore_dev *p_dev)
3565 /* in CMT always only one port */
3566 if (p_dev->num_hwfns > 1)
3569 return p_dev->num_ports_in_engines * ecore_device_num_engines(p_dev);