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,
60 struct ecore_ptt *p_ptt,
63 u32 bar_reg = (bar_id == BAR_ID_0 ?
64 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
67 if (IS_VF(p_hwfn->p_dev)) {
68 /* TODO - assume each VF hwfn has 64Kb for Bar0; Bar1 can be
69 * read from actual register, but we're currently not using
70 * it for actual doorbelling.
75 val = ecore_rd(p_hwfn, p_ptt, bar_reg);
77 return 1 << (val + 15);
79 /* The above registers were updated in the past only in CMT mode. Since
80 * they were found to be useful MFW started updating them from 8.7.7.0.
81 * In older MFW versions they are set to 0 which means disabled.
83 if (p_hwfn->p_dev->num_hwfns > 1) {
85 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
86 val = BAR_ID_0 ? 256 * 1024 : 512 * 1024;
89 "BAR size not configured. Assuming BAR size of 512kB 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 #ifdef CONFIG_ECORE_LOCK_ALLOC
125 OSAL_MUTEX_ALLOC(p_hwfn, &p_hwfn->dmae_info.mutex);
127 OSAL_MUTEX_INIT(&p_hwfn->dmae_info.mutex);
130 /* hwfn 0 is always active */
131 p_dev->hwfns[0].b_active = true;
133 /* set the default cache alignment to 128 (may be overridden later) */
134 p_dev->cache_shift = 7;
137 static void ecore_qm_info_free(struct ecore_hwfn *p_hwfn)
139 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
141 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_pq_params);
142 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_vport_params);
143 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_port_params);
144 OSAL_FREE(p_hwfn->p_dev, qm_info->wfq_data);
147 void ecore_resc_free(struct ecore_dev *p_dev)
152 for_each_hwfn(p_dev, i)
153 ecore_l2_free(&p_dev->hwfns[i]);
157 OSAL_FREE(p_dev, p_dev->fw_data);
159 OSAL_FREE(p_dev, p_dev->reset_stats);
161 for_each_hwfn(p_dev, i) {
162 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
164 ecore_cxt_mngr_free(p_hwfn);
165 ecore_qm_info_free(p_hwfn);
166 ecore_spq_free(p_hwfn);
167 ecore_eq_free(p_hwfn);
168 ecore_consq_free(p_hwfn);
169 ecore_int_free(p_hwfn);
170 ecore_iov_free(p_hwfn);
171 ecore_l2_free(p_hwfn);
172 ecore_dmae_info_free(p_hwfn);
173 ecore_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
174 /* @@@TBD Flush work-queue ? */
178 /******************** QM initialization *******************/
180 /* bitmaps for indicating active traffic classes.
181 * Special case for Arrowhead 4 port
183 /* 0..3 actualy used, 4 serves OOO, 7 serves high priority stuff (e.g. DCQCN) */
184 #define ACTIVE_TCS_BMAP 0x9f
185 /* 0..3 actually used, OOO and high priority stuff all use 3 */
186 #define ACTIVE_TCS_BMAP_4PORT_K2 0xf
188 /* determines the physical queue flags for a given PF. */
189 static u32 ecore_get_pq_flags(struct ecore_hwfn *p_hwfn)
197 if (IS_ECORE_SRIOV(p_hwfn->p_dev))
198 flags |= PQ_FLAGS_VFS;
201 switch (p_hwfn->hw_info.personality) {
203 flags |= PQ_FLAGS_MCOS;
206 flags |= PQ_FLAGS_OFLD;
208 case ECORE_PCI_ISCSI:
209 flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
211 case ECORE_PCI_ETH_ROCE:
212 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD;
214 case ECORE_PCI_ETH_IWARP:
215 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_ACK | PQ_FLAGS_OOO |
219 DP_ERR(p_hwfn, "unknown personality %d\n",
220 p_hwfn->hw_info.personality);
226 /* Getters for resource amounts necessary for qm initialization */
227 u8 ecore_init_qm_get_num_tcs(struct ecore_hwfn *p_hwfn)
229 return p_hwfn->hw_info.num_hw_tc;
232 u16 ecore_init_qm_get_num_vfs(struct ecore_hwfn *p_hwfn)
234 return IS_ECORE_SRIOV(p_hwfn->p_dev) ?
235 p_hwfn->p_dev->p_iov_info->total_vfs : 0;
238 #define NUM_DEFAULT_RLS 1
240 u16 ecore_init_qm_get_num_pf_rls(struct ecore_hwfn *p_hwfn)
242 u16 num_pf_rls, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
245 /* num RLs can't exceed resource amount of rls or vports or the
248 num_pf_rls = (u16)OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_RL),
249 (u16)RESC_NUM(p_hwfn, ECORE_VPORT));
251 /* make sure after we reserve the default and VF rls we'll have
254 if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS) {
255 DP_NOTICE(p_hwfn, false,
256 "no rate limiters left for PF rate limiting"
257 " [num_pf_rls %d num_vfs %d]\n", num_pf_rls, num_vfs);
261 /* subtract rls necessary for VFs and one default one for the PF */
262 num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
267 u16 ecore_init_qm_get_num_vports(struct ecore_hwfn *p_hwfn)
269 u32 pq_flags = ecore_get_pq_flags(p_hwfn);
271 /* all pqs share the same vport (hence the 1 below), except for vfs
274 return (!!(PQ_FLAGS_RLS & pq_flags)) *
275 ecore_init_qm_get_num_pf_rls(p_hwfn) +
276 (!!(PQ_FLAGS_VFS & pq_flags)) *
277 ecore_init_qm_get_num_vfs(p_hwfn) + 1;
280 /* calc amount of PQs according to the requested flags */
281 u16 ecore_init_qm_get_num_pqs(struct ecore_hwfn *p_hwfn)
283 u32 pq_flags = ecore_get_pq_flags(p_hwfn);
285 return (!!(PQ_FLAGS_RLS & pq_flags)) *
286 ecore_init_qm_get_num_pf_rls(p_hwfn) +
287 (!!(PQ_FLAGS_MCOS & pq_flags)) *
288 ecore_init_qm_get_num_tcs(p_hwfn) +
289 (!!(PQ_FLAGS_LB & pq_flags)) +
290 (!!(PQ_FLAGS_OOO & pq_flags)) +
291 (!!(PQ_FLAGS_ACK & pq_flags)) +
292 (!!(PQ_FLAGS_OFLD & pq_flags)) +
293 (!!(PQ_FLAGS_VFS & pq_flags)) *
294 ecore_init_qm_get_num_vfs(p_hwfn);
297 /* initialize the top level QM params */
298 static void ecore_init_qm_params(struct ecore_hwfn *p_hwfn)
300 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
303 /* pq and vport bases for this PF */
304 qm_info->start_pq = (u16)RESC_START(p_hwfn, ECORE_PQ);
305 qm_info->start_vport = (u8)RESC_START(p_hwfn, ECORE_VPORT);
307 /* rate limiting and weighted fair queueing are always enabled */
308 qm_info->vport_rl_en = 1;
309 qm_info->vport_wfq_en = 1;
311 /* TC config is different for AH 4 port */
312 four_port = p_hwfn->p_dev->num_ports_in_engines == MAX_NUM_PORTS_K2;
314 /* in AH 4 port we have fewer TCs per port */
315 qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 :
318 /* unless MFW indicated otherwise, ooo_tc should be 3 for AH 4 port and
321 if (!qm_info->ooo_tc)
322 qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC :
326 /* initialize qm vport params */
327 static void ecore_init_qm_vport_params(struct ecore_hwfn *p_hwfn)
329 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
332 /* all vports participate in weighted fair queueing */
333 for (i = 0; i < ecore_init_qm_get_num_vports(p_hwfn); i++)
334 qm_info->qm_vport_params[i].vport_wfq = 1;
337 /* initialize qm port params */
338 static void ecore_init_qm_port_params(struct ecore_hwfn *p_hwfn)
340 /* Initialize qm port parameters */
341 u8 i, active_phys_tcs, num_ports = p_hwfn->p_dev->num_ports_in_engines;
343 /* indicate how ooo and high pri traffic is dealt with */
344 active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
345 ACTIVE_TCS_BMAP_4PORT_K2 : ACTIVE_TCS_BMAP;
347 for (i = 0; i < num_ports; i++) {
348 struct init_qm_port_params *p_qm_port =
349 &p_hwfn->qm_info.qm_port_params[i];
351 p_qm_port->active = 1;
352 p_qm_port->active_phys_tcs = active_phys_tcs;
353 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
354 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
358 /* Reset the params which must be reset for qm init. QM init may be called as
359 * a result of flows other than driver load (e.g. dcbx renegotiation). Other
360 * params may be affected by the init but would simply recalculate to the same
361 * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
362 * affected as these amounts stay the same.
364 static void ecore_init_qm_reset_params(struct ecore_hwfn *p_hwfn)
366 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
368 qm_info->num_pqs = 0;
369 qm_info->num_vports = 0;
370 qm_info->num_pf_rls = 0;
371 qm_info->num_vf_pqs = 0;
372 qm_info->first_vf_pq = 0;
373 qm_info->first_mcos_pq = 0;
374 qm_info->first_rl_pq = 0;
377 static void ecore_init_qm_advance_vport(struct ecore_hwfn *p_hwfn)
379 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
381 qm_info->num_vports++;
383 if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
385 "vport overflow! qm_info->num_vports %d,"
386 " qm_init_get_num_vports() %d\n",
388 ecore_init_qm_get_num_vports(p_hwfn));
391 /* initialize a single pq and manage qm_info resources accounting.
392 * The pq_init_flags param determines whether the PQ is rate limited
394 * and whether a new vport is allocated to the pq or not (i.e. vport will be
398 /* flags for pq init */
399 #define PQ_INIT_SHARE_VPORT (1 << 0)
400 #define PQ_INIT_PF_RL (1 << 1)
401 #define PQ_INIT_VF_RL (1 << 2)
403 /* defines for pq init */
404 #define PQ_INIT_DEFAULT_WRR_GROUP 1
405 #define PQ_INIT_DEFAULT_TC 0
406 #define PQ_INIT_OFLD_TC (p_hwfn->hw_info.offload_tc)
408 static void ecore_init_qm_pq(struct ecore_hwfn *p_hwfn,
409 struct ecore_qm_info *qm_info,
410 u8 tc, u32 pq_init_flags)
412 u16 pq_idx = qm_info->num_pqs, max_pq =
413 ecore_init_qm_get_num_pqs(p_hwfn);
417 "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
420 qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
422 qm_info->qm_pq_params[pq_idx].tc_id = tc;
423 qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
424 qm_info->qm_pq_params[pq_idx].rl_valid =
425 (pq_init_flags & PQ_INIT_PF_RL ||
426 pq_init_flags & PQ_INIT_VF_RL);
428 /* qm params accounting */
430 if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
431 qm_info->num_vports++;
433 if (pq_init_flags & PQ_INIT_PF_RL)
434 qm_info->num_pf_rls++;
436 if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
438 "vport overflow! qm_info->num_vports %d,"
439 " qm_init_get_num_vports() %d\n",
441 ecore_init_qm_get_num_vports(p_hwfn));
443 if (qm_info->num_pf_rls > ecore_init_qm_get_num_pf_rls(p_hwfn))
444 DP_ERR(p_hwfn, "rl overflow! qm_info->num_pf_rls %d,"
445 " qm_init_get_num_pf_rls() %d\n",
447 ecore_init_qm_get_num_pf_rls(p_hwfn));
450 /* get pq index according to PQ_FLAGS */
451 static u16 *ecore_init_qm_get_idx_from_flags(struct ecore_hwfn *p_hwfn,
454 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
456 /* Can't have multiple flags set here */
457 if (OSAL_BITMAP_WEIGHT((unsigned long *)&pq_flags,
458 sizeof(pq_flags)) > 1)
463 return &qm_info->first_rl_pq;
465 return &qm_info->first_mcos_pq;
467 return &qm_info->pure_lb_pq;
469 return &qm_info->ooo_pq;
471 return &qm_info->pure_ack_pq;
473 return &qm_info->offload_pq;
475 return &qm_info->first_vf_pq;
481 DP_ERR(p_hwfn, "BAD pq flags %d\n", pq_flags);
485 /* save pq index in qm info */
486 static void ecore_init_qm_set_idx(struct ecore_hwfn *p_hwfn,
487 u32 pq_flags, u16 pq_val)
489 u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
491 *base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
494 /* get tx pq index, with the PQ TX base already set (ready for context init) */
495 u16 ecore_get_cm_pq_idx(struct ecore_hwfn *p_hwfn, u32 pq_flags)
497 u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
499 return *base_pq_idx + CM_TX_PQ_BASE;
502 u16 ecore_get_cm_pq_idx_mcos(struct ecore_hwfn *p_hwfn, u8 tc)
504 u8 max_tc = ecore_init_qm_get_num_tcs(p_hwfn);
507 DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
509 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
512 u16 ecore_get_cm_pq_idx_vf(struct ecore_hwfn *p_hwfn, u16 vf)
514 u16 max_vf = ecore_init_qm_get_num_vfs(p_hwfn);
517 DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
519 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
522 u16 ecore_get_cm_pq_idx_rl(struct ecore_hwfn *p_hwfn, u8 rl)
524 u16 max_rl = ecore_init_qm_get_num_pf_rls(p_hwfn);
527 DP_ERR(p_hwfn, "rl %d must be smaller than %d\n", rl, max_rl);
529 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
532 /* Functions for creating specific types of pqs */
533 static void ecore_init_qm_lb_pq(struct ecore_hwfn *p_hwfn)
535 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
537 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
540 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
541 ecore_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
544 static void ecore_init_qm_ooo_pq(struct ecore_hwfn *p_hwfn)
546 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
548 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
551 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
552 ecore_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
555 static void ecore_init_qm_pure_ack_pq(struct ecore_hwfn *p_hwfn)
557 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
559 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
562 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
563 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
566 static void ecore_init_qm_offload_pq(struct ecore_hwfn *p_hwfn)
568 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
570 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
573 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
574 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
577 static void ecore_init_qm_mcos_pqs(struct ecore_hwfn *p_hwfn)
579 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
582 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
585 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
586 for (tc_idx = 0; tc_idx < ecore_init_qm_get_num_tcs(p_hwfn); tc_idx++)
587 ecore_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
590 static void ecore_init_qm_vf_pqs(struct ecore_hwfn *p_hwfn)
592 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
593 u16 vf_idx, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
595 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
598 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
600 qm_info->num_vf_pqs = num_vfs;
601 for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
602 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_DEFAULT_TC,
606 static void ecore_init_qm_rl_pqs(struct ecore_hwfn *p_hwfn)
608 u16 pf_rls_idx, num_pf_rls = ecore_init_qm_get_num_pf_rls(p_hwfn);
609 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
611 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
614 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
615 for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
616 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC,
620 static void ecore_init_qm_pq_params(struct ecore_hwfn *p_hwfn)
622 /* rate limited pqs, must come first (FW assumption) */
623 ecore_init_qm_rl_pqs(p_hwfn);
625 /* pqs for multi cos */
626 ecore_init_qm_mcos_pqs(p_hwfn);
628 /* pure loopback pq */
629 ecore_init_qm_lb_pq(p_hwfn);
631 /* out of order pq */
632 ecore_init_qm_ooo_pq(p_hwfn);
635 ecore_init_qm_pure_ack_pq(p_hwfn);
637 /* pq for offloaded protocol */
638 ecore_init_qm_offload_pq(p_hwfn);
640 /* done sharing vports */
641 ecore_init_qm_advance_vport(p_hwfn);
644 ecore_init_qm_vf_pqs(p_hwfn);
647 /* compare values of getters against resources amounts */
648 static enum _ecore_status_t ecore_init_qm_sanity(struct ecore_hwfn *p_hwfn)
650 if (ecore_init_qm_get_num_vports(p_hwfn) >
651 RESC_NUM(p_hwfn, ECORE_VPORT)) {
652 DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
656 if (ecore_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, ECORE_PQ)) {
657 DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
661 return ECORE_SUCCESS;
665 * Function for verbose printing of the qm initialization results
667 static void ecore_dp_init_qm_params(struct ecore_hwfn *p_hwfn)
669 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
670 struct init_qm_vport_params *vport;
671 struct init_qm_port_params *port;
672 struct init_qm_pq_params *pq;
675 /* top level params */
676 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
677 "qm init top level params: start_pq %d, start_vport %d,"
678 " pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
679 qm_info->start_pq, qm_info->start_vport, qm_info->pure_lb_pq,
680 qm_info->offload_pq, qm_info->pure_ack_pq);
681 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
682 "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d,"
683 " num_vports %d, max_phys_tcs_per_port %d\n",
684 qm_info->ooo_pq, qm_info->first_vf_pq, qm_info->num_pqs,
685 qm_info->num_vf_pqs, qm_info->num_vports,
686 qm_info->max_phys_tcs_per_port);
687 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
688 "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d,"
689 " pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
690 qm_info->pf_rl_en, qm_info->pf_wfq_en, qm_info->vport_rl_en,
691 qm_info->vport_wfq_en, qm_info->pf_wfq, qm_info->pf_rl,
692 qm_info->num_pf_rls, ecore_get_pq_flags(p_hwfn));
695 for (i = 0; i < p_hwfn->p_dev->num_ports_in_engines; i++) {
696 port = &qm_info->qm_port_params[i];
697 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
698 "port idx %d, active %d, active_phys_tcs %d,"
699 " num_pbf_cmd_lines %d, num_btb_blocks %d,"
701 i, port->active, port->active_phys_tcs,
702 port->num_pbf_cmd_lines, port->num_btb_blocks,
707 for (i = 0; i < qm_info->num_vports; i++) {
708 vport = &qm_info->qm_vport_params[i];
709 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
710 "vport idx %d, vport_rl %d, wfq %d,"
711 " first_tx_pq_id [ ",
712 qm_info->start_vport + i, vport->vport_rl,
714 for (tc = 0; tc < NUM_OF_TCS; tc++)
715 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "%d ",
716 vport->first_tx_pq_id[tc]);
717 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "]\n");
721 for (i = 0; i < qm_info->num_pqs; i++) {
722 pq = &qm_info->qm_pq_params[i];
723 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
724 "pq idx %d, vport_id %d, tc %d, wrr_grp %d,"
726 qm_info->start_pq + i, pq->vport_id, pq->tc_id,
727 pq->wrr_group, pq->rl_valid);
731 static void ecore_init_qm_info(struct ecore_hwfn *p_hwfn)
733 /* reset params required for init run */
734 ecore_init_qm_reset_params(p_hwfn);
736 /* init QM top level params */
737 ecore_init_qm_params(p_hwfn);
739 /* init QM port params */
740 ecore_init_qm_port_params(p_hwfn);
742 /* init QM vport params */
743 ecore_init_qm_vport_params(p_hwfn);
745 /* init QM physical queue params */
746 ecore_init_qm_pq_params(p_hwfn);
748 /* display all that init */
749 ecore_dp_init_qm_params(p_hwfn);
752 /* This function reconfigures the QM pf on the fly.
753 * For this purpose we:
754 * 1. reconfigure the QM database
755 * 2. set new values to runtime array
756 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
757 * 4. activate init tool in QM_PF stage
758 * 5. send an sdm_qm_cmd through rbc interface to release the QM
760 enum _ecore_status_t ecore_qm_reconf(struct ecore_hwfn *p_hwfn,
761 struct ecore_ptt *p_ptt)
763 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
765 enum _ecore_status_t rc;
767 /* initialize ecore's qm data structure */
768 ecore_init_qm_info(p_hwfn);
770 /* stop PF's qm queues */
771 OSAL_SPIN_LOCK(&qm_lock);
772 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
773 qm_info->start_pq, qm_info->num_pqs);
774 OSAL_SPIN_UNLOCK(&qm_lock);
778 /* clear the QM_PF runtime phase leftovers from previous init */
779 ecore_init_clear_rt_data(p_hwfn);
781 /* prepare QM portion of runtime array */
782 ecore_qm_init_pf(p_hwfn, p_ptt);
784 /* activate init tool on runtime array */
785 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
786 p_hwfn->hw_info.hw_mode);
787 if (rc != ECORE_SUCCESS)
790 /* start PF's qm queues */
791 OSAL_SPIN_LOCK(&qm_lock);
792 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
793 qm_info->start_pq, qm_info->num_pqs);
794 OSAL_SPIN_UNLOCK(&qm_lock);
798 return ECORE_SUCCESS;
801 static enum _ecore_status_t ecore_alloc_qm_data(struct ecore_hwfn *p_hwfn)
803 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
804 enum _ecore_status_t rc;
806 rc = ecore_init_qm_sanity(p_hwfn);
807 if (rc != ECORE_SUCCESS)
810 qm_info->qm_pq_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
811 sizeof(struct init_qm_pq_params) *
812 ecore_init_qm_get_num_pqs(p_hwfn));
813 if (!qm_info->qm_pq_params)
816 qm_info->qm_vport_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
817 sizeof(struct init_qm_vport_params) *
818 ecore_init_qm_get_num_vports(p_hwfn));
819 if (!qm_info->qm_vport_params)
822 qm_info->qm_port_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
823 sizeof(struct init_qm_port_params) *
824 p_hwfn->p_dev->num_ports_in_engines);
825 if (!qm_info->qm_port_params)
828 qm_info->wfq_data = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
829 sizeof(struct ecore_wfq_data) *
830 ecore_init_qm_get_num_vports(p_hwfn));
831 if (!qm_info->wfq_data)
834 return ECORE_SUCCESS;
837 DP_NOTICE(p_hwfn, false, "Failed to allocate memory for QM params\n");
838 ecore_qm_info_free(p_hwfn);
841 /******************** End QM initialization ***************/
843 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev)
845 enum _ecore_status_t rc = ECORE_SUCCESS;
849 for_each_hwfn(p_dev, i) {
850 rc = ecore_l2_alloc(&p_dev->hwfns[i]);
851 if (rc != ECORE_SUCCESS)
857 p_dev->fw_data = OSAL_ZALLOC(p_dev, GFP_KERNEL,
858 sizeof(*p_dev->fw_data));
862 for_each_hwfn(p_dev, i) {
863 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
864 u32 n_eqes, num_cons;
866 /* First allocate the context manager structure */
867 rc = ecore_cxt_mngr_alloc(p_hwfn);
871 /* Set the HW cid/tid numbers (in the contest manager)
872 * Must be done prior to any further computations.
874 rc = ecore_cxt_set_pf_params(p_hwfn);
878 rc = ecore_alloc_qm_data(p_hwfn);
883 ecore_init_qm_info(p_hwfn);
885 /* Compute the ILT client partition */
886 rc = ecore_cxt_cfg_ilt_compute(p_hwfn);
890 /* CID map / ILT shadow table / T2
891 * The talbes sizes are determined by the computations above
893 rc = ecore_cxt_tables_alloc(p_hwfn);
897 /* SPQ, must follow ILT because initializes SPQ context */
898 rc = ecore_spq_alloc(p_hwfn);
902 /* SP status block allocation */
903 p_hwfn->p_dpc_ptt = ecore_get_reserved_ptt(p_hwfn,
906 rc = ecore_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
910 rc = ecore_iov_alloc(p_hwfn);
915 n_eqes = ecore_chain_get_capacity(&p_hwfn->p_spq->chain);
916 if (ECORE_IS_RDMA_PERSONALITY(p_hwfn)) {
917 /* Calculate the EQ size
918 * ---------------------
919 * Each ICID may generate up to one event at a time i.e.
920 * the event must be handled/cleared before a new one
921 * can be generated. We calculate the sum of events per
922 * protocol and create an EQ deep enough to handle the
924 * - Core - according to SPQ.
925 * - RoCE - per QP there are a couple of ICIDs, one
926 * responder and one requester, each can
927 * generate an EQE => n_eqes_qp = 2 * n_qp.
928 * Each CQ can generate an EQE. There are 2 CQs
929 * per QP => n_eqes_cq = 2 * n_qp.
930 * Hence the RoCE total is 4 * n_qp or
932 * - ENet - There can be up to two events per VF. One
933 * for VF-PF channel and another for VF FLR
934 * initial cleanup. The number of VFs is
935 * bounded by MAX_NUM_VFS_BB, and is much
936 * smaller than RoCE's so we avoid exact
939 if (ECORE_IS_ROCE_PERSONALITY(p_hwfn)) {
941 ecore_cxt_get_proto_cid_count(
947 num_cons = ecore_cxt_get_proto_cid_count(
952 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
953 } else if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
955 ecore_cxt_get_proto_cid_count(p_hwfn,
958 n_eqes += 2 * num_cons;
961 if (n_eqes > 0xFFFF) {
962 DP_ERR(p_hwfn, "Cannot allocate 0x%x EQ elements."
963 "The maximum of a u16 chain is 0x%x\n",
968 rc = ecore_eq_alloc(p_hwfn, (u16)n_eqes);
972 rc = ecore_consq_alloc(p_hwfn);
976 rc = ecore_l2_alloc(p_hwfn);
977 if (rc != ECORE_SUCCESS)
980 /* DMA info initialization */
981 rc = ecore_dmae_info_alloc(p_hwfn);
983 DP_NOTICE(p_hwfn, true,
984 "Failed to allocate memory for dmae_info"
989 /* DCBX initialization */
990 rc = ecore_dcbx_info_alloc(p_hwfn);
992 DP_NOTICE(p_hwfn, true,
993 "Failed to allocate memory for dcbx structure\n");
998 p_dev->reset_stats = OSAL_ZALLOC(p_dev, GFP_KERNEL,
999 sizeof(*p_dev->reset_stats));
1000 if (!p_dev->reset_stats) {
1001 DP_NOTICE(p_dev, true, "Failed to allocate reset statistics\n");
1005 return ECORE_SUCCESS;
1010 ecore_resc_free(p_dev);
1014 void ecore_resc_setup(struct ecore_dev *p_dev)
1019 for_each_hwfn(p_dev, i)
1020 ecore_l2_setup(&p_dev->hwfns[i]);
1024 for_each_hwfn(p_dev, i) {
1025 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1027 ecore_cxt_mngr_setup(p_hwfn);
1028 ecore_spq_setup(p_hwfn);
1029 ecore_eq_setup(p_hwfn);
1030 ecore_consq_setup(p_hwfn);
1032 /* Read shadow of current MFW mailbox */
1033 ecore_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
1034 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1035 p_hwfn->mcp_info->mfw_mb_cur,
1036 p_hwfn->mcp_info->mfw_mb_length);
1038 ecore_int_setup(p_hwfn, p_hwfn->p_main_ptt);
1040 ecore_l2_setup(p_hwfn);
1041 ecore_iov_setup(p_hwfn);
1045 #define FINAL_CLEANUP_POLL_CNT (100)
1046 #define FINAL_CLEANUP_POLL_TIME (10)
1047 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
1048 struct ecore_ptt *p_ptt,
1051 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
1052 enum _ecore_status_t rc = ECORE_TIMEOUT;
1055 if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev) ||
1056 CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1057 DP_INFO(p_hwfn, "Skipping final cleanup for non-ASIC\n");
1058 return ECORE_SUCCESS;
1062 addr = GTT_BAR0_MAP_REG_USDM_RAM +
1063 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
1068 command |= X_FINAL_CLEANUP_AGG_INT <<
1069 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
1070 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
1071 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
1072 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
1074 /* Make sure notification is not set before initiating final cleanup */
1076 if (REG_RD(p_hwfn, addr)) {
1077 DP_NOTICE(p_hwfn, false,
1078 "Unexpected; Found final cleanup notification");
1079 DP_NOTICE(p_hwfn, false,
1080 " before initiating final cleanup\n");
1081 REG_WR(p_hwfn, addr, 0);
1084 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1085 "Sending final cleanup for PFVF[%d] [Command %08x]\n",
1088 ecore_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
1090 /* Poll until completion */
1091 while (!REG_RD(p_hwfn, addr) && count--)
1092 OSAL_MSLEEP(FINAL_CLEANUP_POLL_TIME);
1094 if (REG_RD(p_hwfn, addr))
1097 DP_NOTICE(p_hwfn, true,
1098 "Failed to receive FW final cleanup notification\n");
1100 /* Cleanup afterwards */
1101 REG_WR(p_hwfn, addr, 0);
1106 static enum _ecore_status_t ecore_calc_hw_mode(struct ecore_hwfn *p_hwfn)
1110 if (ECORE_IS_BB_B0(p_hwfn->p_dev)) {
1111 hw_mode |= 1 << MODE_BB;
1112 } else if (ECORE_IS_AH(p_hwfn->p_dev)) {
1113 hw_mode |= 1 << MODE_K2;
1115 DP_NOTICE(p_hwfn, true, "Unknown chip type %#x\n",
1116 p_hwfn->p_dev->type);
1120 /* Ports per engine is based on the values in CNIG_REG_NW_PORT_MODE */
1121 switch (p_hwfn->p_dev->num_ports_in_engines) {
1123 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
1126 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
1129 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
1132 DP_NOTICE(p_hwfn, true,
1133 "num_ports_in_engine = %d not supported\n",
1134 p_hwfn->p_dev->num_ports_in_engines);
1138 switch (p_hwfn->p_dev->mf_mode) {
1139 case ECORE_MF_DEFAULT:
1141 hw_mode |= 1 << MODE_MF_SI;
1143 case ECORE_MF_OVLAN:
1144 hw_mode |= 1 << MODE_MF_SD;
1147 DP_NOTICE(p_hwfn, true,
1148 "Unsupported MF mode, init as DEFAULT\n");
1149 hw_mode |= 1 << MODE_MF_SI;
1153 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1154 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1155 hw_mode |= 1 << MODE_FPGA;
1157 if (p_hwfn->p_dev->b_is_emul_full)
1158 hw_mode |= 1 << MODE_EMUL_FULL;
1160 hw_mode |= 1 << MODE_EMUL_REDUCED;
1164 hw_mode |= 1 << MODE_ASIC;
1166 if (p_hwfn->p_dev->num_hwfns > 1)
1167 hw_mode |= 1 << MODE_100G;
1169 p_hwfn->hw_info.hw_mode = hw_mode;
1171 DP_VERBOSE(p_hwfn, (ECORE_MSG_PROBE | ECORE_MSG_IFUP),
1172 "Configuring function for hw_mode: 0x%08x\n",
1173 p_hwfn->hw_info.hw_mode);
1175 return ECORE_SUCCESS;
1179 /* MFW-replacement initializations for non-ASIC */
1180 static enum _ecore_status_t ecore_hw_init_chip(struct ecore_hwfn *p_hwfn,
1181 struct ecore_ptt *p_ptt)
1183 struct ecore_dev *p_dev = p_hwfn->p_dev;
1187 if (CHIP_REV_IS_EMUL(p_dev)) {
1188 if (ECORE_IS_AH(p_dev))
1192 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV + 4, pl_hv);
1194 if (CHIP_REV_IS_EMUL(p_dev) &&
1195 (ECORE_IS_AH(p_dev)))
1196 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV_2_K2_E5,
1199 /* initialize port mode to 4x10G_E (10G with 4x10 SERDES) */
1200 /* CNIG_REG_NW_PORT_MODE is same for A0 and B0 */
1201 if (!CHIP_REV_IS_EMUL(p_dev) || ECORE_IS_BB(p_dev))
1202 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB, 4);
1204 if (CHIP_REV_IS_EMUL(p_dev)) {
1205 if (ECORE_IS_AH(p_dev)) {
1206 /* 2 for 4-port, 1 for 2-port, 0 for 1-port */
1207 ecore_wr(p_hwfn, p_ptt, MISC_REG_PORT_MODE,
1208 (p_dev->num_ports_in_engines >> 1));
1210 ecore_wr(p_hwfn, p_ptt, MISC_REG_BLOCK_256B_EN,
1211 p_dev->num_ports_in_engines == 4 ? 0 : 3);
1216 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_RBC_DONE, 1);
1217 for (i = 0; i < 100; i++) {
1219 if (ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_CFG_DONE) == 1)
1223 DP_NOTICE(p_hwfn, true,
1224 "RBC done failed to complete in PSWRQ2\n");
1226 return ECORE_SUCCESS;
1230 /* Init run time data for all PFs and their VFs on an engine.
1231 * TBD - for VFs - Once we have parent PF info for each VF in
1232 * shmem available as CAU requires knowledge of parent PF for each VF.
1234 static void ecore_init_cau_rt_data(struct ecore_dev *p_dev)
1236 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
1239 for_each_hwfn(p_dev, i) {
1240 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1241 struct ecore_igu_info *p_igu_info;
1242 struct ecore_igu_block *p_block;
1243 struct cau_sb_entry sb_entry;
1245 p_igu_info = p_hwfn->hw_info.p_igu_info;
1248 igu_sb_id < ECORE_MAPPING_MEMORY_SIZE(p_dev);
1250 p_block = &p_igu_info->entry[igu_sb_id];
1252 if (!p_block->is_pf)
1255 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
1256 p_block->function_id, 0, 0);
1257 STORE_RT_REG_AGG(p_hwfn, offset + igu_sb_id * 2,
1263 static void ecore_init_cache_line_size(struct ecore_hwfn *p_hwfn,
1264 struct ecore_ptt *p_ptt)
1266 u32 val, wr_mbs, cache_line_size;
1268 val = ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_WR_MBS0);
1281 "Unexpected value of PSWRQ2_REG_WR_MBS0 [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1286 cache_line_size = OSAL_MIN_T(u32, OSAL_CACHE_LINE_SIZE, wr_mbs);
1287 switch (cache_line_size) {
1302 "Unexpected value of cache line size [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1306 if (wr_mbs < OSAL_CACHE_LINE_SIZE)
1308 "The cache line size for padding is suboptimal for performance [OS cache line size 0x%x, wr mbs 0x%x]\n",
1309 OSAL_CACHE_LINE_SIZE, wr_mbs);
1311 STORE_RT_REG(p_hwfn, PGLUE_REG_B_CACHE_LINE_SIZE_RT_OFFSET, val);
1313 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_WR_RT_OFFSET, val);
1314 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_RD_RT_OFFSET, val);
1318 static enum _ecore_status_t ecore_hw_init_common(struct ecore_hwfn *p_hwfn,
1319 struct ecore_ptt *p_ptt,
1322 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
1323 struct ecore_dev *p_dev = p_hwfn->p_dev;
1324 u8 vf_id, max_num_vfs;
1327 enum _ecore_status_t rc = ECORE_SUCCESS;
1329 ecore_init_cau_rt_data(p_dev);
1331 /* Program GTT windows */
1332 ecore_gtt_init(p_hwfn, p_ptt);
1335 if (CHIP_REV_IS_EMUL(p_dev)) {
1336 rc = ecore_hw_init_chip(p_hwfn, p_ptt);
1337 if (rc != ECORE_SUCCESS)
1342 if (p_hwfn->mcp_info) {
1343 if (p_hwfn->mcp_info->func_info.bandwidth_max)
1344 qm_info->pf_rl_en = 1;
1345 if (p_hwfn->mcp_info->func_info.bandwidth_min)
1346 qm_info->pf_wfq_en = 1;
1349 ecore_qm_common_rt_init(p_hwfn,
1350 p_dev->num_ports_in_engines,
1351 qm_info->max_phys_tcs_per_port,
1352 qm_info->pf_rl_en, qm_info->pf_wfq_en,
1353 qm_info->vport_rl_en, qm_info->vport_wfq_en,
1354 qm_info->qm_port_params);
1356 ecore_cxt_hw_init_common(p_hwfn);
1358 ecore_init_cache_line_size(p_hwfn, p_ptt);
1360 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
1361 if (rc != ECORE_SUCCESS)
1364 /* @@TBD MichalK - should add VALIDATE_VFID to init tool...
1365 * need to decide with which value, maybe runtime
1367 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
1368 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
1370 if (ECORE_IS_BB(p_dev)) {
1371 /* Workaround clears ROCE search for all functions to prevent
1372 * involving non initialized function in processing ROCE packet.
1374 num_pfs = NUM_OF_ENG_PFS(p_dev);
1375 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
1376 ecore_fid_pretend(p_hwfn, p_ptt, pf_id);
1377 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1378 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1380 /* pretend to original PF */
1381 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1384 /* Workaround for avoiding CCFC execution error when getting packets
1385 * with CRC errors, and allowing instead the invoking of the FW error
1387 * This is not done inside the init tool since it currently can't
1388 * perform a pretending to VFs.
1390 max_num_vfs = ECORE_IS_AH(p_dev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
1391 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
1392 concrete_fid = ecore_vfid_to_concrete(p_hwfn, vf_id);
1393 ecore_fid_pretend(p_hwfn, p_ptt, (u16)concrete_fid);
1394 ecore_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
1395 ecore_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
1396 ecore_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
1397 ecore_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
1399 /* pretend to original PF */
1400 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1406 #define MISC_REG_RESET_REG_2_XMAC_BIT (1 << 4)
1407 #define MISC_REG_RESET_REG_2_XMAC_SOFT_BIT (1 << 5)
1409 #define PMEG_IF_BYTE_COUNT 8
1411 static void ecore_wr_nw_port(struct ecore_hwfn *p_hwfn,
1412 struct ecore_ptt *p_ptt,
1413 u32 addr, u64 data, u8 reg_type, u8 port)
1415 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1416 "CMD: %08x, ADDR: 0x%08x, DATA: %08x:%08x\n",
1417 ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) |
1418 (8 << PMEG_IF_BYTE_COUNT),
1419 (reg_type << 25) | (addr << 8) | port,
1420 (u32)((data >> 32) & 0xffffffff),
1421 (u32)(data & 0xffffffff));
1423 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB,
1424 (ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) &
1425 0xffff00fe) | (8 << PMEG_IF_BYTE_COUNT));
1426 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_ADDR_BB,
1427 (reg_type << 25) | (addr << 8) | port);
1428 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB, data & 0xffffffff);
1429 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB,
1430 (data >> 32) & 0xffffffff);
1433 #define XLPORT_MODE_REG (0x20a)
1434 #define XLPORT_MAC_CONTROL (0x210)
1435 #define XLPORT_FLOW_CONTROL_CONFIG (0x207)
1436 #define XLPORT_ENABLE_REG (0x20b)
1438 #define XLMAC_CTRL (0x600)
1439 #define XLMAC_MODE (0x601)
1440 #define XLMAC_RX_MAX_SIZE (0x608)
1441 #define XLMAC_TX_CTRL (0x604)
1442 #define XLMAC_PAUSE_CTRL (0x60d)
1443 #define XLMAC_PFC_CTRL (0x60e)
1445 static void ecore_emul_link_init_bb(struct ecore_hwfn *p_hwfn,
1446 struct ecore_ptt *p_ptt)
1448 u8 loopback = 0, port = p_hwfn->port_id * 2;
1450 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
1452 /* XLPORT MAC MODE *//* 0 Quad, 4 Single... */
1453 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MODE_REG, (0x4 << 4) | 0x4, 1,
1455 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MAC_CONTROL, 0, 1, port);
1456 /* XLMAC: SOFT RESET */
1457 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x40, 0, port);
1458 /* XLMAC: Port Speed >= 10Gbps */
1459 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_MODE, 0x40, 0, port);
1460 /* XLMAC: Max Size */
1461 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_RX_MAX_SIZE, 0x3fff, 0, port);
1462 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_TX_CTRL,
1463 0x01000000800ULL | (0xa << 12) | ((u64)1 << 38),
1465 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PAUSE_CTRL, 0x7c000, 0, port);
1466 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PFC_CTRL,
1467 0x30ffffc000ULL, 0, port);
1468 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x3 | (loopback << 2), 0,
1469 port); /* XLMAC: TX_EN, RX_EN */
1470 /* XLMAC: TX_EN, RX_EN, SW_LINK_STATUS */
1471 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL,
1472 0x1003 | (loopback << 2), 0, port);
1473 /* Enabled Parallel PFC interface */
1474 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_FLOW_CONTROL_CONFIG, 1, 0, port);
1476 /* XLPORT port enable */
1477 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_ENABLE_REG, 0xf, 1, port);
1480 static void ecore_emul_link_init_ah_e5(struct ecore_hwfn *p_hwfn,
1481 struct ecore_ptt *p_ptt)
1483 u8 port = p_hwfn->port_id;
1484 u32 mac_base = NWM_REG_MAC0_K2_E5 + (port << 2) * NWM_REG_MAC0_SIZE;
1486 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
1488 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NIG_PORT0_CONF_K2_E5 + (port << 2),
1489 (1 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_ENABLE_0_K2_E5_SHIFT) |
1491 CNIG_REG_NIG_PORT0_CONF_NIG_PORT_NWM_PORT_MAP_0_K2_E5_SHIFT) |
1492 (0 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_RATE_0_K2_E5_SHIFT));
1494 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_XIF_MODE_K2_E5,
1495 1 << ETH_MAC_REG_XIF_MODE_XGMII_K2_E5_SHIFT);
1497 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_FRM_LENGTH_K2_E5,
1498 9018 << ETH_MAC_REG_FRM_LENGTH_FRM_LENGTH_K2_E5_SHIFT);
1500 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_IPG_LENGTH_K2_E5,
1501 0xc << ETH_MAC_REG_TX_IPG_LENGTH_TXIPG_K2_E5_SHIFT);
1503 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_RX_FIFO_SECTIONS_K2_E5,
1504 8 << ETH_MAC_REG_RX_FIFO_SECTIONS_RX_SECTION_FULL_K2_E5_SHIFT);
1506 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_FIFO_SECTIONS_K2_E5,
1508 ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_EMPTY_K2_E5_SHIFT) |
1510 ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_FULL_K2_E5_SHIFT));
1512 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_COMMAND_CONFIG_K2_E5,
1516 static void ecore_emul_link_init(struct ecore_hwfn *p_hwfn,
1517 struct ecore_ptt *p_ptt)
1519 if (ECORE_IS_AH(p_hwfn->p_dev))
1520 ecore_emul_link_init_ah_e5(p_hwfn, p_ptt);
1522 ecore_emul_link_init_bb(p_hwfn, p_ptt);
1525 static void ecore_link_init_bb(struct ecore_hwfn *p_hwfn,
1526 struct ecore_ptt *p_ptt, u8 port)
1528 int port_offset = port ? 0x800 : 0;
1529 u32 xmac_rxctrl = 0;
1532 /* FIXME: move to common start */
1533 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
1534 MISC_REG_RESET_REG_2_XMAC_BIT); /* Clear */
1536 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
1537 MISC_REG_RESET_REG_2_XMAC_BIT); /* Set */
1539 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_CORE_PORT_MODE_BB, 1);
1541 /* Set the number of ports on the Warp Core to 10G */
1542 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_PHY_PORT_MODE_BB, 3);
1544 /* Soft reset of XMAC */
1545 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
1546 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
1548 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
1549 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
1551 /* FIXME: move to common end */
1552 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
1553 ecore_wr(p_hwfn, p_ptt, XMAC_REG_MODE_BB + port_offset, 0x20);
1555 /* Set Max packet size: initialize XMAC block register for port 0 */
1556 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_MAX_SIZE_BB + port_offset, 0x2710);
1558 /* CRC append for Tx packets: init XMAC block register for port 1 */
1559 ecore_wr(p_hwfn, p_ptt, XMAC_REG_TX_CTRL_LO_BB + port_offset, 0xC800);
1561 /* Enable TX and RX: initialize XMAC block register for port 1 */
1562 ecore_wr(p_hwfn, p_ptt, XMAC_REG_CTRL_BB + port_offset,
1563 XMAC_REG_CTRL_TX_EN_BB | XMAC_REG_CTRL_RX_EN_BB);
1564 xmac_rxctrl = ecore_rd(p_hwfn, p_ptt,
1565 XMAC_REG_RX_CTRL_BB + port_offset);
1566 xmac_rxctrl |= XMAC_REG_RX_CTRL_PROCESS_VARIABLE_PREAMBLE_BB;
1567 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_CTRL_BB + port_offset, xmac_rxctrl);
1571 static enum _ecore_status_t
1572 ecore_hw_init_dpi_size(struct ecore_hwfn *p_hwfn,
1573 struct ecore_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
1575 u32 dpi_page_size_1, dpi_page_size_2, dpi_page_size;
1576 u32 dpi_bit_shift, dpi_count;
1579 /* Calculate DPI size
1580 * ------------------
1581 * The PWM region contains Doorbell Pages. The first is reserverd for
1582 * the kernel for, e.g, L2. The others are free to be used by non-
1583 * trusted applications, typically from user space. Each page, called a
1584 * doorbell page is sectioned into windows that allow doorbells to be
1585 * issued in parallel by the kernel/application. The size of such a
1586 * window (a.k.a. WID) is 1kB.
1588 * 1kB WID x N WIDS = DPI page size
1589 * DPI page size x N DPIs = PWM region size
1591 * The size of the DPI page size must be in multiples of OSAL_PAGE_SIZE
1592 * in order to ensure that two applications won't share the same page.
1593 * It also must contain at least one WID per CPU to allow parallelism.
1594 * It also must be a power of 2, since it is stored as a bit shift.
1596 * The DPI page size is stored in a register as 'dpi_bit_shift' so that
1597 * 0 is 4kB, 1 is 8kB and etc. Hence the minimum size is 4,096
1598 * containing 4 WIDs.
1600 dpi_page_size_1 = ECORE_WID_SIZE * n_cpus;
1601 dpi_page_size_2 = OSAL_MAX_T(u32, ECORE_WID_SIZE, OSAL_PAGE_SIZE);
1602 dpi_page_size = OSAL_MAX_T(u32, dpi_page_size_1, dpi_page_size_2);
1603 dpi_page_size = OSAL_ROUNDUP_POW_OF_TWO(dpi_page_size);
1604 dpi_bit_shift = OSAL_LOG2(dpi_page_size / 4096);
1606 dpi_count = pwm_region_size / dpi_page_size;
1608 min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
1609 min_dpis = OSAL_MAX_T(u32, ECORE_MIN_DPIS, min_dpis);
1612 p_hwfn->dpi_size = dpi_page_size;
1613 p_hwfn->dpi_count = dpi_count;
1615 /* Update registers */
1616 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
1618 if (dpi_count < min_dpis)
1619 return ECORE_NORESOURCES;
1621 return ECORE_SUCCESS;
1624 enum ECORE_ROCE_EDPM_MODE {
1625 ECORE_ROCE_EDPM_MODE_ENABLE = 0,
1626 ECORE_ROCE_EDPM_MODE_FORCE_ON = 1,
1627 ECORE_ROCE_EDPM_MODE_DISABLE = 2,
1630 static enum _ecore_status_t
1631 ecore_hw_init_pf_doorbell_bar(struct ecore_hwfn *p_hwfn,
1632 struct ecore_ptt *p_ptt)
1634 u32 pwm_regsize, norm_regsize;
1635 u32 non_pwm_conn, min_addr_reg1;
1636 u32 db_bar_size, n_cpus;
1639 enum _ecore_status_t rc = ECORE_SUCCESS;
1642 db_bar_size = ecore_hw_bar_size(p_hwfn, p_ptt, BAR_ID_1);
1643 if (p_hwfn->p_dev->num_hwfns > 1)
1646 /* Calculate doorbell regions
1647 * -----------------------------------
1648 * The doorbell BAR is made of two regions. The first is called normal
1649 * region and the second is called PWM region. In the normal region
1650 * each ICID has its own set of addresses so that writing to that
1651 * specific address identifies the ICID. In the Process Window Mode
1652 * region the ICID is given in the data written to the doorbell. The
1653 * above per PF register denotes the offset in the doorbell BAR in which
1654 * the PWM region begins.
1655 * The normal region has ECORE_PF_DEMS_SIZE bytes per ICID, that is per
1656 * non-PWM connection. The calculation below computes the total non-PWM
1657 * connections. The DORQ_REG_PF_MIN_ADDR_REG1 register is
1658 * in units of 4,096 bytes.
1660 non_pwm_conn = ecore_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1661 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1663 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, OSAL_NULL);
1664 norm_regsize = ROUNDUP(ECORE_PF_DEMS_SIZE * non_pwm_conn, 4096);
1665 min_addr_reg1 = norm_regsize / 4096;
1666 pwm_regsize = db_bar_size - norm_regsize;
1668 /* Check that the normal and PWM sizes are valid */
1669 if (db_bar_size < norm_regsize) {
1670 DP_ERR(p_hwfn->p_dev,
1671 "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
1672 db_bar_size, norm_regsize);
1673 return ECORE_NORESOURCES;
1675 if (pwm_regsize < ECORE_MIN_PWM_REGION) {
1676 DP_ERR(p_hwfn->p_dev,
1677 "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",
1678 pwm_regsize, ECORE_MIN_PWM_REGION, db_bar_size,
1680 return ECORE_NORESOURCES;
1683 /* Calculate number of DPIs */
1684 roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
1685 if ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE) ||
1686 ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_FORCE_ON))) {
1687 /* Either EDPM is mandatory, or we are attempting to allocate a
1690 n_cpus = OSAL_NUM_ACTIVE_CPU();
1691 rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1694 cond = ((rc != ECORE_SUCCESS) &&
1695 (roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE)) ||
1696 (roce_edpm_mode == ECORE_ROCE_EDPM_MODE_DISABLE);
1697 if (cond || p_hwfn->dcbx_no_edpm) {
1698 /* Either EDPM is disabled from user configuration, or it is
1699 * disabled via DCBx, or it is not mandatory and we failed to
1700 * allocated a WID per CPU.
1703 rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1705 /* If we entered this flow due to DCBX then the DPM register is
1706 * already configured.
1711 "doorbell bar: normal_region_size=%d, pwm_region_size=%d",
1712 norm_regsize, pwm_regsize);
1714 " dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
1715 p_hwfn->dpi_size, p_hwfn->dpi_count,
1716 ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
1717 "disabled" : "enabled");
1719 /* Check return codes from above calls */
1720 if (rc != ECORE_SUCCESS) {
1722 "Failed to allocate enough DPIs\n");
1723 return ECORE_NORESOURCES;
1727 p_hwfn->dpi_start_offset = norm_regsize;
1729 /* Update registers */
1730 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1731 pf_dems_shift = OSAL_LOG2(ECORE_PF_DEMS_SIZE / 4);
1732 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1733 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1735 return ECORE_SUCCESS;
1738 static enum _ecore_status_t ecore_hw_init_port(struct ecore_hwfn *p_hwfn,
1739 struct ecore_ptt *p_ptt,
1742 enum _ecore_status_t rc = ECORE_SUCCESS;
1744 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
1746 if (rc != ECORE_SUCCESS)
1749 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_MASTER_WRITE_PAD_ENABLE, 0);
1752 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev))
1753 return ECORE_SUCCESS;
1755 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1756 if (ECORE_IS_AH(p_hwfn->p_dev))
1757 return ECORE_SUCCESS;
1758 else if (ECORE_IS_BB(p_hwfn->p_dev))
1759 ecore_link_init_bb(p_hwfn, p_ptt, p_hwfn->port_id);
1760 } else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
1761 if (p_hwfn->p_dev->num_hwfns > 1) {
1762 /* Activate OPTE in CMT */
1765 val = ecore_rd(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV);
1767 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV, val);
1768 ecore_wr(p_hwfn, p_ptt, MISC_REG_CLK_100G_MODE, 1);
1769 ecore_wr(p_hwfn, p_ptt, MISCS_REG_CLK_100G_MODE, 1);
1770 ecore_wr(p_hwfn, p_ptt, MISC_REG_OPTE_MODE, 1);
1771 ecore_wr(p_hwfn, p_ptt,
1772 NIG_REG_LLH_ENG_CLS_TCP_4_TUPLE_SEARCH, 1);
1773 ecore_wr(p_hwfn, p_ptt,
1774 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL, 0x55555555);
1775 ecore_wr(p_hwfn, p_ptt,
1776 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL + 0x4,
1780 ecore_emul_link_init(p_hwfn, p_ptt);
1782 DP_INFO(p_hwfn->p_dev, "link is not being configured\n");
1789 static enum _ecore_status_t
1790 ecore_hw_init_pf(struct ecore_hwfn *p_hwfn,
1791 struct ecore_ptt *p_ptt,
1792 struct ecore_tunnel_info *p_tunn,
1795 enum ecore_int_mode int_mode, bool allow_npar_tx_switch)
1797 u8 rel_pf_id = p_hwfn->rel_pf_id;
1799 enum _ecore_status_t rc = ECORE_SUCCESS;
1803 if (p_hwfn->mcp_info) {
1804 struct ecore_mcp_function_info *p_info;
1806 p_info = &p_hwfn->mcp_info->func_info;
1807 if (p_info->bandwidth_min)
1808 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1810 /* Update rate limit once we'll actually have a link */
1811 p_hwfn->qm_info.pf_rl = 100000;
1813 ecore_cxt_hw_init_pf(p_hwfn, p_ptt);
1815 ecore_int_igu_init_rt(p_hwfn);
1817 /* Set VLAN in NIG if needed */
1818 if (hw_mode & (1 << MODE_MF_SD)) {
1819 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1820 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1821 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1822 p_hwfn->hw_info.ovlan);
1825 /* Enable classification by MAC if needed */
1826 if (hw_mode & (1 << MODE_MF_SI)) {
1827 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
1828 "Configuring TAGMAC_CLS_TYPE\n");
1829 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET,
1833 /* Protocl Configuration - @@@TBD - should we set 0 otherwise? */
1834 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
1835 (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) ? 1 : 0);
1836 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
1837 (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) ? 1 : 0);
1838 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
1840 /* perform debug configuration when chip is out of reset */
1841 OSAL_BEFORE_PF_START((void *)p_hwfn->p_dev, p_hwfn->my_id);
1843 /* PF Init sequence */
1844 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1848 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1849 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1853 /* Pure runtime initializations - directly to the HW */
1854 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1856 /* PCI relaxed ordering causes a decrease in the performance on some
1857 * systems. Till a root cause is found, disable this attribute in the
1861 * pos = OSAL_PCI_FIND_CAPABILITY(p_hwfn->p_dev, PCI_CAP_ID_EXP);
1863 * DP_NOTICE(p_hwfn, true,
1864 * "Failed to find the PCIe Cap\n");
1867 * OSAL_PCI_READ_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, &ctrl);
1868 * ctrl &= ~PCI_EXP_DEVCTL_RELAX_EN;
1869 * OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, ctrl);
1872 rc = ecore_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1876 /* enable interrupts */
1877 rc = ecore_int_igu_enable(p_hwfn, p_ptt, int_mode);
1878 if (rc != ECORE_SUCCESS)
1881 /* send function start command */
1882 rc = ecore_sp_pf_start(p_hwfn, p_ptt, p_tunn,
1883 p_hwfn->p_dev->mf_mode,
1884 allow_npar_tx_switch);
1886 DP_NOTICE(p_hwfn, true,
1887 "Function start ramrod failed\n");
1889 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1890 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1891 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1893 if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) {
1894 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1,
1896 ecore_wr(p_hwfn, p_ptt,
1897 PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
1900 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1901 "PRS_REG_SEARCH registers after start PFn\n");
1902 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP);
1903 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1904 "PRS_REG_SEARCH_TCP: %x\n", prs_reg);
1905 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP);
1906 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1907 "PRS_REG_SEARCH_UDP: %x\n", prs_reg);
1908 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE);
1909 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1910 "PRS_REG_SEARCH_FCOE: %x\n", prs_reg);
1911 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE);
1912 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1913 "PRS_REG_SEARCH_ROCE: %x\n", prs_reg);
1914 prs_reg = ecore_rd(p_hwfn, p_ptt,
1915 PRS_REG_SEARCH_TCP_FIRST_FRAG);
1916 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1917 "PRS_REG_SEARCH_TCP_FIRST_FRAG: %x\n",
1919 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1920 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1921 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1927 enum _ecore_status_t ecore_pglueb_set_pfid_enable(struct ecore_hwfn *p_hwfn,
1928 struct ecore_ptt *p_ptt,
1931 u32 delay_idx = 0, val, set_val = b_enable ? 1 : 0;
1933 /* Configure the PF's internal FID_enable for master transactions */
1934 ecore_wr(p_hwfn, p_ptt,
1935 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1937 /* Wait until value is set - try for 1 second every 50us */
1938 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1939 val = ecore_rd(p_hwfn, p_ptt,
1940 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1947 if (val != set_val) {
1948 DP_NOTICE(p_hwfn, true,
1949 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1950 return ECORE_UNKNOWN_ERROR;
1953 return ECORE_SUCCESS;
1956 static void ecore_reset_mb_shadow(struct ecore_hwfn *p_hwfn,
1957 struct ecore_ptt *p_main_ptt)
1959 /* Read shadow of current MFW mailbox */
1960 ecore_mcp_read_mb(p_hwfn, p_main_ptt);
1961 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1962 p_hwfn->mcp_info->mfw_mb_cur,
1963 p_hwfn->mcp_info->mfw_mb_length);
1966 enum _ecore_status_t ecore_vf_start(struct ecore_hwfn *p_hwfn,
1967 struct ecore_hw_init_params *p_params)
1969 if (p_params->p_tunn) {
1970 ecore_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
1971 ecore_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
1974 p_hwfn->b_int_enabled = 1;
1976 return ECORE_SUCCESS;
1979 static void ecore_pglueb_clear_err(struct ecore_hwfn *p_hwfn,
1980 struct ecore_ptt *p_ptt)
1982 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
1983 1 << p_hwfn->abs_pf_id);
1987 ecore_fill_load_req_params(struct ecore_load_req_params *p_load_req,
1988 struct ecore_drv_load_params *p_drv_load)
1990 /* Make sure that if ecore-client didn't provide inputs, all the
1991 * expected defaults are indeed zero.
1993 OSAL_BUILD_BUG_ON(ECORE_DRV_ROLE_OS != 0);
1994 OSAL_BUILD_BUG_ON(ECORE_LOAD_REQ_LOCK_TO_DEFAULT != 0);
1995 OSAL_BUILD_BUG_ON(ECORE_OVERRIDE_FORCE_LOAD_NONE != 0);
1997 OSAL_MEM_ZERO(p_load_req, sizeof(*p_load_req));
1999 if (p_drv_load != OSAL_NULL) {
2000 p_load_req->drv_role = p_drv_load->is_crash_kernel ?
2001 ECORE_DRV_ROLE_KDUMP :
2003 p_load_req->timeout_val = p_drv_load->mfw_timeout_val;
2004 p_load_req->avoid_eng_reset = p_drv_load->avoid_eng_reset;
2005 p_load_req->override_force_load =
2006 p_drv_load->override_force_load;
2010 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
2011 struct ecore_hw_init_params *p_params)
2013 struct ecore_load_req_params load_req_params;
2014 u32 load_code, resp, param, drv_mb_param;
2015 bool b_default_mtu = true;
2016 struct ecore_hwfn *p_hwfn;
2017 enum _ecore_status_t rc = ECORE_SUCCESS;
2020 if ((p_params->int_mode == ECORE_INT_MODE_MSI) &&
2021 (p_dev->num_hwfns > 1)) {
2022 DP_NOTICE(p_dev, false,
2023 "MSI mode is not supported for CMT devices\n");
2028 rc = ecore_init_fw_data(p_dev, p_params->bin_fw_data);
2029 if (rc != ECORE_SUCCESS)
2033 for_each_hwfn(p_dev, i) {
2034 p_hwfn = &p_dev->hwfns[i];
2036 /* If management didn't provide a default, set one of our own */
2037 if (!p_hwfn->hw_info.mtu) {
2038 p_hwfn->hw_info.mtu = 1500;
2039 b_default_mtu = false;
2043 ecore_vf_start(p_hwfn, p_params);
2047 rc = ecore_calc_hw_mode(p_hwfn);
2048 if (rc != ECORE_SUCCESS)
2051 ecore_fill_load_req_params(&load_req_params,
2052 p_params->p_drv_load_params);
2053 rc = ecore_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
2055 if (rc != ECORE_SUCCESS) {
2056 DP_NOTICE(p_hwfn, true,
2057 "Failed sending a LOAD_REQ command\n");
2061 load_code = load_req_params.load_code;
2062 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
2063 "Load request was sent. Load code: 0x%x\n",
2066 ecore_mcp_set_capabilities(p_hwfn, p_hwfn->p_main_ptt);
2069 * When coming back from hiberbate state, the registers from
2070 * which shadow is read initially are not initialized. It turns
2071 * out that these registers get initialized during the call to
2072 * ecore_mcp_load_req request. So we need to reread them here
2073 * to get the proper shadow register value.
2074 * Note: This is a workaround for the missing MFW
2075 * initialization. It may be removed once the implementation
2078 ecore_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
2080 /* Only relevant for recovery:
2081 * Clear the indication after the LOAD_REQ command is responded
2084 p_dev->recov_in_prog = false;
2086 p_hwfn->first_on_engine = (load_code ==
2087 FW_MSG_CODE_DRV_LOAD_ENGINE);
2089 if (!qm_lock_init) {
2090 OSAL_SPIN_LOCK_INIT(&qm_lock);
2091 qm_lock_init = true;
2094 /* Clean up chip from previous driver if such remains exist.
2095 * This is not needed when the PF is the first one on the
2096 * engine, since afterwards we are going to init the FW.
2098 if (load_code != FW_MSG_CODE_DRV_LOAD_ENGINE) {
2099 rc = ecore_final_cleanup(p_hwfn, p_hwfn->p_main_ptt,
2100 p_hwfn->rel_pf_id, false);
2101 if (rc != ECORE_SUCCESS) {
2102 ecore_hw_err_notify(p_hwfn,
2103 ECORE_HW_ERR_RAMROD_FAIL);
2108 /* Log and clean previous pglue_b errors if such exist */
2109 ecore_pglueb_rbc_attn_handler(p_hwfn, p_hwfn->p_main_ptt);
2110 ecore_pglueb_clear_err(p_hwfn, p_hwfn->p_main_ptt);
2112 /* Enable the PF's internal FID_enable in the PXP */
2113 rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_hwfn->p_main_ptt,
2115 if (rc != ECORE_SUCCESS)
2118 switch (load_code) {
2119 case FW_MSG_CODE_DRV_LOAD_ENGINE:
2120 rc = ecore_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
2121 p_hwfn->hw_info.hw_mode);
2122 if (rc != ECORE_SUCCESS)
2125 case FW_MSG_CODE_DRV_LOAD_PORT:
2126 rc = ecore_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
2127 p_hwfn->hw_info.hw_mode);
2128 if (rc != ECORE_SUCCESS)
2131 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
2132 rc = ecore_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
2134 p_hwfn->hw_info.hw_mode,
2135 p_params->b_hw_start,
2137 p_params->allow_npar_tx_switch);
2140 DP_NOTICE(p_hwfn, false,
2141 "Unexpected load code [0x%08x]", load_code);
2146 if (rc != ECORE_SUCCESS) {
2147 DP_NOTICE(p_hwfn, true,
2148 "init phase failed for loadcode 0x%x (rc %d)\n",
2153 rc = ecore_mcp_load_done(p_hwfn, p_hwfn->p_main_ptt);
2154 if (rc != ECORE_SUCCESS)
2157 /* send DCBX attention request command */
2158 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
2159 "sending phony dcbx set command to trigger DCBx attention handling\n");
2160 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2161 DRV_MSG_CODE_SET_DCBX,
2162 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT, &resp,
2164 if (rc != ECORE_SUCCESS) {
2165 DP_NOTICE(p_hwfn, true,
2166 "Failed to send DCBX attention request\n");
2170 p_hwfn->hw_init_done = true;
2174 p_hwfn = ECORE_LEADING_HWFN(p_dev);
2175 drv_mb_param = STORM_FW_VERSION;
2176 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2177 DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
2178 drv_mb_param, &resp, ¶m);
2179 if (rc != ECORE_SUCCESS)
2180 DP_INFO(p_hwfn, "Failed to update firmware version\n");
2183 rc = ecore_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
2184 p_hwfn->hw_info.mtu);
2185 if (rc != ECORE_SUCCESS)
2186 DP_INFO(p_hwfn, "Failed to update default mtu\n");
2188 rc = ecore_mcp_ov_update_driver_state(p_hwfn,
2190 ECORE_OV_DRIVER_STATE_DISABLED);
2191 if (rc != ECORE_SUCCESS)
2192 DP_INFO(p_hwfn, "Failed to update driver state\n");
2198 /* The MFW load lock should be released regardless of success or failure
2199 * of initialization.
2200 * TODO: replace this with an attempt to send cancel_load.
2202 ecore_mcp_load_done(p_hwfn, p_hwfn->p_main_ptt);
2206 #define ECORE_HW_STOP_RETRY_LIMIT (10)
2207 static void ecore_hw_timers_stop(struct ecore_dev *p_dev,
2208 struct ecore_hwfn *p_hwfn,
2209 struct ecore_ptt *p_ptt)
2214 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
2215 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
2216 for (i = 0; i < ECORE_HW_STOP_RETRY_LIMIT && !p_dev->recov_in_prog;
2218 if ((!ecore_rd(p_hwfn, p_ptt,
2219 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
2220 (!ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
2223 /* Dependent on number of connection/tasks, possibly
2224 * 1ms sleep is required between polls
2229 if (i < ECORE_HW_STOP_RETRY_LIMIT)
2232 DP_NOTICE(p_hwfn, true, "Timers linear scans are not over"
2233 " [Connection %02x Tasks %02x]\n",
2234 (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
2235 (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
2238 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev)
2242 for_each_hwfn(p_dev, j) {
2243 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2244 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2246 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
2250 static enum _ecore_status_t ecore_verify_reg_val(struct ecore_hwfn *p_hwfn,
2251 struct ecore_ptt *p_ptt,
2252 u32 addr, u32 expected_val)
2254 u32 val = ecore_rd(p_hwfn, p_ptt, addr);
2256 if (val != expected_val) {
2257 DP_NOTICE(p_hwfn, true,
2258 "Value at address 0x%08x is 0x%08x while the expected value is 0x%08x\n",
2259 addr, val, expected_val);
2260 return ECORE_UNKNOWN_ERROR;
2263 return ECORE_SUCCESS;
2266 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev)
2268 struct ecore_hwfn *p_hwfn;
2269 struct ecore_ptt *p_ptt;
2270 enum _ecore_status_t rc, rc2 = ECORE_SUCCESS;
2273 for_each_hwfn(p_dev, j) {
2274 p_hwfn = &p_dev->hwfns[j];
2275 p_ptt = p_hwfn->p_main_ptt;
2277 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Stopping hw/fw\n");
2280 ecore_vf_pf_int_cleanup(p_hwfn);
2281 rc = ecore_vf_pf_reset(p_hwfn);
2282 if (rc != ECORE_SUCCESS) {
2283 DP_NOTICE(p_hwfn, true,
2284 "ecore_vf_pf_reset failed. rc = %d.\n",
2286 rc2 = ECORE_UNKNOWN_ERROR;
2291 /* mark the hw as uninitialized... */
2292 p_hwfn->hw_init_done = false;
2294 /* Send unload command to MCP */
2295 if (!p_dev->recov_in_prog) {
2296 rc = ecore_mcp_unload_req(p_hwfn, p_ptt);
2297 if (rc != ECORE_SUCCESS) {
2298 DP_NOTICE(p_hwfn, true,
2299 "Failed sending a UNLOAD_REQ command. rc = %d.\n",
2301 rc2 = ECORE_UNKNOWN_ERROR;
2305 OSAL_DPC_SYNC(p_hwfn);
2307 /* After this point no MFW attentions are expected, e.g. prevent
2308 * race between pf stop and dcbx pf update.
2311 rc = ecore_sp_pf_stop(p_hwfn);
2312 if (rc != ECORE_SUCCESS) {
2313 DP_NOTICE(p_hwfn, true,
2314 "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
2316 rc2 = ECORE_UNKNOWN_ERROR;
2319 /* perform debug action after PF stop was sent */
2320 OSAL_AFTER_PF_STOP((void *)p_dev, p_hwfn->my_id);
2322 /* close NIG to BRB gate */
2323 ecore_wr(p_hwfn, p_ptt,
2324 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2327 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2328 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2329 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2330 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2331 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2333 /* @@@TBD - clean transmission queues (5.b) */
2334 /* @@@TBD - clean BTB (5.c) */
2336 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
2338 /* @@@TBD - verify DMAE requests are done (8) */
2340 /* Disable Attention Generation */
2341 ecore_int_igu_disable_int(p_hwfn, p_ptt);
2342 ecore_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
2343 ecore_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
2344 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
2345 rc = ecore_int_igu_reset_cam_default(p_hwfn, p_ptt);
2346 if (rc != ECORE_SUCCESS) {
2347 DP_NOTICE(p_hwfn, true,
2348 "Failed to return IGU CAM to default\n");
2349 rc2 = ECORE_UNKNOWN_ERROR;
2352 /* Need to wait 1ms to guarantee SBs are cleared */
2355 if (!p_dev->recov_in_prog) {
2356 ecore_verify_reg_val(p_hwfn, p_ptt,
2357 QM_REG_USG_CNT_PF_TX, 0);
2358 ecore_verify_reg_val(p_hwfn, p_ptt,
2359 QM_REG_USG_CNT_PF_OTHER, 0);
2360 /* @@@TBD - assert on incorrect xCFC values (10.b) */
2363 /* Disable PF in HW blocks */
2364 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
2365 ecore_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
2367 if (!p_dev->recov_in_prog) {
2368 ecore_mcp_unload_done(p_hwfn, p_ptt);
2369 if (rc != ECORE_SUCCESS) {
2370 DP_NOTICE(p_hwfn, true,
2371 "Failed sending a UNLOAD_DONE command. rc = %d.\n",
2373 rc2 = ECORE_UNKNOWN_ERROR;
2378 if (IS_PF(p_dev) && !p_dev->recov_in_prog) {
2379 p_hwfn = ECORE_LEADING_HWFN(p_dev);
2380 p_ptt = ECORE_LEADING_HWFN(p_dev)->p_main_ptt;
2382 /* Clear the PF's internal FID_enable in the PXP.
2383 * In CMT this should only be done for first hw-function, and
2384 * only after all transactions have stopped for all active
2387 rc = ecore_pglueb_set_pfid_enable(p_hwfn, p_hwfn->p_main_ptt,
2389 if (rc != ECORE_SUCCESS) {
2390 DP_NOTICE(p_hwfn, true,
2391 "ecore_pglueb_set_pfid_enable() failed. rc = %d.\n",
2393 rc2 = ECORE_UNKNOWN_ERROR;
2400 enum _ecore_status_t ecore_hw_stop_fastpath(struct ecore_dev *p_dev)
2404 for_each_hwfn(p_dev, j) {
2405 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2406 struct ecore_ptt *p_ptt;
2409 ecore_vf_pf_int_cleanup(p_hwfn);
2412 p_ptt = ecore_ptt_acquire(p_hwfn);
2416 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
2417 "Shutting down the fastpath\n");
2419 ecore_wr(p_hwfn, p_ptt,
2420 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2422 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2423 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2424 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2425 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2426 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2428 /* @@@TBD - clean transmission queues (5.b) */
2429 /* @@@TBD - clean BTB (5.c) */
2431 /* @@@TBD - verify DMAE requests are done (8) */
2433 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
2434 /* Need to wait 1ms to guarantee SBs are cleared */
2436 ecore_ptt_release(p_hwfn, p_ptt);
2439 return ECORE_SUCCESS;
2442 enum _ecore_status_t ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn)
2444 struct ecore_ptt *p_ptt;
2446 if (IS_VF(p_hwfn->p_dev))
2447 return ECORE_SUCCESS;
2449 p_ptt = ecore_ptt_acquire(p_hwfn);
2453 /* If roce info is allocated it means roce is initialized and should
2454 * be enabled in searcher.
2456 if (p_hwfn->p_rdma_info) {
2457 if (p_hwfn->b_rdma_enabled_in_prs)
2458 ecore_wr(p_hwfn, p_ptt,
2459 p_hwfn->rdma_prs_search_reg, 0x1);
2460 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x1);
2463 /* Re-open incoming traffic */
2464 ecore_wr(p_hwfn, p_ptt,
2465 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
2466 ecore_ptt_release(p_hwfn, p_ptt);
2468 return ECORE_SUCCESS;
2471 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
2472 static void ecore_hw_hwfn_free(struct ecore_hwfn *p_hwfn)
2474 ecore_ptt_pool_free(p_hwfn);
2475 OSAL_FREE(p_hwfn->p_dev, p_hwfn->hw_info.p_igu_info);
2478 /* Setup bar access */
2479 static void ecore_hw_hwfn_prepare(struct ecore_hwfn *p_hwfn)
2481 /* clear indirect access */
2482 if (ECORE_IS_AH(p_hwfn->p_dev)) {
2483 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2484 PGLUE_B_REG_PGL_ADDR_E8_F0_K2_E5, 0);
2485 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2486 PGLUE_B_REG_PGL_ADDR_EC_F0_K2_E5, 0);
2487 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2488 PGLUE_B_REG_PGL_ADDR_F0_F0_K2_E5, 0);
2489 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2490 PGLUE_B_REG_PGL_ADDR_F4_F0_K2_E5, 0);
2492 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2493 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
2494 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2495 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
2496 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2497 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
2498 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2499 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
2502 /* Clean previous pglue_b errors if such exist */
2503 ecore_pglueb_clear_err(p_hwfn, p_hwfn->p_main_ptt);
2505 /* enable internal target-read */
2506 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2507 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
2510 static void get_function_id(struct ecore_hwfn *p_hwfn)
2513 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn,
2514 PXP_PF_ME_OPAQUE_ADDR);
2516 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
2518 /* Bits 16-19 from the ME registers are the pf_num */
2519 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
2520 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2521 PXP_CONCRETE_FID_PFID);
2522 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2523 PXP_CONCRETE_FID_PORT);
2525 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2526 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
2527 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
2530 static void ecore_hw_set_feat(struct ecore_hwfn *p_hwfn)
2532 u32 *feat_num = p_hwfn->hw_info.feat_num;
2533 struct ecore_sb_cnt_info sb_cnt;
2536 OSAL_MEM_ZERO(&sb_cnt, sizeof(sb_cnt));
2537 ecore_int_get_num_sbs(p_hwfn, &sb_cnt);
2539 /* L2 Queues require each: 1 status block. 1 L2 queue */
2540 if (ECORE_IS_L2_PERSONALITY(p_hwfn)) {
2541 /* Start by allocating VF queues, then PF's */
2542 feat_num[ECORE_VF_L2_QUE] =
2544 RESC_NUM(p_hwfn, ECORE_L2_QUEUE),
2546 feat_num[ECORE_PF_L2_QUE] =
2548 sb_cnt.cnt - non_l2_sbs,
2549 RESC_NUM(p_hwfn, ECORE_L2_QUEUE) -
2550 FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE));
2553 feat_num[ECORE_FCOE_CQ] = OSAL_MIN_T(u32, sb_cnt.cnt,
2556 feat_num[ECORE_ISCSI_CQ] = OSAL_MIN_T(u32, sb_cnt.cnt,
2560 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2561 "#PF_L2_QUEUE=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d #FCOE_CQ=%d #ISCSI_CQ=%d #SB=%d\n",
2562 (int)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE),
2563 (int)FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE),
2564 (int)FEAT_NUM(p_hwfn, ECORE_RDMA_CNQ),
2565 (int)FEAT_NUM(p_hwfn, ECORE_FCOE_CQ),
2566 (int)FEAT_NUM(p_hwfn, ECORE_ISCSI_CQ),
2570 const char *ecore_hw_get_resc_name(enum ecore_resources res_id)
2573 case ECORE_L2_QUEUE:
2587 case ECORE_RDMA_CNQ_RAM:
2588 return "RDMA_CNQ_RAM";
2591 case ECORE_LL2_QUEUE:
2593 case ECORE_CMDQS_CQS:
2595 case ECORE_RDMA_STATS_QUEUE:
2596 return "RDMA_STATS_QUEUE";
2602 return "UNKNOWN_RESOURCE";
2606 static enum _ecore_status_t
2607 __ecore_hw_set_soft_resc_size(struct ecore_hwfn *p_hwfn,
2608 struct ecore_ptt *p_ptt,
2609 enum ecore_resources res_id,
2613 enum _ecore_status_t rc;
2615 rc = ecore_mcp_set_resc_max_val(p_hwfn, p_ptt, res_id,
2616 resc_max_val, p_mcp_resp);
2617 if (rc != ECORE_SUCCESS) {
2618 DP_NOTICE(p_hwfn, true,
2619 "MFW response failure for a max value setting of resource %d [%s]\n",
2620 res_id, ecore_hw_get_resc_name(res_id));
2624 if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
2626 "Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
2627 res_id, ecore_hw_get_resc_name(res_id), *p_mcp_resp);
2629 return ECORE_SUCCESS;
2632 static enum _ecore_status_t
2633 ecore_hw_set_soft_resc_size(struct ecore_hwfn *p_hwfn,
2634 struct ecore_ptt *p_ptt)
2636 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2637 u32 resc_max_val, mcp_resp;
2639 enum _ecore_status_t rc;
2641 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
2644 case ECORE_LL2_QUEUE:
2645 case ECORE_RDMA_CNQ_RAM:
2646 case ECORE_RDMA_STATS_QUEUE:
2654 rc = __ecore_hw_set_soft_resc_size(p_hwfn, p_ptt, res_id,
2655 resc_max_val, &mcp_resp);
2656 if (rc != ECORE_SUCCESS)
2659 /* There's no point to continue to the next resource if the
2660 * command is not supported by the MFW.
2661 * We do continue if the command is supported but the resource
2662 * is unknown to the MFW. Such a resource will be later
2663 * configured with the default allocation values.
2665 if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
2666 return ECORE_NOTIMPL;
2669 return ECORE_SUCCESS;
2673 enum _ecore_status_t ecore_hw_get_dflt_resc(struct ecore_hwfn *p_hwfn,
2674 enum ecore_resources res_id,
2675 u32 *p_resc_num, u32 *p_resc_start)
2677 u8 num_funcs = p_hwfn->num_funcs_on_engine;
2678 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2681 case ECORE_L2_QUEUE:
2682 *p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
2683 MAX_NUM_L2_QUEUES_BB) / num_funcs;
2686 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2687 MAX_NUM_VPORTS_BB) / num_funcs;
2690 *p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
2691 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
2694 *p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
2695 MAX_QM_TX_QUEUES_BB) / num_funcs;
2698 *p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
2702 /* Each VFC resource can accommodate both a MAC and a VLAN */
2703 *p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
2706 *p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
2707 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
2709 case ECORE_LL2_QUEUE:
2710 *p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
2712 case ECORE_RDMA_CNQ_RAM:
2713 case ECORE_CMDQS_CQS:
2714 /* CNQ/CMDQS are the same resource */
2716 *p_resc_num = (NUM_OF_GLOBAL_QUEUES / 2) / num_funcs;
2718 case ECORE_RDMA_STATS_QUEUE:
2720 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2721 MAX_NUM_VPORTS_BB) / num_funcs;
2738 /* Since we want its value to reflect whether MFW supports
2739 * the new scheme, have a default of 0.
2744 *p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
2748 return ECORE_SUCCESS;
2751 static enum _ecore_status_t
2752 __ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn, enum ecore_resources res_id,
2753 bool drv_resc_alloc)
2755 u32 dflt_resc_num = 0, dflt_resc_start = 0;
2756 u32 mcp_resp, *p_resc_num, *p_resc_start;
2757 enum _ecore_status_t rc;
2759 p_resc_num = &RESC_NUM(p_hwfn, res_id);
2760 p_resc_start = &RESC_START(p_hwfn, res_id);
2762 rc = ecore_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
2764 if (rc != ECORE_SUCCESS) {
2766 "Failed to get default amount for resource %d [%s]\n",
2767 res_id, ecore_hw_get_resc_name(res_id));
2772 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2773 *p_resc_num = dflt_resc_num;
2774 *p_resc_start = dflt_resc_start;
2779 rc = ecore_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
2780 &mcp_resp, p_resc_num, p_resc_start);
2781 if (rc != ECORE_SUCCESS) {
2782 DP_NOTICE(p_hwfn, true,
2783 "MFW response failure for an allocation request for"
2784 " resource %d [%s]\n",
2785 res_id, ecore_hw_get_resc_name(res_id));
2789 /* Default driver values are applied in the following cases:
2790 * - The resource allocation MB command is not supported by the MFW
2791 * - There is an internal error in the MFW while processing the request
2792 * - The resource ID is unknown to the MFW
2794 if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
2796 "Failed to receive allocation info for resource %d [%s]."
2797 " mcp_resp = 0x%x. Applying default values"
2799 res_id, ecore_hw_get_resc_name(res_id), mcp_resp,
2800 dflt_resc_num, dflt_resc_start);
2802 *p_resc_num = dflt_resc_num;
2803 *p_resc_start = dflt_resc_start;
2807 if ((*p_resc_num != dflt_resc_num ||
2808 *p_resc_start != dflt_resc_start) &&
2809 res_id != ECORE_SB) {
2811 "MFW allocation for resource %d [%s] differs from default values [%d,%d vs. %d,%d]%s\n",
2812 res_id, ecore_hw_get_resc_name(res_id), *p_resc_num,
2813 *p_resc_start, dflt_resc_num, dflt_resc_start,
2814 drv_resc_alloc ? " - Applying default values" : "");
2815 if (drv_resc_alloc) {
2816 *p_resc_num = dflt_resc_num;
2817 *p_resc_start = dflt_resc_start;
2821 return ECORE_SUCCESS;
2824 static enum _ecore_status_t ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn,
2825 bool drv_resc_alloc)
2827 enum _ecore_status_t rc;
2830 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
2831 rc = __ecore_hw_set_resc_info(p_hwfn, res_id, drv_resc_alloc);
2832 if (rc != ECORE_SUCCESS)
2836 return ECORE_SUCCESS;
2839 #define ECORE_RESC_ALLOC_LOCK_RETRY_CNT 10
2840 #define ECORE_RESC_ALLOC_LOCK_RETRY_INTVL_US 10000 /* 10 msec */
2842 static enum _ecore_status_t ecore_hw_get_resc(struct ecore_hwfn *p_hwfn,
2843 struct ecore_ptt *p_ptt,
2844 bool drv_resc_alloc)
2846 struct ecore_resc_unlock_params resc_unlock_params;
2847 struct ecore_resc_lock_params resc_lock_params;
2848 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2850 enum _ecore_status_t rc;
2852 u32 *resc_start = p_hwfn->hw_info.resc_start;
2853 u32 *resc_num = p_hwfn->hw_info.resc_num;
2854 /* For AH, an equal share of the ILT lines between the maximal number of
2855 * PFs is not enough for RoCE. This would be solved by the future
2856 * resource allocation scheme, but isn't currently present for
2857 * FPGA/emulation. For now we keep a number that is sufficient for RoCE
2858 * to work - the BB number of ILT lines divided by its max PFs number.
2860 u32 roce_min_ilt_lines = PXP_NUM_ILT_RECORDS_BB / MAX_NUM_PFS_BB;
2863 /* Setting the max values of the soft resources and the following
2864 * resources allocation queries should be atomic. Since several PFs can
2865 * run in parallel - a resource lock is needed.
2866 * If either the resource lock or resource set value commands are not
2867 * supported - skip the the max values setting, release the lock if
2868 * needed, and proceed to the queries. Other failures, including a
2869 * failure to acquire the lock, will cause this function to fail.
2870 * Old drivers that don't acquire the lock can run in parallel, and
2871 * their allocation values won't be affected by the updated max values.
2873 OSAL_MEM_ZERO(&resc_lock_params, sizeof(resc_lock_params));
2874 resc_lock_params.resource = ECORE_RESC_LOCK_RESC_ALLOC;
2875 resc_lock_params.retry_num = ECORE_RESC_ALLOC_LOCK_RETRY_CNT;
2876 resc_lock_params.retry_interval = ECORE_RESC_ALLOC_LOCK_RETRY_INTVL_US;
2877 resc_lock_params.sleep_b4_retry = true;
2878 OSAL_MEM_ZERO(&resc_unlock_params, sizeof(resc_unlock_params));
2879 resc_unlock_params.resource = ECORE_RESC_LOCK_RESC_ALLOC;
2881 rc = ecore_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
2882 if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
2884 } else if (rc == ECORE_NOTIMPL) {
2886 "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
2887 } else if (rc == ECORE_SUCCESS && !resc_lock_params.b_granted) {
2888 DP_NOTICE(p_hwfn, false,
2889 "Failed to acquire the resource lock for the resource allocation commands\n");
2891 goto unlock_and_exit;
2893 rc = ecore_hw_set_soft_resc_size(p_hwfn, p_ptt);
2894 if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
2895 DP_NOTICE(p_hwfn, false,
2896 "Failed to set the max values of the soft resources\n");
2897 goto unlock_and_exit;
2898 } else if (rc == ECORE_NOTIMPL) {
2900 "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
2901 rc = ecore_mcp_resc_unlock(p_hwfn, p_ptt,
2902 &resc_unlock_params);
2903 if (rc != ECORE_SUCCESS)
2905 "Failed to release the resource lock for the resource allocation commands\n");
2909 rc = ecore_hw_set_resc_info(p_hwfn, drv_resc_alloc);
2910 if (rc != ECORE_SUCCESS)
2911 goto unlock_and_exit;
2913 if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
2914 rc = ecore_mcp_resc_unlock(p_hwfn, p_ptt,
2915 &resc_unlock_params);
2916 if (rc != ECORE_SUCCESS)
2918 "Failed to release the resource lock for the resource allocation commands\n");
2922 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2923 /* Reduced build contains less PQs */
2924 if (!(p_hwfn->p_dev->b_is_emul_full)) {
2925 resc_num[ECORE_PQ] = 32;
2926 resc_start[ECORE_PQ] = resc_num[ECORE_PQ] *
2927 p_hwfn->enabled_func_idx;
2930 /* For AH emulation, since we have a possible maximal number of
2931 * 16 enabled PFs, in case there are not enough ILT lines -
2932 * allocate only first PF as RoCE and have all the other ETH
2933 * only with less ILT lines.
2935 if (!p_hwfn->rel_pf_id && p_hwfn->p_dev->b_is_emul_full)
2936 resc_num[ECORE_ILT] = OSAL_MAX_T(u32,
2937 resc_num[ECORE_ILT],
2938 roce_min_ilt_lines);
2941 /* Correct the common ILT calculation if PF0 has more */
2942 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev) &&
2943 p_hwfn->p_dev->b_is_emul_full &&
2944 p_hwfn->rel_pf_id && resc_num[ECORE_ILT] < roce_min_ilt_lines)
2945 resc_start[ECORE_ILT] += roce_min_ilt_lines -
2946 resc_num[ECORE_ILT];
2949 /* Sanity for ILT */
2950 if ((b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2951 (!b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
2952 DP_NOTICE(p_hwfn, true,
2953 "Can't assign ILT pages [%08x,...,%08x]\n",
2954 RESC_START(p_hwfn, ECORE_ILT), RESC_END(p_hwfn,
2960 /* This will also learn the number of SBs from MFW */
2961 if (ecore_int_igu_reset_cam(p_hwfn, p_ptt))
2964 ecore_hw_set_feat(p_hwfn);
2966 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2967 "The numbers for each resource are:\n");
2968 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++)
2969 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE, "%s = %d start = %d\n",
2970 ecore_hw_get_resc_name(res_id),
2971 RESC_NUM(p_hwfn, res_id),
2972 RESC_START(p_hwfn, res_id));
2974 return ECORE_SUCCESS;
2977 if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
2978 ecore_mcp_resc_unlock(p_hwfn, p_ptt,
2979 &resc_unlock_params);
2983 static enum _ecore_status_t
2984 ecore_hw_get_nvm_info(struct ecore_hwfn *p_hwfn,
2985 struct ecore_ptt *p_ptt,
2986 struct ecore_hw_prepare_params *p_params)
2988 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg, dcbx_mode;
2989 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
2990 struct ecore_mcp_link_capabilities *p_caps;
2991 struct ecore_mcp_link_params *link;
2992 enum _ecore_status_t rc;
2994 /* Read global nvm_cfg address */
2995 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2997 /* Verify MCP has initialized it */
2998 if (!nvm_cfg_addr) {
2999 DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
3000 if (p_params->b_relaxed_probe)
3001 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_NVM;
3005 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
3007 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
3009 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3010 OFFSETOF(struct nvm_cfg1, glob) + OFFSETOF(struct nvm_cfg1_glob,
3013 core_cfg = ecore_rd(p_hwfn, p_ptt, addr);
3015 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
3016 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
3017 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
3018 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X40G;
3020 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
3021 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X50G;
3023 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
3024 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X100G;
3026 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
3027 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_F;
3029 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
3030 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_E;
3032 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
3033 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X20G;
3035 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
3036 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X40G;
3038 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
3039 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X25G;
3041 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
3042 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X10G;
3044 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
3045 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X25G;
3047 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
3048 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X25G;
3051 DP_NOTICE(p_hwfn, true, "Unknown port mode in 0x%08x\n",
3056 /* Read DCBX configuration */
3057 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3058 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
3059 dcbx_mode = ecore_rd(p_hwfn, p_ptt,
3061 OFFSETOF(struct nvm_cfg1_port, generic_cont0));
3062 dcbx_mode = (dcbx_mode & NVM_CFG1_PORT_DCBX_MODE_MASK)
3063 >> NVM_CFG1_PORT_DCBX_MODE_OFFSET;
3064 switch (dcbx_mode) {
3065 case NVM_CFG1_PORT_DCBX_MODE_DYNAMIC:
3066 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DYNAMIC;
3068 case NVM_CFG1_PORT_DCBX_MODE_CEE:
3069 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_CEE;
3071 case NVM_CFG1_PORT_DCBX_MODE_IEEE:
3072 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_IEEE;
3075 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DISABLED;
3078 /* Read default link configuration */
3079 link = &p_hwfn->mcp_info->link_input;
3080 p_caps = &p_hwfn->mcp_info->link_capabilities;
3081 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3082 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
3083 link_temp = ecore_rd(p_hwfn, p_ptt,
3085 OFFSETOF(struct nvm_cfg1_port, speed_cap_mask));
3086 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
3087 link->speed.advertised_speeds = link_temp;
3088 p_caps->speed_capabilities = link->speed.advertised_speeds;
3090 link_temp = ecore_rd(p_hwfn, p_ptt,
3092 OFFSETOF(struct nvm_cfg1_port, link_settings));
3093 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
3094 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
3095 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
3096 link->speed.autoneg = true;
3098 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
3099 link->speed.forced_speed = 1000;
3101 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
3102 link->speed.forced_speed = 10000;
3104 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
3105 link->speed.forced_speed = 25000;
3107 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
3108 link->speed.forced_speed = 40000;
3110 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
3111 link->speed.forced_speed = 50000;
3113 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
3114 link->speed.forced_speed = 100000;
3117 DP_NOTICE(p_hwfn, true, "Unknown Speed in 0x%08x\n", link_temp);
3120 p_caps->default_speed = link->speed.forced_speed;
3121 p_caps->default_speed_autoneg = link->speed.autoneg;
3123 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
3124 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
3125 link->pause.autoneg = !!(link_temp &
3126 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
3127 link->pause.forced_rx = !!(link_temp &
3128 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
3129 link->pause.forced_tx = !!(link_temp &
3130 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
3131 link->loopback_mode = 0;
3133 if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) {
3134 link_temp = ecore_rd(p_hwfn, p_ptt, port_cfg_addr +
3135 OFFSETOF(struct nvm_cfg1_port, ext_phy));
3136 link_temp &= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_MASK;
3137 link_temp >>= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_OFFSET;
3138 p_caps->default_eee = ECORE_MCP_EEE_ENABLED;
3139 link->eee.enable = true;
3140 switch (link_temp) {
3141 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_DISABLED:
3142 p_caps->default_eee = ECORE_MCP_EEE_DISABLED;
3143 link->eee.enable = false;
3145 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_BALANCED:
3146 p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_BALANCED_TIME;
3148 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_AGGRESSIVE:
3149 p_caps->eee_lpi_timer =
3150 EEE_TX_TIMER_USEC_AGGRESSIVE_TIME;
3152 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_LOW_LATENCY:
3153 p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_LATENCY_TIME;
3157 link->eee.tx_lpi_timer = p_caps->eee_lpi_timer;
3158 link->eee.tx_lpi_enable = link->eee.enable;
3159 link->eee.adv_caps = ECORE_EEE_1G_ADV | ECORE_EEE_10G_ADV;
3161 p_caps->default_eee = ECORE_MCP_EEE_UNSUPPORTED;
3164 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3165 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n EEE: %02x [%08x usec]",
3166 link->speed.forced_speed, link->speed.advertised_speeds,
3167 link->speed.autoneg, link->pause.autoneg,
3168 p_caps->default_eee, p_caps->eee_lpi_timer);
3170 /* Read Multi-function information from shmem */
3171 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3172 OFFSETOF(struct nvm_cfg1, glob) +
3173 OFFSETOF(struct nvm_cfg1_glob, generic_cont0);
3175 generic_cont0 = ecore_rd(p_hwfn, p_ptt, addr);
3177 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
3178 NVM_CFG1_GLOB_MF_MODE_OFFSET;
3181 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
3182 p_hwfn->p_dev->mf_mode = ECORE_MF_OVLAN;
3184 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
3185 p_hwfn->p_dev->mf_mode = ECORE_MF_NPAR;
3187 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
3188 p_hwfn->p_dev->mf_mode = ECORE_MF_DEFAULT;
3191 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
3192 p_hwfn->p_dev->mf_mode);
3194 /* Read Multi-function information from shmem */
3195 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3196 OFFSETOF(struct nvm_cfg1, glob) +
3197 OFFSETOF(struct nvm_cfg1_glob, device_capabilities);
3199 device_capabilities = ecore_rd(p_hwfn, p_ptt, addr);
3200 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
3201 OSAL_SET_BIT(ECORE_DEV_CAP_ETH,
3202 &p_hwfn->hw_info.device_capabilities);
3203 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
3204 OSAL_SET_BIT(ECORE_DEV_CAP_FCOE,
3205 &p_hwfn->hw_info.device_capabilities);
3206 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
3207 OSAL_SET_BIT(ECORE_DEV_CAP_ISCSI,
3208 &p_hwfn->hw_info.device_capabilities);
3209 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
3210 OSAL_SET_BIT(ECORE_DEV_CAP_ROCE,
3211 &p_hwfn->hw_info.device_capabilities);
3212 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_IWARP)
3213 OSAL_SET_BIT(ECORE_DEV_CAP_IWARP,
3214 &p_hwfn->hw_info.device_capabilities);
3216 rc = ecore_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
3217 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3219 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3225 static void ecore_get_num_funcs(struct ecore_hwfn *p_hwfn,
3226 struct ecore_ptt *p_ptt)
3228 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
3229 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
3230 struct ecore_dev *p_dev = p_hwfn->p_dev;
3232 num_funcs = ECORE_IS_AH(p_dev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
3234 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
3235 * in the other bits are selected.
3236 * Bits 1-15 are for functions 1-15, respectively, and their value is
3237 * '0' only for enabled functions (function 0 always exists and
3239 * In case of CMT in BB, only the "even" functions are enabled, and thus
3240 * the number of functions for both hwfns is learnt from the same bits.
3242 if (ECORE_IS_BB(p_dev) || ECORE_IS_AH(p_dev)) {
3243 reg_function_hide = ecore_rd(p_hwfn, p_ptt,
3244 MISCS_REG_FUNCTION_HIDE_BB_K2);
3246 reg_function_hide = 0;
3249 if (reg_function_hide & 0x1) {
3250 if (ECORE_IS_BB(p_dev)) {
3251 if (ECORE_PATH_ID(p_hwfn) && p_dev->num_hwfns == 1) {
3263 /* Get the number of the enabled functions on the engine */
3264 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
3271 /* Get the PF index within the enabled functions */
3272 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
3273 tmp = reg_function_hide & eng_mask & low_pfs_mask;
3281 p_hwfn->num_funcs_on_engine = num_funcs;
3282 p_hwfn->enabled_func_idx = enabled_func_idx;
3285 if (CHIP_REV_IS_FPGA(p_dev)) {
3286 DP_NOTICE(p_hwfn, false,
3287 "FPGA: Limit number of PFs to 4 [would affect resource allocation, needed for IOV]\n");
3288 p_hwfn->num_funcs_on_engine = 4;
3292 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
3293 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
3294 p_hwfn->rel_pf_id, p_hwfn->abs_pf_id,
3295 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
3298 static void ecore_hw_info_port_num_bb(struct ecore_hwfn *p_hwfn,
3299 struct ecore_ptt *p_ptt)
3304 /* Read the port mode */
3305 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
3307 else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) &&
3308 (p_hwfn->p_dev->num_hwfns > 1))
3309 /* In CMT on emulation, assume 1 port */
3313 port_mode = ecore_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
3315 if (port_mode < 3) {
3316 p_hwfn->p_dev->num_ports_in_engines = 1;
3317 } else if (port_mode <= 5) {
3318 p_hwfn->p_dev->num_ports_in_engines = 2;
3320 DP_NOTICE(p_hwfn, true, "PORT MODE: %d not supported\n",
3321 p_hwfn->p_dev->num_ports_in_engines);
3323 /* Default num_ports_in_engines to something */
3324 p_hwfn->p_dev->num_ports_in_engines = 1;
3328 static void ecore_hw_info_port_num_ah_e5(struct ecore_hwfn *p_hwfn,
3329 struct ecore_ptt *p_ptt)
3334 p_hwfn->p_dev->num_ports_in_engines = 0;
3337 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
3338 port = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
3339 switch ((port & 0xf000) >> 12) {
3341 p_hwfn->p_dev->num_ports_in_engines = 1;
3344 p_hwfn->p_dev->num_ports_in_engines = 2;
3347 p_hwfn->p_dev->num_ports_in_engines = 4;
3350 DP_NOTICE(p_hwfn, false,
3351 "Unknown port mode in ECO_RESERVED %08x\n",
3356 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
3357 port = ecore_rd(p_hwfn, p_ptt,
3358 CNIG_REG_NIG_PORT0_CONF_K2_E5 +
3361 p_hwfn->p_dev->num_ports_in_engines++;
3365 static void ecore_hw_info_port_num(struct ecore_hwfn *p_hwfn,
3366 struct ecore_ptt *p_ptt)
3368 if (ECORE_IS_BB(p_hwfn->p_dev))
3369 ecore_hw_info_port_num_bb(p_hwfn, p_ptt);
3371 ecore_hw_info_port_num_ah_e5(p_hwfn, p_ptt);
3374 static void ecore_mcp_get_eee_caps(struct ecore_hwfn *p_hwfn,
3375 struct ecore_ptt *p_ptt)
3377 struct ecore_mcp_link_capabilities *p_caps;
3380 p_caps = &p_hwfn->mcp_info->link_capabilities;
3381 if (p_caps->default_eee == ECORE_MCP_EEE_UNSUPPORTED)
3384 p_caps->eee_speed_caps = 0;
3385 eee_status = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
3386 OFFSETOF(struct public_port, eee_status));
3387 eee_status = (eee_status & EEE_SUPPORTED_SPEED_MASK) >>
3388 EEE_SUPPORTED_SPEED_OFFSET;
3389 if (eee_status & EEE_1G_SUPPORTED)
3390 p_caps->eee_speed_caps |= ECORE_EEE_1G_ADV;
3391 if (eee_status & EEE_10G_ADV)
3392 p_caps->eee_speed_caps |= ECORE_EEE_10G_ADV;
3395 static enum _ecore_status_t
3396 ecore_get_hw_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3397 enum ecore_pci_personality personality,
3398 struct ecore_hw_prepare_params *p_params)
3400 bool drv_resc_alloc = p_params->drv_resc_alloc;
3401 enum _ecore_status_t rc;
3403 /* Since all information is common, only first hwfns should do this */
3404 if (IS_LEAD_HWFN(p_hwfn)) {
3405 rc = ecore_iov_hw_info(p_hwfn);
3406 if (rc != ECORE_SUCCESS) {
3407 if (p_params->b_relaxed_probe)
3408 p_params->p_relaxed_res =
3409 ECORE_HW_PREPARE_BAD_IOV;
3415 /* TODO In get_hw_info, amoungst others:
3416 * Get MCP FW revision and determine according to it the supported
3417 * featrues (e.g. DCB)
3419 * ecore_get_pcie_width_speed, WOL capability.
3420 * Number of global CQ-s (for storage
3422 ecore_hw_info_port_num(p_hwfn, p_ptt);
3424 ecore_mcp_get_capabilities(p_hwfn, p_ptt);
3427 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev)) {
3429 rc = ecore_hw_get_nvm_info(p_hwfn, p_ptt, p_params);
3430 if (rc != ECORE_SUCCESS)
3436 rc = ecore_int_igu_read_cam(p_hwfn, p_ptt);
3437 if (rc != ECORE_SUCCESS) {
3438 if (p_params->b_relaxed_probe)
3439 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_IGU;
3445 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev) && ecore_mcp_is_init(p_hwfn)) {
3447 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr,
3448 p_hwfn->mcp_info->func_info.mac, ETH_ALEN);
3451 static u8 mcp_hw_mac[6] = { 0, 2, 3, 4, 5, 6 };
3453 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr, mcp_hw_mac, ETH_ALEN);
3454 p_hwfn->hw_info.hw_mac_addr[5] = p_hwfn->abs_pf_id;
3458 if (ecore_mcp_is_init(p_hwfn)) {
3459 if (p_hwfn->mcp_info->func_info.ovlan != ECORE_MCP_VLAN_UNSET)
3460 p_hwfn->hw_info.ovlan =
3461 p_hwfn->mcp_info->func_info.ovlan;
3463 ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
3465 ecore_mcp_get_eee_caps(p_hwfn, p_ptt);
3468 if (personality != ECORE_PCI_DEFAULT) {
3469 p_hwfn->hw_info.personality = personality;
3470 } else if (ecore_mcp_is_init(p_hwfn)) {
3471 enum ecore_pci_personality protocol;
3473 protocol = p_hwfn->mcp_info->func_info.protocol;
3474 p_hwfn->hw_info.personality = protocol;
3478 /* To overcome ILT lack for emulation, until at least until we'll have
3479 * a definite answer from system about it, allow only PF0 to be RoCE.
3481 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev)) {
3482 if (!p_hwfn->rel_pf_id)
3483 p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
3485 p_hwfn->hw_info.personality = ECORE_PCI_ETH;
3489 /* although in BB some constellations may support more than 4 tcs,
3490 * that can result in performance penalty in some cases. 4
3491 * represents a good tradeoff between performance and flexibility.
3493 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
3495 /* start out with a single active tc. This can be increased either
3496 * by dcbx negotiation or by upper layer driver
3498 p_hwfn->hw_info.num_active_tc = 1;
3500 ecore_get_num_funcs(p_hwfn, p_ptt);
3502 if (ecore_mcp_is_init(p_hwfn))
3503 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
3505 /* In case of forcing the driver's default resource allocation, calling
3506 * ecore_hw_get_resc() should come after initializing the personality
3507 * and after getting the number of functions, since the calculation of
3508 * the resources/features depends on them.
3509 * This order is not harmful if not forcing.
3511 rc = ecore_hw_get_resc(p_hwfn, p_ptt, drv_resc_alloc);
3512 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3514 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3520 static enum _ecore_status_t ecore_get_dev_info(struct ecore_hwfn *p_hwfn,
3521 struct ecore_ptt *p_ptt)
3523 struct ecore_dev *p_dev = p_hwfn->p_dev;
3527 /* Read Vendor Id / Device Id */
3528 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_VENDOR_ID_OFFSET,
3530 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_DEVICE_ID_OFFSET,
3533 /* Determine type */
3534 device_id_mask = p_dev->device_id & ECORE_DEV_ID_MASK;
3535 switch (device_id_mask) {
3536 case ECORE_DEV_ID_MASK_BB:
3537 p_dev->type = ECORE_DEV_TYPE_BB;
3539 case ECORE_DEV_ID_MASK_AH:
3540 p_dev->type = ECORE_DEV_TYPE_AH;
3543 DP_NOTICE(p_hwfn, true, "Unknown device id 0x%x\n",
3545 return ECORE_ABORTED;
3548 p_dev->chip_num = (u16)ecore_rd(p_hwfn, p_ptt,
3549 MISCS_REG_CHIP_NUM);
3550 p_dev->chip_rev = (u16)ecore_rd(p_hwfn, p_ptt,
3551 MISCS_REG_CHIP_REV);
3553 MASK_FIELD(CHIP_REV, p_dev->chip_rev);
3555 /* Learn number of HW-functions */
3556 tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
3558 if (tmp & (1 << p_hwfn->rel_pf_id)) {
3559 DP_NOTICE(p_dev->hwfns, false, "device in CMT mode\n");
3560 p_dev->num_hwfns = 2;
3562 p_dev->num_hwfns = 1;
3566 if (CHIP_REV_IS_EMUL(p_dev)) {
3567 /* For some reason we have problems with this register
3568 * in B0 emulation; Simply assume no CMT
3570 DP_NOTICE(p_dev->hwfns, false,
3571 "device on emul - assume no CMT\n");
3572 p_dev->num_hwfns = 1;
3576 p_dev->chip_bond_id = ecore_rd(p_hwfn, p_ptt,
3577 MISCS_REG_CHIP_TEST_REG) >> 4;
3578 MASK_FIELD(CHIP_BOND_ID, p_dev->chip_bond_id);
3579 p_dev->chip_metal = (u16)ecore_rd(p_hwfn, p_ptt,
3580 MISCS_REG_CHIP_METAL);
3581 MASK_FIELD(CHIP_METAL, p_dev->chip_metal);
3582 DP_INFO(p_dev->hwfns,
3583 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
3584 ECORE_IS_BB(p_dev) ? "BB" : "AH",
3585 'A' + p_dev->chip_rev, (int)p_dev->chip_metal,
3586 p_dev->chip_num, p_dev->chip_rev, p_dev->chip_bond_id,
3589 if (ECORE_IS_BB(p_dev) && CHIP_REV_IS_A0(p_dev)) {
3590 DP_NOTICE(p_dev->hwfns, false,
3591 "The chip type/rev (BB A0) is not supported!\n");
3592 return ECORE_ABORTED;
3595 if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_AH(p_dev))
3596 ecore_wr(p_hwfn, p_ptt, MISCS_REG_PLL_MAIN_CTRL_4, 0x1);
3598 if (CHIP_REV_IS_EMUL(p_dev)) {
3599 tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
3600 if (tmp & (1 << 29)) {
3601 DP_NOTICE(p_hwfn, false,
3602 "Emulation: Running on a FULL build\n");
3603 p_dev->b_is_emul_full = true;
3605 DP_NOTICE(p_hwfn, false,
3606 "Emulation: Running on a REDUCED build\n");
3611 return ECORE_SUCCESS;
3614 #ifndef LINUX_REMOVE
3615 void ecore_prepare_hibernate(struct ecore_dev *p_dev)
3622 for_each_hwfn(p_dev, j) {
3623 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
3625 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
3626 "Mark hw/fw uninitialized\n");
3628 p_hwfn->hw_init_done = false;
3629 p_hwfn->first_on_engine = false;
3631 ecore_ptt_invalidate(p_hwfn);
3636 static enum _ecore_status_t
3637 ecore_hw_prepare_single(struct ecore_hwfn *p_hwfn,
3638 void OSAL_IOMEM * p_regview,
3639 void OSAL_IOMEM * p_doorbells,
3640 struct ecore_hw_prepare_params *p_params)
3642 struct ecore_mdump_retain_data mdump_retain;
3643 struct ecore_dev *p_dev = p_hwfn->p_dev;
3644 struct ecore_mdump_info mdump_info;
3645 enum _ecore_status_t rc = ECORE_SUCCESS;
3647 /* Split PCI bars evenly between hwfns */
3648 p_hwfn->regview = p_regview;
3649 p_hwfn->doorbells = p_doorbells;
3652 return ecore_vf_hw_prepare(p_hwfn);
3654 /* Validate that chip access is feasible */
3655 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
3657 "Reading the ME register returns all Fs; Preventing further chip access\n");
3658 if (p_params->b_relaxed_probe)
3659 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_ME;
3663 get_function_id(p_hwfn);
3665 /* Allocate PTT pool */
3666 rc = ecore_ptt_pool_alloc(p_hwfn);
3668 DP_NOTICE(p_hwfn, true, "Failed to prepare hwfn's hw\n");
3669 if (p_params->b_relaxed_probe)
3670 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3674 /* Allocate the main PTT */
3675 p_hwfn->p_main_ptt = ecore_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
3677 /* First hwfn learns basic information, e.g., number of hwfns */
3678 if (!p_hwfn->my_id) {
3679 rc = ecore_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
3680 if (rc != ECORE_SUCCESS) {
3681 if (p_params->b_relaxed_probe)
3682 p_params->p_relaxed_res =
3683 ECORE_HW_PREPARE_FAILED_DEV;
3688 ecore_hw_hwfn_prepare(p_hwfn);
3690 /* Initialize MCP structure */
3691 rc = ecore_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
3693 DP_NOTICE(p_hwfn, true, "Failed initializing mcp command\n");
3694 if (p_params->b_relaxed_probe)
3695 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3699 /* Read the device configuration information from the HW and SHMEM */
3700 rc = ecore_get_hw_info(p_hwfn, p_hwfn->p_main_ptt,
3701 p_params->personality, p_params);
3703 DP_NOTICE(p_hwfn, true, "Failed to get HW information\n");
3707 /* Sending a mailbox to the MFW should be after ecore_get_hw_info() is
3708 * called, since among others it sets the ports number in an engine.
3710 if (p_params->initiate_pf_flr && IS_LEAD_HWFN(p_hwfn) &&
3711 !p_dev->recov_in_prog) {
3712 rc = ecore_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
3713 if (rc != ECORE_SUCCESS)
3714 DP_NOTICE(p_hwfn, false, "Failed to initiate PF FLR\n");
3717 /* Check if mdump logs/data are present and update the epoch value */
3718 if (IS_LEAD_HWFN(p_hwfn)) {
3720 if (!CHIP_REV_IS_EMUL(p_dev)) {
3722 rc = ecore_mcp_mdump_get_info(p_hwfn, p_hwfn->p_main_ptt,
3724 if (rc == ECORE_SUCCESS && mdump_info.num_of_logs)
3725 DP_NOTICE(p_hwfn, false,
3726 "* * * IMPORTANT - HW ERROR register dump captured by device * * *\n");
3728 rc = ecore_mcp_mdump_get_retain(p_hwfn, p_hwfn->p_main_ptt,
3730 if (rc == ECORE_SUCCESS && mdump_retain.valid)
3731 DP_NOTICE(p_hwfn, false,
3732 "mdump retained data: epoch 0x%08x, pf 0x%x, status 0x%08x\n",
3733 mdump_retain.epoch, mdump_retain.pf,
3734 mdump_retain.status);
3736 ecore_mcp_mdump_set_values(p_hwfn, p_hwfn->p_main_ptt,
3743 /* Allocate the init RT array and initialize the init-ops engine */
3744 rc = ecore_init_alloc(p_hwfn);
3746 DP_NOTICE(p_hwfn, true, "Failed to allocate the init array\n");
3747 if (p_params->b_relaxed_probe)
3748 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3752 if (CHIP_REV_IS_FPGA(p_dev)) {
3753 DP_NOTICE(p_hwfn, false,
3754 "FPGA: workaround; Prevent DMAE parities\n");
3755 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PCIE_REG_PRTY_MASK_K2_E5,
3758 DP_NOTICE(p_hwfn, false,
3759 "FPGA: workaround: Set VF bar0 size\n");
3760 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
3761 PGLUE_B_REG_VF_BAR0_SIZE_K2_E5, 4);
3767 if (IS_LEAD_HWFN(p_hwfn))
3768 ecore_iov_free_hw_info(p_dev);
3769 ecore_mcp_free(p_hwfn);
3771 ecore_hw_hwfn_free(p_hwfn);
3776 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
3777 struct ecore_hw_prepare_params *p_params)
3779 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3780 enum _ecore_status_t rc;
3782 p_dev->chk_reg_fifo = p_params->chk_reg_fifo;
3783 p_dev->allow_mdump = p_params->allow_mdump;
3785 if (p_params->b_relaxed_probe)
3786 p_params->p_relaxed_res = ECORE_HW_PREPARE_SUCCESS;
3788 /* Store the precompiled init data ptrs */
3790 ecore_init_iro_array(p_dev);
3792 /* Initialize the first hwfn - will learn number of hwfns */
3793 rc = ecore_hw_prepare_single(p_hwfn,
3795 p_dev->doorbells, p_params);
3796 if (rc != ECORE_SUCCESS)
3799 p_params->personality = p_hwfn->hw_info.personality;
3801 /* initilalize 2nd hwfn if necessary */
3802 if (p_dev->num_hwfns > 1) {
3803 void OSAL_IOMEM *p_regview, *p_doorbell;
3804 u8 OSAL_IOMEM *addr;
3806 /* adjust bar offset for second engine */
3807 addr = (u8 OSAL_IOMEM *)p_dev->regview +
3808 ecore_hw_bar_size(p_hwfn,
3811 p_regview = (void OSAL_IOMEM *)addr;
3813 addr = (u8 OSAL_IOMEM *)p_dev->doorbells +
3814 ecore_hw_bar_size(p_hwfn,
3817 p_doorbell = (void OSAL_IOMEM *)addr;
3819 /* prepare second hw function */
3820 rc = ecore_hw_prepare_single(&p_dev->hwfns[1], p_regview,
3821 p_doorbell, p_params);
3823 /* in case of error, need to free the previously
3824 * initiliazed hwfn 0.
3826 if (rc != ECORE_SUCCESS) {
3827 if (p_params->b_relaxed_probe)
3828 p_params->p_relaxed_res =
3829 ECORE_HW_PREPARE_FAILED_ENG2;
3832 ecore_init_free(p_hwfn);
3833 ecore_mcp_free(p_hwfn);
3834 ecore_hw_hwfn_free(p_hwfn);
3836 DP_NOTICE(p_dev, true,
3837 "What do we need to free when VF hwfn1 init fails\n");
3846 void ecore_hw_remove(struct ecore_dev *p_dev)
3848 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3852 ecore_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
3853 ECORE_OV_DRIVER_STATE_NOT_LOADED);
3855 for_each_hwfn(p_dev, i) {
3856 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3859 ecore_vf_pf_release(p_hwfn);
3863 ecore_init_free(p_hwfn);
3864 ecore_hw_hwfn_free(p_hwfn);
3865 ecore_mcp_free(p_hwfn);
3867 #ifdef CONFIG_ECORE_LOCK_ALLOC
3868 OSAL_MUTEX_DEALLOC(&p_hwfn->dmae_info.mutex);
3872 ecore_iov_free_hw_info(p_dev);
3875 static void ecore_chain_free_next_ptr(struct ecore_dev *p_dev,
3876 struct ecore_chain *p_chain)
3878 void *p_virt = p_chain->p_virt_addr, *p_virt_next = OSAL_NULL;
3879 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3880 struct ecore_chain_next *p_next;
3886 size = p_chain->elem_size * p_chain->usable_per_page;
3888 for (i = 0; i < p_chain->page_cnt; i++) {
3892 p_next = (struct ecore_chain_next *)((u8 *)p_virt + size);
3893 p_virt_next = p_next->next_virt;
3894 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3896 OSAL_DMA_FREE_COHERENT(p_dev, p_virt, p_phys,
3897 ECORE_CHAIN_PAGE_SIZE);
3899 p_virt = p_virt_next;
3900 p_phys = p_phys_next;
3904 static void ecore_chain_free_single(struct ecore_dev *p_dev,
3905 struct ecore_chain *p_chain)
3907 if (!p_chain->p_virt_addr)
3910 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->p_virt_addr,
3911 p_chain->p_phys_addr, ECORE_CHAIN_PAGE_SIZE);
3914 static void ecore_chain_free_pbl(struct ecore_dev *p_dev,
3915 struct ecore_chain *p_chain)
3917 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3918 u8 *p_pbl_virt = (u8 *)p_chain->pbl_sp.p_virt_table;
3919 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
3921 if (!pp_virt_addr_tbl)
3927 for (i = 0; i < page_cnt; i++) {
3928 if (!pp_virt_addr_tbl[i])
3931 OSAL_DMA_FREE_COHERENT(p_dev, pp_virt_addr_tbl[i],
3932 *(dma_addr_t *)p_pbl_virt,
3933 ECORE_CHAIN_PAGE_SIZE);
3935 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
3938 pbl_size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
3940 if (!p_chain->b_external_pbl)
3941 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->pbl_sp.p_virt_table,
3942 p_chain->pbl_sp.p_phys_table, pbl_size);
3944 OSAL_VFREE(p_dev, p_chain->pbl.pp_virt_addr_tbl);
3947 void ecore_chain_free(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3949 switch (p_chain->mode) {
3950 case ECORE_CHAIN_MODE_NEXT_PTR:
3951 ecore_chain_free_next_ptr(p_dev, p_chain);
3953 case ECORE_CHAIN_MODE_SINGLE:
3954 ecore_chain_free_single(p_dev, p_chain);
3956 case ECORE_CHAIN_MODE_PBL:
3957 ecore_chain_free_pbl(p_dev, p_chain);
3962 static enum _ecore_status_t
3963 ecore_chain_alloc_sanity_check(struct ecore_dev *p_dev,
3964 enum ecore_chain_cnt_type cnt_type,
3965 osal_size_t elem_size, u32 page_cnt)
3967 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3969 /* The actual chain size can be larger than the maximal possible value
3970 * after rounding up the requested elements number to pages, and after
3971 * taking into acount the unusuable elements (next-ptr elements).
3972 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3973 * size/capacity fields are of a u32 type.
3975 if ((cnt_type == ECORE_CHAIN_CNT_TYPE_U16 &&
3976 chain_size > ((u32)ECORE_U16_MAX + 1)) ||
3977 (cnt_type == ECORE_CHAIN_CNT_TYPE_U32 &&
3978 chain_size > ECORE_U32_MAX)) {
3979 DP_NOTICE(p_dev, true,
3980 "The actual chain size (0x%lx) is larger than the maximal possible value\n",
3981 (unsigned long)chain_size);
3985 return ECORE_SUCCESS;
3988 static enum _ecore_status_t
3989 ecore_chain_alloc_next_ptr(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3991 void *p_virt = OSAL_NULL, *p_virt_prev = OSAL_NULL;
3992 dma_addr_t p_phys = 0;
3995 for (i = 0; i < p_chain->page_cnt; i++) {
3996 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
3997 ECORE_CHAIN_PAGE_SIZE);
3999 DP_NOTICE(p_dev, true,
4000 "Failed to allocate chain memory\n");
4005 ecore_chain_init_mem(p_chain, p_virt, p_phys);
4006 ecore_chain_reset(p_chain);
4008 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
4012 p_virt_prev = p_virt;
4014 /* Last page's next element should point to the beginning of the
4017 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
4018 p_chain->p_virt_addr,
4019 p_chain->p_phys_addr);
4021 return ECORE_SUCCESS;
4024 static enum _ecore_status_t
4025 ecore_chain_alloc_single(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
4027 dma_addr_t p_phys = 0;
4028 void *p_virt = OSAL_NULL;
4030 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys, ECORE_CHAIN_PAGE_SIZE);
4032 DP_NOTICE(p_dev, true, "Failed to allocate chain memory\n");
4036 ecore_chain_init_mem(p_chain, p_virt, p_phys);
4037 ecore_chain_reset(p_chain);
4039 return ECORE_SUCCESS;
4042 static enum _ecore_status_t
4043 ecore_chain_alloc_pbl(struct ecore_dev *p_dev,
4044 struct ecore_chain *p_chain,
4045 struct ecore_chain_ext_pbl *ext_pbl)
4047 void *p_virt = OSAL_NULL;
4048 u8 *p_pbl_virt = OSAL_NULL;
4049 void **pp_virt_addr_tbl = OSAL_NULL;
4050 dma_addr_t p_phys = 0, p_pbl_phys = 0;
4051 u32 page_cnt = p_chain->page_cnt, size, i;
4053 size = page_cnt * sizeof(*pp_virt_addr_tbl);
4054 pp_virt_addr_tbl = (void **)OSAL_VZALLOC(p_dev, size);
4055 if (!pp_virt_addr_tbl) {
4056 DP_NOTICE(p_dev, true,
4057 "Failed to allocate memory for the chain virtual addresses table\n");
4061 /* The allocation of the PBL table is done with its full size, since it
4062 * is expected to be successive.
4063 * ecore_chain_init_pbl_mem() is called even in a case of an allocation
4064 * failure, since pp_virt_addr_tbl was previously allocated, and it
4065 * should be saved to allow its freeing during the error flow.
4067 size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
4069 if (ext_pbl == OSAL_NULL) {
4070 p_pbl_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_pbl_phys, size);
4072 p_pbl_virt = ext_pbl->p_pbl_virt;
4073 p_pbl_phys = ext_pbl->p_pbl_phys;
4074 p_chain->b_external_pbl = true;
4077 ecore_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
4080 DP_NOTICE(p_dev, true, "Failed to allocate chain pbl memory\n");
4084 for (i = 0; i < page_cnt; i++) {
4085 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
4086 ECORE_CHAIN_PAGE_SIZE);
4088 DP_NOTICE(p_dev, true,
4089 "Failed to allocate chain memory\n");
4094 ecore_chain_init_mem(p_chain, p_virt, p_phys);
4095 ecore_chain_reset(p_chain);
4098 /* Fill the PBL table with the physical address of the page */
4099 *(dma_addr_t *)p_pbl_virt = p_phys;
4100 /* Keep the virtual address of the page */
4101 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
4103 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
4106 return ECORE_SUCCESS;
4109 enum _ecore_status_t ecore_chain_alloc(struct ecore_dev *p_dev,
4110 enum ecore_chain_use_mode intended_use,
4111 enum ecore_chain_mode mode,
4112 enum ecore_chain_cnt_type cnt_type,
4113 u32 num_elems, osal_size_t elem_size,
4114 struct ecore_chain *p_chain,
4115 struct ecore_chain_ext_pbl *ext_pbl)
4118 enum _ecore_status_t rc = ECORE_SUCCESS;
4120 if (mode == ECORE_CHAIN_MODE_SINGLE)
4123 page_cnt = ECORE_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
4125 rc = ecore_chain_alloc_sanity_check(p_dev, cnt_type, elem_size,
4128 DP_NOTICE(p_dev, true,
4129 "Cannot allocate a chain with the given arguments:\n"
4130 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
4131 intended_use, mode, cnt_type, num_elems, elem_size);
4135 ecore_chain_init_params(p_chain, page_cnt, (u8)elem_size, intended_use,
4136 mode, cnt_type, p_dev->dp_ctx);
4139 case ECORE_CHAIN_MODE_NEXT_PTR:
4140 rc = ecore_chain_alloc_next_ptr(p_dev, p_chain);
4142 case ECORE_CHAIN_MODE_SINGLE:
4143 rc = ecore_chain_alloc_single(p_dev, p_chain);
4145 case ECORE_CHAIN_MODE_PBL:
4146 rc = ecore_chain_alloc_pbl(p_dev, p_chain, ext_pbl);
4152 return ECORE_SUCCESS;
4155 ecore_chain_free(p_dev, p_chain);
4159 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
4160 u16 src_id, u16 *dst_id)
4162 if (src_id >= RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
4165 min = (u16)RESC_START(p_hwfn, ECORE_L2_QUEUE);
4166 max = min + RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
4167 DP_NOTICE(p_hwfn, true,
4168 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
4174 *dst_id = RESC_START(p_hwfn, ECORE_L2_QUEUE) + src_id;
4176 return ECORE_SUCCESS;
4179 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
4180 u8 src_id, u8 *dst_id)
4182 if (src_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
4185 min = (u8)RESC_START(p_hwfn, ECORE_VPORT);
4186 max = min + RESC_NUM(p_hwfn, ECORE_VPORT);
4187 DP_NOTICE(p_hwfn, true,
4188 "vport id [%d] is not valid, available indices [%d - %d]\n",
4194 *dst_id = RESC_START(p_hwfn, ECORE_VPORT) + src_id;
4196 return ECORE_SUCCESS;
4199 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
4200 u8 src_id, u8 *dst_id)
4202 if (src_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG)) {
4205 min = (u8)RESC_START(p_hwfn, ECORE_RSS_ENG);
4206 max = min + RESC_NUM(p_hwfn, ECORE_RSS_ENG);
4207 DP_NOTICE(p_hwfn, true,
4208 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
4214 *dst_id = RESC_START(p_hwfn, ECORE_RSS_ENG) + src_id;
4216 return ECORE_SUCCESS;
4219 static enum _ecore_status_t
4220 ecore_llh_add_mac_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4221 struct ecore_ptt *p_ptt, u32 high, u32 low,
4227 /* Find a free entry and utilize it */
4228 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4229 en = ecore_rd(p_hwfn, p_ptt,
4230 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4234 ecore_wr(p_hwfn, p_ptt,
4235 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4236 2 * i * sizeof(u32), low);
4237 ecore_wr(p_hwfn, p_ptt,
4238 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4239 (2 * i + 1) * sizeof(u32), high);
4240 ecore_wr(p_hwfn, p_ptt,
4241 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4242 i * sizeof(u32), 0);
4243 ecore_wr(p_hwfn, p_ptt,
4244 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4245 i * sizeof(u32), 0);
4246 ecore_wr(p_hwfn, p_ptt,
4247 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4248 i * sizeof(u32), 1);
4252 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4253 return ECORE_NORESOURCES;
4257 return ECORE_SUCCESS;
4260 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
4261 struct ecore_ptt *p_ptt, u8 *p_filter)
4263 u32 high, low, entry_num;
4264 enum _ecore_status_t rc;
4266 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4267 return ECORE_SUCCESS;
4269 high = p_filter[1] | (p_filter[0] << 8);
4270 low = p_filter[5] | (p_filter[4] << 8) |
4271 (p_filter[3] << 16) | (p_filter[2] << 24);
4273 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4274 rc = ecore_llh_add_mac_filter_bb_ah(p_hwfn, p_ptt, high, low,
4276 if (rc != ECORE_SUCCESS) {
4277 DP_NOTICE(p_hwfn, false,
4278 "Failed to find an empty LLH filter to utilize\n");
4282 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4283 "MAC: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx is added at %d\n",
4284 p_filter[0], p_filter[1], p_filter[2], p_filter[3],
4285 p_filter[4], p_filter[5], entry_num);
4287 return ECORE_SUCCESS;
4290 static enum _ecore_status_t
4291 ecore_llh_remove_mac_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4292 struct ecore_ptt *p_ptt, u32 high, u32 low,
4297 /* Find the entry and clean it */
4298 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4299 if (ecore_rd(p_hwfn, p_ptt,
4300 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4301 2 * i * sizeof(u32)) != low)
4303 if (ecore_rd(p_hwfn, p_ptt,
4304 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4305 (2 * i + 1) * sizeof(u32)) != high)
4308 ecore_wr(p_hwfn, p_ptt,
4309 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 0);
4310 ecore_wr(p_hwfn, p_ptt,
4311 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4312 2 * i * sizeof(u32), 0);
4313 ecore_wr(p_hwfn, p_ptt,
4314 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4315 (2 * i + 1) * sizeof(u32), 0);
4319 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4324 return ECORE_SUCCESS;
4327 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
4328 struct ecore_ptt *p_ptt, u8 *p_filter)
4330 u32 high, low, entry_num;
4331 enum _ecore_status_t rc;
4333 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4336 high = p_filter[1] | (p_filter[0] << 8);
4337 low = p_filter[5] | (p_filter[4] << 8) |
4338 (p_filter[3] << 16) | (p_filter[2] << 24);
4340 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4341 rc = ecore_llh_remove_mac_filter_bb_ah(p_hwfn, p_ptt, high,
4343 if (rc != ECORE_SUCCESS) {
4344 DP_NOTICE(p_hwfn, false,
4345 "Tried to remove a non-configured filter\n");
4350 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4351 "MAC: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx was removed from %d\n",
4352 p_filter[0], p_filter[1], p_filter[2], p_filter[3],
4353 p_filter[4], p_filter[5], entry_num);
4356 static enum _ecore_status_t
4357 ecore_llh_add_protocol_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4358 struct ecore_ptt *p_ptt,
4359 enum ecore_llh_port_filter_type_t type,
4360 u32 high, u32 low, u32 *p_entry_num)
4365 /* Find a free entry and utilize it */
4366 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4367 en = ecore_rd(p_hwfn, p_ptt,
4368 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4372 ecore_wr(p_hwfn, p_ptt,
4373 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4374 2 * i * sizeof(u32), low);
4375 ecore_wr(p_hwfn, p_ptt,
4376 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4377 (2 * i + 1) * sizeof(u32), high);
4378 ecore_wr(p_hwfn, p_ptt,
4379 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4380 i * sizeof(u32), 1);
4381 ecore_wr(p_hwfn, p_ptt,
4382 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4383 i * sizeof(u32), 1 << type);
4384 ecore_wr(p_hwfn, p_ptt,
4385 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 1);
4389 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4390 return ECORE_NORESOURCES;
4394 return ECORE_SUCCESS;
4397 enum _ecore_status_t
4398 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
4399 struct ecore_ptt *p_ptt,
4400 u16 source_port_or_eth_type,
4402 enum ecore_llh_port_filter_type_t type)
4404 u32 high, low, entry_num;
4405 enum _ecore_status_t rc;
4407 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4408 return ECORE_SUCCESS;
4414 case ECORE_LLH_FILTER_ETHERTYPE:
4415 high = source_port_or_eth_type;
4417 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4418 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4419 low = source_port_or_eth_type << 16;
4421 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4422 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4425 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4426 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4427 low = (source_port_or_eth_type << 16) | dest_port;
4430 DP_NOTICE(p_hwfn, true,
4431 "Non valid LLH protocol filter type %d\n", type);
4435 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4436 rc = ecore_llh_add_protocol_filter_bb_ah(p_hwfn, p_ptt, type,
4437 high, low, &entry_num);
4438 if (rc != ECORE_SUCCESS) {
4439 DP_NOTICE(p_hwfn, false,
4440 "Failed to find an empty LLH filter to utilize\n");
4444 case ECORE_LLH_FILTER_ETHERTYPE:
4445 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4446 "ETH type %x is added at %d\n",
4447 source_port_or_eth_type, entry_num);
4449 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4450 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4451 "TCP src port %x is added at %d\n",
4452 source_port_or_eth_type, entry_num);
4454 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4455 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4456 "UDP src port %x is added at %d\n",
4457 source_port_or_eth_type, entry_num);
4459 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4460 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4461 "TCP dst port %x is added at %d\n", dest_port,
4464 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4465 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4466 "UDP dst port %x is added at %d\n", dest_port,
4469 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4470 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4471 "TCP src/dst ports %x/%x are added at %d\n",
4472 source_port_or_eth_type, dest_port, entry_num);
4474 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4475 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4476 "UDP src/dst ports %x/%x are added at %d\n",
4477 source_port_or_eth_type, dest_port, entry_num);
4481 return ECORE_SUCCESS;
4484 static enum _ecore_status_t
4485 ecore_llh_remove_protocol_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4486 struct ecore_ptt *p_ptt,
4487 enum ecore_llh_port_filter_type_t type,
4488 u32 high, u32 low, u32 *p_entry_num)
4492 /* Find the entry and clean it */
4493 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4494 if (!ecore_rd(p_hwfn, p_ptt,
4495 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4498 if (!ecore_rd(p_hwfn, p_ptt,
4499 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4502 if (!(ecore_rd(p_hwfn, p_ptt,
4503 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4504 i * sizeof(u32)) & (1 << type)))
4506 if (ecore_rd(p_hwfn, p_ptt,
4507 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4508 2 * i * sizeof(u32)) != low)
4510 if (ecore_rd(p_hwfn, p_ptt,
4511 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4512 (2 * i + 1) * sizeof(u32)) != high)
4515 ecore_wr(p_hwfn, p_ptt,
4516 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 0);
4517 ecore_wr(p_hwfn, p_ptt,
4518 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4519 i * sizeof(u32), 0);
4520 ecore_wr(p_hwfn, p_ptt,
4521 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4522 i * sizeof(u32), 0);
4523 ecore_wr(p_hwfn, p_ptt,
4524 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4525 2 * i * sizeof(u32), 0);
4526 ecore_wr(p_hwfn, p_ptt,
4527 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4528 (2 * i + 1) * sizeof(u32), 0);
4532 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4537 return ECORE_SUCCESS;
4541 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
4542 struct ecore_ptt *p_ptt,
4543 u16 source_port_or_eth_type,
4545 enum ecore_llh_port_filter_type_t type)
4547 u32 high, low, entry_num;
4548 enum _ecore_status_t rc;
4550 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4557 case ECORE_LLH_FILTER_ETHERTYPE:
4558 high = source_port_or_eth_type;
4560 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4561 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4562 low = source_port_or_eth_type << 16;
4564 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4565 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4568 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4569 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4570 low = (source_port_or_eth_type << 16) | dest_port;
4573 DP_NOTICE(p_hwfn, true,
4574 "Non valid LLH protocol filter type %d\n", type);
4578 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4579 rc = ecore_llh_remove_protocol_filter_bb_ah(p_hwfn, p_ptt, type,
4582 if (rc != ECORE_SUCCESS) {
4583 DP_NOTICE(p_hwfn, false,
4584 "Tried to remove a non-configured filter [type %d, source_port_or_eth_type 0x%x, dest_port 0x%x]\n",
4585 type, source_port_or_eth_type, dest_port);
4589 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4590 "Protocol filter [type %d, source_port_or_eth_type 0x%x, dest_port 0x%x] was removed from %d\n",
4591 type, source_port_or_eth_type, dest_port, entry_num);
4594 static void ecore_llh_clear_all_filters_bb_ah(struct ecore_hwfn *p_hwfn,
4595 struct ecore_ptt *p_ptt)
4599 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4602 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4603 ecore_wr(p_hwfn, p_ptt,
4604 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4605 i * sizeof(u32), 0);
4606 ecore_wr(p_hwfn, p_ptt,
4607 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4608 2 * i * sizeof(u32), 0);
4609 ecore_wr(p_hwfn, p_ptt,
4610 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4611 (2 * i + 1) * sizeof(u32), 0);
4615 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
4616 struct ecore_ptt *p_ptt)
4618 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4621 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4622 ecore_llh_clear_all_filters_bb_ah(p_hwfn, p_ptt);
4625 enum _ecore_status_t
4626 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
4627 struct ecore_ptt *p_ptt)
4629 if (IS_MF_DEFAULT(p_hwfn) && ECORE_IS_BB(p_hwfn->p_dev)) {
4630 ecore_wr(p_hwfn, p_ptt,
4631 NIG_REG_LLH_TAGMAC_DEF_PF_VECTOR,
4632 1 << p_hwfn->abs_pf_id / 2);
4633 ecore_wr(p_hwfn, p_ptt, PRS_REG_MSG_INFO, 0);
4634 return ECORE_SUCCESS;
4637 DP_NOTICE(p_hwfn, false,
4638 "This function can't be set as default\n");
4642 static enum _ecore_status_t ecore_set_coalesce(struct ecore_hwfn *p_hwfn,
4643 struct ecore_ptt *p_ptt,
4644 u32 hw_addr, void *p_eth_qzone,
4645 osal_size_t eth_qzone_size,
4648 struct coalescing_timeset *p_coal_timeset;
4650 if (p_hwfn->p_dev->int_coalescing_mode != ECORE_COAL_MODE_ENABLE) {
4651 DP_NOTICE(p_hwfn, true,
4652 "Coalescing configuration not enabled\n");
4656 p_coal_timeset = p_eth_qzone;
4657 OSAL_MEMSET(p_eth_qzone, 0, eth_qzone_size);
4658 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
4659 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
4660 ecore_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
4662 return ECORE_SUCCESS;
4665 enum _ecore_status_t ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn,
4666 u16 rx_coal, u16 tx_coal,
4669 struct ecore_queue_cid *p_cid = (struct ecore_queue_cid *)p_handle;
4670 enum _ecore_status_t rc = ECORE_SUCCESS;
4671 struct ecore_ptt *p_ptt;
4673 /* TODO - Configuring a single queue's coalescing but
4674 * claiming all queues are abiding same configuration
4675 * for PF and VF both.
4678 if (IS_VF(p_hwfn->p_dev))
4679 return ecore_vf_pf_set_coalesce(p_hwfn, rx_coal,
4682 p_ptt = ecore_ptt_acquire(p_hwfn);
4687 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
4690 p_hwfn->p_dev->rx_coalesce_usecs = rx_coal;
4694 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
4697 p_hwfn->p_dev->tx_coalesce_usecs = tx_coal;
4700 ecore_ptt_release(p_hwfn, p_ptt);
4705 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
4706 struct ecore_ptt *p_ptt,
4708 struct ecore_queue_cid *p_cid)
4710 struct ustorm_eth_queue_zone eth_qzone;
4711 u8 timeset, timer_res;
4713 enum _ecore_status_t rc;
4715 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4716 if (coalesce <= 0x7F) {
4718 } else if (coalesce <= 0xFF) {
4720 } else if (coalesce <= 0x1FF) {
4723 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4726 timeset = (u8)(coalesce >> timer_res);
4728 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
4729 p_cid->sb_igu_id, false);
4730 if (rc != ECORE_SUCCESS)
4733 address = BAR0_MAP_REG_USDM_RAM +
4734 USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4736 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4737 sizeof(struct ustorm_eth_queue_zone), timeset);
4738 if (rc != ECORE_SUCCESS)
4745 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
4746 struct ecore_ptt *p_ptt,
4748 struct ecore_queue_cid *p_cid)
4750 struct xstorm_eth_queue_zone eth_qzone;
4751 u8 timeset, timer_res;
4753 enum _ecore_status_t rc;
4755 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4756 if (coalesce <= 0x7F) {
4758 } else if (coalesce <= 0xFF) {
4760 } else if (coalesce <= 0x1FF) {
4763 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4767 timeset = (u8)(coalesce >> timer_res);
4769 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
4770 p_cid->sb_igu_id, true);
4771 if (rc != ECORE_SUCCESS)
4774 address = BAR0_MAP_REG_XSDM_RAM +
4775 XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4777 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4778 sizeof(struct xstorm_eth_queue_zone), timeset);
4783 /* Calculate final WFQ values for all vports and configure it.
4784 * After this configuration each vport must have
4785 * approx min rate = vport_wfq * min_pf_rate / ECORE_WFQ_UNIT
4787 static void ecore_configure_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4788 struct ecore_ptt *p_ptt,
4791 struct init_qm_vport_params *vport_params;
4794 vport_params = p_hwfn->qm_info.qm_vport_params;
4796 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4797 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4799 vport_params[i].vport_wfq = (wfq_speed * ECORE_WFQ_UNIT) /
4801 ecore_init_vport_wfq(p_hwfn, p_ptt,
4802 vport_params[i].first_tx_pq_id,
4803 vport_params[i].vport_wfq);
4808 ecore_init_wfq_default_param(struct ecore_hwfn *p_hwfn, u32 min_pf_rate)
4812 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
4813 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
4816 static void ecore_disable_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4817 struct ecore_ptt *p_ptt,
4820 struct init_qm_vport_params *vport_params;
4823 vport_params = p_hwfn->qm_info.qm_vport_params;
4825 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4826 ecore_init_wfq_default_param(p_hwfn, min_pf_rate);
4827 ecore_init_vport_wfq(p_hwfn, p_ptt,
4828 vport_params[i].first_tx_pq_id,
4829 vport_params[i].vport_wfq);
4833 /* This function performs several validations for WFQ
4834 * configuration and required min rate for a given vport
4835 * 1. req_rate must be greater than one percent of min_pf_rate.
4836 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
4837 * rates to get less than one percent of min_pf_rate.
4838 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
4840 static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
4841 u16 vport_id, u32 req_rate,
4844 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
4845 int non_requested_count = 0, req_count = 0, i, num_vports;
4847 num_vports = p_hwfn->qm_info.num_vports;
4849 /* Accounting for the vports which are configured for WFQ explicitly */
4851 for (i = 0; i < num_vports; i++) {
4854 if ((i != vport_id) && p_hwfn->qm_info.wfq_data[i].configured) {
4856 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4857 total_req_min_rate += tmp_speed;
4861 /* Include current vport data as well */
4863 total_req_min_rate += req_rate;
4864 non_requested_count = num_vports - req_count;
4866 /* validate possible error cases */
4867 if (req_rate > min_pf_rate) {
4868 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4869 "Vport [%d] - Requested rate[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4870 vport_id, req_rate, min_pf_rate);
4874 if (req_rate < min_pf_rate / ECORE_WFQ_UNIT) {
4875 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4876 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4877 vport_id, req_rate, min_pf_rate);
4881 /* TBD - for number of vports greater than 100 */
4882 if (num_vports > ECORE_WFQ_UNIT) {
4883 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4884 "Number of vports is greater than %d\n",
4889 if (total_req_min_rate > min_pf_rate) {
4890 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4891 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4892 total_req_min_rate, min_pf_rate);
4896 /* Data left for non requested vports */
4897 total_left_rate = min_pf_rate - total_req_min_rate;
4898 left_rate_per_vp = total_left_rate / non_requested_count;
4900 /* validate if non requested get < 1% of min bw */
4901 if (left_rate_per_vp < min_pf_rate / ECORE_WFQ_UNIT) {
4902 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4903 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4904 left_rate_per_vp, min_pf_rate);
4908 /* now req_rate for given vport passes all scenarios.
4909 * assign final wfq rates to all vports.
4911 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
4912 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
4914 for (i = 0; i < num_vports; i++) {
4915 if (p_hwfn->qm_info.wfq_data[i].configured)
4918 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
4921 return ECORE_SUCCESS;
4924 static int __ecore_configure_vport_wfq(struct ecore_hwfn *p_hwfn,
4925 struct ecore_ptt *p_ptt,
4926 u16 vp_id, u32 rate)
4928 struct ecore_mcp_link_state *p_link;
4929 int rc = ECORE_SUCCESS;
4931 p_link = &p_hwfn->p_dev->hwfns[0].mcp_info->link_output;
4933 if (!p_link->min_pf_rate) {
4934 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
4935 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
4939 rc = ecore_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
4941 if (rc == ECORE_SUCCESS)
4942 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt,
4943 p_link->min_pf_rate);
4945 DP_NOTICE(p_hwfn, false,
4946 "Validation failed while configuring min rate\n");
4951 static int __ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn *p_hwfn,
4952 struct ecore_ptt *p_ptt,
4955 bool use_wfq = false;
4956 int rc = ECORE_SUCCESS;
4959 /* Validate all pre configured vports for wfq */
4960 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4963 if (!p_hwfn->qm_info.wfq_data[i].configured)
4966 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
4969 rc = ecore_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
4970 if (rc != ECORE_SUCCESS) {
4971 DP_NOTICE(p_hwfn, false,
4972 "WFQ validation failed while configuring min rate\n");
4977 if (rc == ECORE_SUCCESS && use_wfq)
4978 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4980 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4985 /* Main API for ecore clients to configure vport min rate.
4986 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
4987 * rate - Speed in Mbps needs to be assigned to a given vport.
4989 int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate)
4991 int i, rc = ECORE_INVAL;
4993 /* TBD - for multiple hardware functions - that is 100 gig */
4994 if (p_dev->num_hwfns > 1) {
4995 DP_NOTICE(p_dev, false,
4996 "WFQ configuration is not supported for this device\n");
5000 for_each_hwfn(p_dev, i) {
5001 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5002 struct ecore_ptt *p_ptt;
5004 p_ptt = ecore_ptt_acquire(p_hwfn);
5006 return ECORE_TIMEOUT;
5008 rc = __ecore_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
5010 if (rc != ECORE_SUCCESS) {
5011 ecore_ptt_release(p_hwfn, p_ptt);
5015 ecore_ptt_release(p_hwfn, p_ptt);
5021 /* API to configure WFQ from mcp link change */
5022 void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
5023 struct ecore_ptt *p_ptt,
5028 /* TBD - for multiple hardware functions - that is 100 gig */
5029 if (p_dev->num_hwfns > 1) {
5030 DP_VERBOSE(p_dev, ECORE_MSG_LINK,
5031 "WFQ configuration is not supported for this device\n");
5035 for_each_hwfn(p_dev, i) {
5036 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5038 __ecore_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
5043 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
5044 struct ecore_ptt *p_ptt,
5045 struct ecore_mcp_link_state *p_link,
5048 int rc = ECORE_SUCCESS;
5050 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
5052 if (!p_link->line_speed && (max_bw != 100))
5055 p_link->speed = (p_link->line_speed * max_bw) / 100;
5056 p_hwfn->qm_info.pf_rl = p_link->speed;
5058 /* Since the limiter also affects Tx-switched traffic, we don't want it
5059 * to limit such traffic in case there's no actual limit.
5060 * In that case, set limit to imaginary high boundary.
5063 p_hwfn->qm_info.pf_rl = 100000;
5065 rc = ecore_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
5066 p_hwfn->qm_info.pf_rl);
5068 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
5069 "Configured MAX bandwidth to be %08x Mb/sec\n",
5075 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
5076 int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw)
5078 int i, rc = ECORE_INVAL;
5080 if (max_bw < 1 || max_bw > 100) {
5081 DP_NOTICE(p_dev, false, "PF max bw valid range is [1-100]\n");
5085 for_each_hwfn(p_dev, i) {
5086 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5087 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
5088 struct ecore_mcp_link_state *p_link;
5089 struct ecore_ptt *p_ptt;
5091 p_link = &p_lead->mcp_info->link_output;
5093 p_ptt = ecore_ptt_acquire(p_hwfn);
5095 return ECORE_TIMEOUT;
5097 rc = __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
5100 ecore_ptt_release(p_hwfn, p_ptt);
5102 if (rc != ECORE_SUCCESS)
5109 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
5110 struct ecore_ptt *p_ptt,
5111 struct ecore_mcp_link_state *p_link,
5114 int rc = ECORE_SUCCESS;
5116 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
5117 p_hwfn->qm_info.pf_wfq = min_bw;
5119 if (!p_link->line_speed)
5122 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
5124 rc = ecore_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
5126 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
5127 "Configured MIN bandwidth to be %d Mb/sec\n",
5128 p_link->min_pf_rate);
5133 /* Main API to configure PF min bandwidth where bw range is [1-100] */
5134 int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw)
5136 int i, rc = ECORE_INVAL;
5138 if (min_bw < 1 || min_bw > 100) {
5139 DP_NOTICE(p_dev, false, "PF min bw valid range is [1-100]\n");
5143 for_each_hwfn(p_dev, i) {
5144 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5145 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
5146 struct ecore_mcp_link_state *p_link;
5147 struct ecore_ptt *p_ptt;
5149 p_link = &p_lead->mcp_info->link_output;
5151 p_ptt = ecore_ptt_acquire(p_hwfn);
5153 return ECORE_TIMEOUT;
5155 rc = __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
5157 if (rc != ECORE_SUCCESS) {
5158 ecore_ptt_release(p_hwfn, p_ptt);
5162 if (p_link->min_pf_rate) {
5163 u32 min_rate = p_link->min_pf_rate;
5165 rc = __ecore_configure_vp_wfq_on_link_change(p_hwfn,
5170 ecore_ptt_release(p_hwfn, p_ptt);
5176 void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
5178 struct ecore_mcp_link_state *p_link;
5180 p_link = &p_hwfn->mcp_info->link_output;
5182 if (p_link->min_pf_rate)
5183 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt,
5184 p_link->min_pf_rate);
5186 OSAL_MEMSET(p_hwfn->qm_info.wfq_data, 0,
5187 sizeof(*p_hwfn->qm_info.wfq_data) *
5188 p_hwfn->qm_info.num_vports);
5191 int ecore_device_num_engines(struct ecore_dev *p_dev)
5193 return ECORE_IS_BB(p_dev) ? 2 : 1;
5196 int ecore_device_num_ports(struct ecore_dev *p_dev)
5198 /* in CMT always only one port */
5199 if (p_dev->num_hwfns > 1)
5202 return p_dev->num_ports_in_engines * ecore_device_num_engines(p_dev);
5205 void ecore_set_fw_mac_addr(__le16 *fw_msb,
5210 ((u8 *)fw_msb)[0] = mac[1];
5211 ((u8 *)fw_msb)[1] = mac[0];
5212 ((u8 *)fw_mid)[0] = mac[3];
5213 ((u8 *)fw_mid)[1] = mac[2];
5214 ((u8 *)fw_lsb)[0] = mac[5];
5215 ((u8 *)fw_lsb)[1] = mac[4];