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 static enum _ecore_status_t ecore_hw_get_resc(struct ecore_hwfn *p_hwfn,
2840 struct ecore_ptt *p_ptt,
2841 bool drv_resc_alloc)
2843 struct ecore_resc_unlock_params resc_unlock_params;
2844 struct ecore_resc_lock_params resc_lock_params;
2845 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2847 enum _ecore_status_t rc;
2849 u32 *resc_start = p_hwfn->hw_info.resc_start;
2850 u32 *resc_num = p_hwfn->hw_info.resc_num;
2851 /* For AH, an equal share of the ILT lines between the maximal number of
2852 * PFs is not enough for RoCE. This would be solved by the future
2853 * resource allocation scheme, but isn't currently present for
2854 * FPGA/emulation. For now we keep a number that is sufficient for RoCE
2855 * to work - the BB number of ILT lines divided by its max PFs number.
2857 u32 roce_min_ilt_lines = PXP_NUM_ILT_RECORDS_BB / MAX_NUM_PFS_BB;
2860 /* Setting the max values of the soft resources and the following
2861 * resources allocation queries should be atomic. Since several PFs can
2862 * run in parallel - a resource lock is needed.
2863 * If either the resource lock or resource set value commands are not
2864 * supported - skip the the max values setting, release the lock if
2865 * needed, and proceed to the queries. Other failures, including a
2866 * failure to acquire the lock, will cause this function to fail.
2867 * Old drivers that don't acquire the lock can run in parallel, and
2868 * their allocation values won't be affected by the updated max values.
2870 ecore_mcp_resc_lock_default_init(p_hwfn, &resc_lock_params,
2871 &resc_unlock_params,
2872 ECORE_RESC_LOCK_RESC_ALLOC, false);
2874 rc = ecore_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
2875 if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
2877 } else if (rc == ECORE_NOTIMPL) {
2879 "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
2880 } else if (rc == ECORE_SUCCESS && !resc_lock_params.b_granted) {
2881 DP_NOTICE(p_hwfn, false,
2882 "Failed to acquire the resource lock for the resource allocation commands\n");
2884 goto unlock_and_exit;
2886 rc = ecore_hw_set_soft_resc_size(p_hwfn, p_ptt);
2887 if (rc != ECORE_SUCCESS && rc != ECORE_NOTIMPL) {
2888 DP_NOTICE(p_hwfn, false,
2889 "Failed to set the max values of the soft resources\n");
2890 goto unlock_and_exit;
2891 } else if (rc == ECORE_NOTIMPL) {
2893 "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
2894 rc = ecore_mcp_resc_unlock(p_hwfn, p_ptt,
2895 &resc_unlock_params);
2896 if (rc != ECORE_SUCCESS)
2898 "Failed to release the resource lock for the resource allocation commands\n");
2902 rc = ecore_hw_set_resc_info(p_hwfn, drv_resc_alloc);
2903 if (rc != ECORE_SUCCESS)
2904 goto unlock_and_exit;
2906 if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
2907 rc = ecore_mcp_resc_unlock(p_hwfn, p_ptt,
2908 &resc_unlock_params);
2909 if (rc != ECORE_SUCCESS)
2911 "Failed to release the resource lock for the resource allocation commands\n");
2915 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2916 /* Reduced build contains less PQs */
2917 if (!(p_hwfn->p_dev->b_is_emul_full)) {
2918 resc_num[ECORE_PQ] = 32;
2919 resc_start[ECORE_PQ] = resc_num[ECORE_PQ] *
2920 p_hwfn->enabled_func_idx;
2923 /* For AH emulation, since we have a possible maximal number of
2924 * 16 enabled PFs, in case there are not enough ILT lines -
2925 * allocate only first PF as RoCE and have all the other ETH
2926 * only with less ILT lines.
2928 if (!p_hwfn->rel_pf_id && p_hwfn->p_dev->b_is_emul_full)
2929 resc_num[ECORE_ILT] = OSAL_MAX_T(u32,
2930 resc_num[ECORE_ILT],
2931 roce_min_ilt_lines);
2934 /* Correct the common ILT calculation if PF0 has more */
2935 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev) &&
2936 p_hwfn->p_dev->b_is_emul_full &&
2937 p_hwfn->rel_pf_id && resc_num[ECORE_ILT] < roce_min_ilt_lines)
2938 resc_start[ECORE_ILT] += roce_min_ilt_lines -
2939 resc_num[ECORE_ILT];
2942 /* Sanity for ILT */
2943 if ((b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2944 (!b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
2945 DP_NOTICE(p_hwfn, true,
2946 "Can't assign ILT pages [%08x,...,%08x]\n",
2947 RESC_START(p_hwfn, ECORE_ILT), RESC_END(p_hwfn,
2953 /* This will also learn the number of SBs from MFW */
2954 if (ecore_int_igu_reset_cam(p_hwfn, p_ptt))
2957 ecore_hw_set_feat(p_hwfn);
2959 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2960 "The numbers for each resource are:\n");
2961 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++)
2962 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE, "%s = %d start = %d\n",
2963 ecore_hw_get_resc_name(res_id),
2964 RESC_NUM(p_hwfn, res_id),
2965 RESC_START(p_hwfn, res_id));
2967 return ECORE_SUCCESS;
2970 if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
2971 ecore_mcp_resc_unlock(p_hwfn, p_ptt,
2972 &resc_unlock_params);
2976 static enum _ecore_status_t
2977 ecore_hw_get_nvm_info(struct ecore_hwfn *p_hwfn,
2978 struct ecore_ptt *p_ptt,
2979 struct ecore_hw_prepare_params *p_params)
2981 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg, dcbx_mode;
2982 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
2983 struct ecore_mcp_link_capabilities *p_caps;
2984 struct ecore_mcp_link_params *link;
2985 enum _ecore_status_t rc;
2987 /* Read global nvm_cfg address */
2988 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2990 /* Verify MCP has initialized it */
2991 if (!nvm_cfg_addr) {
2992 DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
2993 if (p_params->b_relaxed_probe)
2994 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_NVM;
2998 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
3000 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
3002 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3003 OFFSETOF(struct nvm_cfg1, glob) + OFFSETOF(struct nvm_cfg1_glob,
3006 core_cfg = ecore_rd(p_hwfn, p_ptt, addr);
3008 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
3009 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
3010 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
3011 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X40G;
3013 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
3014 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X50G;
3016 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
3017 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X100G;
3019 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
3020 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_F;
3022 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
3023 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_E;
3025 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
3026 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X20G;
3028 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
3029 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X40G;
3031 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
3032 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X25G;
3034 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
3035 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X10G;
3037 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
3038 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X25G;
3040 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
3041 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X25G;
3044 DP_NOTICE(p_hwfn, true, "Unknown port mode in 0x%08x\n",
3049 /* Read DCBX configuration */
3050 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3051 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
3052 dcbx_mode = ecore_rd(p_hwfn, p_ptt,
3054 OFFSETOF(struct nvm_cfg1_port, generic_cont0));
3055 dcbx_mode = (dcbx_mode & NVM_CFG1_PORT_DCBX_MODE_MASK)
3056 >> NVM_CFG1_PORT_DCBX_MODE_OFFSET;
3057 switch (dcbx_mode) {
3058 case NVM_CFG1_PORT_DCBX_MODE_DYNAMIC:
3059 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DYNAMIC;
3061 case NVM_CFG1_PORT_DCBX_MODE_CEE:
3062 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_CEE;
3064 case NVM_CFG1_PORT_DCBX_MODE_IEEE:
3065 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_IEEE;
3068 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DISABLED;
3071 /* Read default link configuration */
3072 link = &p_hwfn->mcp_info->link_input;
3073 p_caps = &p_hwfn->mcp_info->link_capabilities;
3074 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3075 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
3076 link_temp = ecore_rd(p_hwfn, p_ptt,
3078 OFFSETOF(struct nvm_cfg1_port, speed_cap_mask));
3079 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
3080 link->speed.advertised_speeds = link_temp;
3081 p_caps->speed_capabilities = link->speed.advertised_speeds;
3083 link_temp = ecore_rd(p_hwfn, p_ptt,
3085 OFFSETOF(struct nvm_cfg1_port, link_settings));
3086 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
3087 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
3088 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
3089 link->speed.autoneg = true;
3091 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
3092 link->speed.forced_speed = 1000;
3094 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
3095 link->speed.forced_speed = 10000;
3097 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
3098 link->speed.forced_speed = 25000;
3100 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
3101 link->speed.forced_speed = 40000;
3103 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
3104 link->speed.forced_speed = 50000;
3106 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
3107 link->speed.forced_speed = 100000;
3110 DP_NOTICE(p_hwfn, true, "Unknown Speed in 0x%08x\n", link_temp);
3113 p_caps->default_speed = link->speed.forced_speed;
3114 p_caps->default_speed_autoneg = link->speed.autoneg;
3116 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
3117 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
3118 link->pause.autoneg = !!(link_temp &
3119 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
3120 link->pause.forced_rx = !!(link_temp &
3121 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
3122 link->pause.forced_tx = !!(link_temp &
3123 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
3124 link->loopback_mode = 0;
3126 if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) {
3127 link_temp = ecore_rd(p_hwfn, p_ptt, port_cfg_addr +
3128 OFFSETOF(struct nvm_cfg1_port, ext_phy));
3129 link_temp &= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_MASK;
3130 link_temp >>= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_OFFSET;
3131 p_caps->default_eee = ECORE_MCP_EEE_ENABLED;
3132 link->eee.enable = true;
3133 switch (link_temp) {
3134 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_DISABLED:
3135 p_caps->default_eee = ECORE_MCP_EEE_DISABLED;
3136 link->eee.enable = false;
3138 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_BALANCED:
3139 p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_BALANCED_TIME;
3141 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_AGGRESSIVE:
3142 p_caps->eee_lpi_timer =
3143 EEE_TX_TIMER_USEC_AGGRESSIVE_TIME;
3145 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_LOW_LATENCY:
3146 p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_LATENCY_TIME;
3150 link->eee.tx_lpi_timer = p_caps->eee_lpi_timer;
3151 link->eee.tx_lpi_enable = link->eee.enable;
3152 link->eee.adv_caps = ECORE_EEE_1G_ADV | ECORE_EEE_10G_ADV;
3154 p_caps->default_eee = ECORE_MCP_EEE_UNSUPPORTED;
3157 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
3158 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n EEE: %02x [%08x usec]",
3159 link->speed.forced_speed, link->speed.advertised_speeds,
3160 link->speed.autoneg, link->pause.autoneg,
3161 p_caps->default_eee, p_caps->eee_lpi_timer);
3163 /* Read Multi-function information from shmem */
3164 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3165 OFFSETOF(struct nvm_cfg1, glob) +
3166 OFFSETOF(struct nvm_cfg1_glob, generic_cont0);
3168 generic_cont0 = ecore_rd(p_hwfn, p_ptt, addr);
3170 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
3171 NVM_CFG1_GLOB_MF_MODE_OFFSET;
3174 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
3175 p_hwfn->p_dev->mf_mode = ECORE_MF_OVLAN;
3177 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
3178 p_hwfn->p_dev->mf_mode = ECORE_MF_NPAR;
3180 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
3181 p_hwfn->p_dev->mf_mode = ECORE_MF_DEFAULT;
3184 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
3185 p_hwfn->p_dev->mf_mode);
3187 /* Read Multi-function information from shmem */
3188 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
3189 OFFSETOF(struct nvm_cfg1, glob) +
3190 OFFSETOF(struct nvm_cfg1_glob, device_capabilities);
3192 device_capabilities = ecore_rd(p_hwfn, p_ptt, addr);
3193 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
3194 OSAL_SET_BIT(ECORE_DEV_CAP_ETH,
3195 &p_hwfn->hw_info.device_capabilities);
3196 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
3197 OSAL_SET_BIT(ECORE_DEV_CAP_FCOE,
3198 &p_hwfn->hw_info.device_capabilities);
3199 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
3200 OSAL_SET_BIT(ECORE_DEV_CAP_ISCSI,
3201 &p_hwfn->hw_info.device_capabilities);
3202 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
3203 OSAL_SET_BIT(ECORE_DEV_CAP_ROCE,
3204 &p_hwfn->hw_info.device_capabilities);
3205 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_IWARP)
3206 OSAL_SET_BIT(ECORE_DEV_CAP_IWARP,
3207 &p_hwfn->hw_info.device_capabilities);
3209 rc = ecore_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
3210 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3212 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3218 static void ecore_get_num_funcs(struct ecore_hwfn *p_hwfn,
3219 struct ecore_ptt *p_ptt)
3221 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
3222 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
3223 struct ecore_dev *p_dev = p_hwfn->p_dev;
3225 num_funcs = ECORE_IS_AH(p_dev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
3227 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
3228 * in the other bits are selected.
3229 * Bits 1-15 are for functions 1-15, respectively, and their value is
3230 * '0' only for enabled functions (function 0 always exists and
3232 * In case of CMT in BB, only the "even" functions are enabled, and thus
3233 * the number of functions for both hwfns is learnt from the same bits.
3235 if (ECORE_IS_BB(p_dev) || ECORE_IS_AH(p_dev)) {
3236 reg_function_hide = ecore_rd(p_hwfn, p_ptt,
3237 MISCS_REG_FUNCTION_HIDE_BB_K2);
3239 reg_function_hide = 0;
3242 if (reg_function_hide & 0x1) {
3243 if (ECORE_IS_BB(p_dev)) {
3244 if (ECORE_PATH_ID(p_hwfn) && p_dev->num_hwfns == 1) {
3256 /* Get the number of the enabled functions on the engine */
3257 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
3264 /* Get the PF index within the enabled functions */
3265 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
3266 tmp = reg_function_hide & eng_mask & low_pfs_mask;
3274 p_hwfn->num_funcs_on_engine = num_funcs;
3275 p_hwfn->enabled_func_idx = enabled_func_idx;
3278 if (CHIP_REV_IS_FPGA(p_dev)) {
3279 DP_NOTICE(p_hwfn, false,
3280 "FPGA: Limit number of PFs to 4 [would affect resource allocation, needed for IOV]\n");
3281 p_hwfn->num_funcs_on_engine = 4;
3285 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
3286 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
3287 p_hwfn->rel_pf_id, p_hwfn->abs_pf_id,
3288 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
3291 static void ecore_hw_info_port_num_bb(struct ecore_hwfn *p_hwfn,
3292 struct ecore_ptt *p_ptt)
3297 /* Read the port mode */
3298 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
3300 else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) &&
3301 (p_hwfn->p_dev->num_hwfns > 1))
3302 /* In CMT on emulation, assume 1 port */
3306 port_mode = ecore_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
3308 if (port_mode < 3) {
3309 p_hwfn->p_dev->num_ports_in_engines = 1;
3310 } else if (port_mode <= 5) {
3311 p_hwfn->p_dev->num_ports_in_engines = 2;
3313 DP_NOTICE(p_hwfn, true, "PORT MODE: %d not supported\n",
3314 p_hwfn->p_dev->num_ports_in_engines);
3316 /* Default num_ports_in_engines to something */
3317 p_hwfn->p_dev->num_ports_in_engines = 1;
3321 static void ecore_hw_info_port_num_ah_e5(struct ecore_hwfn *p_hwfn,
3322 struct ecore_ptt *p_ptt)
3327 p_hwfn->p_dev->num_ports_in_engines = 0;
3330 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
3331 port = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
3332 switch ((port & 0xf000) >> 12) {
3334 p_hwfn->p_dev->num_ports_in_engines = 1;
3337 p_hwfn->p_dev->num_ports_in_engines = 2;
3340 p_hwfn->p_dev->num_ports_in_engines = 4;
3343 DP_NOTICE(p_hwfn, false,
3344 "Unknown port mode in ECO_RESERVED %08x\n",
3349 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
3350 port = ecore_rd(p_hwfn, p_ptt,
3351 CNIG_REG_NIG_PORT0_CONF_K2_E5 +
3354 p_hwfn->p_dev->num_ports_in_engines++;
3358 static void ecore_hw_info_port_num(struct ecore_hwfn *p_hwfn,
3359 struct ecore_ptt *p_ptt)
3361 if (ECORE_IS_BB(p_hwfn->p_dev))
3362 ecore_hw_info_port_num_bb(p_hwfn, p_ptt);
3364 ecore_hw_info_port_num_ah_e5(p_hwfn, p_ptt);
3367 static void ecore_mcp_get_eee_caps(struct ecore_hwfn *p_hwfn,
3368 struct ecore_ptt *p_ptt)
3370 struct ecore_mcp_link_capabilities *p_caps;
3373 p_caps = &p_hwfn->mcp_info->link_capabilities;
3374 if (p_caps->default_eee == ECORE_MCP_EEE_UNSUPPORTED)
3377 p_caps->eee_speed_caps = 0;
3378 eee_status = ecore_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
3379 OFFSETOF(struct public_port, eee_status));
3380 eee_status = (eee_status & EEE_SUPPORTED_SPEED_MASK) >>
3381 EEE_SUPPORTED_SPEED_OFFSET;
3382 if (eee_status & EEE_1G_SUPPORTED)
3383 p_caps->eee_speed_caps |= ECORE_EEE_1G_ADV;
3384 if (eee_status & EEE_10G_ADV)
3385 p_caps->eee_speed_caps |= ECORE_EEE_10G_ADV;
3388 static enum _ecore_status_t
3389 ecore_get_hw_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3390 enum ecore_pci_personality personality,
3391 struct ecore_hw_prepare_params *p_params)
3393 bool drv_resc_alloc = p_params->drv_resc_alloc;
3394 enum _ecore_status_t rc;
3396 /* Since all information is common, only first hwfns should do this */
3397 if (IS_LEAD_HWFN(p_hwfn)) {
3398 rc = ecore_iov_hw_info(p_hwfn);
3399 if (rc != ECORE_SUCCESS) {
3400 if (p_params->b_relaxed_probe)
3401 p_params->p_relaxed_res =
3402 ECORE_HW_PREPARE_BAD_IOV;
3408 /* TODO In get_hw_info, amoungst others:
3409 * Get MCP FW revision and determine according to it the supported
3410 * featrues (e.g. DCB)
3412 * ecore_get_pcie_width_speed, WOL capability.
3413 * Number of global CQ-s (for storage
3415 ecore_hw_info_port_num(p_hwfn, p_ptt);
3417 ecore_mcp_get_capabilities(p_hwfn, p_ptt);
3420 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev)) {
3422 rc = ecore_hw_get_nvm_info(p_hwfn, p_ptt, p_params);
3423 if (rc != ECORE_SUCCESS)
3429 rc = ecore_int_igu_read_cam(p_hwfn, p_ptt);
3430 if (rc != ECORE_SUCCESS) {
3431 if (p_params->b_relaxed_probe)
3432 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_IGU;
3438 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev) && ecore_mcp_is_init(p_hwfn)) {
3440 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr,
3441 p_hwfn->mcp_info->func_info.mac, ETH_ALEN);
3444 static u8 mcp_hw_mac[6] = { 0, 2, 3, 4, 5, 6 };
3446 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr, mcp_hw_mac, ETH_ALEN);
3447 p_hwfn->hw_info.hw_mac_addr[5] = p_hwfn->abs_pf_id;
3451 if (ecore_mcp_is_init(p_hwfn)) {
3452 if (p_hwfn->mcp_info->func_info.ovlan != ECORE_MCP_VLAN_UNSET)
3453 p_hwfn->hw_info.ovlan =
3454 p_hwfn->mcp_info->func_info.ovlan;
3456 ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
3458 ecore_mcp_get_eee_caps(p_hwfn, p_ptt);
3461 if (personality != ECORE_PCI_DEFAULT) {
3462 p_hwfn->hw_info.personality = personality;
3463 } else if (ecore_mcp_is_init(p_hwfn)) {
3464 enum ecore_pci_personality protocol;
3466 protocol = p_hwfn->mcp_info->func_info.protocol;
3467 p_hwfn->hw_info.personality = protocol;
3471 /* To overcome ILT lack for emulation, until at least until we'll have
3472 * a definite answer from system about it, allow only PF0 to be RoCE.
3474 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev)) {
3475 if (!p_hwfn->rel_pf_id)
3476 p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
3478 p_hwfn->hw_info.personality = ECORE_PCI_ETH;
3482 /* although in BB some constellations may support more than 4 tcs,
3483 * that can result in performance penalty in some cases. 4
3484 * represents a good tradeoff between performance and flexibility.
3486 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
3488 /* start out with a single active tc. This can be increased either
3489 * by dcbx negotiation or by upper layer driver
3491 p_hwfn->hw_info.num_active_tc = 1;
3493 ecore_get_num_funcs(p_hwfn, p_ptt);
3495 if (ecore_mcp_is_init(p_hwfn))
3496 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
3498 /* In case of forcing the driver's default resource allocation, calling
3499 * ecore_hw_get_resc() should come after initializing the personality
3500 * and after getting the number of functions, since the calculation of
3501 * the resources/features depends on them.
3502 * This order is not harmful if not forcing.
3504 rc = ecore_hw_get_resc(p_hwfn, p_ptt, drv_resc_alloc);
3505 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3507 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3513 static enum _ecore_status_t ecore_get_dev_info(struct ecore_hwfn *p_hwfn,
3514 struct ecore_ptt *p_ptt)
3516 struct ecore_dev *p_dev = p_hwfn->p_dev;
3520 /* Read Vendor Id / Device Id */
3521 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_VENDOR_ID_OFFSET,
3523 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_DEVICE_ID_OFFSET,
3526 /* Determine type */
3527 device_id_mask = p_dev->device_id & ECORE_DEV_ID_MASK;
3528 switch (device_id_mask) {
3529 case ECORE_DEV_ID_MASK_BB:
3530 p_dev->type = ECORE_DEV_TYPE_BB;
3532 case ECORE_DEV_ID_MASK_AH:
3533 p_dev->type = ECORE_DEV_TYPE_AH;
3536 DP_NOTICE(p_hwfn, true, "Unknown device id 0x%x\n",
3538 return ECORE_ABORTED;
3541 p_dev->chip_num = (u16)ecore_rd(p_hwfn, p_ptt,
3542 MISCS_REG_CHIP_NUM);
3543 p_dev->chip_rev = (u16)ecore_rd(p_hwfn, p_ptt,
3544 MISCS_REG_CHIP_REV);
3546 MASK_FIELD(CHIP_REV, p_dev->chip_rev);
3548 /* Learn number of HW-functions */
3549 tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
3551 if (tmp & (1 << p_hwfn->rel_pf_id)) {
3552 DP_NOTICE(p_dev->hwfns, false, "device in CMT mode\n");
3553 p_dev->num_hwfns = 2;
3555 p_dev->num_hwfns = 1;
3559 if (CHIP_REV_IS_EMUL(p_dev)) {
3560 /* For some reason we have problems with this register
3561 * in B0 emulation; Simply assume no CMT
3563 DP_NOTICE(p_dev->hwfns, false,
3564 "device on emul - assume no CMT\n");
3565 p_dev->num_hwfns = 1;
3569 p_dev->chip_bond_id = ecore_rd(p_hwfn, p_ptt,
3570 MISCS_REG_CHIP_TEST_REG) >> 4;
3571 MASK_FIELD(CHIP_BOND_ID, p_dev->chip_bond_id);
3572 p_dev->chip_metal = (u16)ecore_rd(p_hwfn, p_ptt,
3573 MISCS_REG_CHIP_METAL);
3574 MASK_FIELD(CHIP_METAL, p_dev->chip_metal);
3575 DP_INFO(p_dev->hwfns,
3576 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
3577 ECORE_IS_BB(p_dev) ? "BB" : "AH",
3578 'A' + p_dev->chip_rev, (int)p_dev->chip_metal,
3579 p_dev->chip_num, p_dev->chip_rev, p_dev->chip_bond_id,
3582 if (ECORE_IS_BB(p_dev) && CHIP_REV_IS_A0(p_dev)) {
3583 DP_NOTICE(p_dev->hwfns, false,
3584 "The chip type/rev (BB A0) is not supported!\n");
3585 return ECORE_ABORTED;
3588 if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_AH(p_dev))
3589 ecore_wr(p_hwfn, p_ptt, MISCS_REG_PLL_MAIN_CTRL_4, 0x1);
3591 if (CHIP_REV_IS_EMUL(p_dev)) {
3592 tmp = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
3593 if (tmp & (1 << 29)) {
3594 DP_NOTICE(p_hwfn, false,
3595 "Emulation: Running on a FULL build\n");
3596 p_dev->b_is_emul_full = true;
3598 DP_NOTICE(p_hwfn, false,
3599 "Emulation: Running on a REDUCED build\n");
3604 return ECORE_SUCCESS;
3607 #ifndef LINUX_REMOVE
3608 void ecore_prepare_hibernate(struct ecore_dev *p_dev)
3615 for_each_hwfn(p_dev, j) {
3616 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
3618 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
3619 "Mark hw/fw uninitialized\n");
3621 p_hwfn->hw_init_done = false;
3622 p_hwfn->first_on_engine = false;
3624 ecore_ptt_invalidate(p_hwfn);
3629 static enum _ecore_status_t
3630 ecore_hw_prepare_single(struct ecore_hwfn *p_hwfn,
3631 void OSAL_IOMEM * p_regview,
3632 void OSAL_IOMEM * p_doorbells,
3633 struct ecore_hw_prepare_params *p_params)
3635 struct ecore_mdump_retain_data mdump_retain;
3636 struct ecore_dev *p_dev = p_hwfn->p_dev;
3637 struct ecore_mdump_info mdump_info;
3638 enum _ecore_status_t rc = ECORE_SUCCESS;
3640 /* Split PCI bars evenly between hwfns */
3641 p_hwfn->regview = p_regview;
3642 p_hwfn->doorbells = p_doorbells;
3645 return ecore_vf_hw_prepare(p_hwfn);
3647 /* Validate that chip access is feasible */
3648 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
3650 "Reading the ME register returns all Fs; Preventing further chip access\n");
3651 if (p_params->b_relaxed_probe)
3652 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_ME;
3656 get_function_id(p_hwfn);
3658 /* Allocate PTT pool */
3659 rc = ecore_ptt_pool_alloc(p_hwfn);
3661 DP_NOTICE(p_hwfn, true, "Failed to prepare hwfn's hw\n");
3662 if (p_params->b_relaxed_probe)
3663 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3667 /* Allocate the main PTT */
3668 p_hwfn->p_main_ptt = ecore_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
3670 /* First hwfn learns basic information, e.g., number of hwfns */
3671 if (!p_hwfn->my_id) {
3672 rc = ecore_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
3673 if (rc != ECORE_SUCCESS) {
3674 if (p_params->b_relaxed_probe)
3675 p_params->p_relaxed_res =
3676 ECORE_HW_PREPARE_FAILED_DEV;
3681 ecore_hw_hwfn_prepare(p_hwfn);
3683 /* Initialize MCP structure */
3684 rc = ecore_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
3686 DP_NOTICE(p_hwfn, true, "Failed initializing mcp command\n");
3687 if (p_params->b_relaxed_probe)
3688 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3692 /* Read the device configuration information from the HW and SHMEM */
3693 rc = ecore_get_hw_info(p_hwfn, p_hwfn->p_main_ptt,
3694 p_params->personality, p_params);
3696 DP_NOTICE(p_hwfn, true, "Failed to get HW information\n");
3700 /* Sending a mailbox to the MFW should be after ecore_get_hw_info() is
3701 * called, since among others it sets the ports number in an engine.
3703 if (p_params->initiate_pf_flr && IS_LEAD_HWFN(p_hwfn) &&
3704 !p_dev->recov_in_prog) {
3705 rc = ecore_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
3706 if (rc != ECORE_SUCCESS)
3707 DP_NOTICE(p_hwfn, false, "Failed to initiate PF FLR\n");
3710 /* Check if mdump logs/data are present and update the epoch value */
3711 if (IS_LEAD_HWFN(p_hwfn)) {
3713 if (!CHIP_REV_IS_EMUL(p_dev)) {
3715 rc = ecore_mcp_mdump_get_info(p_hwfn, p_hwfn->p_main_ptt,
3717 if (rc == ECORE_SUCCESS && mdump_info.num_of_logs)
3718 DP_NOTICE(p_hwfn, false,
3719 "* * * IMPORTANT - HW ERROR register dump captured by device * * *\n");
3721 rc = ecore_mcp_mdump_get_retain(p_hwfn, p_hwfn->p_main_ptt,
3723 if (rc == ECORE_SUCCESS && mdump_retain.valid)
3724 DP_NOTICE(p_hwfn, false,
3725 "mdump retained data: epoch 0x%08x, pf 0x%x, status 0x%08x\n",
3726 mdump_retain.epoch, mdump_retain.pf,
3727 mdump_retain.status);
3729 ecore_mcp_mdump_set_values(p_hwfn, p_hwfn->p_main_ptt,
3736 /* Allocate the init RT array and initialize the init-ops engine */
3737 rc = ecore_init_alloc(p_hwfn);
3739 DP_NOTICE(p_hwfn, true, "Failed to allocate the init array\n");
3740 if (p_params->b_relaxed_probe)
3741 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3745 if (CHIP_REV_IS_FPGA(p_dev)) {
3746 DP_NOTICE(p_hwfn, false,
3747 "FPGA: workaround; Prevent DMAE parities\n");
3748 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PCIE_REG_PRTY_MASK_K2_E5,
3751 DP_NOTICE(p_hwfn, false,
3752 "FPGA: workaround: Set VF bar0 size\n");
3753 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
3754 PGLUE_B_REG_VF_BAR0_SIZE_K2_E5, 4);
3760 if (IS_LEAD_HWFN(p_hwfn))
3761 ecore_iov_free_hw_info(p_dev);
3762 ecore_mcp_free(p_hwfn);
3764 ecore_hw_hwfn_free(p_hwfn);
3769 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
3770 struct ecore_hw_prepare_params *p_params)
3772 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3773 enum _ecore_status_t rc;
3775 p_dev->chk_reg_fifo = p_params->chk_reg_fifo;
3776 p_dev->allow_mdump = p_params->allow_mdump;
3778 if (p_params->b_relaxed_probe)
3779 p_params->p_relaxed_res = ECORE_HW_PREPARE_SUCCESS;
3781 /* Store the precompiled init data ptrs */
3783 ecore_init_iro_array(p_dev);
3785 /* Initialize the first hwfn - will learn number of hwfns */
3786 rc = ecore_hw_prepare_single(p_hwfn,
3788 p_dev->doorbells, p_params);
3789 if (rc != ECORE_SUCCESS)
3792 p_params->personality = p_hwfn->hw_info.personality;
3794 /* initilalize 2nd hwfn if necessary */
3795 if (p_dev->num_hwfns > 1) {
3796 void OSAL_IOMEM *p_regview, *p_doorbell;
3797 u8 OSAL_IOMEM *addr;
3799 /* adjust bar offset for second engine */
3800 addr = (u8 OSAL_IOMEM *)p_dev->regview +
3801 ecore_hw_bar_size(p_hwfn,
3804 p_regview = (void OSAL_IOMEM *)addr;
3806 addr = (u8 OSAL_IOMEM *)p_dev->doorbells +
3807 ecore_hw_bar_size(p_hwfn,
3810 p_doorbell = (void OSAL_IOMEM *)addr;
3812 /* prepare second hw function */
3813 rc = ecore_hw_prepare_single(&p_dev->hwfns[1], p_regview,
3814 p_doorbell, p_params);
3816 /* in case of error, need to free the previously
3817 * initiliazed hwfn 0.
3819 if (rc != ECORE_SUCCESS) {
3820 if (p_params->b_relaxed_probe)
3821 p_params->p_relaxed_res =
3822 ECORE_HW_PREPARE_FAILED_ENG2;
3825 ecore_init_free(p_hwfn);
3826 ecore_mcp_free(p_hwfn);
3827 ecore_hw_hwfn_free(p_hwfn);
3829 DP_NOTICE(p_dev, true,
3830 "What do we need to free when VF hwfn1 init fails\n");
3839 void ecore_hw_remove(struct ecore_dev *p_dev)
3841 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3845 ecore_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
3846 ECORE_OV_DRIVER_STATE_NOT_LOADED);
3848 for_each_hwfn(p_dev, i) {
3849 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3852 ecore_vf_pf_release(p_hwfn);
3856 ecore_init_free(p_hwfn);
3857 ecore_hw_hwfn_free(p_hwfn);
3858 ecore_mcp_free(p_hwfn);
3860 #ifdef CONFIG_ECORE_LOCK_ALLOC
3861 OSAL_MUTEX_DEALLOC(&p_hwfn->dmae_info.mutex);
3865 ecore_iov_free_hw_info(p_dev);
3868 static void ecore_chain_free_next_ptr(struct ecore_dev *p_dev,
3869 struct ecore_chain *p_chain)
3871 void *p_virt = p_chain->p_virt_addr, *p_virt_next = OSAL_NULL;
3872 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3873 struct ecore_chain_next *p_next;
3879 size = p_chain->elem_size * p_chain->usable_per_page;
3881 for (i = 0; i < p_chain->page_cnt; i++) {
3885 p_next = (struct ecore_chain_next *)((u8 *)p_virt + size);
3886 p_virt_next = p_next->next_virt;
3887 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3889 OSAL_DMA_FREE_COHERENT(p_dev, p_virt, p_phys,
3890 ECORE_CHAIN_PAGE_SIZE);
3892 p_virt = p_virt_next;
3893 p_phys = p_phys_next;
3897 static void ecore_chain_free_single(struct ecore_dev *p_dev,
3898 struct ecore_chain *p_chain)
3900 if (!p_chain->p_virt_addr)
3903 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->p_virt_addr,
3904 p_chain->p_phys_addr, ECORE_CHAIN_PAGE_SIZE);
3907 static void ecore_chain_free_pbl(struct ecore_dev *p_dev,
3908 struct ecore_chain *p_chain)
3910 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3911 u8 *p_pbl_virt = (u8 *)p_chain->pbl_sp.p_virt_table;
3912 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
3914 if (!pp_virt_addr_tbl)
3920 for (i = 0; i < page_cnt; i++) {
3921 if (!pp_virt_addr_tbl[i])
3924 OSAL_DMA_FREE_COHERENT(p_dev, pp_virt_addr_tbl[i],
3925 *(dma_addr_t *)p_pbl_virt,
3926 ECORE_CHAIN_PAGE_SIZE);
3928 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
3931 pbl_size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
3933 if (!p_chain->b_external_pbl)
3934 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->pbl_sp.p_virt_table,
3935 p_chain->pbl_sp.p_phys_table, pbl_size);
3937 OSAL_VFREE(p_dev, p_chain->pbl.pp_virt_addr_tbl);
3940 void ecore_chain_free(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3942 switch (p_chain->mode) {
3943 case ECORE_CHAIN_MODE_NEXT_PTR:
3944 ecore_chain_free_next_ptr(p_dev, p_chain);
3946 case ECORE_CHAIN_MODE_SINGLE:
3947 ecore_chain_free_single(p_dev, p_chain);
3949 case ECORE_CHAIN_MODE_PBL:
3950 ecore_chain_free_pbl(p_dev, p_chain);
3955 static enum _ecore_status_t
3956 ecore_chain_alloc_sanity_check(struct ecore_dev *p_dev,
3957 enum ecore_chain_cnt_type cnt_type,
3958 osal_size_t elem_size, u32 page_cnt)
3960 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3962 /* The actual chain size can be larger than the maximal possible value
3963 * after rounding up the requested elements number to pages, and after
3964 * taking into acount the unusuable elements (next-ptr elements).
3965 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3966 * size/capacity fields are of a u32 type.
3968 if ((cnt_type == ECORE_CHAIN_CNT_TYPE_U16 &&
3969 chain_size > ((u32)ECORE_U16_MAX + 1)) ||
3970 (cnt_type == ECORE_CHAIN_CNT_TYPE_U32 &&
3971 chain_size > ECORE_U32_MAX)) {
3972 DP_NOTICE(p_dev, true,
3973 "The actual chain size (0x%lx) is larger than the maximal possible value\n",
3974 (unsigned long)chain_size);
3978 return ECORE_SUCCESS;
3981 static enum _ecore_status_t
3982 ecore_chain_alloc_next_ptr(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3984 void *p_virt = OSAL_NULL, *p_virt_prev = OSAL_NULL;
3985 dma_addr_t p_phys = 0;
3988 for (i = 0; i < p_chain->page_cnt; i++) {
3989 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
3990 ECORE_CHAIN_PAGE_SIZE);
3992 DP_NOTICE(p_dev, true,
3993 "Failed to allocate chain memory\n");
3998 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3999 ecore_chain_reset(p_chain);
4001 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
4005 p_virt_prev = p_virt;
4007 /* Last page's next element should point to the beginning of the
4010 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
4011 p_chain->p_virt_addr,
4012 p_chain->p_phys_addr);
4014 return ECORE_SUCCESS;
4017 static enum _ecore_status_t
4018 ecore_chain_alloc_single(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
4020 dma_addr_t p_phys = 0;
4021 void *p_virt = OSAL_NULL;
4023 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys, ECORE_CHAIN_PAGE_SIZE);
4025 DP_NOTICE(p_dev, true, "Failed to allocate chain memory\n");
4029 ecore_chain_init_mem(p_chain, p_virt, p_phys);
4030 ecore_chain_reset(p_chain);
4032 return ECORE_SUCCESS;
4035 static enum _ecore_status_t
4036 ecore_chain_alloc_pbl(struct ecore_dev *p_dev,
4037 struct ecore_chain *p_chain,
4038 struct ecore_chain_ext_pbl *ext_pbl)
4040 void *p_virt = OSAL_NULL;
4041 u8 *p_pbl_virt = OSAL_NULL;
4042 void **pp_virt_addr_tbl = OSAL_NULL;
4043 dma_addr_t p_phys = 0, p_pbl_phys = 0;
4044 u32 page_cnt = p_chain->page_cnt, size, i;
4046 size = page_cnt * sizeof(*pp_virt_addr_tbl);
4047 pp_virt_addr_tbl = (void **)OSAL_VZALLOC(p_dev, size);
4048 if (!pp_virt_addr_tbl) {
4049 DP_NOTICE(p_dev, true,
4050 "Failed to allocate memory for the chain virtual addresses table\n");
4054 /* The allocation of the PBL table is done with its full size, since it
4055 * is expected to be successive.
4056 * ecore_chain_init_pbl_mem() is called even in a case of an allocation
4057 * failure, since pp_virt_addr_tbl was previously allocated, and it
4058 * should be saved to allow its freeing during the error flow.
4060 size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
4062 if (ext_pbl == OSAL_NULL) {
4063 p_pbl_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_pbl_phys, size);
4065 p_pbl_virt = ext_pbl->p_pbl_virt;
4066 p_pbl_phys = ext_pbl->p_pbl_phys;
4067 p_chain->b_external_pbl = true;
4070 ecore_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
4073 DP_NOTICE(p_dev, true, "Failed to allocate chain pbl memory\n");
4077 for (i = 0; i < page_cnt; i++) {
4078 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
4079 ECORE_CHAIN_PAGE_SIZE);
4081 DP_NOTICE(p_dev, true,
4082 "Failed to allocate chain memory\n");
4087 ecore_chain_init_mem(p_chain, p_virt, p_phys);
4088 ecore_chain_reset(p_chain);
4091 /* Fill the PBL table with the physical address of the page */
4092 *(dma_addr_t *)p_pbl_virt = p_phys;
4093 /* Keep the virtual address of the page */
4094 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
4096 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
4099 return ECORE_SUCCESS;
4102 enum _ecore_status_t ecore_chain_alloc(struct ecore_dev *p_dev,
4103 enum ecore_chain_use_mode intended_use,
4104 enum ecore_chain_mode mode,
4105 enum ecore_chain_cnt_type cnt_type,
4106 u32 num_elems, osal_size_t elem_size,
4107 struct ecore_chain *p_chain,
4108 struct ecore_chain_ext_pbl *ext_pbl)
4111 enum _ecore_status_t rc = ECORE_SUCCESS;
4113 if (mode == ECORE_CHAIN_MODE_SINGLE)
4116 page_cnt = ECORE_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
4118 rc = ecore_chain_alloc_sanity_check(p_dev, cnt_type, elem_size,
4121 DP_NOTICE(p_dev, true,
4122 "Cannot allocate a chain with the given arguments:\n"
4123 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
4124 intended_use, mode, cnt_type, num_elems, elem_size);
4128 ecore_chain_init_params(p_chain, page_cnt, (u8)elem_size, intended_use,
4129 mode, cnt_type, p_dev->dp_ctx);
4132 case ECORE_CHAIN_MODE_NEXT_PTR:
4133 rc = ecore_chain_alloc_next_ptr(p_dev, p_chain);
4135 case ECORE_CHAIN_MODE_SINGLE:
4136 rc = ecore_chain_alloc_single(p_dev, p_chain);
4138 case ECORE_CHAIN_MODE_PBL:
4139 rc = ecore_chain_alloc_pbl(p_dev, p_chain, ext_pbl);
4145 return ECORE_SUCCESS;
4148 ecore_chain_free(p_dev, p_chain);
4152 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
4153 u16 src_id, u16 *dst_id)
4155 if (src_id >= RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
4158 min = (u16)RESC_START(p_hwfn, ECORE_L2_QUEUE);
4159 max = min + RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
4160 DP_NOTICE(p_hwfn, true,
4161 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
4167 *dst_id = RESC_START(p_hwfn, ECORE_L2_QUEUE) + src_id;
4169 return ECORE_SUCCESS;
4172 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
4173 u8 src_id, u8 *dst_id)
4175 if (src_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
4178 min = (u8)RESC_START(p_hwfn, ECORE_VPORT);
4179 max = min + RESC_NUM(p_hwfn, ECORE_VPORT);
4180 DP_NOTICE(p_hwfn, true,
4181 "vport id [%d] is not valid, available indices [%d - %d]\n",
4187 *dst_id = RESC_START(p_hwfn, ECORE_VPORT) + src_id;
4189 return ECORE_SUCCESS;
4192 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
4193 u8 src_id, u8 *dst_id)
4195 if (src_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG)) {
4198 min = (u8)RESC_START(p_hwfn, ECORE_RSS_ENG);
4199 max = min + RESC_NUM(p_hwfn, ECORE_RSS_ENG);
4200 DP_NOTICE(p_hwfn, true,
4201 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
4207 *dst_id = RESC_START(p_hwfn, ECORE_RSS_ENG) + src_id;
4209 return ECORE_SUCCESS;
4212 static enum _ecore_status_t
4213 ecore_llh_add_mac_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4214 struct ecore_ptt *p_ptt, u32 high, u32 low,
4220 /* Find a free entry and utilize it */
4221 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4222 en = ecore_rd(p_hwfn, p_ptt,
4223 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4227 ecore_wr(p_hwfn, p_ptt,
4228 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4229 2 * i * sizeof(u32), low);
4230 ecore_wr(p_hwfn, p_ptt,
4231 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4232 (2 * i + 1) * sizeof(u32), high);
4233 ecore_wr(p_hwfn, p_ptt,
4234 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4235 i * sizeof(u32), 0);
4236 ecore_wr(p_hwfn, p_ptt,
4237 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4238 i * sizeof(u32), 0);
4239 ecore_wr(p_hwfn, p_ptt,
4240 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4241 i * sizeof(u32), 1);
4245 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4246 return ECORE_NORESOURCES;
4250 return ECORE_SUCCESS;
4253 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
4254 struct ecore_ptt *p_ptt, u8 *p_filter)
4256 u32 high, low, entry_num;
4257 enum _ecore_status_t rc;
4259 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4260 return ECORE_SUCCESS;
4262 high = p_filter[1] | (p_filter[0] << 8);
4263 low = p_filter[5] | (p_filter[4] << 8) |
4264 (p_filter[3] << 16) | (p_filter[2] << 24);
4266 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4267 rc = ecore_llh_add_mac_filter_bb_ah(p_hwfn, p_ptt, high, low,
4269 if (rc != ECORE_SUCCESS) {
4270 DP_NOTICE(p_hwfn, false,
4271 "Failed to find an empty LLH filter to utilize\n");
4275 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4276 "MAC: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx is added at %d\n",
4277 p_filter[0], p_filter[1], p_filter[2], p_filter[3],
4278 p_filter[4], p_filter[5], entry_num);
4280 return ECORE_SUCCESS;
4283 static enum _ecore_status_t
4284 ecore_llh_remove_mac_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4285 struct ecore_ptt *p_ptt, u32 high, u32 low,
4290 /* Find the entry and clean it */
4291 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4292 if (ecore_rd(p_hwfn, p_ptt,
4293 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4294 2 * i * sizeof(u32)) != low)
4296 if (ecore_rd(p_hwfn, p_ptt,
4297 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4298 (2 * i + 1) * sizeof(u32)) != high)
4301 ecore_wr(p_hwfn, p_ptt,
4302 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 0);
4303 ecore_wr(p_hwfn, p_ptt,
4304 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4305 2 * i * sizeof(u32), 0);
4306 ecore_wr(p_hwfn, p_ptt,
4307 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4308 (2 * i + 1) * sizeof(u32), 0);
4312 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4317 return ECORE_SUCCESS;
4320 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
4321 struct ecore_ptt *p_ptt, u8 *p_filter)
4323 u32 high, low, entry_num;
4324 enum _ecore_status_t rc;
4326 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4329 high = p_filter[1] | (p_filter[0] << 8);
4330 low = p_filter[5] | (p_filter[4] << 8) |
4331 (p_filter[3] << 16) | (p_filter[2] << 24);
4333 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4334 rc = ecore_llh_remove_mac_filter_bb_ah(p_hwfn, p_ptt, high,
4336 if (rc != ECORE_SUCCESS) {
4337 DP_NOTICE(p_hwfn, false,
4338 "Tried to remove a non-configured filter\n");
4343 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4344 "MAC: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx was removed from %d\n",
4345 p_filter[0], p_filter[1], p_filter[2], p_filter[3],
4346 p_filter[4], p_filter[5], entry_num);
4349 static enum _ecore_status_t
4350 ecore_llh_add_protocol_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4351 struct ecore_ptt *p_ptt,
4352 enum ecore_llh_port_filter_type_t type,
4353 u32 high, u32 low, u32 *p_entry_num)
4358 /* Find a free entry and utilize it */
4359 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4360 en = ecore_rd(p_hwfn, p_ptt,
4361 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4365 ecore_wr(p_hwfn, p_ptt,
4366 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4367 2 * i * sizeof(u32), low);
4368 ecore_wr(p_hwfn, p_ptt,
4369 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4370 (2 * i + 1) * sizeof(u32), high);
4371 ecore_wr(p_hwfn, p_ptt,
4372 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4373 i * sizeof(u32), 1);
4374 ecore_wr(p_hwfn, p_ptt,
4375 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4376 i * sizeof(u32), 1 << type);
4377 ecore_wr(p_hwfn, p_ptt,
4378 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 1);
4382 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4383 return ECORE_NORESOURCES;
4387 return ECORE_SUCCESS;
4390 enum _ecore_status_t
4391 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
4392 struct ecore_ptt *p_ptt,
4393 u16 source_port_or_eth_type,
4395 enum ecore_llh_port_filter_type_t type)
4397 u32 high, low, entry_num;
4398 enum _ecore_status_t rc;
4400 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4401 return ECORE_SUCCESS;
4407 case ECORE_LLH_FILTER_ETHERTYPE:
4408 high = source_port_or_eth_type;
4410 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4411 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4412 low = source_port_or_eth_type << 16;
4414 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4415 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4418 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4419 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4420 low = (source_port_or_eth_type << 16) | dest_port;
4423 DP_NOTICE(p_hwfn, true,
4424 "Non valid LLH protocol filter type %d\n", type);
4428 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4429 rc = ecore_llh_add_protocol_filter_bb_ah(p_hwfn, p_ptt, type,
4430 high, low, &entry_num);
4431 if (rc != ECORE_SUCCESS) {
4432 DP_NOTICE(p_hwfn, false,
4433 "Failed to find an empty LLH filter to utilize\n");
4437 case ECORE_LLH_FILTER_ETHERTYPE:
4438 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4439 "ETH type %x is added at %d\n",
4440 source_port_or_eth_type, entry_num);
4442 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4443 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4444 "TCP src port %x is added at %d\n",
4445 source_port_or_eth_type, entry_num);
4447 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4448 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4449 "UDP src port %x is added at %d\n",
4450 source_port_or_eth_type, entry_num);
4452 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4453 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4454 "TCP dst port %x is added at %d\n", dest_port,
4457 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4458 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4459 "UDP dst port %x is added at %d\n", dest_port,
4462 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4463 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4464 "TCP src/dst ports %x/%x are added at %d\n",
4465 source_port_or_eth_type, dest_port, entry_num);
4467 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4468 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4469 "UDP src/dst ports %x/%x are added at %d\n",
4470 source_port_or_eth_type, dest_port, entry_num);
4474 return ECORE_SUCCESS;
4477 static enum _ecore_status_t
4478 ecore_llh_remove_protocol_filter_bb_ah(struct ecore_hwfn *p_hwfn,
4479 struct ecore_ptt *p_ptt,
4480 enum ecore_llh_port_filter_type_t type,
4481 u32 high, u32 low, u32 *p_entry_num)
4485 /* Find the entry and clean it */
4486 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4487 if (!ecore_rd(p_hwfn, p_ptt,
4488 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4491 if (!ecore_rd(p_hwfn, p_ptt,
4492 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4495 if (!(ecore_rd(p_hwfn, p_ptt,
4496 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4497 i * sizeof(u32)) & (1 << type)))
4499 if (ecore_rd(p_hwfn, p_ptt,
4500 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4501 2 * i * sizeof(u32)) != low)
4503 if (ecore_rd(p_hwfn, p_ptt,
4504 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4505 (2 * i + 1) * sizeof(u32)) != high)
4508 ecore_wr(p_hwfn, p_ptt,
4509 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 + i * sizeof(u32), 0);
4510 ecore_wr(p_hwfn, p_ptt,
4511 NIG_REG_LLH_FUNC_FILTER_MODE_BB_K2 +
4512 i * sizeof(u32), 0);
4513 ecore_wr(p_hwfn, p_ptt,
4514 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE_BB_K2 +
4515 i * sizeof(u32), 0);
4516 ecore_wr(p_hwfn, p_ptt,
4517 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4518 2 * i * sizeof(u32), 0);
4519 ecore_wr(p_hwfn, p_ptt,
4520 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4521 (2 * i + 1) * sizeof(u32), 0);
4525 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4530 return ECORE_SUCCESS;
4534 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
4535 struct ecore_ptt *p_ptt,
4536 u16 source_port_or_eth_type,
4538 enum ecore_llh_port_filter_type_t type)
4540 u32 high, low, entry_num;
4541 enum _ecore_status_t rc;
4543 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4550 case ECORE_LLH_FILTER_ETHERTYPE:
4551 high = source_port_or_eth_type;
4553 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4554 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4555 low = source_port_or_eth_type << 16;
4557 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4558 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4561 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4562 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4563 low = (source_port_or_eth_type << 16) | dest_port;
4566 DP_NOTICE(p_hwfn, true,
4567 "Non valid LLH protocol filter type %d\n", type);
4571 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4572 rc = ecore_llh_remove_protocol_filter_bb_ah(p_hwfn, p_ptt, type,
4575 if (rc != ECORE_SUCCESS) {
4576 DP_NOTICE(p_hwfn, false,
4577 "Tried to remove a non-configured filter [type %d, source_port_or_eth_type 0x%x, dest_port 0x%x]\n",
4578 type, source_port_or_eth_type, dest_port);
4582 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4583 "Protocol filter [type %d, source_port_or_eth_type 0x%x, dest_port 0x%x] was removed from %d\n",
4584 type, source_port_or_eth_type, dest_port, entry_num);
4587 static void ecore_llh_clear_all_filters_bb_ah(struct ecore_hwfn *p_hwfn,
4588 struct ecore_ptt *p_ptt)
4592 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4595 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4596 ecore_wr(p_hwfn, p_ptt,
4597 NIG_REG_LLH_FUNC_FILTER_EN_BB_K2 +
4598 i * sizeof(u32), 0);
4599 ecore_wr(p_hwfn, p_ptt,
4600 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4601 2 * i * sizeof(u32), 0);
4602 ecore_wr(p_hwfn, p_ptt,
4603 NIG_REG_LLH_FUNC_FILTER_VALUE_BB_K2 +
4604 (2 * i + 1) * sizeof(u32), 0);
4608 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
4609 struct ecore_ptt *p_ptt)
4611 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4614 if (ECORE_IS_BB(p_hwfn->p_dev) || ECORE_IS_AH(p_hwfn->p_dev))
4615 ecore_llh_clear_all_filters_bb_ah(p_hwfn, p_ptt);
4618 enum _ecore_status_t
4619 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
4620 struct ecore_ptt *p_ptt)
4622 if (IS_MF_DEFAULT(p_hwfn) && ECORE_IS_BB(p_hwfn->p_dev)) {
4623 ecore_wr(p_hwfn, p_ptt,
4624 NIG_REG_LLH_TAGMAC_DEF_PF_VECTOR,
4625 1 << p_hwfn->abs_pf_id / 2);
4626 ecore_wr(p_hwfn, p_ptt, PRS_REG_MSG_INFO, 0);
4627 return ECORE_SUCCESS;
4630 DP_NOTICE(p_hwfn, false,
4631 "This function can't be set as default\n");
4635 static enum _ecore_status_t ecore_set_coalesce(struct ecore_hwfn *p_hwfn,
4636 struct ecore_ptt *p_ptt,
4637 u32 hw_addr, void *p_eth_qzone,
4638 osal_size_t eth_qzone_size,
4641 struct coalescing_timeset *p_coal_timeset;
4643 if (p_hwfn->p_dev->int_coalescing_mode != ECORE_COAL_MODE_ENABLE) {
4644 DP_NOTICE(p_hwfn, true,
4645 "Coalescing configuration not enabled\n");
4649 p_coal_timeset = p_eth_qzone;
4650 OSAL_MEMSET(p_eth_qzone, 0, eth_qzone_size);
4651 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
4652 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
4653 ecore_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
4655 return ECORE_SUCCESS;
4658 enum _ecore_status_t ecore_set_queue_coalesce(struct ecore_hwfn *p_hwfn,
4659 u16 rx_coal, u16 tx_coal,
4662 struct ecore_queue_cid *p_cid = (struct ecore_queue_cid *)p_handle;
4663 enum _ecore_status_t rc = ECORE_SUCCESS;
4664 struct ecore_ptt *p_ptt;
4666 /* TODO - Configuring a single queue's coalescing but
4667 * claiming all queues are abiding same configuration
4668 * for PF and VF both.
4671 if (IS_VF(p_hwfn->p_dev))
4672 return ecore_vf_pf_set_coalesce(p_hwfn, rx_coal,
4675 p_ptt = ecore_ptt_acquire(p_hwfn);
4680 rc = ecore_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
4683 p_hwfn->p_dev->rx_coalesce_usecs = rx_coal;
4687 rc = ecore_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
4690 p_hwfn->p_dev->tx_coalesce_usecs = tx_coal;
4693 ecore_ptt_release(p_hwfn, p_ptt);
4698 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
4699 struct ecore_ptt *p_ptt,
4701 struct ecore_queue_cid *p_cid)
4703 struct ustorm_eth_queue_zone eth_qzone;
4704 u8 timeset, timer_res;
4706 enum _ecore_status_t rc;
4708 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4709 if (coalesce <= 0x7F) {
4711 } else if (coalesce <= 0xFF) {
4713 } else if (coalesce <= 0x1FF) {
4716 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4719 timeset = (u8)(coalesce >> timer_res);
4721 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
4722 p_cid->sb_igu_id, false);
4723 if (rc != ECORE_SUCCESS)
4726 address = BAR0_MAP_REG_USDM_RAM +
4727 USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4729 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4730 sizeof(struct ustorm_eth_queue_zone), timeset);
4731 if (rc != ECORE_SUCCESS)
4738 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
4739 struct ecore_ptt *p_ptt,
4741 struct ecore_queue_cid *p_cid)
4743 struct xstorm_eth_queue_zone eth_qzone;
4744 u8 timeset, timer_res;
4746 enum _ecore_status_t rc;
4748 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4749 if (coalesce <= 0x7F) {
4751 } else if (coalesce <= 0xFF) {
4753 } else if (coalesce <= 0x1FF) {
4756 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4760 timeset = (u8)(coalesce >> timer_res);
4762 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res,
4763 p_cid->sb_igu_id, true);
4764 if (rc != ECORE_SUCCESS)
4767 address = BAR0_MAP_REG_XSDM_RAM +
4768 XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4770 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4771 sizeof(struct xstorm_eth_queue_zone), timeset);
4776 /* Calculate final WFQ values for all vports and configure it.
4777 * After this configuration each vport must have
4778 * approx min rate = vport_wfq * min_pf_rate / ECORE_WFQ_UNIT
4780 static void ecore_configure_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4781 struct ecore_ptt *p_ptt,
4784 struct init_qm_vport_params *vport_params;
4787 vport_params = p_hwfn->qm_info.qm_vport_params;
4789 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4790 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4792 vport_params[i].vport_wfq = (wfq_speed * ECORE_WFQ_UNIT) /
4794 ecore_init_vport_wfq(p_hwfn, p_ptt,
4795 vport_params[i].first_tx_pq_id,
4796 vport_params[i].vport_wfq);
4801 ecore_init_wfq_default_param(struct ecore_hwfn *p_hwfn, u32 min_pf_rate)
4805 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
4806 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
4809 static void ecore_disable_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4810 struct ecore_ptt *p_ptt,
4813 struct init_qm_vport_params *vport_params;
4816 vport_params = p_hwfn->qm_info.qm_vport_params;
4818 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4819 ecore_init_wfq_default_param(p_hwfn, min_pf_rate);
4820 ecore_init_vport_wfq(p_hwfn, p_ptt,
4821 vport_params[i].first_tx_pq_id,
4822 vport_params[i].vport_wfq);
4826 /* This function performs several validations for WFQ
4827 * configuration and required min rate for a given vport
4828 * 1. req_rate must be greater than one percent of min_pf_rate.
4829 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
4830 * rates to get less than one percent of min_pf_rate.
4831 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
4833 static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
4834 u16 vport_id, u32 req_rate,
4837 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
4838 int non_requested_count = 0, req_count = 0, i, num_vports;
4840 num_vports = p_hwfn->qm_info.num_vports;
4842 /* Accounting for the vports which are configured for WFQ explicitly */
4844 for (i = 0; i < num_vports; i++) {
4847 if ((i != vport_id) && p_hwfn->qm_info.wfq_data[i].configured) {
4849 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4850 total_req_min_rate += tmp_speed;
4854 /* Include current vport data as well */
4856 total_req_min_rate += req_rate;
4857 non_requested_count = num_vports - req_count;
4859 /* validate possible error cases */
4860 if (req_rate > min_pf_rate) {
4861 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4862 "Vport [%d] - Requested rate[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4863 vport_id, req_rate, min_pf_rate);
4867 if (req_rate < min_pf_rate / ECORE_WFQ_UNIT) {
4868 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4869 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4870 vport_id, req_rate, min_pf_rate);
4874 /* TBD - for number of vports greater than 100 */
4875 if (num_vports > ECORE_WFQ_UNIT) {
4876 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4877 "Number of vports is greater than %d\n",
4882 if (total_req_min_rate > min_pf_rate) {
4883 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4884 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4885 total_req_min_rate, min_pf_rate);
4889 /* Data left for non requested vports */
4890 total_left_rate = min_pf_rate - total_req_min_rate;
4891 left_rate_per_vp = total_left_rate / non_requested_count;
4893 /* validate if non requested get < 1% of min bw */
4894 if (left_rate_per_vp < min_pf_rate / ECORE_WFQ_UNIT) {
4895 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4896 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4897 left_rate_per_vp, min_pf_rate);
4901 /* now req_rate for given vport passes all scenarios.
4902 * assign final wfq rates to all vports.
4904 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
4905 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
4907 for (i = 0; i < num_vports; i++) {
4908 if (p_hwfn->qm_info.wfq_data[i].configured)
4911 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
4914 return ECORE_SUCCESS;
4917 static int __ecore_configure_vport_wfq(struct ecore_hwfn *p_hwfn,
4918 struct ecore_ptt *p_ptt,
4919 u16 vp_id, u32 rate)
4921 struct ecore_mcp_link_state *p_link;
4922 int rc = ECORE_SUCCESS;
4924 p_link = &p_hwfn->p_dev->hwfns[0].mcp_info->link_output;
4926 if (!p_link->min_pf_rate) {
4927 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
4928 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
4932 rc = ecore_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
4934 if (rc == ECORE_SUCCESS)
4935 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt,
4936 p_link->min_pf_rate);
4938 DP_NOTICE(p_hwfn, false,
4939 "Validation failed while configuring min rate\n");
4944 static int __ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn *p_hwfn,
4945 struct ecore_ptt *p_ptt,
4948 bool use_wfq = false;
4949 int rc = ECORE_SUCCESS;
4952 /* Validate all pre configured vports for wfq */
4953 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4956 if (!p_hwfn->qm_info.wfq_data[i].configured)
4959 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
4962 rc = ecore_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
4963 if (rc != ECORE_SUCCESS) {
4964 DP_NOTICE(p_hwfn, false,
4965 "WFQ validation failed while configuring min rate\n");
4970 if (rc == ECORE_SUCCESS && use_wfq)
4971 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4973 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4978 /* Main API for ecore clients to configure vport min rate.
4979 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
4980 * rate - Speed in Mbps needs to be assigned to a given vport.
4982 int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate)
4984 int i, rc = ECORE_INVAL;
4986 /* TBD - for multiple hardware functions - that is 100 gig */
4987 if (p_dev->num_hwfns > 1) {
4988 DP_NOTICE(p_dev, false,
4989 "WFQ configuration is not supported for this device\n");
4993 for_each_hwfn(p_dev, i) {
4994 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4995 struct ecore_ptt *p_ptt;
4997 p_ptt = ecore_ptt_acquire(p_hwfn);
4999 return ECORE_TIMEOUT;
5001 rc = __ecore_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
5003 if (rc != ECORE_SUCCESS) {
5004 ecore_ptt_release(p_hwfn, p_ptt);
5008 ecore_ptt_release(p_hwfn, p_ptt);
5014 /* API to configure WFQ from mcp link change */
5015 void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
5016 struct ecore_ptt *p_ptt,
5021 /* TBD - for multiple hardware functions - that is 100 gig */
5022 if (p_dev->num_hwfns > 1) {
5023 DP_VERBOSE(p_dev, ECORE_MSG_LINK,
5024 "WFQ configuration is not supported for this device\n");
5028 for_each_hwfn(p_dev, i) {
5029 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5031 __ecore_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
5036 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
5037 struct ecore_ptt *p_ptt,
5038 struct ecore_mcp_link_state *p_link,
5041 int rc = ECORE_SUCCESS;
5043 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
5045 if (!p_link->line_speed && (max_bw != 100))
5048 p_link->speed = (p_link->line_speed * max_bw) / 100;
5049 p_hwfn->qm_info.pf_rl = p_link->speed;
5051 /* Since the limiter also affects Tx-switched traffic, we don't want it
5052 * to limit such traffic in case there's no actual limit.
5053 * In that case, set limit to imaginary high boundary.
5056 p_hwfn->qm_info.pf_rl = 100000;
5058 rc = ecore_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
5059 p_hwfn->qm_info.pf_rl);
5061 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
5062 "Configured MAX bandwidth to be %08x Mb/sec\n",
5068 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
5069 int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw)
5071 int i, rc = ECORE_INVAL;
5073 if (max_bw < 1 || max_bw > 100) {
5074 DP_NOTICE(p_dev, false, "PF max bw valid range is [1-100]\n");
5078 for_each_hwfn(p_dev, i) {
5079 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5080 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
5081 struct ecore_mcp_link_state *p_link;
5082 struct ecore_ptt *p_ptt;
5084 p_link = &p_lead->mcp_info->link_output;
5086 p_ptt = ecore_ptt_acquire(p_hwfn);
5088 return ECORE_TIMEOUT;
5090 rc = __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
5093 ecore_ptt_release(p_hwfn, p_ptt);
5095 if (rc != ECORE_SUCCESS)
5102 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
5103 struct ecore_ptt *p_ptt,
5104 struct ecore_mcp_link_state *p_link,
5107 int rc = ECORE_SUCCESS;
5109 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
5110 p_hwfn->qm_info.pf_wfq = min_bw;
5112 if (!p_link->line_speed)
5115 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
5117 rc = ecore_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
5119 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
5120 "Configured MIN bandwidth to be %d Mb/sec\n",
5121 p_link->min_pf_rate);
5126 /* Main API to configure PF min bandwidth where bw range is [1-100] */
5127 int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw)
5129 int i, rc = ECORE_INVAL;
5131 if (min_bw < 1 || min_bw > 100) {
5132 DP_NOTICE(p_dev, false, "PF min bw valid range is [1-100]\n");
5136 for_each_hwfn(p_dev, i) {
5137 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
5138 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
5139 struct ecore_mcp_link_state *p_link;
5140 struct ecore_ptt *p_ptt;
5142 p_link = &p_lead->mcp_info->link_output;
5144 p_ptt = ecore_ptt_acquire(p_hwfn);
5146 return ECORE_TIMEOUT;
5148 rc = __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
5150 if (rc != ECORE_SUCCESS) {
5151 ecore_ptt_release(p_hwfn, p_ptt);
5155 if (p_link->min_pf_rate) {
5156 u32 min_rate = p_link->min_pf_rate;
5158 rc = __ecore_configure_vp_wfq_on_link_change(p_hwfn,
5163 ecore_ptt_release(p_hwfn, p_ptt);
5169 void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
5171 struct ecore_mcp_link_state *p_link;
5173 p_link = &p_hwfn->mcp_info->link_output;
5175 if (p_link->min_pf_rate)
5176 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt,
5177 p_link->min_pf_rate);
5179 OSAL_MEMSET(p_hwfn->qm_info.wfq_data, 0,
5180 sizeof(*p_hwfn->qm_info.wfq_data) *
5181 p_hwfn->qm_info.num_vports);
5184 int ecore_device_num_engines(struct ecore_dev *p_dev)
5186 return ECORE_IS_BB(p_dev) ? 2 : 1;
5189 int ecore_device_num_ports(struct ecore_dev *p_dev)
5191 /* in CMT always only one port */
5192 if (p_dev->num_hwfns > 1)
5195 return p_dev->num_ports_in_engines * ecore_device_num_engines(p_dev);
5198 void ecore_set_fw_mac_addr(__le16 *fw_msb,
5203 ((u8 *)fw_msb)[0] = mac[1];
5204 ((u8 *)fw_msb)[1] = mac[0];
5205 ((u8 *)fw_mid)[0] = mac[3];
5206 ((u8 *)fw_mid)[1] = mac[2];
5207 ((u8 *)fw_lsb)[0] = mac[5];
5208 ((u8 *)fw_lsb)[1] = mac[4];