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_dcbx.h"
35 /* TODO - there's a bug in DCBx re-configuration flows in MF, as the QM
36 * registers involved are not split and thus configuration is a race where
37 * some of the PFs configuration might be lost.
38 * Eventually, this needs to move into a MFW-covered HW-lock as arbitration
39 * mechanism as this doesn't cover some cases [E.g., PDA or scenarios where
40 * there's more than a single compiled ecore component in system].
42 static osal_spinlock_t qm_lock;
43 static bool qm_lock_init;
46 #define ECORE_MIN_DPIS (4) /* The minimal num of DPIs required to
47 * load the driver. The number was
52 #define ECORE_MIN_PWM_REGION ((ECORE_WID_SIZE) * (ECORE_MIN_DPIS))
55 BAR_ID_0, /* used for GRC */
56 BAR_ID_1 /* Used for doorbells */
59 static u32 ecore_hw_bar_size(struct ecore_hwfn *p_hwfn, enum BAR_ID bar_id)
61 u32 bar_reg = (bar_id == BAR_ID_0 ?
62 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
65 if (IS_VF(p_hwfn->p_dev)) {
66 /* TODO - assume each VF hwfn has 64Kb for Bar0; Bar1 can be
67 * read from actual register, but we're currently not using
68 * it for actual doorbelling.
73 val = ecore_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
75 return 1 << (val + 15);
77 /* The above registers were updated in the past only in CMT mode. Since
78 * they were found to be useful MFW started updating them from 8.7.7.0.
79 * In older MFW versions they are set to 0 which means disabled.
81 if (p_hwfn->p_dev->num_hwfns > 1) {
82 DP_NOTICE(p_hwfn, false,
83 "BAR size not configured. Assuming BAR size of 256kB"
84 " for GRC and 512kB for DB\n");
85 val = BAR_ID_0 ? 256 * 1024 : 512 * 1024;
87 DP_NOTICE(p_hwfn, false,
88 "BAR size not configured. Assuming BAR size of 512kB"
89 " for GRC and 512kB for DB\n");
96 void ecore_init_dp(struct ecore_dev *p_dev,
97 u32 dp_module, u8 dp_level, void *dp_ctx)
101 p_dev->dp_level = dp_level;
102 p_dev->dp_module = dp_module;
103 p_dev->dp_ctx = dp_ctx;
104 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
105 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
107 p_hwfn->dp_level = dp_level;
108 p_hwfn->dp_module = dp_module;
109 p_hwfn->dp_ctx = dp_ctx;
113 void ecore_init_struct(struct ecore_dev *p_dev)
117 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
118 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
120 p_hwfn->p_dev = p_dev;
122 p_hwfn->b_active = false;
124 OSAL_MUTEX_ALLOC(p_hwfn, &p_hwfn->dmae_info.mutex);
125 OSAL_MUTEX_INIT(&p_hwfn->dmae_info.mutex);
128 /* hwfn 0 is always active */
129 p_dev->hwfns[0].b_active = true;
131 /* set the default cache alignment to 128 (may be overridden later) */
132 p_dev->cache_shift = 7;
135 static void ecore_qm_info_free(struct ecore_hwfn *p_hwfn)
137 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
139 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_pq_params);
140 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_vport_params);
141 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_port_params);
142 OSAL_FREE(p_hwfn->p_dev, qm_info->wfq_data);
145 void ecore_resc_free(struct ecore_dev *p_dev)
150 for_each_hwfn(p_dev, i)
151 ecore_l2_free(&p_dev->hwfns[i]);
155 OSAL_FREE(p_dev, p_dev->fw_data);
157 OSAL_FREE(p_dev, p_dev->reset_stats);
159 for_each_hwfn(p_dev, i) {
160 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
162 ecore_cxt_mngr_free(p_hwfn);
163 ecore_qm_info_free(p_hwfn);
164 ecore_spq_free(p_hwfn);
165 ecore_eq_free(p_hwfn);
166 ecore_consq_free(p_hwfn);
167 ecore_int_free(p_hwfn);
168 ecore_iov_free(p_hwfn);
169 ecore_l2_free(p_hwfn);
170 ecore_dmae_info_free(p_hwfn);
171 ecore_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
172 /* @@@TBD Flush work-queue ? */
176 /******************** QM initialization *******************/
178 /* bitmaps for indicating active traffic classes.
179 * Special case for Arrowhead 4 port
181 /* 0..3 actualy used, 4 serves OOO, 7 serves high priority stuff (e.g. DCQCN) */
182 #define ACTIVE_TCS_BMAP 0x9f
183 /* 0..3 actually used, OOO and high priority stuff all use 3 */
184 #define ACTIVE_TCS_BMAP_4PORT_K2 0xf
186 /* determines the physical queue flags for a given PF. */
187 static u32 ecore_get_pq_flags(struct ecore_hwfn *p_hwfn)
195 if (IS_ECORE_SRIOV(p_hwfn->p_dev))
196 flags |= PQ_FLAGS_VFS;
199 switch (p_hwfn->hw_info.personality) {
201 flags |= PQ_FLAGS_MCOS;
204 flags |= PQ_FLAGS_OFLD;
206 case ECORE_PCI_ISCSI:
207 flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
209 case ECORE_PCI_ETH_ROCE:
210 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD;
212 case ECORE_PCI_ETH_IWARP:
213 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_ACK | PQ_FLAGS_OOO |
217 DP_ERR(p_hwfn, "unknown personality %d\n",
218 p_hwfn->hw_info.personality);
224 /* Getters for resource amounts necessary for qm initialization */
225 u8 ecore_init_qm_get_num_tcs(struct ecore_hwfn *p_hwfn)
227 return p_hwfn->hw_info.num_hw_tc;
230 u16 ecore_init_qm_get_num_vfs(struct ecore_hwfn *p_hwfn)
232 return IS_ECORE_SRIOV(p_hwfn->p_dev) ?
233 p_hwfn->p_dev->p_iov_info->total_vfs : 0;
236 #define NUM_DEFAULT_RLS 1
238 u16 ecore_init_qm_get_num_pf_rls(struct ecore_hwfn *p_hwfn)
240 u16 num_pf_rls, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
243 /* num RLs can't exceed resource amount of rls or vports or the
246 num_pf_rls = (u16)OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_RL),
247 (u16)RESC_NUM(p_hwfn, ECORE_VPORT));
249 /* make sure after we reserve the default and VF rls we'll have
252 if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS) {
253 DP_NOTICE(p_hwfn, false,
254 "no rate limiters left for PF rate limiting"
255 " [num_pf_rls %d num_vfs %d]\n", num_pf_rls, num_vfs);
259 /* subtract rls necessary for VFs and one default one for the PF */
260 num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
265 u16 ecore_init_qm_get_num_vports(struct ecore_hwfn *p_hwfn)
267 u32 pq_flags = ecore_get_pq_flags(p_hwfn);
269 /* all pqs share the same vport (hence the 1 below), except for vfs
272 return (!!(PQ_FLAGS_RLS & pq_flags)) *
273 ecore_init_qm_get_num_pf_rls(p_hwfn) +
274 (!!(PQ_FLAGS_VFS & pq_flags)) *
275 ecore_init_qm_get_num_vfs(p_hwfn) + 1;
278 /* calc amount of PQs according to the requested flags */
279 u16 ecore_init_qm_get_num_pqs(struct ecore_hwfn *p_hwfn)
281 u32 pq_flags = ecore_get_pq_flags(p_hwfn);
283 return (!!(PQ_FLAGS_RLS & pq_flags)) *
284 ecore_init_qm_get_num_pf_rls(p_hwfn) +
285 (!!(PQ_FLAGS_MCOS & pq_flags)) *
286 ecore_init_qm_get_num_tcs(p_hwfn) +
287 (!!(PQ_FLAGS_LB & pq_flags)) +
288 (!!(PQ_FLAGS_OOO & pq_flags)) +
289 (!!(PQ_FLAGS_ACK & pq_flags)) +
290 (!!(PQ_FLAGS_OFLD & pq_flags)) +
291 (!!(PQ_FLAGS_VFS & pq_flags)) *
292 ecore_init_qm_get_num_vfs(p_hwfn);
295 /* initialize the top level QM params */
296 static void ecore_init_qm_params(struct ecore_hwfn *p_hwfn)
298 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
301 /* pq and vport bases for this PF */
302 qm_info->start_pq = (u16)RESC_START(p_hwfn, ECORE_PQ);
303 qm_info->start_vport = (u8)RESC_START(p_hwfn, ECORE_VPORT);
305 /* rate limiting and weighted fair queueing are always enabled */
306 qm_info->vport_rl_en = 1;
307 qm_info->vport_wfq_en = 1;
309 /* TC config is different for AH 4 port */
310 four_port = p_hwfn->p_dev->num_ports_in_engines == MAX_NUM_PORTS_K2;
312 /* in AH 4 port we have fewer TCs per port */
313 qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 :
316 /* unless MFW indicated otherwise, ooo_tc should be 3 for AH 4 port and
319 if (!qm_info->ooo_tc)
320 qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC :
324 /* initialize qm vport params */
325 static void ecore_init_qm_vport_params(struct ecore_hwfn *p_hwfn)
327 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
330 /* all vports participate in weighted fair queueing */
331 for (i = 0; i < ecore_init_qm_get_num_vports(p_hwfn); i++)
332 qm_info->qm_vport_params[i].vport_wfq = 1;
335 /* initialize qm port params */
336 static void ecore_init_qm_port_params(struct ecore_hwfn *p_hwfn)
338 /* Initialize qm port parameters */
339 u8 i, active_phys_tcs, num_ports = p_hwfn->p_dev->num_ports_in_engines;
341 /* indicate how ooo and high pri traffic is dealt with */
342 active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
343 ACTIVE_TCS_BMAP_4PORT_K2 : ACTIVE_TCS_BMAP;
345 for (i = 0; i < num_ports; i++) {
346 struct init_qm_port_params *p_qm_port =
347 &p_hwfn->qm_info.qm_port_params[i];
349 p_qm_port->active = 1;
350 p_qm_port->active_phys_tcs = active_phys_tcs;
351 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
352 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
356 /* Reset the params which must be reset for qm init. QM init may be called as
357 * a result of flows other than driver load (e.g. dcbx renegotiation). Other
358 * params may be affected by the init but would simply recalculate to the same
359 * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
360 * affected as these amounts stay the same.
362 static void ecore_init_qm_reset_params(struct ecore_hwfn *p_hwfn)
364 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
366 qm_info->num_pqs = 0;
367 qm_info->num_vports = 0;
368 qm_info->num_pf_rls = 0;
369 qm_info->num_vf_pqs = 0;
370 qm_info->first_vf_pq = 0;
371 qm_info->first_mcos_pq = 0;
372 qm_info->first_rl_pq = 0;
375 static void ecore_init_qm_advance_vport(struct ecore_hwfn *p_hwfn)
377 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
379 qm_info->num_vports++;
381 if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
383 "vport overflow! qm_info->num_vports %d,"
384 " qm_init_get_num_vports() %d\n",
386 ecore_init_qm_get_num_vports(p_hwfn));
389 /* initialize a single pq and manage qm_info resources accounting.
390 * The pq_init_flags param determines whether the PQ is rate limited
392 * and whether a new vport is allocated to the pq or not (i.e. vport will be
396 /* flags for pq init */
397 #define PQ_INIT_SHARE_VPORT (1 << 0)
398 #define PQ_INIT_PF_RL (1 << 1)
399 #define PQ_INIT_VF_RL (1 << 2)
401 /* defines for pq init */
402 #define PQ_INIT_DEFAULT_WRR_GROUP 1
403 #define PQ_INIT_DEFAULT_TC 0
404 #define PQ_INIT_OFLD_TC (p_hwfn->hw_info.offload_tc)
406 static void ecore_init_qm_pq(struct ecore_hwfn *p_hwfn,
407 struct ecore_qm_info *qm_info,
408 u8 tc, u32 pq_init_flags)
410 u16 pq_idx = qm_info->num_pqs, max_pq =
411 ecore_init_qm_get_num_pqs(p_hwfn);
415 "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
418 qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
420 qm_info->qm_pq_params[pq_idx].tc_id = tc;
421 qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
422 qm_info->qm_pq_params[pq_idx].rl_valid =
423 (pq_init_flags & PQ_INIT_PF_RL ||
424 pq_init_flags & PQ_INIT_VF_RL);
426 /* qm params accounting */
428 if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
429 qm_info->num_vports++;
431 if (pq_init_flags & PQ_INIT_PF_RL)
432 qm_info->num_pf_rls++;
434 if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
436 "vport overflow! qm_info->num_vports %d,"
437 " qm_init_get_num_vports() %d\n",
439 ecore_init_qm_get_num_vports(p_hwfn));
441 if (qm_info->num_pf_rls > ecore_init_qm_get_num_pf_rls(p_hwfn))
442 DP_ERR(p_hwfn, "rl overflow! qm_info->num_pf_rls %d,"
443 " qm_init_get_num_pf_rls() %d\n",
445 ecore_init_qm_get_num_pf_rls(p_hwfn));
448 /* get pq index according to PQ_FLAGS */
449 static u16 *ecore_init_qm_get_idx_from_flags(struct ecore_hwfn *p_hwfn,
452 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
454 /* Can't have multiple flags set here */
455 if (OSAL_BITMAP_WEIGHT((unsigned long *)&pq_flags,
456 sizeof(pq_flags)) > 1)
461 return &qm_info->first_rl_pq;
463 return &qm_info->first_mcos_pq;
465 return &qm_info->pure_lb_pq;
467 return &qm_info->ooo_pq;
469 return &qm_info->pure_ack_pq;
471 return &qm_info->offload_pq;
473 return &qm_info->first_vf_pq;
479 DP_ERR(p_hwfn, "BAD pq flags %d\n", pq_flags);
483 /* save pq index in qm info */
484 static void ecore_init_qm_set_idx(struct ecore_hwfn *p_hwfn,
485 u32 pq_flags, u16 pq_val)
487 u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
489 *base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
492 /* get tx pq index, with the PQ TX base already set (ready for context init) */
493 u16 ecore_get_cm_pq_idx(struct ecore_hwfn *p_hwfn, u32 pq_flags)
495 u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
497 return *base_pq_idx + CM_TX_PQ_BASE;
500 u16 ecore_get_cm_pq_idx_mcos(struct ecore_hwfn *p_hwfn, u8 tc)
502 u8 max_tc = ecore_init_qm_get_num_tcs(p_hwfn);
505 DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
507 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
510 u16 ecore_get_cm_pq_idx_vf(struct ecore_hwfn *p_hwfn, u16 vf)
512 u16 max_vf = ecore_init_qm_get_num_vfs(p_hwfn);
515 DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
517 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
520 u16 ecore_get_cm_pq_idx_rl(struct ecore_hwfn *p_hwfn, u8 rl)
522 u16 max_rl = ecore_init_qm_get_num_pf_rls(p_hwfn);
525 DP_ERR(p_hwfn, "rl %d must be smaller than %d\n", rl, max_rl);
527 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
530 /* Functions for creating specific types of pqs */
531 static void ecore_init_qm_lb_pq(struct ecore_hwfn *p_hwfn)
533 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
535 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
538 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
539 ecore_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
542 static void ecore_init_qm_ooo_pq(struct ecore_hwfn *p_hwfn)
544 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
546 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
549 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
550 ecore_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
553 static void ecore_init_qm_pure_ack_pq(struct ecore_hwfn *p_hwfn)
555 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
557 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
560 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
561 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
564 static void ecore_init_qm_offload_pq(struct ecore_hwfn *p_hwfn)
566 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
568 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
571 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
572 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
575 static void ecore_init_qm_mcos_pqs(struct ecore_hwfn *p_hwfn)
577 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
580 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
583 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
584 for (tc_idx = 0; tc_idx < ecore_init_qm_get_num_tcs(p_hwfn); tc_idx++)
585 ecore_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
588 static void ecore_init_qm_vf_pqs(struct ecore_hwfn *p_hwfn)
590 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
591 u16 vf_idx, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
593 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
596 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
598 qm_info->num_vf_pqs = num_vfs;
599 for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
600 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_DEFAULT_TC,
604 static void ecore_init_qm_rl_pqs(struct ecore_hwfn *p_hwfn)
606 u16 pf_rls_idx, num_pf_rls = ecore_init_qm_get_num_pf_rls(p_hwfn);
607 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
609 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
612 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
613 for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
614 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC,
618 static void ecore_init_qm_pq_params(struct ecore_hwfn *p_hwfn)
620 /* rate limited pqs, must come first (FW assumption) */
621 ecore_init_qm_rl_pqs(p_hwfn);
623 /* pqs for multi cos */
624 ecore_init_qm_mcos_pqs(p_hwfn);
626 /* pure loopback pq */
627 ecore_init_qm_lb_pq(p_hwfn);
629 /* out of order pq */
630 ecore_init_qm_ooo_pq(p_hwfn);
633 ecore_init_qm_pure_ack_pq(p_hwfn);
635 /* pq for offloaded protocol */
636 ecore_init_qm_offload_pq(p_hwfn);
638 /* done sharing vports */
639 ecore_init_qm_advance_vport(p_hwfn);
642 ecore_init_qm_vf_pqs(p_hwfn);
645 /* compare values of getters against resources amounts */
646 static enum _ecore_status_t ecore_init_qm_sanity(struct ecore_hwfn *p_hwfn)
648 if (ecore_init_qm_get_num_vports(p_hwfn) >
649 RESC_NUM(p_hwfn, ECORE_VPORT)) {
650 DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
654 if (ecore_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, ECORE_PQ)) {
655 DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
659 return ECORE_SUCCESS;
663 * Function for verbose printing of the qm initialization results
665 static void ecore_dp_init_qm_params(struct ecore_hwfn *p_hwfn)
667 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
668 struct init_qm_vport_params *vport;
669 struct init_qm_port_params *port;
670 struct init_qm_pq_params *pq;
673 /* top level params */
674 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
675 "qm init top level params: start_pq %d, start_vport %d,"
676 " pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
677 qm_info->start_pq, qm_info->start_vport, qm_info->pure_lb_pq,
678 qm_info->offload_pq, qm_info->pure_ack_pq);
679 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
680 "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d,"
681 " num_vports %d, max_phys_tcs_per_port %d\n",
682 qm_info->ooo_pq, qm_info->first_vf_pq, qm_info->num_pqs,
683 qm_info->num_vf_pqs, qm_info->num_vports,
684 qm_info->max_phys_tcs_per_port);
685 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
686 "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d,"
687 " pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
688 qm_info->pf_rl_en, qm_info->pf_wfq_en, qm_info->vport_rl_en,
689 qm_info->vport_wfq_en, qm_info->pf_wfq, qm_info->pf_rl,
690 qm_info->num_pf_rls, ecore_get_pq_flags(p_hwfn));
693 for (i = 0; i < p_hwfn->p_dev->num_ports_in_engines; i++) {
694 port = &qm_info->qm_port_params[i];
695 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
696 "port idx %d, active %d, active_phys_tcs %d,"
697 " num_pbf_cmd_lines %d, num_btb_blocks %d,"
699 i, port->active, port->active_phys_tcs,
700 port->num_pbf_cmd_lines, port->num_btb_blocks,
705 for (i = 0; i < qm_info->num_vports; i++) {
706 vport = &qm_info->qm_vport_params[i];
707 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
708 "vport idx %d, vport_rl %d, wfq %d,"
709 " first_tx_pq_id [ ",
710 qm_info->start_vport + i, vport->vport_rl,
712 for (tc = 0; tc < NUM_OF_TCS; tc++)
713 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "%d ",
714 vport->first_tx_pq_id[tc]);
715 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "]\n");
719 for (i = 0; i < qm_info->num_pqs; i++) {
720 pq = &qm_info->qm_pq_params[i];
721 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
722 "pq idx %d, vport_id %d, tc %d, wrr_grp %d,"
724 qm_info->start_pq + i, pq->vport_id, pq->tc_id,
725 pq->wrr_group, pq->rl_valid);
729 static void ecore_init_qm_info(struct ecore_hwfn *p_hwfn)
731 /* reset params required for init run */
732 ecore_init_qm_reset_params(p_hwfn);
734 /* init QM top level params */
735 ecore_init_qm_params(p_hwfn);
737 /* init QM port params */
738 ecore_init_qm_port_params(p_hwfn);
740 /* init QM vport params */
741 ecore_init_qm_vport_params(p_hwfn);
743 /* init QM physical queue params */
744 ecore_init_qm_pq_params(p_hwfn);
746 /* display all that init */
747 ecore_dp_init_qm_params(p_hwfn);
750 /* This function reconfigures the QM pf on the fly.
751 * For this purpose we:
752 * 1. reconfigure the QM database
753 * 2. set new values to runtime array
754 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
755 * 4. activate init tool in QM_PF stage
756 * 5. send an sdm_qm_cmd through rbc interface to release the QM
758 enum _ecore_status_t ecore_qm_reconf(struct ecore_hwfn *p_hwfn,
759 struct ecore_ptt *p_ptt)
761 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
763 enum _ecore_status_t rc;
765 /* initialize ecore's qm data structure */
766 ecore_init_qm_info(p_hwfn);
768 /* stop PF's qm queues */
769 OSAL_SPIN_LOCK(&qm_lock);
770 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
771 qm_info->start_pq, qm_info->num_pqs);
772 OSAL_SPIN_UNLOCK(&qm_lock);
776 /* clear the QM_PF runtime phase leftovers from previous init */
777 ecore_init_clear_rt_data(p_hwfn);
779 /* prepare QM portion of runtime array */
780 ecore_qm_init_pf(p_hwfn);
782 /* activate init tool on runtime array */
783 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
784 p_hwfn->hw_info.hw_mode);
785 if (rc != ECORE_SUCCESS)
788 /* start PF's qm queues */
789 OSAL_SPIN_LOCK(&qm_lock);
790 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
791 qm_info->start_pq, qm_info->num_pqs);
792 OSAL_SPIN_UNLOCK(&qm_lock);
796 return ECORE_SUCCESS;
799 static enum _ecore_status_t ecore_alloc_qm_data(struct ecore_hwfn *p_hwfn)
801 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
802 enum _ecore_status_t rc;
804 rc = ecore_init_qm_sanity(p_hwfn);
805 if (rc != ECORE_SUCCESS)
808 qm_info->qm_pq_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
809 sizeof(struct init_qm_pq_params) *
810 ecore_init_qm_get_num_pqs(p_hwfn));
811 if (!qm_info->qm_pq_params)
814 qm_info->qm_vport_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
815 sizeof(struct init_qm_vport_params) *
816 ecore_init_qm_get_num_vports(p_hwfn));
817 if (!qm_info->qm_vport_params)
820 qm_info->qm_port_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
821 sizeof(struct init_qm_port_params) *
822 p_hwfn->p_dev->num_ports_in_engines);
823 if (!qm_info->qm_port_params)
826 qm_info->wfq_data = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
827 sizeof(struct ecore_wfq_data) *
828 ecore_init_qm_get_num_vports(p_hwfn));
829 if (!qm_info->wfq_data)
832 return ECORE_SUCCESS;
835 DP_NOTICE(p_hwfn, false, "Failed to allocate memory for QM params\n");
836 ecore_qm_info_free(p_hwfn);
839 /******************** End QM initialization ***************/
841 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev)
843 enum _ecore_status_t rc = ECORE_SUCCESS;
847 for_each_hwfn(p_dev, i) {
848 rc = ecore_l2_alloc(&p_dev->hwfns[i]);
849 if (rc != ECORE_SUCCESS)
855 p_dev->fw_data = OSAL_ZALLOC(p_dev, GFP_KERNEL,
856 sizeof(*p_dev->fw_data));
860 for_each_hwfn(p_dev, i) {
861 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
862 u32 n_eqes, num_cons;
864 /* First allocate the context manager structure */
865 rc = ecore_cxt_mngr_alloc(p_hwfn);
869 /* Set the HW cid/tid numbers (in the contest manager)
870 * Must be done prior to any further computations.
872 rc = ecore_cxt_set_pf_params(p_hwfn);
876 rc = ecore_alloc_qm_data(p_hwfn);
881 ecore_init_qm_info(p_hwfn);
883 /* Compute the ILT client partition */
884 rc = ecore_cxt_cfg_ilt_compute(p_hwfn);
888 /* CID map / ILT shadow table / T2
889 * The talbes sizes are determined by the computations above
891 rc = ecore_cxt_tables_alloc(p_hwfn);
895 /* SPQ, must follow ILT because initializes SPQ context */
896 rc = ecore_spq_alloc(p_hwfn);
900 /* SP status block allocation */
901 p_hwfn->p_dpc_ptt = ecore_get_reserved_ptt(p_hwfn,
904 rc = ecore_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
908 rc = ecore_iov_alloc(p_hwfn);
913 n_eqes = ecore_chain_get_capacity(&p_hwfn->p_spq->chain);
914 if (ECORE_IS_RDMA_PERSONALITY(p_hwfn)) {
915 /* Calculate the EQ size
916 * ---------------------
917 * Each ICID may generate up to one event at a time i.e.
918 * the event must be handled/cleared before a new one
919 * can be generated. We calculate the sum of events per
920 * protocol and create an EQ deep enough to handle the
922 * - Core - according to SPQ.
923 * - RoCE - per QP there are a couple of ICIDs, one
924 * responder and one requester, each can
925 * generate an EQE => n_eqes_qp = 2 * n_qp.
926 * Each CQ can generate an EQE. There are 2 CQs
927 * per QP => n_eqes_cq = 2 * n_qp.
928 * Hence the RoCE total is 4 * n_qp or
930 * - ENet - There can be up to two events per VF. One
931 * for VF-PF channel and another for VF FLR
932 * initial cleanup. The number of VFs is
933 * bounded by MAX_NUM_VFS_BB, and is much
934 * smaller than RoCE's so we avoid exact
937 if (ECORE_IS_ROCE_PERSONALITY(p_hwfn)) {
939 ecore_cxt_get_proto_cid_count(
945 num_cons = ecore_cxt_get_proto_cid_count(
950 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
951 } else if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
953 ecore_cxt_get_proto_cid_count(p_hwfn,
956 n_eqes += 2 * num_cons;
959 if (n_eqes > 0xFFFF) {
960 DP_ERR(p_hwfn, "Cannot allocate 0x%x EQ elements."
961 "The maximum of a u16 chain is 0x%x\n",
966 rc = ecore_eq_alloc(p_hwfn, (u16)n_eqes);
970 rc = ecore_consq_alloc(p_hwfn);
974 rc = ecore_l2_alloc(p_hwfn);
975 if (rc != ECORE_SUCCESS)
978 /* DMA info initialization */
979 rc = ecore_dmae_info_alloc(p_hwfn);
981 DP_NOTICE(p_hwfn, true,
982 "Failed to allocate memory for dmae_info"
987 /* DCBX initialization */
988 rc = ecore_dcbx_info_alloc(p_hwfn);
990 DP_NOTICE(p_hwfn, true,
991 "Failed to allocate memory for dcbx structure\n");
996 p_dev->reset_stats = OSAL_ZALLOC(p_dev, GFP_KERNEL,
997 sizeof(*p_dev->reset_stats));
998 if (!p_dev->reset_stats) {
999 DP_NOTICE(p_dev, true, "Failed to allocate reset statistics\n");
1003 return ECORE_SUCCESS;
1008 ecore_resc_free(p_dev);
1012 void ecore_resc_setup(struct ecore_dev *p_dev)
1017 for_each_hwfn(p_dev, i)
1018 ecore_l2_setup(&p_dev->hwfns[i]);
1022 for_each_hwfn(p_dev, i) {
1023 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1025 ecore_cxt_mngr_setup(p_hwfn);
1026 ecore_spq_setup(p_hwfn);
1027 ecore_eq_setup(p_hwfn);
1028 ecore_consq_setup(p_hwfn);
1030 /* Read shadow of current MFW mailbox */
1031 ecore_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
1032 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1033 p_hwfn->mcp_info->mfw_mb_cur,
1034 p_hwfn->mcp_info->mfw_mb_length);
1036 ecore_int_setup(p_hwfn, p_hwfn->p_main_ptt);
1038 ecore_l2_setup(p_hwfn);
1039 ecore_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
1043 #define FINAL_CLEANUP_POLL_CNT (100)
1044 #define FINAL_CLEANUP_POLL_TIME (10)
1045 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
1046 struct ecore_ptt *p_ptt,
1049 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
1050 enum _ecore_status_t rc = ECORE_TIMEOUT;
1053 if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev) ||
1054 CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1055 DP_INFO(p_hwfn, "Skipping final cleanup for non-ASIC\n");
1056 return ECORE_SUCCESS;
1060 addr = GTT_BAR0_MAP_REG_USDM_RAM +
1061 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
1066 command |= X_FINAL_CLEANUP_AGG_INT <<
1067 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
1068 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
1069 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
1070 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
1072 /* Make sure notification is not set before initiating final cleanup */
1074 if (REG_RD(p_hwfn, addr)) {
1075 DP_NOTICE(p_hwfn, false,
1076 "Unexpected; Found final cleanup notification");
1077 DP_NOTICE(p_hwfn, false,
1078 " before initiating final cleanup\n");
1079 REG_WR(p_hwfn, addr, 0);
1082 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1083 "Sending final cleanup for PFVF[%d] [Command %08x]\n",
1086 ecore_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
1088 /* Poll until completion */
1089 while (!REG_RD(p_hwfn, addr) && count--)
1090 OSAL_MSLEEP(FINAL_CLEANUP_POLL_TIME);
1092 if (REG_RD(p_hwfn, addr))
1095 DP_NOTICE(p_hwfn, true,
1096 "Failed to receive FW final cleanup notification\n");
1098 /* Cleanup afterwards */
1099 REG_WR(p_hwfn, addr, 0);
1104 static enum _ecore_status_t ecore_calc_hw_mode(struct ecore_hwfn *p_hwfn)
1108 if (ECORE_IS_BB_B0(p_hwfn->p_dev)) {
1109 hw_mode |= 1 << MODE_BB;
1110 } else if (ECORE_IS_AH(p_hwfn->p_dev)) {
1111 hw_mode |= 1 << MODE_K2;
1113 DP_NOTICE(p_hwfn, true, "Unknown chip type %#x\n",
1114 p_hwfn->p_dev->type);
1118 /* Ports per engine is based on the values in CNIG_REG_NW_PORT_MODE */
1119 switch (p_hwfn->p_dev->num_ports_in_engines) {
1121 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
1124 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
1127 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
1130 DP_NOTICE(p_hwfn, true,
1131 "num_ports_in_engine = %d not supported\n",
1132 p_hwfn->p_dev->num_ports_in_engines);
1136 switch (p_hwfn->p_dev->mf_mode) {
1137 case ECORE_MF_DEFAULT:
1139 hw_mode |= 1 << MODE_MF_SI;
1141 case ECORE_MF_OVLAN:
1142 hw_mode |= 1 << MODE_MF_SD;
1145 DP_NOTICE(p_hwfn, true,
1146 "Unsupported MF mode, init as DEFAULT\n");
1147 hw_mode |= 1 << MODE_MF_SI;
1151 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1152 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1153 hw_mode |= 1 << MODE_FPGA;
1155 if (p_hwfn->p_dev->b_is_emul_full)
1156 hw_mode |= 1 << MODE_EMUL_FULL;
1158 hw_mode |= 1 << MODE_EMUL_REDUCED;
1162 hw_mode |= 1 << MODE_ASIC;
1164 if (p_hwfn->p_dev->num_hwfns > 1)
1165 hw_mode |= 1 << MODE_100G;
1167 p_hwfn->hw_info.hw_mode = hw_mode;
1169 DP_VERBOSE(p_hwfn, (ECORE_MSG_PROBE | ECORE_MSG_IFUP),
1170 "Configuring function for hw_mode: 0x%08x\n",
1171 p_hwfn->hw_info.hw_mode);
1173 return ECORE_SUCCESS;
1177 /* MFW-replacement initializations for non-ASIC */
1178 static enum _ecore_status_t ecore_hw_init_chip(struct ecore_hwfn *p_hwfn,
1179 struct ecore_ptt *p_ptt)
1181 struct ecore_dev *p_dev = p_hwfn->p_dev;
1185 if (CHIP_REV_IS_EMUL(p_dev)) {
1186 if (ECORE_IS_AH(p_dev))
1190 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV + 4, pl_hv);
1192 if (CHIP_REV_IS_EMUL(p_dev) &&
1193 (ECORE_IS_AH(p_dev)))
1194 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV_2_K2_E5,
1197 /* initialize port mode to 4x10G_E (10G with 4x10 SERDES) */
1198 /* CNIG_REG_NW_PORT_MODE is same for A0 and B0 */
1199 if (!CHIP_REV_IS_EMUL(p_dev) || ECORE_IS_BB(p_dev))
1200 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB, 4);
1202 if (CHIP_REV_IS_EMUL(p_dev)) {
1203 if (ECORE_IS_AH(p_dev)) {
1204 /* 2 for 4-port, 1 for 2-port, 0 for 1-port */
1205 ecore_wr(p_hwfn, p_ptt, MISC_REG_PORT_MODE,
1206 (p_dev->num_ports_in_engines >> 1));
1208 ecore_wr(p_hwfn, p_ptt, MISC_REG_BLOCK_256B_EN,
1209 p_dev->num_ports_in_engines == 4 ? 0 : 3);
1214 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_RBC_DONE, 1);
1215 for (i = 0; i < 100; i++) {
1217 if (ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_CFG_DONE) == 1)
1221 DP_NOTICE(p_hwfn, true,
1222 "RBC done failed to complete in PSWRQ2\n");
1224 return ECORE_SUCCESS;
1228 /* Init run time data for all PFs and their VFs on an engine.
1229 * TBD - for VFs - Once we have parent PF info for each VF in
1230 * shmem available as CAU requires knowledge of parent PF for each VF.
1232 static void ecore_init_cau_rt_data(struct ecore_dev *p_dev)
1234 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
1237 for_each_hwfn(p_dev, i) {
1238 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1239 struct ecore_igu_info *p_igu_info;
1240 struct ecore_igu_block *p_block;
1241 struct cau_sb_entry sb_entry;
1243 p_igu_info = p_hwfn->hw_info.p_igu_info;
1245 for (sb_id = 0; sb_id < ECORE_MAPPING_MEMORY_SIZE(p_dev);
1247 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
1249 if (!p_block->is_pf)
1252 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
1253 p_block->function_id, 0, 0);
1254 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry);
1259 static enum _ecore_status_t ecore_hw_init_common(struct ecore_hwfn *p_hwfn,
1260 struct ecore_ptt *p_ptt,
1263 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
1264 struct ecore_dev *p_dev = p_hwfn->p_dev;
1265 u8 vf_id, max_num_vfs;
1268 enum _ecore_status_t rc = ECORE_SUCCESS;
1270 ecore_init_cau_rt_data(p_dev);
1272 /* Program GTT windows */
1273 ecore_gtt_init(p_hwfn);
1276 if (CHIP_REV_IS_EMUL(p_dev)) {
1277 rc = ecore_hw_init_chip(p_hwfn, p_hwfn->p_main_ptt);
1278 if (rc != ECORE_SUCCESS)
1283 if (p_hwfn->mcp_info) {
1284 if (p_hwfn->mcp_info->func_info.bandwidth_max)
1285 qm_info->pf_rl_en = 1;
1286 if (p_hwfn->mcp_info->func_info.bandwidth_min)
1287 qm_info->pf_wfq_en = 1;
1290 ecore_qm_common_rt_init(p_hwfn,
1291 p_dev->num_ports_in_engines,
1292 qm_info->max_phys_tcs_per_port,
1293 qm_info->pf_rl_en, qm_info->pf_wfq_en,
1294 qm_info->vport_rl_en, qm_info->vport_wfq_en,
1295 qm_info->qm_port_params);
1297 ecore_cxt_hw_init_common(p_hwfn);
1299 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
1300 if (rc != ECORE_SUCCESS)
1303 /* @@TBD MichalK - should add VALIDATE_VFID to init tool...
1304 * need to decide with which value, maybe runtime
1306 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
1307 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
1309 if (ECORE_IS_BB(p_dev)) {
1310 /* Workaround clears ROCE search for all functions to prevent
1311 * involving non initialized function in processing ROCE packet.
1313 num_pfs = NUM_OF_ENG_PFS(p_dev);
1314 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
1315 ecore_fid_pretend(p_hwfn, p_ptt, pf_id);
1316 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1317 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1319 /* pretend to original PF */
1320 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1323 /* Workaround for avoiding CCFC execution error when getting packets
1324 * with CRC errors, and allowing instead the invoking of the FW error
1326 * This is not done inside the init tool since it currently can't
1327 * perform a pretending to VFs.
1329 max_num_vfs = ECORE_IS_AH(p_dev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
1330 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
1331 concrete_fid = ecore_vfid_to_concrete(p_hwfn, vf_id);
1332 ecore_fid_pretend(p_hwfn, p_ptt, (u16)concrete_fid);
1333 ecore_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
1334 ecore_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
1335 ecore_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
1336 ecore_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
1338 /* pretend to original PF */
1339 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1345 #define MISC_REG_RESET_REG_2_XMAC_BIT (1 << 4)
1346 #define MISC_REG_RESET_REG_2_XMAC_SOFT_BIT (1 << 5)
1348 #define PMEG_IF_BYTE_COUNT 8
1350 static void ecore_wr_nw_port(struct ecore_hwfn *p_hwfn,
1351 struct ecore_ptt *p_ptt,
1352 u32 addr, u64 data, u8 reg_type, u8 port)
1354 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1355 "CMD: %08x, ADDR: 0x%08x, DATA: %08x:%08x\n",
1356 ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) |
1357 (8 << PMEG_IF_BYTE_COUNT),
1358 (reg_type << 25) | (addr << 8) | port,
1359 (u32)((data >> 32) & 0xffffffff),
1360 (u32)(data & 0xffffffff));
1362 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB,
1363 (ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) &
1364 0xffff00fe) | (8 << PMEG_IF_BYTE_COUNT));
1365 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_ADDR_BB,
1366 (reg_type << 25) | (addr << 8) | port);
1367 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB, data & 0xffffffff);
1368 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB,
1369 (data >> 32) & 0xffffffff);
1372 #define XLPORT_MODE_REG (0x20a)
1373 #define XLPORT_MAC_CONTROL (0x210)
1374 #define XLPORT_FLOW_CONTROL_CONFIG (0x207)
1375 #define XLPORT_ENABLE_REG (0x20b)
1377 #define XLMAC_CTRL (0x600)
1378 #define XLMAC_MODE (0x601)
1379 #define XLMAC_RX_MAX_SIZE (0x608)
1380 #define XLMAC_TX_CTRL (0x604)
1381 #define XLMAC_PAUSE_CTRL (0x60d)
1382 #define XLMAC_PFC_CTRL (0x60e)
1384 static void ecore_emul_link_init_bb(struct ecore_hwfn *p_hwfn,
1385 struct ecore_ptt *p_ptt)
1387 u8 loopback = 0, port = p_hwfn->port_id * 2;
1389 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
1391 /* XLPORT MAC MODE *//* 0 Quad, 4 Single... */
1392 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MODE_REG, (0x4 << 4) | 0x4, 1,
1394 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MAC_CONTROL, 0, 1, port);
1395 /* XLMAC: SOFT RESET */
1396 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x40, 0, port);
1397 /* XLMAC: Port Speed >= 10Gbps */
1398 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_MODE, 0x40, 0, port);
1399 /* XLMAC: Max Size */
1400 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_RX_MAX_SIZE, 0x3fff, 0, port);
1401 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_TX_CTRL,
1402 0x01000000800ULL | (0xa << 12) | ((u64)1 << 38),
1404 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PAUSE_CTRL, 0x7c000, 0, port);
1405 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PFC_CTRL,
1406 0x30ffffc000ULL, 0, port);
1407 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x3 | (loopback << 2), 0,
1408 port); /* XLMAC: TX_EN, RX_EN */
1409 /* XLMAC: TX_EN, RX_EN, SW_LINK_STATUS */
1410 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL,
1411 0x1003 | (loopback << 2), 0, port);
1412 /* Enabled Parallel PFC interface */
1413 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_FLOW_CONTROL_CONFIG, 1, 0, port);
1415 /* XLPORT port enable */
1416 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_ENABLE_REG, 0xf, 1, port);
1419 static void ecore_emul_link_init_ah_e5(struct ecore_hwfn *p_hwfn,
1420 struct ecore_ptt *p_ptt)
1422 u8 port = p_hwfn->port_id;
1423 u32 mac_base = NWM_REG_MAC0_K2_E5 + (port << 2) * NWM_REG_MAC0_SIZE;
1425 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
1427 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NIG_PORT0_CONF_K2_E5 + (port << 2),
1428 (1 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_ENABLE_0_K2_E5_SHIFT) |
1430 CNIG_REG_NIG_PORT0_CONF_NIG_PORT_NWM_PORT_MAP_0_K2_E5_SHIFT) |
1431 (0 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_RATE_0_K2_E5_SHIFT));
1433 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_XIF_MODE_K2_E5,
1434 1 << ETH_MAC_REG_XIF_MODE_XGMII_K2_E5_SHIFT);
1436 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_FRM_LENGTH_K2_E5,
1437 9018 << ETH_MAC_REG_FRM_LENGTH_FRM_LENGTH_K2_E5_SHIFT);
1439 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_IPG_LENGTH_K2_E5,
1440 0xc << ETH_MAC_REG_TX_IPG_LENGTH_TXIPG_K2_E5_SHIFT);
1442 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_RX_FIFO_SECTIONS_K2_E5,
1443 8 << ETH_MAC_REG_RX_FIFO_SECTIONS_RX_SECTION_FULL_K2_E5_SHIFT);
1445 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_FIFO_SECTIONS_K2_E5,
1447 ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_EMPTY_K2_E5_SHIFT) |
1449 ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_FULL_K2_E5_SHIFT));
1451 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_COMMAND_CONFIG_K2_E5,
1455 static void ecore_emul_link_init(struct ecore_hwfn *p_hwfn,
1456 struct ecore_ptt *p_ptt)
1458 if (ECORE_IS_AH(p_hwfn->p_dev))
1459 ecore_emul_link_init_ah_e5(p_hwfn, p_ptt);
1461 ecore_emul_link_init_bb(p_hwfn, p_ptt);
1464 static void ecore_link_init_bb(struct ecore_hwfn *p_hwfn,
1465 struct ecore_ptt *p_ptt, u8 port)
1467 int port_offset = port ? 0x800 : 0;
1468 u32 xmac_rxctrl = 0;
1471 /* FIXME: move to common start */
1472 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
1473 MISC_REG_RESET_REG_2_XMAC_BIT); /* Clear */
1475 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
1476 MISC_REG_RESET_REG_2_XMAC_BIT); /* Set */
1478 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_CORE_PORT_MODE_BB, 1);
1480 /* Set the number of ports on the Warp Core to 10G */
1481 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_PHY_PORT_MODE_BB, 3);
1483 /* Soft reset of XMAC */
1484 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
1485 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
1487 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
1488 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
1490 /* FIXME: move to common end */
1491 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
1492 ecore_wr(p_hwfn, p_ptt, XMAC_REG_MODE_BB + port_offset, 0x20);
1494 /* Set Max packet size: initialize XMAC block register for port 0 */
1495 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_MAX_SIZE_BB + port_offset, 0x2710);
1497 /* CRC append for Tx packets: init XMAC block register for port 1 */
1498 ecore_wr(p_hwfn, p_ptt, XMAC_REG_TX_CTRL_LO_BB + port_offset, 0xC800);
1500 /* Enable TX and RX: initialize XMAC block register for port 1 */
1501 ecore_wr(p_hwfn, p_ptt, XMAC_REG_CTRL_BB + port_offset,
1502 XMAC_REG_CTRL_TX_EN_BB | XMAC_REG_CTRL_RX_EN_BB);
1503 xmac_rxctrl = ecore_rd(p_hwfn, p_ptt,
1504 XMAC_REG_RX_CTRL_BB + port_offset);
1505 xmac_rxctrl |= XMAC_REG_RX_CTRL_PROCESS_VARIABLE_PREAMBLE_BB;
1506 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_CTRL_BB + port_offset, xmac_rxctrl);
1510 static enum _ecore_status_t
1511 ecore_hw_init_dpi_size(struct ecore_hwfn *p_hwfn,
1512 struct ecore_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
1514 u32 dpi_page_size_1, dpi_page_size_2, dpi_page_size;
1515 u32 dpi_bit_shift, dpi_count;
1518 /* Calculate DPI size
1519 * ------------------
1520 * The PWM region contains Doorbell Pages. The first is reserverd for
1521 * the kernel for, e.g, L2. The others are free to be used by non-
1522 * trusted applications, typically from user space. Each page, called a
1523 * doorbell page is sectioned into windows that allow doorbells to be
1524 * issued in parallel by the kernel/application. The size of such a
1525 * window (a.k.a. WID) is 1kB.
1527 * 1kB WID x N WIDS = DPI page size
1528 * DPI page size x N DPIs = PWM region size
1530 * The size of the DPI page size must be in multiples of OSAL_PAGE_SIZE
1531 * in order to ensure that two applications won't share the same page.
1532 * It also must contain at least one WID per CPU to allow parallelism.
1533 * It also must be a power of 2, since it is stored as a bit shift.
1535 * The DPI page size is stored in a register as 'dpi_bit_shift' so that
1536 * 0 is 4kB, 1 is 8kB and etc. Hence the minimum size is 4,096
1537 * containing 4 WIDs.
1539 dpi_page_size_1 = ECORE_WID_SIZE * n_cpus;
1540 dpi_page_size_2 = OSAL_MAX_T(u32, ECORE_WID_SIZE, OSAL_PAGE_SIZE);
1541 dpi_page_size = OSAL_MAX_T(u32, dpi_page_size_1, dpi_page_size_2);
1542 dpi_page_size = OSAL_ROUNDUP_POW_OF_TWO(dpi_page_size);
1543 dpi_bit_shift = OSAL_LOG2(dpi_page_size / 4096);
1545 dpi_count = pwm_region_size / dpi_page_size;
1547 min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
1548 min_dpis = OSAL_MAX_T(u32, ECORE_MIN_DPIS, min_dpis);
1551 p_hwfn->dpi_size = dpi_page_size;
1552 p_hwfn->dpi_count = dpi_count;
1554 /* Update registers */
1555 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
1557 if (dpi_count < min_dpis)
1558 return ECORE_NORESOURCES;
1560 return ECORE_SUCCESS;
1563 enum ECORE_ROCE_EDPM_MODE {
1564 ECORE_ROCE_EDPM_MODE_ENABLE = 0,
1565 ECORE_ROCE_EDPM_MODE_FORCE_ON = 1,
1566 ECORE_ROCE_EDPM_MODE_DISABLE = 2,
1569 static enum _ecore_status_t
1570 ecore_hw_init_pf_doorbell_bar(struct ecore_hwfn *p_hwfn,
1571 struct ecore_ptt *p_ptt)
1573 u32 pwm_regsize, norm_regsize;
1574 u32 non_pwm_conn, min_addr_reg1;
1575 u32 db_bar_size, n_cpus;
1578 enum _ecore_status_t rc = ECORE_SUCCESS;
1581 db_bar_size = ecore_hw_bar_size(p_hwfn, BAR_ID_1);
1582 if (p_hwfn->p_dev->num_hwfns > 1)
1585 /* Calculate doorbell regions
1586 * -----------------------------------
1587 * The doorbell BAR is made of two regions. The first is called normal
1588 * region and the second is called PWM region. In the normal region
1589 * each ICID has its own set of addresses so that writing to that
1590 * specific address identifies the ICID. In the Process Window Mode
1591 * region the ICID is given in the data written to the doorbell. The
1592 * above per PF register denotes the offset in the doorbell BAR in which
1593 * the PWM region begins.
1594 * The normal region has ECORE_PF_DEMS_SIZE bytes per ICID, that is per
1595 * non-PWM connection. The calculation below computes the total non-PWM
1596 * connections. The DORQ_REG_PF_MIN_ADDR_REG1 register is
1597 * in units of 4,096 bytes.
1599 non_pwm_conn = ecore_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1600 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1602 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, OSAL_NULL);
1603 norm_regsize = ROUNDUP(ECORE_PF_DEMS_SIZE * non_pwm_conn, 4096);
1604 min_addr_reg1 = norm_regsize / 4096;
1605 pwm_regsize = db_bar_size - norm_regsize;
1607 /* Check that the normal and PWM sizes are valid */
1608 if (db_bar_size < norm_regsize) {
1609 DP_ERR(p_hwfn->p_dev,
1610 "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
1611 db_bar_size, norm_regsize);
1612 return ECORE_NORESOURCES;
1614 if (pwm_regsize < ECORE_MIN_PWM_REGION) {
1615 DP_ERR(p_hwfn->p_dev,
1616 "PWM region size 0x%0x is too small. Should be at least 0x%0x (Doorbell BAR size is 0x%x and normal region size is 0x%0x)\n",
1617 pwm_regsize, ECORE_MIN_PWM_REGION, db_bar_size,
1619 return ECORE_NORESOURCES;
1622 /* Calculate number of DPIs */
1623 roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
1624 if ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE) ||
1625 ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_FORCE_ON))) {
1626 /* Either EDPM is mandatory, or we are attempting to allocate a
1629 n_cpus = OSAL_NUM_ACTIVE_CPU();
1630 rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1633 cond = ((rc != ECORE_SUCCESS) &&
1634 (roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE)) ||
1635 (roce_edpm_mode == ECORE_ROCE_EDPM_MODE_DISABLE);
1636 if (cond || p_hwfn->dcbx_no_edpm) {
1637 /* Either EDPM is disabled from user configuration, or it is
1638 * disabled via DCBx, or it is not mandatory and we failed to
1639 * allocated a WID per CPU.
1642 rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1644 /* If we entered this flow due to DCBX then the DPM register is
1645 * already configured.
1650 "doorbell bar: normal_region_size=%d, pwm_region_size=%d",
1651 norm_regsize, pwm_regsize);
1653 " dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
1654 p_hwfn->dpi_size, p_hwfn->dpi_count,
1655 ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
1656 "disabled" : "enabled");
1658 /* Check return codes from above calls */
1659 if (rc != ECORE_SUCCESS) {
1661 "Failed to allocate enough DPIs\n");
1662 return ECORE_NORESOURCES;
1666 p_hwfn->dpi_start_offset = norm_regsize;
1668 /* Update registers */
1669 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1670 pf_dems_shift = OSAL_LOG2(ECORE_PF_DEMS_SIZE / 4);
1671 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1672 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1674 return ECORE_SUCCESS;
1677 static enum _ecore_status_t ecore_hw_init_port(struct ecore_hwfn *p_hwfn,
1678 struct ecore_ptt *p_ptt,
1681 enum _ecore_status_t rc = ECORE_SUCCESS;
1683 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
1685 if (rc != ECORE_SUCCESS)
1688 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev))
1689 return ECORE_SUCCESS;
1691 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1692 if (ECORE_IS_AH(p_hwfn->p_dev))
1693 return ECORE_SUCCESS;
1694 else if (ECORE_IS_BB(p_hwfn->p_dev))
1695 ecore_link_init_bb(p_hwfn, p_ptt, p_hwfn->port_id);
1696 } else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
1697 if (p_hwfn->p_dev->num_hwfns > 1) {
1698 /* Activate OPTE in CMT */
1701 val = ecore_rd(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV);
1703 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV, val);
1704 ecore_wr(p_hwfn, p_ptt, MISC_REG_CLK_100G_MODE, 1);
1705 ecore_wr(p_hwfn, p_ptt, MISCS_REG_CLK_100G_MODE, 1);
1706 ecore_wr(p_hwfn, p_ptt, MISC_REG_OPTE_MODE, 1);
1707 ecore_wr(p_hwfn, p_ptt,
1708 NIG_REG_LLH_ENG_CLS_TCP_4_TUPLE_SEARCH, 1);
1709 ecore_wr(p_hwfn, p_ptt,
1710 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL, 0x55555555);
1711 ecore_wr(p_hwfn, p_ptt,
1712 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL + 0x4,
1716 ecore_emul_link_init(p_hwfn, p_ptt);
1718 DP_INFO(p_hwfn->p_dev, "link is not being configured\n");
1725 static enum _ecore_status_t
1726 ecore_hw_init_pf(struct ecore_hwfn *p_hwfn,
1727 struct ecore_ptt *p_ptt,
1728 struct ecore_tunnel_info *p_tunn,
1731 enum ecore_int_mode int_mode, bool allow_npar_tx_switch)
1733 u8 rel_pf_id = p_hwfn->rel_pf_id;
1735 enum _ecore_status_t rc = ECORE_SUCCESS;
1739 if (p_hwfn->mcp_info) {
1740 struct ecore_mcp_function_info *p_info;
1742 p_info = &p_hwfn->mcp_info->func_info;
1743 if (p_info->bandwidth_min)
1744 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1746 /* Update rate limit once we'll actually have a link */
1747 p_hwfn->qm_info.pf_rl = 100000;
1749 ecore_cxt_hw_init_pf(p_hwfn);
1751 ecore_int_igu_init_rt(p_hwfn);
1753 /* Set VLAN in NIG if needed */
1754 if (hw_mode & (1 << MODE_MF_SD)) {
1755 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1756 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1757 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1758 p_hwfn->hw_info.ovlan);
1761 /* Enable classification by MAC if needed */
1762 if (hw_mode & (1 << MODE_MF_SI)) {
1763 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
1764 "Configuring TAGMAC_CLS_TYPE\n");
1765 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET,
1769 /* Protocl Configuration - @@@TBD - should we set 0 otherwise? */
1770 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
1771 (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) ? 1 : 0);
1772 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
1773 (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) ? 1 : 0);
1774 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
1776 /* perform debug configuration when chip is out of reset */
1777 OSAL_BEFORE_PF_START((void *)p_hwfn->p_dev, p_hwfn->my_id);
1779 /* PF Init sequence */
1780 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1784 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1785 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1789 /* Pure runtime initializations - directly to the HW */
1790 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1792 /* PCI relaxed ordering causes a decrease in the performance on some
1793 * systems. Till a root cause is found, disable this attribute in the
1797 * pos = OSAL_PCI_FIND_CAPABILITY(p_hwfn->p_dev, PCI_CAP_ID_EXP);
1799 * DP_NOTICE(p_hwfn, true,
1800 * "Failed to find the PCIe Cap\n");
1803 * OSAL_PCI_READ_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, &ctrl);
1804 * ctrl &= ~PCI_EXP_DEVCTL_RELAX_EN;
1805 * OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, ctrl);
1808 rc = ecore_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1812 /* enable interrupts */
1813 rc = ecore_int_igu_enable(p_hwfn, p_ptt, int_mode);
1814 if (rc != ECORE_SUCCESS)
1817 /* send function start command */
1818 rc = ecore_sp_pf_start(p_hwfn, p_tunn, p_hwfn->p_dev->mf_mode,
1819 allow_npar_tx_switch);
1821 DP_NOTICE(p_hwfn, true,
1822 "Function start ramrod failed\n");
1824 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1825 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1826 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1828 if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) {
1829 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1,
1831 ecore_wr(p_hwfn, p_ptt,
1832 PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
1835 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1836 "PRS_REG_SEARCH registers after start PFn\n");
1837 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP);
1838 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1839 "PRS_REG_SEARCH_TCP: %x\n", prs_reg);
1840 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP);
1841 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1842 "PRS_REG_SEARCH_UDP: %x\n", prs_reg);
1843 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE);
1844 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1845 "PRS_REG_SEARCH_FCOE: %x\n", prs_reg);
1846 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE);
1847 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1848 "PRS_REG_SEARCH_ROCE: %x\n", prs_reg);
1849 prs_reg = ecore_rd(p_hwfn, p_ptt,
1850 PRS_REG_SEARCH_TCP_FIRST_FRAG);
1851 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1852 "PRS_REG_SEARCH_TCP_FIRST_FRAG: %x\n",
1854 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1855 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1856 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1862 enum _ecore_status_t ecore_pglueb_set_pfid_enable(struct ecore_hwfn *p_hwfn,
1863 struct ecore_ptt *p_ptt,
1866 u32 delay_idx = 0, val, set_val = b_enable ? 1 : 0;
1868 /* Configure the PF's internal FID_enable for master transactions */
1869 ecore_wr(p_hwfn, p_ptt,
1870 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1872 /* Wait until value is set - try for 1 second every 50us */
1873 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1874 val = ecore_rd(p_hwfn, p_ptt,
1875 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1882 if (val != set_val) {
1883 DP_NOTICE(p_hwfn, true,
1884 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1885 return ECORE_UNKNOWN_ERROR;
1888 return ECORE_SUCCESS;
1891 static void ecore_reset_mb_shadow(struct ecore_hwfn *p_hwfn,
1892 struct ecore_ptt *p_main_ptt)
1894 /* Read shadow of current MFW mailbox */
1895 ecore_mcp_read_mb(p_hwfn, p_main_ptt);
1896 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1897 p_hwfn->mcp_info->mfw_mb_cur,
1898 p_hwfn->mcp_info->mfw_mb_length);
1901 enum _ecore_status_t ecore_vf_start(struct ecore_hwfn *p_hwfn,
1902 struct ecore_hw_init_params *p_params)
1904 if (p_params->p_tunn) {
1905 ecore_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
1906 ecore_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
1909 p_hwfn->b_int_enabled = 1;
1911 return ECORE_SUCCESS;
1914 static void ecore_pglueb_clear_err(struct ecore_hwfn *p_hwfn,
1915 struct ecore_ptt *p_ptt)
1917 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
1918 1 << p_hwfn->abs_pf_id);
1921 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
1922 struct ecore_hw_init_params *p_params)
1924 struct ecore_load_req_params load_req_params;
1925 u32 load_code, resp, param, drv_mb_param;
1926 bool b_default_mtu = true;
1927 struct ecore_hwfn *p_hwfn;
1928 enum _ecore_status_t rc = ECORE_SUCCESS;
1931 if ((p_params->int_mode == ECORE_INT_MODE_MSI) &&
1932 (p_dev->num_hwfns > 1)) {
1933 DP_NOTICE(p_dev, false,
1934 "MSI mode is not supported for CMT devices\n");
1939 rc = ecore_init_fw_data(p_dev, p_params->bin_fw_data);
1940 if (rc != ECORE_SUCCESS)
1944 for_each_hwfn(p_dev, i) {
1945 p_hwfn = &p_dev->hwfns[i];
1947 /* If management didn't provide a default, set one of our own */
1948 if (!p_hwfn->hw_info.mtu) {
1949 p_hwfn->hw_info.mtu = 1500;
1950 b_default_mtu = false;
1954 ecore_vf_start(p_hwfn, p_params);
1958 rc = ecore_calc_hw_mode(p_hwfn);
1959 if (rc != ECORE_SUCCESS)
1962 OSAL_MEM_ZERO(&load_req_params, sizeof(load_req_params));
1963 load_req_params.drv_role = p_params->is_crash_kernel ?
1964 ECORE_DRV_ROLE_KDUMP :
1966 load_req_params.timeout_val = p_params->mfw_timeout_val;
1967 load_req_params.avoid_eng_reset = p_params->avoid_eng_reset;
1968 rc = ecore_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
1970 if (rc != ECORE_SUCCESS) {
1971 DP_NOTICE(p_hwfn, true,
1972 "Failed sending a LOAD_REQ command\n");
1976 load_code = load_req_params.load_code;
1977 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1978 "Load request was sent. Load code: 0x%x\n",
1982 * When coming back from hiberbate state, the registers from
1983 * which shadow is read initially are not initialized. It turns
1984 * out that these registers get initialized during the call to
1985 * ecore_mcp_load_req request. So we need to reread them here
1986 * to get the proper shadow register value.
1987 * Note: This is a workaround for the missing MFW
1988 * initialization. It may be removed once the implementation
1991 ecore_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
1993 /* Only relevant for recovery:
1994 * Clear the indication after the LOAD_REQ command is responded
1997 p_dev->recov_in_prog = false;
1999 p_hwfn->first_on_engine = (load_code ==
2000 FW_MSG_CODE_DRV_LOAD_ENGINE);
2002 if (!qm_lock_init) {
2003 OSAL_SPIN_LOCK_INIT(&qm_lock);
2004 qm_lock_init = true;
2007 /* Clean up chip from previous driver if such remains exist.
2008 * This is not needed when the PF is the first one on the
2009 * engine, since afterwards we are going to init the FW.
2011 if (load_code != FW_MSG_CODE_DRV_LOAD_ENGINE) {
2012 rc = ecore_final_cleanup(p_hwfn, p_hwfn->p_main_ptt,
2013 p_hwfn->rel_pf_id, false);
2014 if (rc != ECORE_SUCCESS) {
2015 ecore_hw_err_notify(p_hwfn,
2016 ECORE_HW_ERR_RAMROD_FAIL);
2021 /* Log and clean previous pglue_b errors if such exist */
2022 ecore_pglueb_rbc_attn_handler(p_hwfn, p_hwfn->p_main_ptt);
2023 ecore_pglueb_clear_err(p_hwfn, p_hwfn->p_main_ptt);
2025 /* Enable the PF's internal FID_enable in the PXP */
2026 rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_hwfn->p_main_ptt,
2028 if (rc != ECORE_SUCCESS)
2031 switch (load_code) {
2032 case FW_MSG_CODE_DRV_LOAD_ENGINE:
2033 rc = ecore_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
2034 p_hwfn->hw_info.hw_mode);
2035 if (rc != ECORE_SUCCESS)
2038 case FW_MSG_CODE_DRV_LOAD_PORT:
2039 rc = ecore_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
2040 p_hwfn->hw_info.hw_mode);
2041 if (rc != ECORE_SUCCESS)
2044 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
2045 rc = ecore_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
2047 p_hwfn->hw_info.hw_mode,
2048 p_params->b_hw_start,
2050 p_params->allow_npar_tx_switch);
2053 DP_NOTICE(p_hwfn, false,
2054 "Unexpected load code [0x%08x]", load_code);
2059 if (rc != ECORE_SUCCESS) {
2060 DP_NOTICE(p_hwfn, true,
2061 "init phase failed for loadcode 0x%x (rc %d)\n",
2066 rc = ecore_mcp_load_done(p_hwfn, p_hwfn->p_main_ptt);
2067 if (rc != ECORE_SUCCESS)
2070 /* send DCBX attention request command */
2071 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
2072 "sending phony dcbx set command to trigger DCBx attention handling\n");
2073 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2074 DRV_MSG_CODE_SET_DCBX,
2075 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT, &resp,
2077 if (rc != ECORE_SUCCESS) {
2078 DP_NOTICE(p_hwfn, true,
2079 "Failed to send DCBX attention request\n");
2083 p_hwfn->hw_init_done = true;
2087 p_hwfn = ECORE_LEADING_HWFN(p_dev);
2088 drv_mb_param = STORM_FW_VERSION;
2089 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2090 DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
2091 drv_mb_param, &resp, ¶m);
2092 if (rc != ECORE_SUCCESS)
2093 DP_INFO(p_hwfn, "Failed to update firmware version\n");
2096 rc = ecore_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
2097 p_hwfn->hw_info.mtu);
2098 if (rc != ECORE_SUCCESS)
2099 DP_INFO(p_hwfn, "Failed to update default mtu\n");
2101 rc = ecore_mcp_ov_update_driver_state(p_hwfn,
2103 ECORE_OV_DRIVER_STATE_DISABLED);
2104 if (rc != ECORE_SUCCESS)
2105 DP_INFO(p_hwfn, "Failed to update driver state\n");
2111 /* The MFW load lock should be released regardless of success or failure
2112 * of initialization.
2113 * TODO: replace this with an attempt to send cancel_load.
2115 ecore_mcp_load_done(p_hwfn, p_hwfn->p_main_ptt);
2119 #define ECORE_HW_STOP_RETRY_LIMIT (10)
2120 static void ecore_hw_timers_stop(struct ecore_dev *p_dev,
2121 struct ecore_hwfn *p_hwfn,
2122 struct ecore_ptt *p_ptt)
2127 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
2128 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
2129 for (i = 0; i < ECORE_HW_STOP_RETRY_LIMIT && !p_dev->recov_in_prog;
2131 if ((!ecore_rd(p_hwfn, p_ptt,
2132 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
2133 (!ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
2136 /* Dependent on number of connection/tasks, possibly
2137 * 1ms sleep is required between polls
2142 if (i < ECORE_HW_STOP_RETRY_LIMIT)
2145 DP_NOTICE(p_hwfn, true, "Timers linear scans are not over"
2146 " [Connection %02x Tasks %02x]\n",
2147 (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
2148 (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
2151 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev)
2155 for_each_hwfn(p_dev, j) {
2156 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2157 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2159 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
2163 static enum _ecore_status_t ecore_verify_reg_val(struct ecore_hwfn *p_hwfn,
2164 struct ecore_ptt *p_ptt,
2165 u32 addr, u32 expected_val)
2167 u32 val = ecore_rd(p_hwfn, p_ptt, addr);
2169 if (val != expected_val) {
2170 DP_NOTICE(p_hwfn, true,
2171 "Value at address 0x%08x is 0x%08x while the expected value is 0x%08x\n",
2172 addr, val, expected_val);
2173 return ECORE_UNKNOWN_ERROR;
2176 return ECORE_SUCCESS;
2179 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev)
2181 struct ecore_hwfn *p_hwfn;
2182 struct ecore_ptt *p_ptt;
2183 enum _ecore_status_t rc, rc2 = ECORE_SUCCESS;
2186 for_each_hwfn(p_dev, j) {
2187 p_hwfn = &p_dev->hwfns[j];
2188 p_ptt = p_hwfn->p_main_ptt;
2190 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Stopping hw/fw\n");
2193 ecore_vf_pf_int_cleanup(p_hwfn);
2194 rc = ecore_vf_pf_reset(p_hwfn);
2195 if (rc != ECORE_SUCCESS) {
2196 DP_NOTICE(p_hwfn, true,
2197 "ecore_vf_pf_reset failed. rc = %d.\n",
2199 rc2 = ECORE_UNKNOWN_ERROR;
2204 /* mark the hw as uninitialized... */
2205 p_hwfn->hw_init_done = false;
2207 /* Send unload command to MCP */
2208 if (!p_dev->recov_in_prog) {
2209 rc = ecore_mcp_unload_req(p_hwfn, p_ptt);
2210 if (rc != ECORE_SUCCESS) {
2211 DP_NOTICE(p_hwfn, true,
2212 "Failed sending a UNLOAD_REQ command. rc = %d.\n",
2214 rc2 = ECORE_UNKNOWN_ERROR;
2218 OSAL_DPC_SYNC(p_hwfn);
2220 /* After this point no MFW attentions are expected, e.g. prevent
2221 * race between pf stop and dcbx pf update.
2224 rc = ecore_sp_pf_stop(p_hwfn);
2225 if (rc != ECORE_SUCCESS) {
2226 DP_NOTICE(p_hwfn, true,
2227 "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
2229 rc2 = ECORE_UNKNOWN_ERROR;
2232 /* perform debug action after PF stop was sent */
2233 OSAL_AFTER_PF_STOP((void *)p_dev, p_hwfn->my_id);
2235 /* close NIG to BRB gate */
2236 ecore_wr(p_hwfn, p_ptt,
2237 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2240 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2241 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2242 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2243 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2244 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2246 /* @@@TBD - clean transmission queues (5.b) */
2247 /* @@@TBD - clean BTB (5.c) */
2249 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
2251 /* @@@TBD - verify DMAE requests are done (8) */
2253 /* Disable Attention Generation */
2254 ecore_int_igu_disable_int(p_hwfn, p_ptt);
2255 ecore_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
2256 ecore_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
2257 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
2258 /* Need to wait 1ms to guarantee SBs are cleared */
2261 if (!p_dev->recov_in_prog) {
2262 ecore_verify_reg_val(p_hwfn, p_ptt,
2263 QM_REG_USG_CNT_PF_TX, 0);
2264 ecore_verify_reg_val(p_hwfn, p_ptt,
2265 QM_REG_USG_CNT_PF_OTHER, 0);
2266 /* @@@TBD - assert on incorrect xCFC values (10.b) */
2269 /* Disable PF in HW blocks */
2270 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
2271 ecore_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
2273 if (!p_dev->recov_in_prog) {
2274 ecore_mcp_unload_done(p_hwfn, p_ptt);
2275 if (rc != ECORE_SUCCESS) {
2276 DP_NOTICE(p_hwfn, true,
2277 "Failed sending a UNLOAD_DONE command. rc = %d.\n",
2279 rc2 = ECORE_UNKNOWN_ERROR;
2284 if (IS_PF(p_dev) && !p_dev->recov_in_prog) {
2285 p_hwfn = ECORE_LEADING_HWFN(p_dev);
2286 p_ptt = ECORE_LEADING_HWFN(p_dev)->p_main_ptt;
2288 /* Clear the PF's internal FID_enable in the PXP.
2289 * In CMT this should only be done for first hw-function, and
2290 * only after all transactions have stopped for all active
2293 rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_hwfn->p_main_ptt,
2295 if (rc != ECORE_SUCCESS) {
2296 DP_NOTICE(p_hwfn, true,
2297 "ecore_pglueb_set_pfid_enable() failed. rc = %d.\n",
2299 rc2 = ECORE_UNKNOWN_ERROR;
2306 void ecore_hw_stop_fastpath(struct ecore_dev *p_dev)
2310 for_each_hwfn(p_dev, j) {
2311 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2312 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2315 ecore_vf_pf_int_cleanup(p_hwfn);
2319 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
2320 "Shutting down the fastpath\n");
2322 ecore_wr(p_hwfn, p_ptt,
2323 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2325 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2326 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2327 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2328 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2329 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2331 /* @@@TBD - clean transmission queues (5.b) */
2332 /* @@@TBD - clean BTB (5.c) */
2334 /* @@@TBD - verify DMAE requests are done (8) */
2336 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
2337 /* Need to wait 1ms to guarantee SBs are cleared */
2342 void ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn)
2344 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2346 if (IS_VF(p_hwfn->p_dev))
2349 /* If roce info is allocated it means roce is initialized and should
2350 * be enabled in searcher.
2352 if (p_hwfn->p_rdma_info) {
2353 if (p_hwfn->b_rdma_enabled_in_prs)
2354 ecore_wr(p_hwfn, p_ptt,
2355 p_hwfn->rdma_prs_search_reg, 0x1);
2356 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x1);
2359 /* Re-open incoming traffic */
2360 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2361 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
2364 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
2365 static void ecore_hw_hwfn_free(struct ecore_hwfn *p_hwfn)
2367 ecore_ptt_pool_free(p_hwfn);
2368 OSAL_FREE(p_hwfn->p_dev, p_hwfn->hw_info.p_igu_info);
2371 /* Setup bar access */
2372 static void ecore_hw_hwfn_prepare(struct ecore_hwfn *p_hwfn)
2374 /* clear indirect access */
2375 if (ECORE_IS_AH(p_hwfn->p_dev)) {
2376 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2377 PGLUE_B_REG_PGL_ADDR_E8_F0_K2_E5, 0);
2378 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2379 PGLUE_B_REG_PGL_ADDR_EC_F0_K2_E5, 0);
2380 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2381 PGLUE_B_REG_PGL_ADDR_F0_F0_K2_E5, 0);
2382 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2383 PGLUE_B_REG_PGL_ADDR_F4_F0_K2_E5, 0);
2385 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2386 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
2387 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2388 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
2389 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2390 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
2391 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2392 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
2395 /* Clean previous pglue_b errors if such exist */
2396 ecore_pglueb_clear_err(p_hwfn, p_hwfn->p_main_ptt);
2398 /* enable internal target-read */
2399 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2400 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
2403 static void get_function_id(struct ecore_hwfn *p_hwfn)
2406 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn,
2407 PXP_PF_ME_OPAQUE_ADDR);
2409 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
2411 /* Bits 16-19 from the ME registers are the pf_num */
2412 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
2413 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2414 PXP_CONCRETE_FID_PFID);
2415 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2416 PXP_CONCRETE_FID_PORT);
2418 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2419 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
2420 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
2423 static void ecore_hw_set_feat(struct ecore_hwfn *p_hwfn)
2425 u32 *feat_num = p_hwfn->hw_info.feat_num;
2428 /* L2 Queues require each: 1 status block. 1 L2 queue */
2429 if (ECORE_IS_L2_PERSONALITY(p_hwfn)) {
2430 struct ecore_sb_cnt_info sb_cnt_info;
2432 OSAL_MEM_ZERO(&sb_cnt_info, sizeof(sb_cnt_info));
2433 ecore_int_get_num_sbs(p_hwfn, &sb_cnt_info);
2435 /* Start by allocating VF queues, then PF's */
2436 feat_num[ECORE_VF_L2_QUE] =
2438 RESC_NUM(p_hwfn, ECORE_L2_QUEUE),
2439 sb_cnt_info.sb_iov_cnt);
2440 feat_num[ECORE_PF_L2_QUE] =
2442 RESC_NUM(p_hwfn, ECORE_SB) - non_l2_sbs,
2443 RESC_NUM(p_hwfn, ECORE_L2_QUEUE) -
2444 FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE));
2447 feat_num[ECORE_FCOE_CQ] = OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_SB),
2448 RESC_NUM(p_hwfn, ECORE_CMDQS_CQS));
2449 feat_num[ECORE_ISCSI_CQ] = OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_SB),
2450 RESC_NUM(p_hwfn, ECORE_CMDQS_CQS));
2452 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2453 "#PF_L2_QUEUE=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d #FCOE_CQ=%d #ISCSI_CQ=%d #SB=%d\n",
2454 (int)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE),
2455 (int)FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE),
2456 (int)FEAT_NUM(p_hwfn, ECORE_RDMA_CNQ),
2457 (int)FEAT_NUM(p_hwfn, ECORE_FCOE_CQ),
2458 (int)FEAT_NUM(p_hwfn, ECORE_ISCSI_CQ),
2459 RESC_NUM(p_hwfn, ECORE_SB));
2462 const char *ecore_hw_get_resc_name(enum ecore_resources res_id)
2467 case ECORE_L2_QUEUE:
2481 case ECORE_RDMA_CNQ_RAM:
2482 return "RDMA_CNQ_RAM";
2485 case ECORE_LL2_QUEUE:
2487 case ECORE_CMDQS_CQS:
2489 case ECORE_RDMA_STATS_QUEUE:
2490 return "RDMA_STATS_QUEUE";
2494 return "UNKNOWN_RESOURCE";
2498 static enum _ecore_status_t
2499 __ecore_hw_set_soft_resc_size(struct ecore_hwfn *p_hwfn,
2500 enum ecore_resources res_id, u32 resc_max_val,
2503 enum _ecore_status_t rc;
2505 rc = ecore_mcp_set_resc_max_val(p_hwfn, p_hwfn->p_main_ptt, res_id,
2506 resc_max_val, p_mcp_resp);
2507 if (rc != ECORE_SUCCESS) {
2508 DP_NOTICE(p_hwfn, true,
2509 "MFW response failure for a max value setting of resource %d [%s]\n",
2510 res_id, ecore_hw_get_resc_name(res_id));
2514 if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
2516 "Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
2517 res_id, ecore_hw_get_resc_name(res_id), *p_mcp_resp);
2519 return ECORE_SUCCESS;
2522 static enum _ecore_status_t
2523 ecore_hw_set_soft_resc_size(struct ecore_hwfn *p_hwfn)
2525 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2526 u32 resc_max_val, mcp_resp;
2528 enum _ecore_status_t rc;
2530 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
2533 case ECORE_LL2_QUEUE:
2534 case ECORE_RDMA_CNQ_RAM:
2535 case ECORE_RDMA_STATS_QUEUE:
2543 rc = __ecore_hw_set_soft_resc_size(p_hwfn, res_id,
2544 resc_max_val, &mcp_resp);
2545 if (rc != ECORE_SUCCESS)
2548 /* There's no point to continue to the next resource if the
2549 * command is not supported by the MFW.
2550 * We do continue if the command is supported but the resource
2551 * is unknown to the MFW. Such a resource will be later
2552 * configured with the default allocation values.
2554 if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
2555 return ECORE_NOTIMPL;
2558 return ECORE_SUCCESS;
2562 enum _ecore_status_t ecore_hw_get_dflt_resc(struct ecore_hwfn *p_hwfn,
2563 enum ecore_resources res_id,
2564 u32 *p_resc_num, u32 *p_resc_start)
2566 u8 num_funcs = p_hwfn->num_funcs_on_engine;
2567 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2568 struct ecore_sb_cnt_info sb_cnt_info;
2572 OSAL_MEM_ZERO(&sb_cnt_info, sizeof(sb_cnt_info));
2573 ecore_int_get_num_sbs(p_hwfn, &sb_cnt_info);
2574 *p_resc_num = sb_cnt_info.sb_cnt;
2576 case ECORE_L2_QUEUE:
2577 *p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
2578 MAX_NUM_L2_QUEUES_BB) / num_funcs;
2581 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2582 MAX_NUM_VPORTS_BB) / num_funcs;
2585 *p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
2586 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
2589 *p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
2590 MAX_QM_TX_QUEUES_BB) / num_funcs;
2593 *p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
2597 /* Each VFC resource can accommodate both a MAC and a VLAN */
2598 *p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
2601 *p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
2602 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
2604 case ECORE_LL2_QUEUE:
2605 *p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
2607 case ECORE_RDMA_CNQ_RAM:
2608 case ECORE_CMDQS_CQS:
2609 /* CNQ/CMDQS are the same resource */
2611 *p_resc_num = (NUM_OF_GLOBAL_QUEUES / 2) / num_funcs;
2613 case ECORE_RDMA_STATS_QUEUE:
2615 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2616 MAX_NUM_VPORTS_BB) / num_funcs;
2633 *p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
2637 return ECORE_SUCCESS;
2640 static enum _ecore_status_t
2641 __ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn, enum ecore_resources res_id,
2642 bool drv_resc_alloc)
2644 u32 dflt_resc_num = 0, dflt_resc_start = 0;
2645 u32 mcp_resp, *p_resc_num, *p_resc_start;
2646 enum _ecore_status_t rc;
2648 p_resc_num = &RESC_NUM(p_hwfn, res_id);
2649 p_resc_start = &RESC_START(p_hwfn, res_id);
2651 rc = ecore_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
2653 if (rc != ECORE_SUCCESS) {
2655 "Failed to get default amount for resource %d [%s]\n",
2656 res_id, ecore_hw_get_resc_name(res_id));
2661 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2662 *p_resc_num = dflt_resc_num;
2663 *p_resc_start = dflt_resc_start;
2668 rc = ecore_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
2669 &mcp_resp, p_resc_num, p_resc_start);
2670 if (rc != ECORE_SUCCESS) {
2671 DP_NOTICE(p_hwfn, true,
2672 "MFW response failure for an allocation request for"
2673 " resource %d [%s]\n",
2674 res_id, ecore_hw_get_resc_name(res_id));
2678 /* Default driver values are applied in the following cases:
2679 * - The resource allocation MB command is not supported by the MFW
2680 * - There is an internal error in the MFW while processing the request
2681 * - The resource ID is unknown to the MFW
2683 if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
2685 "Failed to receive allocation info for resource %d [%s]."
2686 " mcp_resp = 0x%x. Applying default values"
2688 res_id, ecore_hw_get_resc_name(res_id), mcp_resp,
2689 dflt_resc_num, dflt_resc_start);
2691 *p_resc_num = dflt_resc_num;
2692 *p_resc_start = dflt_resc_start;
2696 /* TBD - remove this when revising the handling of the SB resource */
2697 if (res_id == ECORE_SB) {
2698 /* Excluding the slowpath SB */
2700 *p_resc_start -= p_hwfn->enabled_func_idx;
2703 if (*p_resc_num != dflt_resc_num || *p_resc_start != dflt_resc_start) {
2705 "MFW allocation for resource %d [%s] differs from default values [%d,%d vs. %d,%d]%s\n",
2706 res_id, ecore_hw_get_resc_name(res_id), *p_resc_num,
2707 *p_resc_start, dflt_resc_num, dflt_resc_start,
2708 drv_resc_alloc ? " - Applying default values" : "");
2709 if (drv_resc_alloc) {
2710 *p_resc_num = dflt_resc_num;
2711 *p_resc_start = dflt_resc_start;
2715 return ECORE_SUCCESS;
2718 static enum _ecore_status_t ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn,
2719 bool drv_resc_alloc)
2721 enum _ecore_status_t rc;
2724 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
2725 rc = __ecore_hw_set_resc_info(p_hwfn, res_id, drv_resc_alloc);
2726 if (rc != ECORE_SUCCESS)
2730 return ECORE_SUCCESS;
2733 #define ECORE_RESC_ALLOC_LOCK_RETRY_CNT 10
2734 #define ECORE_RESC_ALLOC_LOCK_RETRY_INTVL_US 10000 /* 10 msec */
2736 static enum _ecore_status_t ecore_hw_get_resc(struct ecore_hwfn *p_hwfn,
2737 bool drv_resc_alloc)
2739 struct ecore_resc_unlock_params resc_unlock_params;
2740 struct ecore_resc_lock_params resc_lock_params;
2741 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2743 enum _ecore_status_t rc;
2745 u32 *resc_start = p_hwfn->hw_info.resc_start;
2746 u32 *resc_num = p_hwfn->hw_info.resc_num;
2747 /* For AH, an equal share of the ILT lines between the maximal number of
2748 * PFs is not enough for RoCE. This would be solved by the future
2749 * resource allocation scheme, but isn't currently present for
2750 * FPGA/emulation. For now we keep a number that is sufficient for RoCE
2751 * to work - the BB number of ILT lines divided by its max PFs number.
2753 u32 roce_min_ilt_lines = PXP_NUM_ILT_RECORDS_BB / MAX_NUM_PFS_BB;
2756 /* Setting the max values of the soft resources and the following
2757 * resources allocation queries should be atomic. Since several PFs can
2758 * run in parallel - a resource lock is needed.
2759 * If either the resource lock or resource set value commands are not
2760 * supported - skip the the max values setting, release the lock if
2761 * needed, and proceed to the queries. Other failures, including a
2762 * failure to acquire the lock, will cause this function to fail.
2763 * Old drivers that don't acquire the lock can run in parallel, and
2764 * their allocation values won't be affected by the updated max values.
2766 OSAL_MEM_ZERO(&resc_lock_params, sizeof(resc_lock_params));
2767 resc_lock_params.resource = ECORE_RESC_LOCK_RESC_ALLOC;
2768 resc_lock_params.retry_num = ECORE_RESC_ALLOC_LOCK_RETRY_CNT;
2769 resc_lock_params.retry_interval = ECORE_RESC_ALLOC_LOCK_RETRY_INTVL_US;
2770 resc_lock_params.sleep_b4_retry = true;
2771 OSAL_MEM_ZERO(&resc_unlock_params, sizeof(resc_unlock_params));
2772 resc_unlock_params.resource = ECORE_RESC_LOCK_RESC_ALLOC;
2774 rc = ecore_mcp_resc_lock(p_hwfn, p_hwfn->p_main_ptt, &resc_lock_params);
2775 if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
2777 } else if (rc == ECORE_NOTIMPL) {
2779 "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
2780 } else if (rc == ECORE_SUCCESS && !resc_lock_params.b_granted) {
2781 DP_NOTICE(p_hwfn, false,
2782 "Failed to acquire the resource lock for the resource allocation commands\n");
2784 goto unlock_and_exit;
2786 rc = ecore_hw_set_soft_resc_size(p_hwfn);
2787 if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
2788 DP_NOTICE(p_hwfn, false,
2789 "Failed to set the max values of the soft resources\n");
2790 goto unlock_and_exit;
2791 } else if (rc == ECORE_NOTIMPL) {
2793 "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
2794 rc = ecore_mcp_resc_unlock(p_hwfn, p_hwfn->p_main_ptt,
2795 &resc_unlock_params);
2796 if (rc != ECORE_SUCCESS)
2798 "Failed to release the resource lock for the resource allocation commands\n");
2802 rc = ecore_hw_set_resc_info(p_hwfn, drv_resc_alloc);
2803 if (rc != ECORE_SUCCESS)
2804 goto unlock_and_exit;
2806 if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
2807 rc = ecore_mcp_resc_unlock(p_hwfn, p_hwfn->p_main_ptt,
2808 &resc_unlock_params);
2809 if (rc != ECORE_SUCCESS)
2811 "Failed to release the resource lock for the resource allocation commands\n");
2815 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2816 /* Reduced build contains less PQs */
2817 if (!(p_hwfn->p_dev->b_is_emul_full)) {
2818 resc_num[ECORE_PQ] = 32;
2819 resc_start[ECORE_PQ] = resc_num[ECORE_PQ] *
2820 p_hwfn->enabled_func_idx;
2823 /* For AH emulation, since we have a possible maximal number of
2824 * 16 enabled PFs, in case there are not enough ILT lines -
2825 * allocate only first PF as RoCE and have all the other ETH
2826 * only with less ILT lines.
2828 if (!p_hwfn->rel_pf_id && p_hwfn->p_dev->b_is_emul_full)
2829 resc_num[ECORE_ILT] = OSAL_MAX_T(u32,
2830 resc_num[ECORE_ILT],
2831 roce_min_ilt_lines);
2834 /* Correct the common ILT calculation if PF0 has more */
2835 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev) &&
2836 p_hwfn->p_dev->b_is_emul_full &&
2837 p_hwfn->rel_pf_id && resc_num[ECORE_ILT] < roce_min_ilt_lines)
2838 resc_start[ECORE_ILT] += roce_min_ilt_lines -
2839 resc_num[ECORE_ILT];
2842 /* Sanity for ILT */
2843 if ((b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2844 (!b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
2845 DP_NOTICE(p_hwfn, true,
2846 "Can't assign ILT pages [%08x,...,%08x]\n",
2847 RESC_START(p_hwfn, ECORE_ILT), RESC_END(p_hwfn,
2853 ecore_hw_set_feat(p_hwfn);
2855 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2856 "The numbers for each resource are:\n");
2857 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++)
2858 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE, "%s = %d start = %d\n",
2859 ecore_hw_get_resc_name(res_id),
2860 RESC_NUM(p_hwfn, res_id),
2861 RESC_START(p_hwfn, res_id));
2863 return ECORE_SUCCESS;
2866 ecore_mcp_resc_unlock(p_hwfn, p_hwfn->p_main_ptt, &resc_unlock_params);
2870 static enum _ecore_status_t
2871 ecore_hw_get_nvm_info(struct ecore_hwfn *p_hwfn,
2872 struct ecore_ptt *p_ptt,
2873 struct ecore_hw_prepare_params *p_params)
2875 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg, dcbx_mode;
2876 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
2877 struct ecore_mcp_link_params *link;
2878 enum _ecore_status_t rc;
2880 /* Read global nvm_cfg address */
2881 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2883 /* Verify MCP has initialized it */
2884 if (!nvm_cfg_addr) {
2885 DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
2886 if (p_params->b_relaxed_probe)
2887 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_NVM;
2891 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
2893 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2895 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2896 OFFSETOF(struct nvm_cfg1, glob) + OFFSETOF(struct nvm_cfg1_glob,
2899 core_cfg = ecore_rd(p_hwfn, p_ptt, addr);
2901 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
2902 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
2903 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
2904 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X40G;
2906 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
2907 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X50G;
2909 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
2910 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X100G;
2912 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
2913 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_F;
2915 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
2916 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_E;
2918 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
2919 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X20G;
2921 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
2922 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X40G;
2924 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
2925 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X25G;
2927 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
2928 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X10G;
2930 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
2931 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X25G;
2933 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
2934 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X25G;
2937 DP_NOTICE(p_hwfn, true, "Unknown port mode in 0x%08x\n",
2942 /* Read DCBX configuration */
2943 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2944 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2945 dcbx_mode = ecore_rd(p_hwfn, p_ptt,
2947 OFFSETOF(struct nvm_cfg1_port, generic_cont0));
2948 dcbx_mode = (dcbx_mode & NVM_CFG1_PORT_DCBX_MODE_MASK)
2949 >> NVM_CFG1_PORT_DCBX_MODE_OFFSET;
2950 switch (dcbx_mode) {
2951 case NVM_CFG1_PORT_DCBX_MODE_DYNAMIC:
2952 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DYNAMIC;
2954 case NVM_CFG1_PORT_DCBX_MODE_CEE:
2955 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_CEE;
2957 case NVM_CFG1_PORT_DCBX_MODE_IEEE:
2958 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_IEEE;
2961 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DISABLED;
2964 /* Read default link configuration */
2965 link = &p_hwfn->mcp_info->link_input;
2966 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2967 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2968 link_temp = ecore_rd(p_hwfn, p_ptt,
2970 OFFSETOF(struct nvm_cfg1_port, speed_cap_mask));
2971 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
2972 link->speed.advertised_speeds = link_temp;
2974 link_temp = link->speed.advertised_speeds;
2975 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
2977 link_temp = ecore_rd(p_hwfn, p_ptt,
2979 OFFSETOF(struct nvm_cfg1_port, link_settings));
2980 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
2981 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
2982 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
2983 link->speed.autoneg = true;
2985 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
2986 link->speed.forced_speed = 1000;
2988 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
2989 link->speed.forced_speed = 10000;
2991 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
2992 link->speed.forced_speed = 25000;
2994 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
2995 link->speed.forced_speed = 40000;
2997 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
2998 link->speed.forced_speed = 50000;
3000 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
3001 link->speed.forced_speed = 100000;
3004 DP_NOTICE(p_hwfn, true, "Unknown Speed in 0x%08x\n", link_temp);
3007 p_hwfn->mcp_info->link_capabilities.default_speed =
3008 link->speed.forced_speed;
3009 p_hwfn->mcp_info->link_capabilities.default_speed_autoneg =
3010 link->speed.autoneg;
3012 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
3013 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
3014 link->pause.autoneg = !!(link_temp &
3015 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
3016 link->pause.forced_rx = !!(link_temp &
3017 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
3018 link->pause.forced_tx = !!(link_temp &
3019 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
3020 link->loopback_mode = 0;
3022 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3023 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
3024 link->speed.forced_speed, link->speed.advertised_speeds,
3025 link->speed.autoneg, link->pause.autoneg);
3027 /* Read Multi-function information from shmem */
3028 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3029 OFFSETOF(struct nvm_cfg1, glob) +
3030 OFFSETOF(struct nvm_cfg1_glob, generic_cont0);
3032 generic_cont0 = ecore_rd(p_hwfn, p_ptt, addr);
3034 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
3035 NVM_CFG1_GLOB_MF_MODE_OFFSET;
3038 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
3039 p_hwfn->p_dev->mf_mode = ECORE_MF_OVLAN;
3041 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
3042 p_hwfn->p_dev->mf_mode = ECORE_MF_NPAR;
3044 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
3045 p_hwfn->p_dev->mf_mode = ECORE_MF_DEFAULT;
3048 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
3049 p_hwfn->p_dev->mf_mode);
3051 /* Read Multi-function information from shmem */
3052 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3053 OFFSETOF(struct nvm_cfg1, glob) +
3054 OFFSETOF(struct nvm_cfg1_glob, device_capabilities);
3056 device_capabilities = ecore_rd(p_hwfn, p_ptt, addr);
3057 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
3058 OSAL_SET_BIT(ECORE_DEV_CAP_ETH,
3059 &p_hwfn->hw_info.device_capabilities);
3060 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
3061 OSAL_SET_BIT(ECORE_DEV_CAP_FCOE,
3062 &p_hwfn->hw_info.device_capabilities);
3063 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
3064 OSAL_SET_BIT(ECORE_DEV_CAP_ISCSI,
3065 &p_hwfn->hw_info.device_capabilities);
3066 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
3067 OSAL_SET_BIT(ECORE_DEV_CAP_ROCE,
3068 &p_hwfn->hw_info.device_capabilities);
3069 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_IWARP)
3070 OSAL_SET_BIT(ECORE_DEV_CAP_IWARP,
3071 &p_hwfn->hw_info.device_capabilities);
3073 rc = ecore_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
3074 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3076 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3082 static void ecore_get_num_funcs(struct ecore_hwfn *p_hwfn,
3083 struct ecore_ptt *p_ptt)
3085 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
3086 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
3087 struct ecore_dev *p_dev = p_hwfn->p_dev;
3089 num_funcs = ECORE_IS_AH(p_dev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
3091 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
3092 * in the other bits are selected.
3093 * Bits 1-15 are for functions 1-15, respectively, and their value is
3094 * '0' only for enabled functions (function 0 always exists and
3096 * In case of CMT in BB, only the "even" functions are enabled, and thus
3097 * the number of functions for both hwfns is learnt from the same bits.
3099 if (ECORE_IS_BB(p_dev) || ECORE_IS_AH(p_dev)) {
3100 reg_function_hide = ecore_rd(p_hwfn, p_ptt,
3101 MISCS_REG_FUNCTION_HIDE_BB_K2);
3103 reg_function_hide = 0;
3106 if (reg_function_hide & 0x1) {
3107 if (ECORE_IS_BB(p_dev)) {
3108 if (ECORE_PATH_ID(p_hwfn) && p_dev->num_hwfns == 1) {
3120 /* Get the number of the enabled functions on the engine */
3121 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
3128 /* Get the PF index within the enabled functions */
3129 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
3130 tmp = reg_function_hide & eng_mask & low_pfs_mask;
3138 p_hwfn->num_funcs_on_engine = num_funcs;
3139 p_hwfn->enabled_func_idx = enabled_func_idx;
3142 if (CHIP_REV_IS_FPGA(p_dev)) {
3143 DP_NOTICE(p_hwfn, false,
3144 "FPGA: Limit number of PFs to 4 [would affect resource allocation, needed for IOV]\n");
3145 p_hwfn->num_funcs_on_engine = 4;
3149 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
3150 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
3151 p_hwfn->rel_pf_id, p_hwfn->abs_pf_id,
3152 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
3155 static void ecore_hw_info_port_num_bb(struct ecore_hwfn *p_hwfn,
3156 struct ecore_ptt *p_ptt)
3161 /* Read the port mode */
3162 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
3164 else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) &&
3165 (p_hwfn->p_dev->num_hwfns > 1))
3166 /* In CMT on emulation, assume 1 port */
3170 port_mode = ecore_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
3172 if (port_mode < 3) {
3173 p_hwfn->p_dev->num_ports_in_engines = 1;
3174 } else if (port_mode <= 5) {
3175 p_hwfn->p_dev->num_ports_in_engines = 2;
3177 DP_NOTICE(p_hwfn, true, "PORT MODE: %d not supported\n",
3178 p_hwfn->p_dev->num_ports_in_engines);
3180 /* Default num_ports_in_engines to something */
3181 p_hwfn->p_dev->num_ports_in_engines = 1;
3185 static void ecore_hw_info_port_num_ah_e5(struct ecore_hwfn *p_hwfn,
3186 struct ecore_ptt *p_ptt)
3191 p_hwfn->p_dev->num_ports_in_engines = 0;
3194 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
3195 port = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
3196 switch ((port & 0xf000) >> 12) {
3198 p_hwfn->p_dev->num_ports_in_engines = 1;
3201 p_hwfn->p_dev->num_ports_in_engines = 2;
3204 p_hwfn->p_dev->num_ports_in_engines = 4;
3207 DP_NOTICE(p_hwfn, false,
3208 "Unknown port mode in ECO_RESERVED %08x\n",
3213 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
3214 port = ecore_rd(p_hwfn, p_ptt,
3215 CNIG_REG_NIG_PORT0_CONF_K2_E5 +
3218 p_hwfn->p_dev->num_ports_in_engines++;
3222 static void ecore_hw_info_port_num(struct ecore_hwfn *p_hwfn,
3223 struct ecore_ptt *p_ptt)
3225 if (ECORE_IS_BB(p_hwfn->p_dev))
3226 ecore_hw_info_port_num_bb(p_hwfn, p_ptt);
3228 ecore_hw_info_port_num_ah_e5(p_hwfn, p_ptt);
3231 static enum _ecore_status_t
3232 ecore_get_hw_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3233 enum ecore_pci_personality personality,
3234 struct ecore_hw_prepare_params *p_params)
3236 bool drv_resc_alloc = p_params->drv_resc_alloc;
3237 enum _ecore_status_t rc;
3239 /* Since all information is common, only first hwfns should do this */
3240 if (IS_LEAD_HWFN(p_hwfn)) {
3241 rc = ecore_iov_hw_info(p_hwfn);
3242 if (rc != ECORE_SUCCESS) {
3243 if (p_params->b_relaxed_probe)
3244 p_params->p_relaxed_res =
3245 ECORE_HW_PREPARE_BAD_IOV;
3251 /* TODO In get_hw_info, amoungst others:
3252 * Get MCP FW revision and determine according to it the supported
3253 * featrues (e.g. DCB)
3255 * ecore_get_pcie_width_speed, WOL capability.
3256 * Number of global CQ-s (for storage
3258 ecore_hw_info_port_num(p_hwfn, p_ptt);
3261 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev)) {
3263 rc = ecore_hw_get_nvm_info(p_hwfn, p_ptt, p_params);
3264 if (rc != ECORE_SUCCESS)
3270 rc = ecore_int_igu_read_cam(p_hwfn, p_ptt);
3271 if (rc != ECORE_SUCCESS) {
3272 if (p_params->b_relaxed_probe)
3273 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_IGU;
3279 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev) && ecore_mcp_is_init(p_hwfn)) {
3281 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr,
3282 p_hwfn->mcp_info->func_info.mac, ETH_ALEN);
3285 static u8 mcp_hw_mac[6] = { 0, 2, 3, 4, 5, 6 };
3287 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr, mcp_hw_mac, ETH_ALEN);
3288 p_hwfn->hw_info.hw_mac_addr[5] = p_hwfn->abs_pf_id;
3292 if (ecore_mcp_is_init(p_hwfn)) {
3293 if (p_hwfn->mcp_info->func_info.ovlan != ECORE_MCP_VLAN_UNSET)
3294 p_hwfn->hw_info.ovlan =
3295 p_hwfn->mcp_info->func_info.ovlan;
3297 ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
3300 if (personality != ECORE_PCI_DEFAULT) {
3301 p_hwfn->hw_info.personality = personality;
3302 } else if (ecore_mcp_is_init(p_hwfn)) {
3303 enum ecore_pci_personality protocol;
3305 protocol = p_hwfn->mcp_info->func_info.protocol;
3306 p_hwfn->hw_info.personality = protocol;
3310 /* To overcome ILT lack for emulation, until at least until we'll have
3311 * a definite answer from system about it, allow only PF0 to be RoCE.
3313 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev)) {
3314 if (!p_hwfn->rel_pf_id)
3315 p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
3317 p_hwfn->hw_info.personality = ECORE_PCI_ETH;
3321 /* although in BB some constellations may support more than 4 tcs,
3322 * that can result in performance penalty in some cases. 4
3323 * represents a good tradeoff between performance and flexibility.
3325 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
3327 /* start out with a single active tc. This can be increased either
3328 * by dcbx negotiation or by upper layer driver
3330 p_hwfn->hw_info.num_active_tc = 1;
3332 ecore_get_num_funcs(p_hwfn, p_ptt);
3334 if (ecore_mcp_is_init(p_hwfn))
3335 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
3337 /* In case of forcing the driver's default resource allocation, calling
3338 * ecore_hw_get_resc() should come after initializing the personality
3339 * and after getting the number of functions, since the calculation of
3340 * the resources/features depends on them.
3341 * This order is not harmful if not forcing.
3343 rc = ecore_hw_get_resc(p_hwfn, drv_resc_alloc);
3344 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3346 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3352 static enum _ecore_status_t ecore_get_dev_info(struct ecore_dev *p_dev)
3354 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3357 /* Read Vendor Id / Device Id */
3358 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_VENDOR_ID_OFFSET,
3360 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_DEVICE_ID_OFFSET,
3363 /* Determine type */
3364 if ((p_dev->device_id & ECORE_DEV_ID_MASK) == ECORE_DEV_ID_MASK_AH)
3365 p_dev->type = ECORE_DEV_TYPE_AH;
3367 p_dev->type = ECORE_DEV_TYPE_BB;
3369 p_dev->chip_num = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3370 MISCS_REG_CHIP_NUM);
3371 p_dev->chip_rev = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3372 MISCS_REG_CHIP_REV);
3374 MASK_FIELD(CHIP_REV, p_dev->chip_rev);
3376 /* Learn number of HW-functions */
3377 tmp = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3378 MISCS_REG_CMT_ENABLED_FOR_PAIR);
3380 if (tmp & (1 << p_hwfn->rel_pf_id)) {
3381 DP_NOTICE(p_dev->hwfns, false, "device in CMT mode\n");
3382 p_dev->num_hwfns = 2;
3384 p_dev->num_hwfns = 1;
3388 if (CHIP_REV_IS_EMUL(p_dev)) {
3389 /* For some reason we have problems with this register
3390 * in B0 emulation; Simply assume no CMT
3392 DP_NOTICE(p_dev->hwfns, false,
3393 "device on emul - assume no CMT\n");
3394 p_dev->num_hwfns = 1;
3398 p_dev->chip_bond_id = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3399 MISCS_REG_CHIP_TEST_REG) >> 4;
3400 MASK_FIELD(CHIP_BOND_ID, p_dev->chip_bond_id);
3401 p_dev->chip_metal = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3402 MISCS_REG_CHIP_METAL);
3403 MASK_FIELD(CHIP_METAL, p_dev->chip_metal);
3404 DP_INFO(p_dev->hwfns,
3405 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
3406 ECORE_IS_BB(p_dev) ? "BB" : "AH",
3407 'A' + p_dev->chip_rev, (int)p_dev->chip_metal,
3408 p_dev->chip_num, p_dev->chip_rev, p_dev->chip_bond_id,
3411 if (ECORE_IS_BB(p_dev) && CHIP_REV_IS_A0(p_dev)) {
3412 DP_NOTICE(p_dev->hwfns, false,
3413 "The chip type/rev (BB A0) is not supported!\n");
3414 return ECORE_ABORTED;
3417 if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_AH(p_dev))
3418 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
3419 MISCS_REG_PLL_MAIN_CTRL_4, 0x1);
3421 if (CHIP_REV_IS_EMUL(p_dev)) {
3422 tmp = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3423 MISCS_REG_ECO_RESERVED);
3424 if (tmp & (1 << 29)) {
3425 DP_NOTICE(p_hwfn, false,
3426 "Emulation: Running on a FULL build\n");
3427 p_dev->b_is_emul_full = true;
3429 DP_NOTICE(p_hwfn, false,
3430 "Emulation: Running on a REDUCED build\n");
3435 return ECORE_SUCCESS;
3438 #ifndef LINUX_REMOVE
3439 void ecore_prepare_hibernate(struct ecore_dev *p_dev)
3446 for_each_hwfn(p_dev, j) {
3447 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
3449 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
3450 "Mark hw/fw uninitialized\n");
3452 p_hwfn->hw_init_done = false;
3453 p_hwfn->first_on_engine = false;
3455 ecore_ptt_invalidate(p_hwfn);
3460 static enum _ecore_status_t
3461 ecore_hw_prepare_single(struct ecore_hwfn *p_hwfn,
3462 void OSAL_IOMEM * p_regview,
3463 void OSAL_IOMEM * p_doorbells,
3464 struct ecore_hw_prepare_params *p_params)
3466 struct ecore_dev *p_dev = p_hwfn->p_dev;
3467 struct ecore_mdump_info mdump_info;
3468 enum _ecore_status_t rc = ECORE_SUCCESS;
3470 /* Split PCI bars evenly between hwfns */
3471 p_hwfn->regview = p_regview;
3472 p_hwfn->doorbells = p_doorbells;
3475 return ecore_vf_hw_prepare(p_hwfn);
3477 /* Validate that chip access is feasible */
3478 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
3480 "Reading the ME register returns all Fs; Preventing further chip access\n");
3481 if (p_params->b_relaxed_probe)
3482 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_ME;
3486 get_function_id(p_hwfn);
3488 /* Allocate PTT pool */
3489 rc = ecore_ptt_pool_alloc(p_hwfn);
3491 DP_NOTICE(p_hwfn, true, "Failed to prepare hwfn's hw\n");
3492 if (p_params->b_relaxed_probe)
3493 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3497 /* Allocate the main PTT */
3498 p_hwfn->p_main_ptt = ecore_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
3500 /* First hwfn learns basic information, e.g., number of hwfns */
3501 if (!p_hwfn->my_id) {
3502 rc = ecore_get_dev_info(p_dev);
3503 if (rc != ECORE_SUCCESS) {
3504 if (p_params->b_relaxed_probe)
3505 p_params->p_relaxed_res =
3506 ECORE_HW_PREPARE_FAILED_DEV;
3511 ecore_hw_hwfn_prepare(p_hwfn);
3513 /* Initialize MCP structure */
3514 rc = ecore_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
3516 DP_NOTICE(p_hwfn, true, "Failed initializing mcp command\n");
3517 if (p_params->b_relaxed_probe)
3518 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3522 /* Read the device configuration information from the HW and SHMEM */
3523 rc = ecore_get_hw_info(p_hwfn, p_hwfn->p_main_ptt,
3524 p_params->personality, p_params);
3526 DP_NOTICE(p_hwfn, true, "Failed to get HW information\n");
3530 /* Sending a mailbox to the MFW should be after ecore_get_hw_info() is
3531 * called, since among others it sets the ports number in an engine.
3533 if (p_params->initiate_pf_flr && p_hwfn == ECORE_LEADING_HWFN(p_dev) &&
3534 !p_dev->recov_in_prog) {
3535 rc = ecore_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
3536 if (rc != ECORE_SUCCESS)
3537 DP_NOTICE(p_hwfn, false, "Failed to initiate PF FLR\n");
3540 /* Check if mdump logs are present and update the epoch value */
3541 if (p_hwfn == ECORE_LEADING_HWFN(p_hwfn->p_dev)) {
3542 rc = ecore_mcp_mdump_get_info(p_hwfn, p_hwfn->p_main_ptt,
3544 if (rc == ECORE_SUCCESS && mdump_info.num_of_logs > 0) {
3545 DP_NOTICE(p_hwfn, false,
3546 "* * * IMPORTANT - HW ERROR register dump captured by device * * *\n");
3549 ecore_mcp_mdump_set_values(p_hwfn, p_hwfn->p_main_ptt,
3553 /* Allocate the init RT array and initialize the init-ops engine */
3554 rc = ecore_init_alloc(p_hwfn);
3556 DP_NOTICE(p_hwfn, true, "Failed to allocate the init array\n");
3557 if (p_params->b_relaxed_probe)
3558 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3562 if (CHIP_REV_IS_FPGA(p_dev)) {
3563 DP_NOTICE(p_hwfn, false,
3564 "FPGA: workaround; Prevent DMAE parities\n");
3565 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PCIE_REG_PRTY_MASK_K2_E5,
3568 DP_NOTICE(p_hwfn, false,
3569 "FPGA: workaround: Set VF bar0 size\n");
3570 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
3571 PGLUE_B_REG_VF_BAR0_SIZE_K2_E5, 4);
3577 if (IS_LEAD_HWFN(p_hwfn))
3578 ecore_iov_free_hw_info(p_dev);
3579 ecore_mcp_free(p_hwfn);
3581 ecore_hw_hwfn_free(p_hwfn);
3586 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
3587 struct ecore_hw_prepare_params *p_params)
3589 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3590 enum _ecore_status_t rc;
3592 p_dev->chk_reg_fifo = p_params->chk_reg_fifo;
3593 p_dev->allow_mdump = p_params->allow_mdump;
3595 if (p_params->b_relaxed_probe)
3596 p_params->p_relaxed_res = ECORE_HW_PREPARE_SUCCESS;
3598 /* Store the precompiled init data ptrs */
3600 ecore_init_iro_array(p_dev);
3602 /* Initialize the first hwfn - will learn number of hwfns */
3603 rc = ecore_hw_prepare_single(p_hwfn,
3605 p_dev->doorbells, p_params);
3606 if (rc != ECORE_SUCCESS)
3609 p_params->personality = p_hwfn->hw_info.personality;
3611 /* initilalize 2nd hwfn if necessary */
3612 if (p_dev->num_hwfns > 1) {
3613 void OSAL_IOMEM *p_regview, *p_doorbell;
3614 u8 OSAL_IOMEM *addr;
3616 /* adjust bar offset for second engine */
3617 addr = (u8 OSAL_IOMEM *)p_dev->regview +
3618 ecore_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
3619 p_regview = (void OSAL_IOMEM *)addr;
3621 addr = (u8 OSAL_IOMEM *)p_dev->doorbells +
3622 ecore_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
3623 p_doorbell = (void OSAL_IOMEM *)addr;
3625 /* prepare second hw function */
3626 rc = ecore_hw_prepare_single(&p_dev->hwfns[1], p_regview,
3627 p_doorbell, p_params);
3629 /* in case of error, need to free the previously
3630 * initiliazed hwfn 0.
3632 if (rc != ECORE_SUCCESS) {
3633 if (p_params->b_relaxed_probe)
3634 p_params->p_relaxed_res =
3635 ECORE_HW_PREPARE_FAILED_ENG2;
3638 ecore_init_free(p_hwfn);
3639 ecore_mcp_free(p_hwfn);
3640 ecore_hw_hwfn_free(p_hwfn);
3642 DP_NOTICE(p_dev, true,
3643 "What do we need to free when VF hwfn1 init fails\n");
3652 void ecore_hw_remove(struct ecore_dev *p_dev)
3654 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3658 ecore_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
3659 ECORE_OV_DRIVER_STATE_NOT_LOADED);
3661 for_each_hwfn(p_dev, i) {
3662 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3665 ecore_vf_pf_release(p_hwfn);
3669 ecore_init_free(p_hwfn);
3670 ecore_hw_hwfn_free(p_hwfn);
3671 ecore_mcp_free(p_hwfn);
3673 OSAL_MUTEX_DEALLOC(&p_hwfn->dmae_info.mutex);
3676 ecore_iov_free_hw_info(p_dev);
3679 static void ecore_chain_free_next_ptr(struct ecore_dev *p_dev,
3680 struct ecore_chain *p_chain)
3682 void *p_virt = p_chain->p_virt_addr, *p_virt_next = OSAL_NULL;
3683 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3684 struct ecore_chain_next *p_next;
3690 size = p_chain->elem_size * p_chain->usable_per_page;
3692 for (i = 0; i < p_chain->page_cnt; i++) {
3696 p_next = (struct ecore_chain_next *)((u8 *)p_virt + size);
3697 p_virt_next = p_next->next_virt;
3698 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3700 OSAL_DMA_FREE_COHERENT(p_dev, p_virt, p_phys,
3701 ECORE_CHAIN_PAGE_SIZE);
3703 p_virt = p_virt_next;
3704 p_phys = p_phys_next;
3708 static void ecore_chain_free_single(struct ecore_dev *p_dev,
3709 struct ecore_chain *p_chain)
3711 if (!p_chain->p_virt_addr)
3714 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->p_virt_addr,
3715 p_chain->p_phys_addr, ECORE_CHAIN_PAGE_SIZE);
3718 static void ecore_chain_free_pbl(struct ecore_dev *p_dev,
3719 struct ecore_chain *p_chain)
3721 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3722 u8 *p_pbl_virt = (u8 *)p_chain->pbl_sp.p_virt_table;
3723 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
3725 if (!pp_virt_addr_tbl)
3731 for (i = 0; i < page_cnt; i++) {
3732 if (!pp_virt_addr_tbl[i])
3735 OSAL_DMA_FREE_COHERENT(p_dev, pp_virt_addr_tbl[i],
3736 *(dma_addr_t *)p_pbl_virt,
3737 ECORE_CHAIN_PAGE_SIZE);
3739 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
3742 pbl_size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
3744 if (!p_chain->b_external_pbl)
3745 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->pbl_sp.p_virt_table,
3746 p_chain->pbl_sp.p_phys_table, pbl_size);
3748 OSAL_VFREE(p_dev, p_chain->pbl.pp_virt_addr_tbl);
3751 void ecore_chain_free(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3753 switch (p_chain->mode) {
3754 case ECORE_CHAIN_MODE_NEXT_PTR:
3755 ecore_chain_free_next_ptr(p_dev, p_chain);
3757 case ECORE_CHAIN_MODE_SINGLE:
3758 ecore_chain_free_single(p_dev, p_chain);
3760 case ECORE_CHAIN_MODE_PBL:
3761 ecore_chain_free_pbl(p_dev, p_chain);
3766 static enum _ecore_status_t
3767 ecore_chain_alloc_sanity_check(struct ecore_dev *p_dev,
3768 enum ecore_chain_cnt_type cnt_type,
3769 osal_size_t elem_size, u32 page_cnt)
3771 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3773 /* The actual chain size can be larger than the maximal possible value
3774 * after rounding up the requested elements number to pages, and after
3775 * taking into acount the unusuable elements (next-ptr elements).
3776 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3777 * size/capacity fields are of a u32 type.
3779 if ((cnt_type == ECORE_CHAIN_CNT_TYPE_U16 &&
3780 chain_size > ((u32)ECORE_U16_MAX + 1)) ||
3781 (cnt_type == ECORE_CHAIN_CNT_TYPE_U32 &&
3782 chain_size > ECORE_U32_MAX)) {
3783 DP_NOTICE(p_dev, true,
3784 "The actual chain size (0x%lx) is larger than the maximal possible value\n",
3785 (unsigned long)chain_size);
3789 return ECORE_SUCCESS;
3792 static enum _ecore_status_t
3793 ecore_chain_alloc_next_ptr(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3795 void *p_virt = OSAL_NULL, *p_virt_prev = OSAL_NULL;
3796 dma_addr_t p_phys = 0;
3799 for (i = 0; i < p_chain->page_cnt; i++) {
3800 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
3801 ECORE_CHAIN_PAGE_SIZE);
3803 DP_NOTICE(p_dev, true,
3804 "Failed to allocate chain memory\n");
3809 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3810 ecore_chain_reset(p_chain);
3812 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3816 p_virt_prev = p_virt;
3818 /* Last page's next element should point to the beginning of the
3821 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3822 p_chain->p_virt_addr,
3823 p_chain->p_phys_addr);
3825 return ECORE_SUCCESS;
3828 static enum _ecore_status_t
3829 ecore_chain_alloc_single(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3831 dma_addr_t p_phys = 0;
3832 void *p_virt = OSAL_NULL;
3834 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys, ECORE_CHAIN_PAGE_SIZE);
3836 DP_NOTICE(p_dev, true, "Failed to allocate chain memory\n");
3840 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3841 ecore_chain_reset(p_chain);
3843 return ECORE_SUCCESS;
3846 static enum _ecore_status_t
3847 ecore_chain_alloc_pbl(struct ecore_dev *p_dev,
3848 struct ecore_chain *p_chain,
3849 struct ecore_chain_ext_pbl *ext_pbl)
3851 void *p_virt = OSAL_NULL;
3852 u8 *p_pbl_virt = OSAL_NULL;
3853 void **pp_virt_addr_tbl = OSAL_NULL;
3854 dma_addr_t p_phys = 0, p_pbl_phys = 0;
3855 u32 page_cnt = p_chain->page_cnt, size, i;
3857 size = page_cnt * sizeof(*pp_virt_addr_tbl);
3858 pp_virt_addr_tbl = (void **)OSAL_VZALLOC(p_dev, size);
3859 if (!pp_virt_addr_tbl) {
3860 DP_NOTICE(p_dev, true,
3861 "Failed to allocate memory for the chain virtual addresses table\n");
3865 /* The allocation of the PBL table is done with its full size, since it
3866 * is expected to be successive.
3867 * ecore_chain_init_pbl_mem() is called even in a case of an allocation
3868 * failure, since pp_virt_addr_tbl was previously allocated, and it
3869 * should be saved to allow its freeing during the error flow.
3871 size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
3873 if (ext_pbl == OSAL_NULL) {
3874 p_pbl_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_pbl_phys, size);
3876 p_pbl_virt = ext_pbl->p_pbl_virt;
3877 p_pbl_phys = ext_pbl->p_pbl_phys;
3878 p_chain->b_external_pbl = true;
3881 ecore_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
3884 DP_NOTICE(p_dev, true, "Failed to allocate chain pbl memory\n");
3888 for (i = 0; i < page_cnt; i++) {
3889 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
3890 ECORE_CHAIN_PAGE_SIZE);
3892 DP_NOTICE(p_dev, true,
3893 "Failed to allocate chain memory\n");
3898 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3899 ecore_chain_reset(p_chain);
3902 /* Fill the PBL table with the physical address of the page */
3903 *(dma_addr_t *)p_pbl_virt = p_phys;
3904 /* Keep the virtual address of the page */
3905 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
3907 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
3910 return ECORE_SUCCESS;
3913 enum _ecore_status_t ecore_chain_alloc(struct ecore_dev *p_dev,
3914 enum ecore_chain_use_mode intended_use,
3915 enum ecore_chain_mode mode,
3916 enum ecore_chain_cnt_type cnt_type,
3917 u32 num_elems, osal_size_t elem_size,
3918 struct ecore_chain *p_chain,
3919 struct ecore_chain_ext_pbl *ext_pbl)
3922 enum _ecore_status_t rc = ECORE_SUCCESS;
3924 if (mode == ECORE_CHAIN_MODE_SINGLE)
3927 page_cnt = ECORE_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
3929 rc = ecore_chain_alloc_sanity_check(p_dev, cnt_type, elem_size,
3932 DP_NOTICE(p_dev, true,
3933 "Cannot allocate a chain with the given arguments:\n"
3934 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
3935 intended_use, mode, cnt_type, num_elems, elem_size);
3939 ecore_chain_init_params(p_chain, page_cnt, (u8)elem_size, intended_use,
3940 mode, cnt_type, p_dev->dp_ctx);
3943 case ECORE_CHAIN_MODE_NEXT_PTR:
3944 rc = ecore_chain_alloc_next_ptr(p_dev, p_chain);
3946 case ECORE_CHAIN_MODE_SINGLE:
3947 rc = ecore_chain_alloc_single(p_dev, p_chain);
3949 case ECORE_CHAIN_MODE_PBL:
3950 rc = ecore_chain_alloc_pbl(p_dev, p_chain, ext_pbl);
3956 return ECORE_SUCCESS;
3959 ecore_chain_free(p_dev, p_chain);
3963 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
3964 u16 src_id, u16 *dst_id)
3966 if (src_id >= RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
3969 min = (u16)RESC_START(p_hwfn, ECORE_L2_QUEUE);
3970 max = min + RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
3971 DP_NOTICE(p_hwfn, true,
3972 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
3978 *dst_id = RESC_START(p_hwfn, ECORE_L2_QUEUE) + src_id;
3980 return ECORE_SUCCESS;
3983 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
3984 u8 src_id, u8 *dst_id)
3986 if (src_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
3989 min = (u8)RESC_START(p_hwfn, ECORE_VPORT);
3990 max = min + RESC_NUM(p_hwfn, ECORE_VPORT);
3991 DP_NOTICE(p_hwfn, true,
3992 "vport id [%d] is not valid, available indices [%d - %d]\n",
3998 *dst_id = RESC_START(p_hwfn, ECORE_VPORT) + src_id;
4000 return ECORE_SUCCESS;
4003 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
4004 u8 src_id, u8 *dst_id)
4006 if (src_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG)) {
4009 min = (u8)RESC_START(p_hwfn, ECORE_RSS_ENG);
4010 max = min + RESC_NUM(p_hwfn, ECORE_RSS_ENG);
4011 DP_NOTICE(p_hwfn, true,
4012 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
4018 *dst_id = RESC_START(p_hwfn, ECORE_RSS_ENG) + src_id;
4020 return ECORE_SUCCESS;
4023 static enum _ecore_status_t
4024 ecore_llh_add_mac_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4025 struct ecore_ptt *p_ptt, u32 high, u32 low,
4031 /* Find a free entry and utilize it */
4032 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4033 en = ecore_rd(p_hwfn, p_ptt,
4034 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4038 ecore_wr(p_hwfn, p_ptt,
4039 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4040 2 * i * sizeof(u32), low);
4041 ecore_wr(p_hwfn, p_ptt,
4042 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4043 (2 * i + 1) * sizeof(u32), high);
4044 ecore_wr(p_hwfn, p_ptt,
4045 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4046 i * sizeof(u32), 0);
4047 ecore_wr(p_hwfn, p_ptt,
4048 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4049 i * sizeof(u32), 0);
4050 ecore_wr(p_hwfn, p_ptt,
4051 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4052 i * sizeof(u32), 1);
4056 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4057 return ECORE_NORESOURCES;
4061 return ECORE_SUCCESS;
4064 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
4065 struct ecore_ptt *p_ptt, u8 *p_filter)
4067 u32 high, low, entry_num;
4068 enum _ecore_status_t rc;
4070 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4071 return ECORE_SUCCESS;
4073 high = p_filter[1] | (p_filter[0] << 8);
4074 low = p_filter[5] | (p_filter[4] << 8) |
4075 (p_filter[3] << 16) | (p_filter[2] << 24);
4077 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4078 rc = ecore_llh_add_mac_filter_bb_ah(p_hwfn, p_ptt, high, low,
4080 if (rc != ECORE_SUCCESS) {
4081 DP_NOTICE(p_hwfn, false,
4082 "Failed to find an empty LLH filter to utilize\n");
4086 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4087 "MAC: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx is added at %d\n",
4088 p_filter[0], p_filter[1], p_filter[2], p_filter[3],
4089 p_filter[4], p_filter[5], entry_num);
4091 return ECORE_SUCCESS;
4094 static enum _ecore_status_t
4095 ecore_llh_remove_mac_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4096 struct ecore_ptt *p_ptt, u32 high, u32 low,
4101 /* Find the entry and clean it */
4102 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4103 if (ecore_rd(p_hwfn, p_ptt,
4104 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4105 2 * i * sizeof(u32)) != low)
4107 if (ecore_rd(p_hwfn, p_ptt,
4108 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4109 (2 * i + 1) * sizeof(u32)) != high)
4112 ecore_wr(p_hwfn, p_ptt,
4113 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 0);
4114 ecore_wr(p_hwfn, p_ptt,
4115 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4116 2 * i * sizeof(u32), 0);
4117 ecore_wr(p_hwfn, p_ptt,
4118 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4119 (2 * i + 1) * sizeof(u32), 0);
4123 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4128 return ECORE_SUCCESS;
4131 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
4132 struct ecore_ptt *p_ptt, u8 *p_filter)
4134 u32 high, low, entry_num;
4135 enum _ecore_status_t rc;
4137 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4140 high = p_filter[1] | (p_filter[0] << 8);
4141 low = p_filter[5] | (p_filter[4] << 8) |
4142 (p_filter[3] << 16) | (p_filter[2] << 24);
4144 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4145 rc = ecore_llh_remove_mac_filter_bb_ah(p_hwfn, p_ptt, high,
4147 if (rc != ECORE_SUCCESS) {
4148 DP_NOTICE(p_hwfn, false,
4149 "Tried to remove a non-configured filter\n");
4154 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4155 "MAC: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx was removed from %d\n",
4156 p_filter[0], p_filter[1], p_filter[2], p_filter[3],
4157 p_filter[4], p_filter[5], entry_num);
4160 static enum _ecore_status_t
4161 ecore_llh_add_protocol_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4162 struct ecore_ptt *p_ptt,
4163 enum ecore_llh_port_filter_type_t type,
4164 u32 high, u32 low, u32 *p_entry_num)
4169 /* Find a free entry and utilize it */
4170 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4171 en = ecore_rd(p_hwfn, p_ptt,
4172 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4176 ecore_wr(p_hwfn, p_ptt,
4177 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4178 2 * i * sizeof(u32), low);
4179 ecore_wr(p_hwfn, p_ptt,
4180 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4181 (2 * i + 1) * sizeof(u32), high);
4182 ecore_wr(p_hwfn, p_ptt,
4183 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4184 i * sizeof(u32), 1);
4185 ecore_wr(p_hwfn, p_ptt,
4186 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4187 i * sizeof(u32), 1 << type);
4188 ecore_wr(p_hwfn, p_ptt,
4189 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 1);
4193 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4194 return ECORE_NORESOURCES;
4198 return ECORE_SUCCESS;
4201 enum _ecore_status_t
4202 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
4203 struct ecore_ptt *p_ptt,
4204 u16 source_port_or_eth_type,
4206 enum ecore_llh_port_filter_type_t type)
4208 u32 high, low, entry_num;
4209 enum _ecore_status_t rc;
4211 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4212 return ECORE_SUCCESS;
4218 case ECORE_LLH_FILTER_ETHERTYPE:
4219 high = source_port_or_eth_type;
4221 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4222 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4223 low = source_port_or_eth_type << 16;
4225 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4226 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4229 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4230 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4231 low = (source_port_or_eth_type << 16) | dest_port;
4234 DP_NOTICE(p_hwfn, true,
4235 "Non valid LLH protocol filter type %d\n", type);
4239 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4240 rc = ecore_llh_add_protocol_filter_bb_ah(p_hwfn, p_ptt, type,
4241 high, low, &entry_num);
4242 if (rc != ECORE_SUCCESS) {
4243 DP_NOTICE(p_hwfn, false,
4244 "Failed to find an empty LLH filter to utilize\n");
4248 case ECORE_LLH_FILTER_ETHERTYPE:
4249 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4250 "ETH type %x is added at %d\n",
4251 source_port_or_eth_type, entry_num);
4253 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4254 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4255 "TCP src port %x is added at %d\n",
4256 source_port_or_eth_type, entry_num);
4258 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4259 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4260 "UDP src port %x is added at %d\n",
4261 source_port_or_eth_type, entry_num);
4263 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4264 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4265 "TCP dst port %x is added at %d\n", dest_port,
4268 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4269 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4270 "UDP dst port %x is added at %d\n", dest_port,
4273 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4274 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4275 "TCP src/dst ports %x/%x are added at %d\n",
4276 source_port_or_eth_type, dest_port, entry_num);
4278 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4279 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4280 "UDP src/dst ports %x/%x are added at %d\n",
4281 source_port_or_eth_type, dest_port, entry_num);
4285 return ECORE_SUCCESS;
4288 static enum _ecore_status_t
4289 ecore_llh_remove_protocol_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4290 struct ecore_ptt *p_ptt,
4291 enum ecore_llh_port_filter_type_t type,
4292 u32 high, u32 low, u32 *p_entry_num)
4296 /* Find the entry and clean it */
4297 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4298 if (!ecore_rd(p_hwfn, p_ptt,
4299 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4302 if (!ecore_rd(p_hwfn, p_ptt,
4303 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4306 if (!(ecore_rd(p_hwfn, p_ptt,
4307 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4308 i * sizeof(u32)) & (1 << type)))
4310 if (ecore_rd(p_hwfn, p_ptt,
4311 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4312 2 * i * sizeof(u32)) != low)
4314 if (ecore_rd(p_hwfn, p_ptt,
4315 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4316 (2 * i + 1) * sizeof(u32)) != high)
4319 ecore_wr(p_hwfn, p_ptt,
4320 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 0);
4321 ecore_wr(p_hwfn, p_ptt,
4322 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4323 i * sizeof(u32), 0);
4324 ecore_wr(p_hwfn, p_ptt,
4325 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4326 i * sizeof(u32), 0);
4327 ecore_wr(p_hwfn, p_ptt,
4328 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4329 2 * i * sizeof(u32), 0);
4330 ecore_wr(p_hwfn, p_ptt,
4331 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4332 (2 * i + 1) * sizeof(u32), 0);
4336 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4341 return ECORE_SUCCESS;
4345 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
4346 struct ecore_ptt *p_ptt,
4347 u16 source_port_or_eth_type,
4349 enum ecore_llh_port_filter_type_t type)
4351 u32 high, low, entry_num;
4352 enum _ecore_status_t rc;
4354 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4361 case ECORE_LLH_FILTER_ETHERTYPE:
4362 high = source_port_or_eth_type;
4364 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4365 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4366 low = source_port_or_eth_type << 16;
4368 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4369 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4372 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4373 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4374 low = (source_port_or_eth_type << 16) | dest_port;
4377 DP_NOTICE(p_hwfn, true,
4378 "Non valid LLH protocol filter type %d\n", type);
4382 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4383 rc = ecore_llh_remove_protocol_filter_bb_ah(p_hwfn, p_ptt, type,
4386 if (rc != ECORE_SUCCESS) {
4387 DP_NOTICE(p_hwfn, false,
4388 "Tried to remove a non-configured filter [type %d, source_port_or_eth_type 0x%x, dest_port 0x%x]\n",
4389 type, source_port_or_eth_type, dest_port);
4393 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4394 "Protocol filter [type %d, source_port_or_eth_type 0x%x, dest_port 0x%x] was removed from %d\n",
4395 type, source_port_or_eth_type, dest_port, entry_num);
4398 static void ecore_llh_clear_all_filters_bb_ah(struct ecore_hwfn *p_hwfn,
4399 struct ecore_ptt *p_ptt)
4403 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4406 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4407 ecore_wr(p_hwfn, p_ptt,
4408 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4409 i * sizeof(u32), 0);
4410 ecore_wr(p_hwfn, p_ptt,
4411 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4412 2 * i * sizeof(u32), 0);
4413 ecore_wr(p_hwfn, p_ptt,
4414 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4415 (2 * i + 1) * sizeof(u32), 0);
4419 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
4420 struct ecore_ptt *p_ptt)
4422 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4425 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4426 ecore_llh_clear_all_filters_bb_ah(p_hwfn, p_ptt);
4429 enum _ecore_status_t
4430 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
4431 struct ecore_ptt *p_ptt)
4433 if (IS_MF_DEFAULT(p_hwfn) && ECORE_IS_BB(p_hwfn->p_dev)) {
4434 ecore_wr(p_hwfn, p_ptt,
4435 NIG_REG_LLH_TAGMAC_DEF_PF_VECTOR,
4436 1 << p_hwfn->abs_pf_id / 2);
4437 ecore_wr(p_hwfn, p_ptt, PRS_REG_MSG_INFO, 0);
4438 return ECORE_SUCCESS;
4441 DP_NOTICE(p_hwfn, false,
4442 "This function can't be set as default\n");
4446 static enum _ecore_status_t ecore_set_coalesce(struct ecore_hwfn *p_hwfn,
4447 struct ecore_ptt *p_ptt,
4448 u32 hw_addr, void *p_eth_qzone,
4449 osal_size_t eth_qzone_size,
4452 struct coalescing_timeset *p_coal_timeset;
4454 if (p_hwfn->p_dev->int_coalescing_mode != ECORE_COAL_MODE_ENABLE) {
4455 DP_NOTICE(p_hwfn, true,
4456 "Coalescing configuration not enabled\n");
4460 p_coal_timeset = p_eth_qzone;
4461 OSAL_MEMSET(p_eth_qzone, 0, eth_qzone_size);
4462 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
4463 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
4464 ecore_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
4466 return ECORE_SUCCESS;
4469 enum _ecore_status_t ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn,
4470 u16 rx_coal, u16 tx_coal,
4473 struct ecore_queue_cid *p_cid = (struct ecore_queue_cid *)p_handle;
4474 enum _ecore_status_t rc = ECORE_SUCCESS;
4475 struct ecore_ptt *p_ptt;
4477 /* TODO - Configuring a single queue's coalescing but
4478 * claiming all queues are abiding same configuration
4479 * for PF and VF both.
4482 if (IS_VF(p_hwfn->p_dev))
4483 return ecore_vf_pf_set_coalesce(p_hwfn, rx_coal,
4486 p_ptt = ecore_ptt_acquire(p_hwfn);
4491 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
4494 p_hwfn->p_dev->rx_coalesce_usecs = rx_coal;
4498 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
4501 p_hwfn->p_dev->tx_coalesce_usecs = tx_coal;
4504 ecore_ptt_release(p_hwfn, p_ptt);
4509 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
4510 struct ecore_ptt *p_ptt,
4512 struct ecore_queue_cid *p_cid)
4514 struct ustorm_eth_queue_zone eth_qzone;
4515 u8 timeset, timer_res;
4517 enum _ecore_status_t rc;
4519 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4520 if (coalesce <= 0x7F) {
4522 } else if (coalesce <= 0xFF) {
4524 } else if (coalesce <= 0x1FF) {
4527 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4530 timeset = (u8)(coalesce >> timer_res);
4532 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
4533 p_cid->abs.sb_idx, false);
4534 if (rc != ECORE_SUCCESS)
4537 address = BAR0_MAP_REG_USDM_RAM +
4538 USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4540 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4541 sizeof(struct ustorm_eth_queue_zone), timeset);
4542 if (rc != ECORE_SUCCESS)
4549 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
4550 struct ecore_ptt *p_ptt,
4552 struct ecore_queue_cid *p_cid)
4554 struct xstorm_eth_queue_zone eth_qzone;
4555 u8 timeset, timer_res;
4557 enum _ecore_status_t rc;
4559 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4560 if (coalesce <= 0x7F) {
4562 } else if (coalesce <= 0xFF) {
4564 } else if (coalesce <= 0x1FF) {
4567 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4571 timeset = (u8)(coalesce >> timer_res);
4573 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
4574 p_cid->abs.sb_idx, true);
4575 if (rc != ECORE_SUCCESS)
4578 address = BAR0_MAP_REG_XSDM_RAM +
4579 XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4581 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4582 sizeof(struct xstorm_eth_queue_zone), timeset);
4587 /* Calculate final WFQ values for all vports and configure it.
4588 * After this configuration each vport must have
4589 * approx min rate = vport_wfq * min_pf_rate / ECORE_WFQ_UNIT
4591 static void ecore_configure_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4592 struct ecore_ptt *p_ptt,
4595 struct init_qm_vport_params *vport_params;
4598 vport_params = p_hwfn->qm_info.qm_vport_params;
4600 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4601 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4603 vport_params[i].vport_wfq = (wfq_speed * ECORE_WFQ_UNIT) /
4605 ecore_init_vport_wfq(p_hwfn, p_ptt,
4606 vport_params[i].first_tx_pq_id,
4607 vport_params[i].vport_wfq);
4612 ecore_init_wfq_default_param(struct ecore_hwfn *p_hwfn, u32 min_pf_rate)
4616 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
4617 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
4620 static void ecore_disable_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4621 struct ecore_ptt *p_ptt,
4624 struct init_qm_vport_params *vport_params;
4627 vport_params = p_hwfn->qm_info.qm_vport_params;
4629 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4630 ecore_init_wfq_default_param(p_hwfn, min_pf_rate);
4631 ecore_init_vport_wfq(p_hwfn, p_ptt,
4632 vport_params[i].first_tx_pq_id,
4633 vport_params[i].vport_wfq);
4637 /* This function performs several validations for WFQ
4638 * configuration and required min rate for a given vport
4639 * 1. req_rate must be greater than one percent of min_pf_rate.
4640 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
4641 * rates to get less than one percent of min_pf_rate.
4642 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
4644 static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
4645 u16 vport_id, u32 req_rate,
4648 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
4649 int non_requested_count = 0, req_count = 0, i, num_vports;
4651 num_vports = p_hwfn->qm_info.num_vports;
4653 /* Accounting for the vports which are configured for WFQ explicitly */
4655 for (i = 0; i < num_vports; i++) {
4658 if ((i != vport_id) && p_hwfn->qm_info.wfq_data[i].configured) {
4660 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4661 total_req_min_rate += tmp_speed;
4665 /* Include current vport data as well */
4667 total_req_min_rate += req_rate;
4668 non_requested_count = num_vports - req_count;
4670 /* validate possible error cases */
4671 if (req_rate > min_pf_rate) {
4672 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4673 "Vport [%d] - Requested rate[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4674 vport_id, req_rate, min_pf_rate);
4678 if (req_rate < min_pf_rate / ECORE_WFQ_UNIT) {
4679 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4680 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4681 vport_id, req_rate, min_pf_rate);
4685 /* TBD - for number of vports greater than 100 */
4686 if (num_vports > ECORE_WFQ_UNIT) {
4687 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4688 "Number of vports is greater than %d\n",
4693 if (total_req_min_rate > min_pf_rate) {
4694 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4695 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4696 total_req_min_rate, min_pf_rate);
4700 /* Data left for non requested vports */
4701 total_left_rate = min_pf_rate - total_req_min_rate;
4702 left_rate_per_vp = total_left_rate / non_requested_count;
4704 /* validate if non requested get < 1% of min bw */
4705 if (left_rate_per_vp < min_pf_rate / ECORE_WFQ_UNIT) {
4706 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4707 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4708 left_rate_per_vp, min_pf_rate);
4712 /* now req_rate for given vport passes all scenarios.
4713 * assign final wfq rates to all vports.
4715 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
4716 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
4718 for (i = 0; i < num_vports; i++) {
4719 if (p_hwfn->qm_info.wfq_data[i].configured)
4722 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
4725 return ECORE_SUCCESS;
4728 static int __ecore_configure_vport_wfq(struct ecore_hwfn *p_hwfn,
4729 struct ecore_ptt *p_ptt,
4730 u16 vp_id, u32 rate)
4732 struct ecore_mcp_link_state *p_link;
4733 int rc = ECORE_SUCCESS;
4735 p_link = &p_hwfn->p_dev->hwfns[0].mcp_info->link_output;
4737 if (!p_link->min_pf_rate) {
4738 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
4739 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
4743 rc = ecore_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
4745 if (rc == ECORE_SUCCESS)
4746 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt,
4747 p_link->min_pf_rate);
4749 DP_NOTICE(p_hwfn, false,
4750 "Validation failed while configuring min rate\n");
4755 static int __ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn *p_hwfn,
4756 struct ecore_ptt *p_ptt,
4759 bool use_wfq = false;
4760 int rc = ECORE_SUCCESS;
4763 /* Validate all pre configured vports for wfq */
4764 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4767 if (!p_hwfn->qm_info.wfq_data[i].configured)
4770 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
4773 rc = ecore_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
4774 if (rc != ECORE_SUCCESS) {
4775 DP_NOTICE(p_hwfn, false,
4776 "WFQ validation failed while configuring min rate\n");
4781 if (rc == ECORE_SUCCESS && use_wfq)
4782 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4784 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4789 /* Main API for ecore clients to configure vport min rate.
4790 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
4791 * rate - Speed in Mbps needs to be assigned to a given vport.
4793 int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate)
4795 int i, rc = ECORE_INVAL;
4797 /* TBD - for multiple hardware functions - that is 100 gig */
4798 if (p_dev->num_hwfns > 1) {
4799 DP_NOTICE(p_dev, false,
4800 "WFQ configuration is not supported for this device\n");
4804 for_each_hwfn(p_dev, i) {
4805 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4806 struct ecore_ptt *p_ptt;
4808 p_ptt = ecore_ptt_acquire(p_hwfn);
4810 return ECORE_TIMEOUT;
4812 rc = __ecore_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
4814 if (rc != ECORE_SUCCESS) {
4815 ecore_ptt_release(p_hwfn, p_ptt);
4819 ecore_ptt_release(p_hwfn, p_ptt);
4825 /* API to configure WFQ from mcp link change */
4826 void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
4831 /* TBD - for multiple hardware functions - that is 100 gig */
4832 if (p_dev->num_hwfns > 1) {
4833 DP_VERBOSE(p_dev, ECORE_MSG_LINK,
4834 "WFQ configuration is not supported for this device\n");
4838 for_each_hwfn(p_dev, i) {
4839 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4841 __ecore_configure_vp_wfq_on_link_change(p_hwfn,
4847 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
4848 struct ecore_ptt *p_ptt,
4849 struct ecore_mcp_link_state *p_link,
4852 int rc = ECORE_SUCCESS;
4854 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
4856 if (!p_link->line_speed && (max_bw != 100))
4859 p_link->speed = (p_link->line_speed * max_bw) / 100;
4860 p_hwfn->qm_info.pf_rl = p_link->speed;
4862 /* Since the limiter also affects Tx-switched traffic, we don't want it
4863 * to limit such traffic in case there's no actual limit.
4864 * In that case, set limit to imaginary high boundary.
4867 p_hwfn->qm_info.pf_rl = 100000;
4869 rc = ecore_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
4870 p_hwfn->qm_info.pf_rl);
4872 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4873 "Configured MAX bandwidth to be %08x Mb/sec\n",
4879 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
4880 int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw)
4882 int i, rc = ECORE_INVAL;
4884 if (max_bw < 1 || max_bw > 100) {
4885 DP_NOTICE(p_dev, false, "PF max bw valid range is [1-100]\n");
4889 for_each_hwfn(p_dev, i) {
4890 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4891 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
4892 struct ecore_mcp_link_state *p_link;
4893 struct ecore_ptt *p_ptt;
4895 p_link = &p_lead->mcp_info->link_output;
4897 p_ptt = ecore_ptt_acquire(p_hwfn);
4899 return ECORE_TIMEOUT;
4901 rc = __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
4904 ecore_ptt_release(p_hwfn, p_ptt);
4906 if (rc != ECORE_SUCCESS)
4913 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
4914 struct ecore_ptt *p_ptt,
4915 struct ecore_mcp_link_state *p_link,
4918 int rc = ECORE_SUCCESS;
4920 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
4921 p_hwfn->qm_info.pf_wfq = min_bw;
4923 if (!p_link->line_speed)
4926 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
4928 rc = ecore_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
4930 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4931 "Configured MIN bandwidth to be %d Mb/sec\n",
4932 p_link->min_pf_rate);
4937 /* Main API to configure PF min bandwidth where bw range is [1-100] */
4938 int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw)
4940 int i, rc = ECORE_INVAL;
4942 if (min_bw < 1 || min_bw > 100) {
4943 DP_NOTICE(p_dev, false, "PF min bw valid range is [1-100]\n");
4947 for_each_hwfn(p_dev, i) {
4948 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4949 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
4950 struct ecore_mcp_link_state *p_link;
4951 struct ecore_ptt *p_ptt;
4953 p_link = &p_lead->mcp_info->link_output;
4955 p_ptt = ecore_ptt_acquire(p_hwfn);
4957 return ECORE_TIMEOUT;
4959 rc = __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
4961 if (rc != ECORE_SUCCESS) {
4962 ecore_ptt_release(p_hwfn, p_ptt);
4966 if (p_link->min_pf_rate) {
4967 u32 min_rate = p_link->min_pf_rate;
4969 rc = __ecore_configure_vp_wfq_on_link_change(p_hwfn,
4974 ecore_ptt_release(p_hwfn, p_ptt);
4980 void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
4982 struct ecore_mcp_link_state *p_link;
4984 p_link = &p_hwfn->mcp_info->link_output;
4986 if (p_link->min_pf_rate)
4987 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt,
4988 p_link->min_pf_rate);
4990 OSAL_MEMSET(p_hwfn->qm_info.wfq_data, 0,
4991 sizeof(*p_hwfn->qm_info.wfq_data) *
4992 p_hwfn->qm_info.num_vports);
4995 int ecore_device_num_engines(struct ecore_dev *p_dev)
4997 return ECORE_IS_BB(p_dev) ? 2 : 1;
5000 int ecore_device_num_ports(struct ecore_dev *p_dev)
5002 /* in CMT always only one port */
5003 if (p_dev->num_hwfns > 1)
5006 return p_dev->num_ports_in_engines * ecore_device_num_engines(p_dev);
5009 void ecore_set_fw_mac_addr(__le16 *fw_msb,
5014 ((u8 *)fw_msb)[0] = mac[1];
5015 ((u8 *)fw_msb)[1] = mac[0];
5016 ((u8 *)fw_mid)[0] = mac[3];
5017 ((u8 *)fw_mid)[1] = mac[2];
5018 ((u8 *)fw_lsb)[0] = mac[5];
5019 ((u8 *)fw_lsb)[1] = mac[4];