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"
34 /* TODO - there's a bug in DCBx re-configuration flows in MF, as the QM
35 * registers involved are not split and thus configuration is a race where
36 * some of the PFs configuration might be lost.
37 * Eventually, this needs to move into a MFW-covered HW-lock as arbitration
38 * mechanism as this doesn't cover some cases [E.g., PDA or scenarios where
39 * there's more than a single compiled ecore component in system].
41 static osal_spinlock_t qm_lock;
42 static bool qm_lock_init;
45 #define ECORE_MIN_DPIS (4) /* The minimal num of DPIs required to
46 * load the driver. The number was
51 #define ECORE_MIN_PWM_REGION ((ECORE_WID_SIZE) * (ECORE_MIN_DPIS))
54 BAR_ID_0, /* used for GRC */
55 BAR_ID_1 /* Used for doorbells */
58 static u32 ecore_hw_bar_size(struct ecore_hwfn *p_hwfn, enum BAR_ID bar_id)
60 u32 bar_reg = (bar_id == BAR_ID_0 ?
61 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
64 if (IS_VF(p_hwfn->p_dev)) {
65 /* TODO - assume each VF hwfn has 64Kb for Bar0; Bar1 can be
66 * read from actual register, but we're currently not using
67 * it for actual doorbelling.
72 val = ecore_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
74 return 1 << (val + 15);
76 /* The above registers were updated in the past only in CMT mode. Since
77 * they were found to be useful MFW started updating them from 8.7.7.0.
78 * In older MFW versions they are set to 0 which means disabled.
80 if (p_hwfn->p_dev->num_hwfns > 1) {
81 DP_NOTICE(p_hwfn, false,
82 "BAR size not configured. Assuming BAR size of 256kB"
83 " for GRC and 512kB for DB\n");
84 val = BAR_ID_0 ? 256 * 1024 : 512 * 1024;
86 DP_NOTICE(p_hwfn, false,
87 "BAR size not configured. Assuming BAR size of 512kB"
88 " for GRC and 512kB for DB\n");
95 void ecore_init_dp(struct ecore_dev *p_dev,
96 u32 dp_module, u8 dp_level, void *dp_ctx)
100 p_dev->dp_level = dp_level;
101 p_dev->dp_module = dp_module;
102 p_dev->dp_ctx = dp_ctx;
103 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
104 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
106 p_hwfn->dp_level = dp_level;
107 p_hwfn->dp_module = dp_module;
108 p_hwfn->dp_ctx = dp_ctx;
112 void ecore_init_struct(struct ecore_dev *p_dev)
116 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
117 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
119 p_hwfn->p_dev = p_dev;
121 p_hwfn->b_active = false;
123 OSAL_MUTEX_ALLOC(p_hwfn, &p_hwfn->dmae_info.mutex);
124 OSAL_MUTEX_INIT(&p_hwfn->dmae_info.mutex);
127 /* hwfn 0 is always active */
128 p_dev->hwfns[0].b_active = true;
130 /* set the default cache alignment to 128 (may be overridden later) */
131 p_dev->cache_shift = 7;
134 static void ecore_qm_info_free(struct ecore_hwfn *p_hwfn)
136 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
138 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_pq_params);
139 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_vport_params);
140 OSAL_FREE(p_hwfn->p_dev, qm_info->qm_port_params);
141 OSAL_FREE(p_hwfn->p_dev, qm_info->wfq_data);
144 void ecore_resc_free(struct ecore_dev *p_dev)
151 OSAL_FREE(p_dev, p_dev->fw_data);
153 OSAL_FREE(p_dev, p_dev->reset_stats);
155 for_each_hwfn(p_dev, i) {
156 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
158 ecore_cxt_mngr_free(p_hwfn);
159 ecore_qm_info_free(p_hwfn);
160 ecore_spq_free(p_hwfn);
161 ecore_eq_free(p_hwfn);
162 ecore_consq_free(p_hwfn);
163 ecore_int_free(p_hwfn);
164 ecore_iov_free(p_hwfn);
165 ecore_dmae_info_free(p_hwfn);
166 ecore_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
167 /* @@@TBD Flush work-queue ? */
171 /******************** QM initialization *******************/
173 /* bitmaps for indicating active traffic classes.
174 * Special case for Arrowhead 4 port
176 /* 0..3 actualy used, 4 serves OOO, 7 serves high priority stuff (e.g. DCQCN) */
177 #define ACTIVE_TCS_BMAP 0x9f
178 /* 0..3 actually used, OOO and high priority stuff all use 3 */
179 #define ACTIVE_TCS_BMAP_4PORT_K2 0xf
181 /* determines the physical queue flags for a given PF. */
182 static u32 ecore_get_pq_flags(struct ecore_hwfn *p_hwfn)
190 if (IS_ECORE_SRIOV(p_hwfn->p_dev))
191 flags |= PQ_FLAGS_VFS;
194 switch (p_hwfn->hw_info.personality) {
196 flags |= PQ_FLAGS_MCOS;
199 flags |= PQ_FLAGS_OFLD;
201 case ECORE_PCI_ISCSI:
202 flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
204 case ECORE_PCI_ETH_ROCE:
205 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD;
207 case ECORE_PCI_ETH_IWARP:
208 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_ACK | PQ_FLAGS_OOO |
212 DP_ERR(p_hwfn, "unknown personality %d\n",
213 p_hwfn->hw_info.personality);
219 /* Getters for resource amounts necessary for qm initialization */
220 u8 ecore_init_qm_get_num_tcs(struct ecore_hwfn *p_hwfn)
222 return p_hwfn->hw_info.num_hw_tc;
225 u16 ecore_init_qm_get_num_vfs(struct ecore_hwfn *p_hwfn)
227 return IS_ECORE_SRIOV(p_hwfn->p_dev) ?
228 p_hwfn->p_dev->p_iov_info->total_vfs : 0;
231 #define NUM_DEFAULT_RLS 1
233 u16 ecore_init_qm_get_num_pf_rls(struct ecore_hwfn *p_hwfn)
235 u16 num_pf_rls, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
238 /* num RLs can't exceed resource amount of rls or vports or the
241 num_pf_rls = (u16)OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_RL),
242 (u16)RESC_NUM(p_hwfn, ECORE_VPORT));
244 /* make sure after we reserve the default and VF rls we'll have
247 if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS) {
248 DP_NOTICE(p_hwfn, false,
249 "no rate limiters left for PF rate limiting"
250 " [num_pf_rls %d num_vfs %d]\n", num_pf_rls, num_vfs);
254 /* subtract rls necessary for VFs and one default one for the PF */
255 num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
260 u16 ecore_init_qm_get_num_vports(struct ecore_hwfn *p_hwfn)
262 u32 pq_flags = ecore_get_pq_flags(p_hwfn);
264 /* all pqs share the same vport (hence the 1 below), except for vfs
267 return (!!(PQ_FLAGS_RLS & pq_flags)) *
268 ecore_init_qm_get_num_pf_rls(p_hwfn) +
269 (!!(PQ_FLAGS_VFS & pq_flags)) *
270 ecore_init_qm_get_num_vfs(p_hwfn) + 1;
273 /* calc amount of PQs according to the requested flags */
274 u16 ecore_init_qm_get_num_pqs(struct ecore_hwfn *p_hwfn)
276 u32 pq_flags = ecore_get_pq_flags(p_hwfn);
278 return (!!(PQ_FLAGS_RLS & pq_flags)) *
279 ecore_init_qm_get_num_pf_rls(p_hwfn) +
280 (!!(PQ_FLAGS_MCOS & pq_flags)) *
281 ecore_init_qm_get_num_tcs(p_hwfn) +
282 (!!(PQ_FLAGS_LB & pq_flags)) +
283 (!!(PQ_FLAGS_OOO & pq_flags)) +
284 (!!(PQ_FLAGS_ACK & pq_flags)) +
285 (!!(PQ_FLAGS_OFLD & pq_flags)) +
286 (!!(PQ_FLAGS_VFS & pq_flags)) *
287 ecore_init_qm_get_num_vfs(p_hwfn);
290 /* initialize the top level QM params */
291 static void ecore_init_qm_params(struct ecore_hwfn *p_hwfn)
293 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
295 /* pq and vport bases for this PF */
296 qm_info->start_pq = (u16)RESC_START(p_hwfn, ECORE_PQ);
297 qm_info->start_vport = (u8)RESC_START(p_hwfn, ECORE_VPORT);
299 /* rate limiting and weighted fair queueing are always enabled */
300 qm_info->vport_rl_en = 1;
301 qm_info->vport_wfq_en = 1;
303 /* in AH 4 port we have fewer TCs per port */
304 qm_info->max_phys_tcs_per_port =
305 p_hwfn->p_dev->num_ports_in_engines == MAX_NUM_PORTS_K2 ?
306 NUM_PHYS_TCS_4PORT_K2 : NUM_OF_PHYS_TCS;
309 /* initialize qm vport params */
310 static void ecore_init_qm_vport_params(struct ecore_hwfn *p_hwfn)
312 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
315 /* all vports participate in weighted fair queueing */
316 for (i = 0; i < ecore_init_qm_get_num_vports(p_hwfn); i++)
317 qm_info->qm_vport_params[i].vport_wfq = 1;
320 /* initialize qm port params */
321 static void ecore_init_qm_port_params(struct ecore_hwfn *p_hwfn)
323 /* Initialize qm port parameters */
324 u8 i, active_phys_tcs, num_ports = p_hwfn->p_dev->num_ports_in_engines;
326 /* indicate how ooo and high pri traffic is dealt with */
327 active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
328 ACTIVE_TCS_BMAP_4PORT_K2 : ACTIVE_TCS_BMAP;
330 for (i = 0; i < num_ports; i++) {
331 struct init_qm_port_params *p_qm_port =
332 &p_hwfn->qm_info.qm_port_params[i];
334 p_qm_port->active = 1;
335 p_qm_port->active_phys_tcs = active_phys_tcs;
336 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
337 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
341 /* Reset the params which must be reset for qm init. QM init may be called as
342 * a result of flows other than driver load (e.g. dcbx renegotiation). Other
343 * params may be affected by the init but would simply recalculate to the same
344 * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
345 * affected as these amounts stay the same.
347 static void ecore_init_qm_reset_params(struct ecore_hwfn *p_hwfn)
349 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
351 qm_info->num_pqs = 0;
352 qm_info->num_vports = 0;
353 qm_info->num_pf_rls = 0;
354 qm_info->num_vf_pqs = 0;
355 qm_info->first_vf_pq = 0;
356 qm_info->first_mcos_pq = 0;
357 qm_info->first_rl_pq = 0;
360 static void ecore_init_qm_advance_vport(struct ecore_hwfn *p_hwfn)
362 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
364 qm_info->num_vports++;
366 if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
368 "vport overflow! qm_info->num_vports %d,"
369 " qm_init_get_num_vports() %d\n",
371 ecore_init_qm_get_num_vports(p_hwfn));
374 /* initialize a single pq and manage qm_info resources accounting.
375 * The pq_init_flags param determines whether the PQ is rate limited
377 * and whether a new vport is allocated to the pq or not (i.e. vport will be
381 /* flags for pq init */
382 #define PQ_INIT_SHARE_VPORT (1 << 0)
383 #define PQ_INIT_PF_RL (1 << 1)
384 #define PQ_INIT_VF_RL (1 << 2)
386 /* defines for pq init */
387 #define PQ_INIT_DEFAULT_WRR_GROUP 1
388 #define PQ_INIT_DEFAULT_TC 0
389 #define PQ_INIT_OFLD_TC (p_hwfn->hw_info.offload_tc)
391 static void ecore_init_qm_pq(struct ecore_hwfn *p_hwfn,
392 struct ecore_qm_info *qm_info,
393 u8 tc, u32 pq_init_flags)
395 u16 pq_idx = qm_info->num_pqs, max_pq =
396 ecore_init_qm_get_num_pqs(p_hwfn);
400 "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
403 qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
405 qm_info->qm_pq_params[pq_idx].tc_id = tc;
406 qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
407 qm_info->qm_pq_params[pq_idx].rl_valid =
408 (pq_init_flags & PQ_INIT_PF_RL ||
409 pq_init_flags & PQ_INIT_VF_RL);
411 /* qm params accounting */
413 if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
414 qm_info->num_vports++;
416 if (pq_init_flags & PQ_INIT_PF_RL)
417 qm_info->num_pf_rls++;
419 if (qm_info->num_vports > ecore_init_qm_get_num_vports(p_hwfn))
421 "vport overflow! qm_info->num_vports %d,"
422 " qm_init_get_num_vports() %d\n",
424 ecore_init_qm_get_num_vports(p_hwfn));
426 if (qm_info->num_pf_rls > ecore_init_qm_get_num_pf_rls(p_hwfn))
427 DP_ERR(p_hwfn, "rl overflow! qm_info->num_pf_rls %d,"
428 " qm_init_get_num_pf_rls() %d\n",
430 ecore_init_qm_get_num_pf_rls(p_hwfn));
433 /* get pq index according to PQ_FLAGS */
434 static u16 *ecore_init_qm_get_idx_from_flags(struct ecore_hwfn *p_hwfn,
437 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
439 /* Can't have multiple flags set here */
440 if (OSAL_BITMAP_WEIGHT((unsigned long *)&pq_flags,
441 sizeof(pq_flags)) > 1)
446 return &qm_info->first_rl_pq;
448 return &qm_info->first_mcos_pq;
450 return &qm_info->pure_lb_pq;
452 return &qm_info->ooo_pq;
454 return &qm_info->pure_ack_pq;
456 return &qm_info->offload_pq;
458 return &qm_info->first_vf_pq;
464 DP_ERR(p_hwfn, "BAD pq flags %d\n", pq_flags);
468 /* save pq index in qm info */
469 static void ecore_init_qm_set_idx(struct ecore_hwfn *p_hwfn,
470 u32 pq_flags, u16 pq_val)
472 u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
474 *base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
477 /* get tx pq index, with the PQ TX base already set (ready for context init) */
478 u16 ecore_get_cm_pq_idx(struct ecore_hwfn *p_hwfn, u32 pq_flags)
480 u16 *base_pq_idx = ecore_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
482 return *base_pq_idx + CM_TX_PQ_BASE;
485 u16 ecore_get_cm_pq_idx_mcos(struct ecore_hwfn *p_hwfn, u8 tc)
487 u8 max_tc = ecore_init_qm_get_num_tcs(p_hwfn);
490 DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
492 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
495 u16 ecore_get_cm_pq_idx_vf(struct ecore_hwfn *p_hwfn, u16 vf)
497 u16 max_vf = ecore_init_qm_get_num_vfs(p_hwfn);
500 DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
502 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
505 u16 ecore_get_cm_pq_idx_rl(struct ecore_hwfn *p_hwfn, u8 rl)
507 u16 max_rl = ecore_init_qm_get_num_pf_rls(p_hwfn);
510 DP_ERR(p_hwfn, "rl %d must be smaller than %d\n", rl, max_rl);
512 return ecore_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
515 /* Functions for creating specific types of pqs */
516 static void ecore_init_qm_lb_pq(struct ecore_hwfn *p_hwfn)
518 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
520 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
523 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
524 ecore_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
527 static void ecore_init_qm_ooo_pq(struct ecore_hwfn *p_hwfn)
529 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
531 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
534 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
535 ecore_init_qm_pq(p_hwfn, qm_info, DCBX_ISCSI_OOO_TC,
536 PQ_INIT_SHARE_VPORT);
539 static void ecore_init_qm_pure_ack_pq(struct ecore_hwfn *p_hwfn)
541 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
543 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
546 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
547 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
550 static void ecore_init_qm_offload_pq(struct ecore_hwfn *p_hwfn)
552 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
554 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
557 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
558 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
561 static void ecore_init_qm_mcos_pqs(struct ecore_hwfn *p_hwfn)
563 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
566 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
569 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
570 for (tc_idx = 0; tc_idx < ecore_init_qm_get_num_tcs(p_hwfn); tc_idx++)
571 ecore_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
574 static void ecore_init_qm_vf_pqs(struct ecore_hwfn *p_hwfn)
576 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
577 u16 vf_idx, num_vfs = ecore_init_qm_get_num_vfs(p_hwfn);
579 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
582 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
584 qm_info->num_vf_pqs = num_vfs;
585 for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
586 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_DEFAULT_TC,
590 static void ecore_init_qm_rl_pqs(struct ecore_hwfn *p_hwfn)
592 u16 pf_rls_idx, num_pf_rls = ecore_init_qm_get_num_pf_rls(p_hwfn);
593 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
595 if (!(ecore_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
598 ecore_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
599 for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
600 ecore_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC,
604 static void ecore_init_qm_pq_params(struct ecore_hwfn *p_hwfn)
606 /* rate limited pqs, must come first (FW assumption) */
607 ecore_init_qm_rl_pqs(p_hwfn);
609 /* pqs for multi cos */
610 ecore_init_qm_mcos_pqs(p_hwfn);
612 /* pure loopback pq */
613 ecore_init_qm_lb_pq(p_hwfn);
615 /* out of order pq */
616 ecore_init_qm_ooo_pq(p_hwfn);
619 ecore_init_qm_pure_ack_pq(p_hwfn);
621 /* pq for offloaded protocol */
622 ecore_init_qm_offload_pq(p_hwfn);
624 /* done sharing vports */
625 ecore_init_qm_advance_vport(p_hwfn);
628 ecore_init_qm_vf_pqs(p_hwfn);
631 /* compare values of getters against resources amounts */
632 static enum _ecore_status_t ecore_init_qm_sanity(struct ecore_hwfn *p_hwfn)
634 if (ecore_init_qm_get_num_vports(p_hwfn) >
635 RESC_NUM(p_hwfn, ECORE_VPORT)) {
636 DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
640 if (ecore_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, ECORE_PQ)) {
641 DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
645 return ECORE_SUCCESS;
649 * Function for verbose printing of the qm initialization results
651 static void ecore_dp_init_qm_params(struct ecore_hwfn *p_hwfn)
653 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
654 struct init_qm_vport_params *vport;
655 struct init_qm_port_params *port;
656 struct init_qm_pq_params *pq;
659 /* top level params */
660 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
661 "qm init top level params: start_pq %d, start_vport %d,"
662 " pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
663 qm_info->start_pq, qm_info->start_vport, qm_info->pure_lb_pq,
664 qm_info->offload_pq, qm_info->pure_ack_pq);
665 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
666 "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d,"
667 " num_vports %d, max_phys_tcs_per_port %d\n",
668 qm_info->ooo_pq, qm_info->first_vf_pq, qm_info->num_pqs,
669 qm_info->num_vf_pqs, qm_info->num_vports,
670 qm_info->max_phys_tcs_per_port);
671 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
672 "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d,"
673 " pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
674 qm_info->pf_rl_en, qm_info->pf_wfq_en, qm_info->vport_rl_en,
675 qm_info->vport_wfq_en, qm_info->pf_wfq, qm_info->pf_rl,
676 qm_info->num_pf_rls, ecore_get_pq_flags(p_hwfn));
679 for (i = 0; i < p_hwfn->p_dev->num_ports_in_engines; i++) {
680 port = &qm_info->qm_port_params[i];
681 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
682 "port idx %d, active %d, active_phys_tcs %d,"
683 " num_pbf_cmd_lines %d, num_btb_blocks %d,"
685 i, port->active, port->active_phys_tcs,
686 port->num_pbf_cmd_lines, port->num_btb_blocks,
691 for (i = 0; i < qm_info->num_vports; i++) {
692 vport = &qm_info->qm_vport_params[i];
693 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
694 "vport idx %d, vport_rl %d, wfq %d,"
695 " first_tx_pq_id [ ",
696 qm_info->start_vport + i, vport->vport_rl,
698 for (tc = 0; tc < NUM_OF_TCS; tc++)
699 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "%d ",
700 vport->first_tx_pq_id[tc]);
701 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "]\n");
705 for (i = 0; i < qm_info->num_pqs; i++) {
706 pq = &qm_info->qm_pq_params[i];
707 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
708 "pq idx %d, vport_id %d, tc %d, wrr_grp %d,"
710 qm_info->start_pq + i, pq->vport_id, pq->tc_id,
711 pq->wrr_group, pq->rl_valid);
715 static void ecore_init_qm_info(struct ecore_hwfn *p_hwfn)
717 /* reset params required for init run */
718 ecore_init_qm_reset_params(p_hwfn);
720 /* init QM top level params */
721 ecore_init_qm_params(p_hwfn);
723 /* init QM port params */
724 ecore_init_qm_port_params(p_hwfn);
726 /* init QM vport params */
727 ecore_init_qm_vport_params(p_hwfn);
729 /* init QM physical queue params */
730 ecore_init_qm_pq_params(p_hwfn);
732 /* display all that init */
733 ecore_dp_init_qm_params(p_hwfn);
736 /* This function reconfigures the QM pf on the fly.
737 * For this purpose we:
738 * 1. reconfigure the QM database
739 * 2. set new values to runtime array
740 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
741 * 4. activate init tool in QM_PF stage
742 * 5. send an sdm_qm_cmd through rbc interface to release the QM
744 enum _ecore_status_t ecore_qm_reconf(struct ecore_hwfn *p_hwfn,
745 struct ecore_ptt *p_ptt)
747 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
748 enum _ecore_status_t rc;
751 /* initialize ecore's qm data structure */
752 ecore_init_qm_info(p_hwfn);
754 /* stop PF's qm queues */
755 OSAL_SPIN_LOCK(&qm_lock);
756 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
757 qm_info->start_pq, qm_info->num_pqs);
758 OSAL_SPIN_UNLOCK(&qm_lock);
762 /* clear the QM_PF runtime phase leftovers from previous init */
763 ecore_init_clear_rt_data(p_hwfn);
765 /* prepare QM portion of runtime array */
766 ecore_qm_init_pf(p_hwfn);
768 /* activate init tool on runtime array */
769 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
770 p_hwfn->hw_info.hw_mode);
771 if (rc != ECORE_SUCCESS)
774 /* start PF's qm queues */
775 OSAL_SPIN_LOCK(&qm_lock);
776 b_rc = ecore_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
777 qm_info->start_pq, qm_info->num_pqs);
778 OSAL_SPIN_UNLOCK(&qm_lock);
782 return ECORE_SUCCESS;
785 static enum _ecore_status_t ecore_alloc_qm_data(struct ecore_hwfn *p_hwfn)
787 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
788 enum _ecore_status_t rc;
790 rc = ecore_init_qm_sanity(p_hwfn);
791 if (rc != ECORE_SUCCESS)
794 qm_info->qm_pq_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
795 sizeof(struct init_qm_pq_params) *
796 ecore_init_qm_get_num_pqs(p_hwfn));
797 if (!qm_info->qm_pq_params)
800 qm_info->qm_vport_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
801 sizeof(struct init_qm_vport_params) *
802 ecore_init_qm_get_num_vports(p_hwfn));
803 if (!qm_info->qm_vport_params)
806 qm_info->qm_port_params = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
807 sizeof(struct init_qm_port_params) *
808 p_hwfn->p_dev->num_ports_in_engines);
809 if (!qm_info->qm_port_params)
812 qm_info->wfq_data = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
813 sizeof(struct ecore_wfq_data) *
814 ecore_init_qm_get_num_vports(p_hwfn));
815 if (!qm_info->wfq_data)
818 return ECORE_SUCCESS;
821 DP_NOTICE(p_hwfn, false, "Failed to allocate memory for QM params\n");
822 ecore_qm_info_free(p_hwfn);
825 /******************** End QM initialization ***************/
827 enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev)
829 enum _ecore_status_t rc = ECORE_SUCCESS;
835 p_dev->fw_data = OSAL_ZALLOC(p_dev, GFP_KERNEL,
836 sizeof(*p_dev->fw_data));
840 for_each_hwfn(p_dev, i) {
841 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
842 u32 n_eqes, num_cons;
844 /* First allocate the context manager structure */
845 rc = ecore_cxt_mngr_alloc(p_hwfn);
849 /* Set the HW cid/tid numbers (in the contest manager)
850 * Must be done prior to any further computations.
852 rc = ecore_cxt_set_pf_params(p_hwfn);
856 rc = ecore_alloc_qm_data(p_hwfn);
861 ecore_init_qm_info(p_hwfn);
863 /* Compute the ILT client partition */
864 rc = ecore_cxt_cfg_ilt_compute(p_hwfn);
868 /* CID map / ILT shadow table / T2
869 * The talbes sizes are determined by the computations above
871 rc = ecore_cxt_tables_alloc(p_hwfn);
875 /* SPQ, must follow ILT because initializes SPQ context */
876 rc = ecore_spq_alloc(p_hwfn);
880 /* SP status block allocation */
881 p_hwfn->p_dpc_ptt = ecore_get_reserved_ptt(p_hwfn,
884 rc = ecore_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
888 rc = ecore_iov_alloc(p_hwfn);
893 n_eqes = ecore_chain_get_capacity(&p_hwfn->p_spq->chain);
894 if (ECORE_IS_RDMA_PERSONALITY(p_hwfn)) {
895 /* Calculate the EQ size
896 * ---------------------
897 * Each ICID may generate up to one event at a time i.e.
898 * the event must be handled/cleared before a new one
899 * can be generated. We calculate the sum of events per
900 * protocol and create an EQ deep enough to handle the
902 * - Core - according to SPQ.
903 * - RoCE - per QP there are a couple of ICIDs, one
904 * responder and one requester, each can
905 * generate an EQE => n_eqes_qp = 2 * n_qp.
906 * Each CQ can generate an EQE. There are 2 CQs
907 * per QP => n_eqes_cq = 2 * n_qp.
908 * Hence the RoCE total is 4 * n_qp or
910 * - ENet - There can be up to two events per VF. One
911 * for VF-PF channel and another for VF FLR
912 * initial cleanup. The number of VFs is
913 * bounded by MAX_NUM_VFS_BB, and is much
914 * smaller than RoCE's so we avoid exact
917 if (ECORE_IS_ROCE_PERSONALITY(p_hwfn)) {
919 ecore_cxt_get_proto_cid_count(
925 num_cons = ecore_cxt_get_proto_cid_count(
930 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
931 } else if (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) {
933 ecore_cxt_get_proto_cid_count(p_hwfn,
936 n_eqes += 2 * num_cons;
939 if (n_eqes > 0xFFFF) {
940 DP_ERR(p_hwfn, "Cannot allocate 0x%x EQ elements."
941 "The maximum of a u16 chain is 0x%x\n",
946 rc = ecore_eq_alloc(p_hwfn, (u16)n_eqes);
950 rc = ecore_consq_alloc(p_hwfn);
954 /* DMA info initialization */
955 rc = ecore_dmae_info_alloc(p_hwfn);
957 DP_NOTICE(p_hwfn, true,
958 "Failed to allocate memory for dmae_info"
963 /* DCBX initialization */
964 rc = ecore_dcbx_info_alloc(p_hwfn);
966 DP_NOTICE(p_hwfn, true,
967 "Failed to allocate memory for dcbx structure\n");
972 p_dev->reset_stats = OSAL_ZALLOC(p_dev, GFP_KERNEL,
973 sizeof(*p_dev->reset_stats));
974 if (!p_dev->reset_stats) {
975 DP_NOTICE(p_dev, true, "Failed to allocate reset statistics\n");
979 return ECORE_SUCCESS;
984 ecore_resc_free(p_dev);
988 void ecore_resc_setup(struct ecore_dev *p_dev)
995 for_each_hwfn(p_dev, i) {
996 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
998 ecore_cxt_mngr_setup(p_hwfn);
999 ecore_spq_setup(p_hwfn);
1000 ecore_eq_setup(p_hwfn);
1001 ecore_consq_setup(p_hwfn);
1003 /* Read shadow of current MFW mailbox */
1004 ecore_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
1005 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1006 p_hwfn->mcp_info->mfw_mb_cur,
1007 p_hwfn->mcp_info->mfw_mb_length);
1009 ecore_int_setup(p_hwfn, p_hwfn->p_main_ptt);
1011 ecore_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
1015 #define FINAL_CLEANUP_POLL_CNT (100)
1016 #define FINAL_CLEANUP_POLL_TIME (10)
1017 enum _ecore_status_t ecore_final_cleanup(struct ecore_hwfn *p_hwfn,
1018 struct ecore_ptt *p_ptt,
1021 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
1022 enum _ecore_status_t rc = ECORE_TIMEOUT;
1025 if (CHIP_REV_IS_TEDIBEAR(p_hwfn->p_dev) ||
1026 CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1027 DP_INFO(p_hwfn, "Skipping final cleanup for non-ASIC\n");
1028 return ECORE_SUCCESS;
1032 addr = GTT_BAR0_MAP_REG_USDM_RAM +
1033 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
1038 command |= X_FINAL_CLEANUP_AGG_INT <<
1039 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
1040 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
1041 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
1042 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
1044 /* Make sure notification is not set before initiating final cleanup */
1046 if (REG_RD(p_hwfn, addr)) {
1047 DP_NOTICE(p_hwfn, false,
1048 "Unexpected; Found final cleanup notification");
1049 DP_NOTICE(p_hwfn, false,
1050 " before initiating final cleanup\n");
1051 REG_WR(p_hwfn, addr, 0);
1054 DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
1055 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
1058 ecore_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
1060 /* Poll until completion */
1061 while (!REG_RD(p_hwfn, addr) && count--)
1062 OSAL_MSLEEP(FINAL_CLEANUP_POLL_TIME);
1064 if (REG_RD(p_hwfn, addr))
1067 DP_NOTICE(p_hwfn, true,
1068 "Failed to receive FW final cleanup notification\n");
1070 /* Cleanup afterwards */
1071 REG_WR(p_hwfn, addr, 0);
1076 static enum _ecore_status_t ecore_calc_hw_mode(struct ecore_hwfn *p_hwfn)
1080 if (ECORE_IS_BB_B0(p_hwfn->p_dev)) {
1081 hw_mode |= 1 << MODE_BB;
1082 } else if (ECORE_IS_AH(p_hwfn->p_dev)) {
1083 hw_mode |= 1 << MODE_K2;
1085 DP_NOTICE(p_hwfn, true, "Unknown chip type %#x\n",
1086 p_hwfn->p_dev->type);
1090 /* Ports per engine is based on the values in CNIG_REG_NW_PORT_MODE */
1091 switch (p_hwfn->p_dev->num_ports_in_engines) {
1093 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
1096 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
1099 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
1102 DP_NOTICE(p_hwfn, true,
1103 "num_ports_in_engine = %d not supported\n",
1104 p_hwfn->p_dev->num_ports_in_engines);
1108 switch (p_hwfn->p_dev->mf_mode) {
1109 case ECORE_MF_DEFAULT:
1111 hw_mode |= 1 << MODE_MF_SI;
1113 case ECORE_MF_OVLAN:
1114 hw_mode |= 1 << MODE_MF_SD;
1117 DP_NOTICE(p_hwfn, true,
1118 "Unsupported MF mode, init as DEFAULT\n");
1119 hw_mode |= 1 << MODE_MF_SI;
1123 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
1124 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1125 hw_mode |= 1 << MODE_FPGA;
1127 if (p_hwfn->p_dev->b_is_emul_full)
1128 hw_mode |= 1 << MODE_EMUL_FULL;
1130 hw_mode |= 1 << MODE_EMUL_REDUCED;
1134 hw_mode |= 1 << MODE_ASIC;
1136 if (p_hwfn->p_dev->num_hwfns > 1)
1137 hw_mode |= 1 << MODE_100G;
1139 p_hwfn->hw_info.hw_mode = hw_mode;
1141 DP_VERBOSE(p_hwfn, (ECORE_MSG_PROBE | ECORE_MSG_IFUP),
1142 "Configuring function for hw_mode: 0x%08x\n",
1143 p_hwfn->hw_info.hw_mode);
1145 return ECORE_SUCCESS;
1149 /* MFW-replacement initializations for non-ASIC */
1150 static enum _ecore_status_t ecore_hw_init_chip(struct ecore_hwfn *p_hwfn,
1151 struct ecore_ptt *p_ptt)
1153 struct ecore_dev *p_dev = p_hwfn->p_dev;
1157 if (CHIP_REV_IS_EMUL(p_dev)) {
1158 if (ECORE_IS_AH(p_dev))
1162 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV + 4, pl_hv);
1164 if (CHIP_REV_IS_EMUL(p_dev) &&
1165 (ECORE_IS_AH(p_dev)))
1166 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV_2_K2_E5,
1169 /* initialize port mode to 4x10G_E (10G with 4x10 SERDES) */
1170 /* CNIG_REG_NW_PORT_MODE is same for A0 and B0 */
1171 if (!CHIP_REV_IS_EMUL(p_dev) || ECORE_IS_BB(p_dev))
1172 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB, 4);
1174 if (CHIP_REV_IS_EMUL(p_dev)) {
1175 if (ECORE_IS_AH(p_dev)) {
1176 /* 2 for 4-port, 1 for 2-port, 0 for 1-port */
1177 ecore_wr(p_hwfn, p_ptt, MISC_REG_PORT_MODE,
1178 (p_dev->num_ports_in_engines >> 1));
1180 ecore_wr(p_hwfn, p_ptt, MISC_REG_BLOCK_256B_EN,
1181 p_dev->num_ports_in_engines == 4 ? 0 : 3);
1186 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_RBC_DONE, 1);
1187 for (i = 0; i < 100; i++) {
1189 if (ecore_rd(p_hwfn, p_ptt, PSWRQ2_REG_CFG_DONE) == 1)
1193 DP_NOTICE(p_hwfn, true,
1194 "RBC done failed to complete in PSWRQ2\n");
1196 return ECORE_SUCCESS;
1200 /* Init run time data for all PFs and their VFs on an engine.
1201 * TBD - for VFs - Once we have parent PF info for each VF in
1202 * shmem available as CAU requires knowledge of parent PF for each VF.
1204 static void ecore_init_cau_rt_data(struct ecore_dev *p_dev)
1206 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
1209 for_each_hwfn(p_dev, i) {
1210 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1211 struct ecore_igu_info *p_igu_info;
1212 struct ecore_igu_block *p_block;
1213 struct cau_sb_entry sb_entry;
1215 p_igu_info = p_hwfn->hw_info.p_igu_info;
1217 for (sb_id = 0; sb_id < ECORE_MAPPING_MEMORY_SIZE(p_dev);
1219 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
1221 if (!p_block->is_pf)
1224 ecore_init_cau_sb_entry(p_hwfn, &sb_entry,
1225 p_block->function_id, 0, 0);
1226 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry);
1231 static enum _ecore_status_t ecore_hw_init_common(struct ecore_hwfn *p_hwfn,
1232 struct ecore_ptt *p_ptt,
1235 struct ecore_qm_info *qm_info = &p_hwfn->qm_info;
1236 struct ecore_dev *p_dev = p_hwfn->p_dev;
1237 u8 vf_id, max_num_vfs;
1240 enum _ecore_status_t rc = ECORE_SUCCESS;
1242 ecore_init_cau_rt_data(p_dev);
1244 /* Program GTT windows */
1245 ecore_gtt_init(p_hwfn);
1248 if (CHIP_REV_IS_EMUL(p_dev)) {
1249 rc = ecore_hw_init_chip(p_hwfn, p_hwfn->p_main_ptt);
1250 if (rc != ECORE_SUCCESS)
1255 if (p_hwfn->mcp_info) {
1256 if (p_hwfn->mcp_info->func_info.bandwidth_max)
1257 qm_info->pf_rl_en = 1;
1258 if (p_hwfn->mcp_info->func_info.bandwidth_min)
1259 qm_info->pf_wfq_en = 1;
1262 ecore_qm_common_rt_init(p_hwfn,
1263 p_dev->num_ports_in_engines,
1264 qm_info->max_phys_tcs_per_port,
1265 qm_info->pf_rl_en, qm_info->pf_wfq_en,
1266 qm_info->vport_rl_en, qm_info->vport_wfq_en,
1267 qm_info->qm_port_params);
1269 ecore_cxt_hw_init_common(p_hwfn);
1271 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
1272 if (rc != ECORE_SUCCESS)
1275 /* @@TBD MichalK - should add VALIDATE_VFID to init tool...
1276 * need to decide with which value, maybe runtime
1278 ecore_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
1279 ecore_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
1281 if (ECORE_IS_BB(p_dev)) {
1282 /* Workaround clears ROCE search for all functions to prevent
1283 * involving non initialized function in processing ROCE packet.
1285 num_pfs = NUM_OF_ENG_PFS(p_dev);
1286 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
1287 ecore_fid_pretend(p_hwfn, p_ptt, pf_id);
1288 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1289 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1291 /* pretend to original PF */
1292 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1295 /* Workaround for avoiding CCFC execution error when getting packets
1296 * with CRC errors, and allowing instead the invoking of the FW error
1298 * This is not done inside the init tool since it currently can't
1299 * perform a pretending to VFs.
1301 max_num_vfs = ECORE_IS_AH(p_dev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
1302 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
1303 concrete_fid = ecore_vfid_to_concrete(p_hwfn, vf_id);
1304 ecore_fid_pretend(p_hwfn, p_ptt, (u16)concrete_fid);
1305 ecore_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
1306 ecore_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
1307 ecore_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
1308 ecore_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
1310 /* pretend to original PF */
1311 ecore_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1317 #define MISC_REG_RESET_REG_2_XMAC_BIT (1 << 4)
1318 #define MISC_REG_RESET_REG_2_XMAC_SOFT_BIT (1 << 5)
1320 #define PMEG_IF_BYTE_COUNT 8
1322 static void ecore_wr_nw_port(struct ecore_hwfn *p_hwfn,
1323 struct ecore_ptt *p_ptt,
1324 u32 addr, u64 data, u8 reg_type, u8 port)
1326 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
1327 "CMD: %08x, ADDR: 0x%08x, DATA: %08x:%08x\n",
1328 ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) |
1329 (8 << PMEG_IF_BYTE_COUNT),
1330 (reg_type << 25) | (addr << 8) | port,
1331 (u32)((data >> 32) & 0xffffffff),
1332 (u32)(data & 0xffffffff));
1334 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB,
1335 (ecore_rd(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_CMD_BB) &
1336 0xffff00fe) | (8 << PMEG_IF_BYTE_COUNT));
1337 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_ADDR_BB,
1338 (reg_type << 25) | (addr << 8) | port);
1339 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB, data & 0xffffffff);
1340 ecore_wr(p_hwfn, p_ptt, CNIG_REG_PMEG_IF_WRDATA_BB,
1341 (data >> 32) & 0xffffffff);
1344 #define XLPORT_MODE_REG (0x20a)
1345 #define XLPORT_MAC_CONTROL (0x210)
1346 #define XLPORT_FLOW_CONTROL_CONFIG (0x207)
1347 #define XLPORT_ENABLE_REG (0x20b)
1349 #define XLMAC_CTRL (0x600)
1350 #define XLMAC_MODE (0x601)
1351 #define XLMAC_RX_MAX_SIZE (0x608)
1352 #define XLMAC_TX_CTRL (0x604)
1353 #define XLMAC_PAUSE_CTRL (0x60d)
1354 #define XLMAC_PFC_CTRL (0x60e)
1356 static void ecore_emul_link_init_bb(struct ecore_hwfn *p_hwfn,
1357 struct ecore_ptt *p_ptt)
1359 u8 loopback = 0, port = p_hwfn->port_id * 2;
1361 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
1363 /* XLPORT MAC MODE *//* 0 Quad, 4 Single... */
1364 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MODE_REG, (0x4 << 4) | 0x4, 1,
1366 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_MAC_CONTROL, 0, 1, port);
1367 /* XLMAC: SOFT RESET */
1368 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x40, 0, port);
1369 /* XLMAC: Port Speed >= 10Gbps */
1370 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_MODE, 0x40, 0, port);
1371 /* XLMAC: Max Size */
1372 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_RX_MAX_SIZE, 0x3fff, 0, port);
1373 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_TX_CTRL,
1374 0x01000000800ULL | (0xa << 12) | ((u64)1 << 38),
1376 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PAUSE_CTRL, 0x7c000, 0, port);
1377 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_PFC_CTRL,
1378 0x30ffffc000ULL, 0, port);
1379 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL, 0x3 | (loopback << 2), 0,
1380 port); /* XLMAC: TX_EN, RX_EN */
1381 /* XLMAC: TX_EN, RX_EN, SW_LINK_STATUS */
1382 ecore_wr_nw_port(p_hwfn, p_ptt, XLMAC_CTRL,
1383 0x1003 | (loopback << 2), 0, port);
1384 /* Enabled Parallel PFC interface */
1385 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_FLOW_CONTROL_CONFIG, 1, 0, port);
1387 /* XLPORT port enable */
1388 ecore_wr_nw_port(p_hwfn, p_ptt, XLPORT_ENABLE_REG, 0xf, 1, port);
1391 static void ecore_emul_link_init_ah_e5(struct ecore_hwfn *p_hwfn,
1392 struct ecore_ptt *p_ptt)
1394 u8 port = p_hwfn->port_id;
1395 u32 mac_base = NWM_REG_MAC0_K2_E5 + (port << 2) * NWM_REG_MAC0_SIZE;
1397 DP_INFO(p_hwfn->p_dev, "Configurating Emulation Link %02x\n", port);
1399 ecore_wr(p_hwfn, p_ptt, CNIG_REG_NIG_PORT0_CONF_K2_E5 + (port << 2),
1400 (1 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_ENABLE_0_K2_E5_SHIFT) |
1402 CNIG_REG_NIG_PORT0_CONF_NIG_PORT_NWM_PORT_MAP_0_K2_E5_SHIFT) |
1403 (0 << CNIG_REG_NIG_PORT0_CONF_NIG_PORT_RATE_0_K2_E5_SHIFT));
1405 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_XIF_MODE_K2_E5,
1406 1 << ETH_MAC_REG_XIF_MODE_XGMII_K2_E5_SHIFT);
1408 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_FRM_LENGTH_K2_E5,
1409 9018 << ETH_MAC_REG_FRM_LENGTH_FRM_LENGTH_K2_E5_SHIFT);
1411 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_IPG_LENGTH_K2_E5,
1412 0xc << ETH_MAC_REG_TX_IPG_LENGTH_TXIPG_K2_E5_SHIFT);
1414 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_RX_FIFO_SECTIONS_K2_E5,
1415 8 << ETH_MAC_REG_RX_FIFO_SECTIONS_RX_SECTION_FULL_K2_E5_SHIFT);
1417 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_TX_FIFO_SECTIONS_K2_E5,
1419 ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_EMPTY_K2_E5_SHIFT) |
1421 ETH_MAC_REG_TX_FIFO_SECTIONS_TX_SECTION_FULL_K2_E5_SHIFT));
1423 ecore_wr(p_hwfn, p_ptt, mac_base + ETH_MAC_REG_COMMAND_CONFIG_K2_E5,
1427 static void ecore_emul_link_init(struct ecore_hwfn *p_hwfn,
1428 struct ecore_ptt *p_ptt)
1430 if (ECORE_IS_AH(p_hwfn->p_dev))
1431 ecore_emul_link_init_ah_e5(p_hwfn, p_ptt);
1433 ecore_emul_link_init_bb(p_hwfn, p_ptt);
1436 static void ecore_link_init_bb(struct ecore_hwfn *p_hwfn,
1437 struct ecore_ptt *p_ptt, u8 port)
1439 int port_offset = port ? 0x800 : 0;
1440 u32 xmac_rxctrl = 0;
1443 /* FIXME: move to common start */
1444 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
1445 MISC_REG_RESET_REG_2_XMAC_BIT); /* Clear */
1447 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
1448 MISC_REG_RESET_REG_2_XMAC_BIT); /* Set */
1450 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_CORE_PORT_MODE_BB, 1);
1452 /* Set the number of ports on the Warp Core to 10G */
1453 ecore_wr(p_hwfn, p_ptt, MISC_REG_XMAC_PHY_PORT_MODE_BB, 3);
1455 /* Soft reset of XMAC */
1456 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + 2 * sizeof(u32),
1457 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
1459 ecore_wr(p_hwfn, p_ptt, MISC_REG_RESET_PL_PDA_VAUX + sizeof(u32),
1460 MISC_REG_RESET_REG_2_XMAC_SOFT_BIT);
1462 /* FIXME: move to common end */
1463 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
1464 ecore_wr(p_hwfn, p_ptt, XMAC_REG_MODE_BB + port_offset, 0x20);
1466 /* Set Max packet size: initialize XMAC block register for port 0 */
1467 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_MAX_SIZE_BB + port_offset, 0x2710);
1469 /* CRC append for Tx packets: init XMAC block register for port 1 */
1470 ecore_wr(p_hwfn, p_ptt, XMAC_REG_TX_CTRL_LO_BB + port_offset, 0xC800);
1472 /* Enable TX and RX: initialize XMAC block register for port 1 */
1473 ecore_wr(p_hwfn, p_ptt, XMAC_REG_CTRL_BB + port_offset,
1474 XMAC_REG_CTRL_TX_EN_BB | XMAC_REG_CTRL_RX_EN_BB);
1475 xmac_rxctrl = ecore_rd(p_hwfn, p_ptt,
1476 XMAC_REG_RX_CTRL_BB + port_offset);
1477 xmac_rxctrl |= XMAC_REG_RX_CTRL_PROCESS_VARIABLE_PREAMBLE_BB;
1478 ecore_wr(p_hwfn, p_ptt, XMAC_REG_RX_CTRL_BB + port_offset, xmac_rxctrl);
1482 static enum _ecore_status_t ecore_hw_init_port(struct ecore_hwfn *p_hwfn,
1483 struct ecore_ptt *p_ptt,
1486 enum _ecore_status_t rc = ECORE_SUCCESS;
1488 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
1490 if (rc != ECORE_SUCCESS)
1493 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev))
1494 return ECORE_SUCCESS;
1496 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev)) {
1497 if (ECORE_IS_AH(p_hwfn->p_dev))
1498 return ECORE_SUCCESS;
1499 else if (ECORE_IS_BB(p_hwfn->p_dev))
1500 ecore_link_init_bb(p_hwfn, p_ptt, p_hwfn->port_id);
1501 } else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
1502 if (p_hwfn->p_dev->num_hwfns > 1) {
1503 /* Activate OPTE in CMT */
1506 val = ecore_rd(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV);
1508 ecore_wr(p_hwfn, p_ptt, MISCS_REG_RESET_PL_HV, val);
1509 ecore_wr(p_hwfn, p_ptt, MISC_REG_CLK_100G_MODE, 1);
1510 ecore_wr(p_hwfn, p_ptt, MISCS_REG_CLK_100G_MODE, 1);
1511 ecore_wr(p_hwfn, p_ptt, MISC_REG_OPTE_MODE, 1);
1512 ecore_wr(p_hwfn, p_ptt,
1513 NIG_REG_LLH_ENG_CLS_TCP_4_TUPLE_SEARCH, 1);
1514 ecore_wr(p_hwfn, p_ptt,
1515 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL, 0x55555555);
1516 ecore_wr(p_hwfn, p_ptt,
1517 NIG_REG_LLH_ENG_CLS_ENG_ID_TBL + 0x4,
1521 ecore_emul_link_init(p_hwfn, p_ptt);
1523 DP_INFO(p_hwfn->p_dev, "link is not being configured\n");
1530 static enum _ecore_status_t
1531 ecore_hw_init_dpi_size(struct ecore_hwfn *p_hwfn,
1532 struct ecore_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
1534 u32 dpi_page_size_1, dpi_page_size_2, dpi_page_size;
1535 u32 dpi_bit_shift, dpi_count;
1538 /* Calculate DPI size
1539 * ------------------
1540 * The PWM region contains Doorbell Pages. The first is reserverd for
1541 * the kernel for, e.g, L2. The others are free to be used by non-
1542 * trusted applications, typically from user space. Each page, called a
1543 * doorbell page is sectioned into windows that allow doorbells to be
1544 * issued in parallel by the kernel/application. The size of such a
1545 * window (a.k.a. WID) is 1kB.
1547 * 1kB WID x N WIDS = DPI page size
1548 * DPI page size x N DPIs = PWM region size
1550 * The size of the DPI page size must be in multiples of OSAL_PAGE_SIZE
1551 * in order to ensure that two applications won't share the same page.
1552 * It also must contain at least one WID per CPU to allow parallelism.
1553 * It also must be a power of 2, since it is stored as a bit shift.
1555 * The DPI page size is stored in a register as 'dpi_bit_shift' so that
1556 * 0 is 4kB, 1 is 8kB and etc. Hence the minimum size is 4,096
1557 * containing 4 WIDs.
1559 dpi_page_size_1 = ECORE_WID_SIZE * n_cpus;
1560 dpi_page_size_2 = OSAL_MAX_T(u32, ECORE_WID_SIZE, OSAL_PAGE_SIZE);
1561 dpi_page_size = OSAL_MAX_T(u32, dpi_page_size_1, dpi_page_size_2);
1562 dpi_page_size = OSAL_ROUNDUP_POW_OF_TWO(dpi_page_size);
1563 dpi_bit_shift = OSAL_LOG2(dpi_page_size / 4096);
1565 dpi_count = pwm_region_size / dpi_page_size;
1567 min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
1568 min_dpis = OSAL_MAX_T(u32, ECORE_MIN_DPIS, min_dpis);
1571 p_hwfn->dpi_size = dpi_page_size;
1572 p_hwfn->dpi_count = dpi_count;
1574 /* Update registers */
1575 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
1577 if (dpi_count < min_dpis)
1578 return ECORE_NORESOURCES;
1580 return ECORE_SUCCESS;
1583 enum ECORE_ROCE_EDPM_MODE {
1584 ECORE_ROCE_EDPM_MODE_ENABLE = 0,
1585 ECORE_ROCE_EDPM_MODE_FORCE_ON = 1,
1586 ECORE_ROCE_EDPM_MODE_DISABLE = 2,
1589 static enum _ecore_status_t
1590 ecore_hw_init_pf_doorbell_bar(struct ecore_hwfn *p_hwfn,
1591 struct ecore_ptt *p_ptt)
1593 u32 pwm_regsize, norm_regsize;
1594 u32 non_pwm_conn, min_addr_reg1;
1595 u32 db_bar_size, n_cpus;
1598 int rc = ECORE_SUCCESS;
1601 db_bar_size = ecore_hw_bar_size(p_hwfn, BAR_ID_1);
1602 if (p_hwfn->p_dev->num_hwfns > 1)
1605 /* Calculate doorbell regions
1606 * -----------------------------------
1607 * The doorbell BAR is made of two regions. The first is called normal
1608 * region and the second is called PWM region. In the normal region
1609 * each ICID has its own set of addresses so that writing to that
1610 * specific address identifies the ICID. In the Process Window Mode
1611 * region the ICID is given in the data written to the doorbell. The
1612 * above per PF register denotes the offset in the doorbell BAR in which
1613 * the PWM region begins.
1614 * The normal region has ECORE_PF_DEMS_SIZE bytes per ICID, that is per
1615 * non-PWM connection. The calculation below computes the total non-PWM
1616 * connections. The DORQ_REG_PF_MIN_ADDR_REG1 register is
1617 * in units of 4,096 bytes.
1619 non_pwm_conn = ecore_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1620 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1622 ecore_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, OSAL_NULL);
1623 norm_regsize = ROUNDUP(ECORE_PF_DEMS_SIZE * non_pwm_conn, 4096);
1624 min_addr_reg1 = norm_regsize / 4096;
1625 pwm_regsize = db_bar_size - norm_regsize;
1627 /* Check that the normal and PWM sizes are valid */
1628 if (db_bar_size < norm_regsize) {
1629 DP_ERR(p_hwfn->p_dev,
1630 "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
1631 db_bar_size, norm_regsize);
1632 return ECORE_NORESOURCES;
1634 if (pwm_regsize < ECORE_MIN_PWM_REGION) {
1635 DP_ERR(p_hwfn->p_dev,
1636 "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",
1637 pwm_regsize, ECORE_MIN_PWM_REGION, db_bar_size,
1639 return ECORE_NORESOURCES;
1642 /* Calculate number of DPIs */
1643 roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
1644 if ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE) ||
1645 ((roce_edpm_mode == ECORE_ROCE_EDPM_MODE_FORCE_ON))) {
1646 /* Either EDPM is mandatory, or we are attempting to allocate a
1649 n_cpus = OSAL_NUM_ACTIVE_CPU();
1650 rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1653 cond = ((rc) && (roce_edpm_mode == ECORE_ROCE_EDPM_MODE_ENABLE)) ||
1654 (roce_edpm_mode == ECORE_ROCE_EDPM_MODE_DISABLE);
1655 if (cond || p_hwfn->dcbx_no_edpm) {
1656 /* Either EDPM is disabled from user configuration, or it is
1657 * disabled via DCBx, or it is not mandatory and we failed to
1658 * allocated a WID per CPU.
1661 rc = ecore_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1663 /* If we entered this flow due to DCBX then the DPM register is
1664 * already configured.
1669 "doorbell bar: normal_region_size=%d, pwm_region_size=%d",
1670 norm_regsize, pwm_regsize);
1672 " dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
1673 p_hwfn->dpi_size, p_hwfn->dpi_count,
1674 ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
1675 "disabled" : "enabled");
1677 /* Check return codes from above calls */
1680 "Failed to allocate enough DPIs\n");
1681 return ECORE_NORESOURCES;
1685 p_hwfn->dpi_start_offset = norm_regsize;
1687 /* Update registers */
1688 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1689 pf_dems_shift = OSAL_LOG2(ECORE_PF_DEMS_SIZE / 4);
1690 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1691 ecore_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1693 return ECORE_SUCCESS;
1696 static enum _ecore_status_t
1697 ecore_hw_init_pf(struct ecore_hwfn *p_hwfn,
1698 struct ecore_ptt *p_ptt,
1699 struct ecore_tunnel_info *p_tunn,
1702 enum ecore_int_mode int_mode, bool allow_npar_tx_switch)
1704 u8 rel_pf_id = p_hwfn->rel_pf_id;
1706 enum _ecore_status_t rc = ECORE_SUCCESS;
1710 if (p_hwfn->mcp_info) {
1711 struct ecore_mcp_function_info *p_info;
1713 p_info = &p_hwfn->mcp_info->func_info;
1714 if (p_info->bandwidth_min)
1715 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1717 /* Update rate limit once we'll actually have a link */
1718 p_hwfn->qm_info.pf_rl = 100000;
1720 ecore_cxt_hw_init_pf(p_hwfn);
1722 ecore_int_igu_init_rt(p_hwfn);
1724 /* Set VLAN in NIG if needed */
1725 if (hw_mode & (1 << MODE_MF_SD)) {
1726 DP_VERBOSE(p_hwfn, ECORE_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1727 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1728 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1729 p_hwfn->hw_info.ovlan);
1732 /* Enable classification by MAC if needed */
1733 if (hw_mode & (1 << MODE_MF_SI)) {
1734 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
1735 "Configuring TAGMAC_CLS_TYPE\n");
1736 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET,
1740 /* Protocl Configuration - @@@TBD - should we set 0 otherwise? */
1741 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
1742 (p_hwfn->hw_info.personality == ECORE_PCI_ISCSI) ? 1 : 0);
1743 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
1744 (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) ? 1 : 0);
1745 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
1747 /* perform debug configuration when chip is out of reset */
1748 OSAL_BEFORE_PF_START((void *)p_hwfn->p_dev, p_hwfn->my_id);
1750 /* Cleanup chip from previous driver if such remains exist */
1751 rc = ecore_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
1752 if (rc != ECORE_SUCCESS) {
1753 ecore_hw_err_notify(p_hwfn, ECORE_HW_ERR_RAMROD_FAIL);
1757 /* PF Init sequence */
1758 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1762 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1763 rc = ecore_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1767 /* Pure runtime initializations - directly to the HW */
1768 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1770 /* PCI relaxed ordering causes a decrease in the performance on some
1771 * systems. Till a root cause is found, disable this attribute in the
1775 * pos = OSAL_PCI_FIND_CAPABILITY(p_hwfn->p_dev, PCI_CAP_ID_EXP);
1777 * DP_NOTICE(p_hwfn, true,
1778 * "Failed to find the PCIe Cap\n");
1781 * OSAL_PCI_READ_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, &ctrl);
1782 * ctrl &= ~PCI_EXP_DEVCTL_RELAX_EN;
1783 * OSAL_PCI_WRITE_CONFIG_WORD(p_hwfn->p_dev, pos + PCI_EXP_DEVCTL, ctrl);
1786 rc = ecore_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1790 /* enable interrupts */
1791 rc = ecore_int_igu_enable(p_hwfn, p_ptt, int_mode);
1792 if (rc != ECORE_SUCCESS)
1795 /* send function start command */
1796 rc = ecore_sp_pf_start(p_hwfn, p_tunn, p_hwfn->p_dev->mf_mode,
1797 allow_npar_tx_switch);
1799 DP_NOTICE(p_hwfn, true,
1800 "Function start ramrod failed\n");
1802 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1803 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1804 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1806 if (p_hwfn->hw_info.personality == ECORE_PCI_FCOE) {
1807 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1,
1809 ecore_wr(p_hwfn, p_ptt,
1810 PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
1813 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1814 "PRS_REG_SEARCH registers after start PFn\n");
1815 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP);
1816 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1817 "PRS_REG_SEARCH_TCP: %x\n", prs_reg);
1818 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP);
1819 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1820 "PRS_REG_SEARCH_UDP: %x\n", prs_reg);
1821 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE);
1822 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1823 "PRS_REG_SEARCH_FCOE: %x\n", prs_reg);
1824 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE);
1825 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1826 "PRS_REG_SEARCH_ROCE: %x\n", prs_reg);
1827 prs_reg = ecore_rd(p_hwfn, p_ptt,
1828 PRS_REG_SEARCH_TCP_FIRST_FRAG);
1829 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1830 "PRS_REG_SEARCH_TCP_FIRST_FRAG: %x\n",
1832 prs_reg = ecore_rd(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1);
1833 DP_VERBOSE(p_hwfn, ECORE_MSG_STORAGE,
1834 "PRS_REG_SEARCH_TAG1: %x\n", prs_reg);
1840 static enum _ecore_status_t
1841 ecore_change_pci_hwfn(struct ecore_hwfn *p_hwfn,
1842 struct ecore_ptt *p_ptt, u8 enable)
1844 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
1846 /* Change PF in PXP */
1847 ecore_wr(p_hwfn, p_ptt,
1848 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1850 /* wait until value is set - try for 1 second every 50us */
1851 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1852 val = ecore_rd(p_hwfn, p_ptt,
1853 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1860 if (val != set_val) {
1861 DP_NOTICE(p_hwfn, true,
1862 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1863 return ECORE_UNKNOWN_ERROR;
1866 return ECORE_SUCCESS;
1869 static void ecore_reset_mb_shadow(struct ecore_hwfn *p_hwfn,
1870 struct ecore_ptt *p_main_ptt)
1872 /* Read shadow of current MFW mailbox */
1873 ecore_mcp_read_mb(p_hwfn, p_main_ptt);
1874 OSAL_MEMCPY(p_hwfn->mcp_info->mfw_mb_shadow,
1875 p_hwfn->mcp_info->mfw_mb_cur,
1876 p_hwfn->mcp_info->mfw_mb_length);
1879 enum _ecore_status_t ecore_hw_init(struct ecore_dev *p_dev,
1880 struct ecore_hw_init_params *p_params)
1882 enum _ecore_status_t rc = ECORE_SUCCESS, mfw_rc;
1883 u32 load_code, param, drv_mb_param;
1884 bool b_default_mtu = true;
1885 struct ecore_hwfn *p_hwfn;
1888 if ((p_params->int_mode == ECORE_INT_MODE_MSI) &&
1889 (p_dev->num_hwfns > 1)) {
1890 DP_NOTICE(p_dev, false,
1891 "MSI mode is not supported for CMT devices\n");
1896 rc = ecore_init_fw_data(p_dev, p_params->bin_fw_data);
1897 if (rc != ECORE_SUCCESS)
1901 for_each_hwfn(p_dev, i) {
1902 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
1904 /* If management didn't provide a default, set one of our own */
1905 if (!p_hwfn->hw_info.mtu) {
1906 p_hwfn->hw_info.mtu = 1500;
1907 b_default_mtu = false;
1911 p_hwfn->b_int_enabled = 1;
1915 /* Enable DMAE in PXP */
1916 rc = ecore_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
1917 if (rc != ECORE_SUCCESS)
1920 rc = ecore_calc_hw_mode(p_hwfn);
1921 if (rc != ECORE_SUCCESS)
1924 /* @@@TBD need to add here:
1925 * Check for fan failure
1928 rc = ecore_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt, &load_code);
1930 DP_NOTICE(p_hwfn, true,
1931 "Failed sending LOAD_REQ command\n");
1936 * When coming back from hiberbate state, the registers from
1937 * which shadow is read initially are not initialized. It turns
1938 * out that these registers get initialized during the call to
1939 * ecore_mcp_load_req request. So we need to reread them here
1940 * to get the proper shadow register value.
1941 * Note: This is a workaround for the missing MFW
1942 * initialization. It may be removed once the implementation
1945 ecore_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
1947 DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
1948 "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
1951 /* Only relevant for recovery:
1952 * Clear the indication after the LOAD_REQ command is responded
1955 p_dev->recov_in_prog = false;
1957 p_hwfn->first_on_engine = (load_code ==
1958 FW_MSG_CODE_DRV_LOAD_ENGINE);
1960 if (!qm_lock_init) {
1961 OSAL_SPIN_LOCK_INIT(&qm_lock);
1962 qm_lock_init = true;
1965 switch (load_code) {
1966 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1967 rc = ecore_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
1968 p_hwfn->hw_info.hw_mode);
1972 case FW_MSG_CODE_DRV_LOAD_PORT:
1973 rc = ecore_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
1974 p_hwfn->hw_info.hw_mode);
1978 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1979 rc = ecore_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
1981 p_hwfn->hw_info.hw_mode,
1982 p_params->b_hw_start,
1984 p_params->allow_npar_tx_switch);
1991 if (rc != ECORE_SUCCESS)
1992 DP_NOTICE(p_hwfn, true,
1993 "init phase failed for loadcode 0x%x (rc %d)\n",
1996 /* ACK mfw regardless of success or failure of initialization */
1997 mfw_rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1998 DRV_MSG_CODE_LOAD_DONE,
1999 0, &load_code, ¶m);
2000 if (rc != ECORE_SUCCESS)
2002 if (mfw_rc != ECORE_SUCCESS) {
2003 DP_NOTICE(p_hwfn, true,
2004 "Failed sending LOAD_DONE command\n");
2008 /* send DCBX attention request command */
2009 DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
2010 "sending phony dcbx set command to trigger DCBx attention handling\n");
2011 mfw_rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2012 DRV_MSG_CODE_SET_DCBX,
2013 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
2014 &load_code, ¶m);
2015 if (mfw_rc != ECORE_SUCCESS) {
2016 DP_NOTICE(p_hwfn, true,
2017 "Failed to send DCBX attention request\n");
2021 p_hwfn->hw_init_done = true;
2025 p_hwfn = ECORE_LEADING_HWFN(p_dev);
2026 drv_mb_param = (FW_MAJOR_VERSION << 24) |
2027 (FW_MINOR_VERSION << 16) |
2028 (FW_REVISION_VERSION << 8) |
2029 (FW_ENGINEERING_VERSION);
2030 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2031 DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
2032 drv_mb_param, &load_code, ¶m);
2033 if (rc != ECORE_SUCCESS)
2034 DP_INFO(p_hwfn, "Failed to update firmware version\n");
2037 rc = ecore_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
2038 p_hwfn->hw_info.mtu);
2039 if (rc != ECORE_SUCCESS)
2040 DP_INFO(p_hwfn, "Failed to update default mtu\n");
2042 rc = ecore_mcp_ov_update_driver_state(p_hwfn,
2044 ECORE_OV_DRIVER_STATE_DISABLED);
2045 if (rc != ECORE_SUCCESS)
2046 DP_INFO(p_hwfn, "Failed to update driver state\n");
2052 #define ECORE_HW_STOP_RETRY_LIMIT (10)
2053 static void ecore_hw_timers_stop(struct ecore_dev *p_dev,
2054 struct ecore_hwfn *p_hwfn,
2055 struct ecore_ptt *p_ptt)
2060 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
2061 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
2062 for (i = 0; i < ECORE_HW_STOP_RETRY_LIMIT && !p_dev->recov_in_prog;
2064 if ((!ecore_rd(p_hwfn, p_ptt,
2065 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
2066 (!ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
2069 /* Dependent on number of connection/tasks, possibly
2070 * 1ms sleep is required between polls
2075 if (i < ECORE_HW_STOP_RETRY_LIMIT)
2078 DP_NOTICE(p_hwfn, true, "Timers linear scans are not over"
2079 " [Connection %02x Tasks %02x]\n",
2080 (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
2081 (u8)ecore_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
2084 void ecore_hw_timers_stop_all(struct ecore_dev *p_dev)
2088 for_each_hwfn(p_dev, j) {
2089 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2090 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2092 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
2096 enum _ecore_status_t ecore_hw_stop(struct ecore_dev *p_dev)
2098 enum _ecore_status_t rc = ECORE_SUCCESS, t_rc;
2101 for_each_hwfn(p_dev, j) {
2102 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2103 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2105 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Stopping hw/fw\n");
2108 ecore_vf_pf_int_cleanup(p_hwfn);
2112 /* mark the hw as uninitialized... */
2113 p_hwfn->hw_init_done = false;
2115 rc = ecore_sp_pf_stop(p_hwfn);
2117 DP_NOTICE(p_hwfn, true,
2118 "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
2120 /* perform debug action after PF stop was sent */
2121 OSAL_AFTER_PF_STOP((void *)p_hwfn->p_dev, p_hwfn->my_id);
2123 /* close NIG to BRB gate */
2124 ecore_wr(p_hwfn, p_ptt,
2125 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2128 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2129 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2130 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2131 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2132 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2134 /* @@@TBD - clean transmission queues (5.b) */
2135 /* @@@TBD - clean BTB (5.c) */
2137 ecore_hw_timers_stop(p_dev, p_hwfn, p_ptt);
2139 /* @@@TBD - verify DMAE requests are done (8) */
2141 /* Disable Attention Generation */
2142 ecore_int_igu_disable_int(p_hwfn, p_ptt);
2143 ecore_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
2144 ecore_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
2145 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
2146 /* Need to wait 1ms to guarantee SBs are cleared */
2151 /* Disable DMAE in PXP - in CMT, this should only be done for
2152 * first hw-function, and only after all transactions have
2153 * stopped for all active hw-functions.
2155 t_rc = ecore_change_pci_hwfn(&p_dev->hwfns[0],
2156 p_dev->hwfns[0].p_main_ptt, false);
2157 if (t_rc != ECORE_SUCCESS)
2164 void ecore_hw_stop_fastpath(struct ecore_dev *p_dev)
2168 for_each_hwfn(p_dev, j) {
2169 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
2170 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2173 ecore_vf_pf_int_cleanup(p_hwfn);
2177 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
2178 "Shutting down the fastpath\n");
2180 ecore_wr(p_hwfn, p_ptt,
2181 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2183 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2184 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2185 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2186 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2187 ecore_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2189 /* @@@TBD - clean transmission queues (5.b) */
2190 /* @@@TBD - clean BTB (5.c) */
2192 /* @@@TBD - verify DMAE requests are done (8) */
2194 ecore_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
2195 /* Need to wait 1ms to guarantee SBs are cleared */
2200 void ecore_hw_start_fastpath(struct ecore_hwfn *p_hwfn)
2202 struct ecore_ptt *p_ptt = p_hwfn->p_main_ptt;
2204 if (IS_VF(p_hwfn->p_dev))
2207 /* If roce info is allocated it means roce is initialized and should
2208 * be enabled in searcher.
2210 if (p_hwfn->p_rdma_info) {
2211 if (p_hwfn->b_rdma_enabled_in_prs)
2212 ecore_wr(p_hwfn, p_ptt,
2213 p_hwfn->rdma_prs_search_reg, 0x1);
2214 ecore_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x1);
2217 /* Re-open incoming traffic */
2218 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2219 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
2222 static enum _ecore_status_t ecore_reg_assert(struct ecore_hwfn *p_hwfn,
2223 struct ecore_ptt *p_ptt, u32 reg,
2226 u32 assert_val = ecore_rd(p_hwfn, p_ptt, reg);
2228 if (assert_val != expected) {
2229 DP_NOTICE(p_hwfn, true, "Value at address 0x%08x != 0x%08x\n",
2231 return ECORE_UNKNOWN_ERROR;
2237 enum _ecore_status_t ecore_hw_reset(struct ecore_dev *p_dev)
2239 enum _ecore_status_t rc = ECORE_SUCCESS;
2240 u32 unload_resp, unload_param;
2243 for_each_hwfn(p_dev, i) {
2244 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
2247 rc = ecore_vf_pf_reset(p_hwfn);
2253 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN, "Resetting hw/fw\n");
2255 /* Check for incorrect states */
2256 if (!p_dev->recov_in_prog) {
2257 ecore_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
2258 QM_REG_USG_CNT_PF_TX, 0);
2259 ecore_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
2260 QM_REG_USG_CNT_PF_OTHER, 0);
2261 /* @@@TBD - assert on incorrect xCFC values (10.b) */
2264 /* Disable PF in HW blocks */
2265 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
2266 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
2268 if (p_dev->recov_in_prog) {
2269 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
2270 "Recovery is in progress -> skip sending unload_req/done\n");
2274 /* Send unload command to MCP */
2275 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2276 DRV_MSG_CODE_UNLOAD_REQ,
2277 DRV_MB_PARAM_UNLOAD_WOL_MCP,
2278 &unload_resp, &unload_param);
2279 if (rc != ECORE_SUCCESS) {
2280 DP_NOTICE(p_hwfn, true,
2281 "ecore_hw_reset: UNLOAD_REQ failed\n");
2282 /* @@TBD - what to do? for now, assume ENG. */
2283 unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
2286 rc = ecore_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
2287 DRV_MSG_CODE_UNLOAD_DONE,
2288 0, &unload_resp, &unload_param);
2289 if (rc != ECORE_SUCCESS) {
2291 true, "ecore_hw_reset: UNLOAD_DONE failed\n");
2292 /* @@@TBD - Should it really ASSERT here ? */
2300 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
2301 static void ecore_hw_hwfn_free(struct ecore_hwfn *p_hwfn)
2303 ecore_ptt_pool_free(p_hwfn);
2304 OSAL_FREE(p_hwfn->p_dev, p_hwfn->hw_info.p_igu_info);
2307 /* Setup bar access */
2308 static void ecore_hw_hwfn_prepare(struct ecore_hwfn *p_hwfn)
2310 /* clear indirect access */
2311 if (ECORE_IS_AH(p_hwfn->p_dev)) {
2312 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2313 PGLUE_B_REG_PGL_ADDR_E8_F0_K2_E5, 0);
2314 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2315 PGLUE_B_REG_PGL_ADDR_EC_F0_K2_E5, 0);
2316 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2317 PGLUE_B_REG_PGL_ADDR_F0_F0_K2_E5, 0);
2318 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2319 PGLUE_B_REG_PGL_ADDR_F4_F0_K2_E5, 0);
2321 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2322 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
2323 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2324 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
2325 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2326 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
2327 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2328 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
2331 /* Clean Previous errors if such exist */
2332 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2333 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
2335 /* enable internal target-read */
2336 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
2337 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
2340 static void get_function_id(struct ecore_hwfn *p_hwfn)
2343 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn,
2344 PXP_PF_ME_OPAQUE_ADDR);
2346 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
2348 /* Bits 16-19 from the ME registers are the pf_num */
2349 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
2350 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2351 PXP_CONCRETE_FID_PFID);
2352 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2353 PXP_CONCRETE_FID_PORT);
2355 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2356 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
2357 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
2360 static void ecore_hw_set_feat(struct ecore_hwfn *p_hwfn)
2362 u32 *feat_num = p_hwfn->hw_info.feat_num;
2363 struct ecore_sb_cnt_info sb_cnt_info;
2364 int num_features = 1;
2366 /* L2 Queues require each: 1 status block. 1 L2 queue */
2367 feat_num[ECORE_PF_L2_QUE] =
2369 RESC_NUM(p_hwfn, ECORE_SB) / num_features,
2370 RESC_NUM(p_hwfn, ECORE_L2_QUEUE));
2372 OSAL_MEM_ZERO(&sb_cnt_info, sizeof(sb_cnt_info));
2373 ecore_int_get_num_sbs(p_hwfn, &sb_cnt_info);
2374 feat_num[ECORE_VF_L2_QUE] =
2376 RESC_NUM(p_hwfn, ECORE_L2_QUEUE) -
2377 FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE),
2378 sb_cnt_info.sb_iov_cnt);
2380 feat_num[ECORE_FCOE_CQ] = OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_SB),
2381 RESC_NUM(p_hwfn, ECORE_CMDQS_CQS));
2382 feat_num[ECORE_ISCSI_CQ] = OSAL_MIN_T(u32, RESC_NUM(p_hwfn, ECORE_SB),
2383 RESC_NUM(p_hwfn, ECORE_CMDQS_CQS));
2385 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2386 "#PF_L2_QUEUE=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d #FCOE_CQ=%d #ISCSI_CQ=%d #SB=%d\n",
2387 (int)FEAT_NUM(p_hwfn, ECORE_PF_L2_QUE),
2388 (int)FEAT_NUM(p_hwfn, ECORE_VF_L2_QUE),
2389 (int)FEAT_NUM(p_hwfn, ECORE_RDMA_CNQ),
2390 (int)FEAT_NUM(p_hwfn, ECORE_FCOE_CQ),
2391 (int)FEAT_NUM(p_hwfn, ECORE_ISCSI_CQ),
2392 RESC_NUM(p_hwfn, ECORE_SB));
2395 static enum resource_id_enum
2396 ecore_hw_get_mfw_res_id(enum ecore_resources res_id)
2398 enum resource_id_enum mfw_res_id = RESOURCE_NUM_INVALID;
2402 mfw_res_id = RESOURCE_NUM_SB_E;
2404 case ECORE_L2_QUEUE:
2405 mfw_res_id = RESOURCE_NUM_L2_QUEUE_E;
2408 mfw_res_id = RESOURCE_NUM_VPORT_E;
2411 mfw_res_id = RESOURCE_NUM_RSS_ENGINES_E;
2414 mfw_res_id = RESOURCE_NUM_PQ_E;
2417 mfw_res_id = RESOURCE_NUM_RL_E;
2421 /* Each VFC resource can accommodate both a MAC and a VLAN */
2422 mfw_res_id = RESOURCE_VFC_FILTER_E;
2425 mfw_res_id = RESOURCE_ILT_E;
2427 case ECORE_LL2_QUEUE:
2428 mfw_res_id = RESOURCE_LL2_QUEUE_E;
2430 case ECORE_RDMA_CNQ_RAM:
2431 case ECORE_CMDQS_CQS:
2432 /* CNQ/CMDQS are the same resource */
2433 mfw_res_id = RESOURCE_CQS_E;
2435 case ECORE_RDMA_STATS_QUEUE:
2436 mfw_res_id = RESOURCE_RDMA_STATS_QUEUE_E;
2445 static u32 ecore_hw_get_dflt_resc_num(struct ecore_hwfn *p_hwfn,
2446 enum ecore_resources res_id)
2448 u8 num_funcs = p_hwfn->num_funcs_on_engine;
2449 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2450 struct ecore_sb_cnt_info sb_cnt_info;
2451 u32 dflt_resc_num = 0;
2455 OSAL_MEM_ZERO(&sb_cnt_info, sizeof(sb_cnt_info));
2456 ecore_int_get_num_sbs(p_hwfn, &sb_cnt_info);
2457 dflt_resc_num = sb_cnt_info.sb_cnt;
2459 case ECORE_L2_QUEUE:
2460 dflt_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
2461 MAX_NUM_L2_QUEUES_BB) / num_funcs;
2464 dflt_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2465 MAX_NUM_VPORTS_BB) / num_funcs;
2468 dflt_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
2469 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
2472 dflt_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
2473 MAX_QM_TX_QUEUES_BB) / num_funcs;
2476 dflt_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
2480 /* Each VFC resource can accommodate both a MAC and a VLAN */
2481 dflt_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
2484 dflt_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
2485 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
2487 case ECORE_LL2_QUEUE:
2488 dflt_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
2490 case ECORE_RDMA_CNQ_RAM:
2491 case ECORE_CMDQS_CQS:
2492 /* CNQ/CMDQS are the same resource */
2494 dflt_resc_num = (NUM_OF_GLOBAL_QUEUES / 2) / num_funcs;
2496 case ECORE_RDMA_STATS_QUEUE:
2498 dflt_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2499 MAX_NUM_VPORTS_BB) / num_funcs;
2505 return dflt_resc_num;
2508 static const char *ecore_hw_get_resc_name(enum ecore_resources res_id)
2513 case ECORE_L2_QUEUE:
2527 case ECORE_RDMA_CNQ_RAM:
2528 return "RDMA_CNQ_RAM";
2531 case ECORE_LL2_QUEUE:
2533 case ECORE_CMDQS_CQS:
2535 case ECORE_RDMA_STATS_QUEUE:
2536 return "RDMA_STATS_QUEUE";
2538 return "UNKNOWN_RESOURCE";
2542 static enum _ecore_status_t ecore_hw_set_resc_info(struct ecore_hwfn *p_hwfn,
2543 enum ecore_resources res_id,
2544 bool drv_resc_alloc)
2546 u32 dflt_resc_num = 0, dflt_resc_start = 0, mcp_resp, mcp_param;
2547 u32 *p_resc_num, *p_resc_start;
2548 struct resource_info resc_info;
2549 enum _ecore_status_t rc;
2551 p_resc_num = &RESC_NUM(p_hwfn, res_id);
2552 p_resc_start = &RESC_START(p_hwfn, res_id);
2554 dflt_resc_num = ecore_hw_get_dflt_resc_num(p_hwfn, res_id);
2555 if (!dflt_resc_num) {
2557 "Failed to get default amount for resource %d [%s]\n",
2558 res_id, ecore_hw_get_resc_name(res_id));
2561 dflt_resc_start = dflt_resc_num * p_hwfn->enabled_func_idx;
2564 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2565 *p_resc_num = dflt_resc_num;
2566 *p_resc_start = dflt_resc_start;
2571 OSAL_MEM_ZERO(&resc_info, sizeof(resc_info));
2572 resc_info.res_id = ecore_hw_get_mfw_res_id(res_id);
2573 if (resc_info.res_id == RESOURCE_NUM_INVALID) {
2575 "Failed to match resource %d with MFW resources\n",
2580 rc = ecore_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, &resc_info,
2581 &mcp_resp, &mcp_param);
2582 if (rc != ECORE_SUCCESS) {
2583 DP_NOTICE(p_hwfn, true,
2584 "MFW response failure for an allocation request for"
2585 " resource %d [%s]\n",
2586 res_id, ecore_hw_get_resc_name(res_id));
2590 /* Default driver values are applied in the following cases:
2591 * - The resource allocation MB command is not supported by the MFW
2592 * - There is an internal error in the MFW while processing the request
2593 * - The resource ID is unknown to the MFW
2595 if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK &&
2596 mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_DEPRECATED) {
2599 "Resource %d [%s]: No allocation info was received"
2600 " [mcp_resp 0x%x]. Applying default values"
2601 " [num %d, start %d].\n",
2602 res_id, ecore_hw_get_resc_name(res_id), mcp_resp,
2603 dflt_resc_num, dflt_resc_start);
2605 *p_resc_num = dflt_resc_num;
2606 *p_resc_start = dflt_resc_start;
2610 /* TBD - remove this when revising the handling of the SB resource */
2611 if (res_id == ECORE_SB) {
2612 /* Excluding the slowpath SB */
2613 resc_info.size -= 1;
2614 resc_info.offset -= p_hwfn->enabled_func_idx;
2617 *p_resc_num = resc_info.size;
2618 *p_resc_start = resc_info.offset;
2620 if (*p_resc_num != dflt_resc_num || *p_resc_start != dflt_resc_start) {
2622 "Resource %d [%s]: MFW allocation [num %d, start %d] differs from default values [num %d, start %d]%s\n",
2623 res_id, ecore_hw_get_resc_name(res_id), *p_resc_num,
2624 *p_resc_start, dflt_resc_num, dflt_resc_start,
2625 drv_resc_alloc ? " - Applying default values" : "");
2626 if (drv_resc_alloc) {
2627 *p_resc_num = dflt_resc_num;
2628 *p_resc_start = dflt_resc_start;
2632 return ECORE_SUCCESS;
2635 static enum _ecore_status_t ecore_hw_get_resc(struct ecore_hwfn *p_hwfn,
2636 bool drv_resc_alloc)
2638 bool b_ah = ECORE_IS_AH(p_hwfn->p_dev);
2639 enum _ecore_status_t rc;
2642 u32 *resc_start = p_hwfn->hw_info.resc_start;
2643 u32 *resc_num = p_hwfn->hw_info.resc_num;
2644 /* For AH, an equal share of the ILT lines between the maximal number of
2645 * PFs is not enough for RoCE. This would be solved by the future
2646 * resource allocation scheme, but isn't currently present for
2647 * FPGA/emulation. For now we keep a number that is sufficient for RoCE
2648 * to work - the BB number of ILT lines divided by its max PFs number.
2650 u32 roce_min_ilt_lines = PXP_NUM_ILT_RECORDS_BB / MAX_NUM_PFS_BB;
2653 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++) {
2654 rc = ecore_hw_set_resc_info(p_hwfn, res_id, drv_resc_alloc);
2655 if (rc != ECORE_SUCCESS)
2660 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev)) {
2661 /* Reduced build contains less PQs */
2662 if (!(p_hwfn->p_dev->b_is_emul_full)) {
2663 resc_num[ECORE_PQ] = 32;
2664 resc_start[ECORE_PQ] = resc_num[ECORE_PQ] *
2665 p_hwfn->enabled_func_idx;
2668 /* For AH emulation, since we have a possible maximal number of
2669 * 16 enabled PFs, in case there are not enough ILT lines -
2670 * allocate only first PF as RoCE and have all the other ETH
2671 * only with less ILT lines.
2673 if (!p_hwfn->rel_pf_id && p_hwfn->p_dev->b_is_emul_full)
2674 resc_num[ECORE_ILT] = OSAL_MAX_T(u32,
2675 resc_num[ECORE_ILT],
2676 roce_min_ilt_lines);
2679 /* Correct the common ILT calculation if PF0 has more */
2680 if (CHIP_REV_IS_SLOW(p_hwfn->p_dev) &&
2681 p_hwfn->p_dev->b_is_emul_full &&
2682 p_hwfn->rel_pf_id && resc_num[ECORE_ILT] < roce_min_ilt_lines)
2683 resc_start[ECORE_ILT] += roce_min_ilt_lines -
2684 resc_num[ECORE_ILT];
2687 /* Sanity for ILT */
2688 if ((b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2689 (!b_ah && (RESC_END(p_hwfn, ECORE_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
2690 DP_NOTICE(p_hwfn, true,
2691 "Can't assign ILT pages [%08x,...,%08x]\n",
2692 RESC_START(p_hwfn, ECORE_ILT), RESC_END(p_hwfn,
2698 ecore_hw_set_feat(p_hwfn);
2700 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2701 "The numbers for each resource are:\n");
2702 for (res_id = 0; res_id < ECORE_MAX_RESC; res_id++)
2703 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE, "%s = %d start = %d\n",
2704 ecore_hw_get_resc_name(res_id),
2705 RESC_NUM(p_hwfn, res_id),
2706 RESC_START(p_hwfn, res_id));
2708 return ECORE_SUCCESS;
2711 static enum _ecore_status_t
2712 ecore_hw_get_nvm_info(struct ecore_hwfn *p_hwfn,
2713 struct ecore_ptt *p_ptt,
2714 struct ecore_hw_prepare_params *p_params)
2716 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg, dcbx_mode;
2717 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
2718 struct ecore_mcp_link_params *link;
2719 enum _ecore_status_t rc;
2721 /* Read global nvm_cfg address */
2722 nvm_cfg_addr = ecore_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2724 /* Verify MCP has initialized it */
2725 if (!nvm_cfg_addr) {
2726 DP_NOTICE(p_hwfn, false, "Shared memory not initialized\n");
2727 if (p_params->b_relaxed_probe)
2728 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_NVM;
2732 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
2734 nvm_cfg1_offset = ecore_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2736 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2737 OFFSETOF(struct nvm_cfg1, glob) + OFFSETOF(struct nvm_cfg1_glob,
2740 core_cfg = ecore_rd(p_hwfn, p_ptt, addr);
2742 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
2743 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
2744 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
2745 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X40G;
2747 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
2748 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X50G;
2750 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
2751 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X100G;
2753 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
2754 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_F;
2756 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
2757 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X10G_E;
2759 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
2760 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X20G;
2762 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
2763 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X40G;
2765 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
2766 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X25G;
2768 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
2769 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_2X10G;
2771 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
2772 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_1X25G;
2774 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
2775 p_hwfn->hw_info.port_mode = ECORE_PORT_MODE_DE_4X25G;
2778 DP_NOTICE(p_hwfn, true, "Unknown port mode in 0x%08x\n",
2783 /* Read DCBX configuration */
2784 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2785 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2786 dcbx_mode = ecore_rd(p_hwfn, p_ptt,
2788 OFFSETOF(struct nvm_cfg1_port, generic_cont0));
2789 dcbx_mode = (dcbx_mode & NVM_CFG1_PORT_DCBX_MODE_MASK)
2790 >> NVM_CFG1_PORT_DCBX_MODE_OFFSET;
2791 switch (dcbx_mode) {
2792 case NVM_CFG1_PORT_DCBX_MODE_DYNAMIC:
2793 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DYNAMIC;
2795 case NVM_CFG1_PORT_DCBX_MODE_CEE:
2796 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_CEE;
2798 case NVM_CFG1_PORT_DCBX_MODE_IEEE:
2799 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_IEEE;
2802 p_hwfn->hw_info.dcbx_mode = ECORE_DCBX_VERSION_DISABLED;
2805 /* Read default link configuration */
2806 link = &p_hwfn->mcp_info->link_input;
2807 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2808 OFFSETOF(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2809 link_temp = ecore_rd(p_hwfn, p_ptt,
2811 OFFSETOF(struct nvm_cfg1_port, speed_cap_mask));
2812 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
2813 link->speed.advertised_speeds = link_temp;
2815 link_temp = link->speed.advertised_speeds;
2816 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
2818 link_temp = ecore_rd(p_hwfn, p_ptt,
2820 OFFSETOF(struct nvm_cfg1_port, link_settings));
2821 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
2822 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
2823 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
2824 link->speed.autoneg = true;
2826 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
2827 link->speed.forced_speed = 1000;
2829 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
2830 link->speed.forced_speed = 10000;
2832 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
2833 link->speed.forced_speed = 25000;
2835 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
2836 link->speed.forced_speed = 40000;
2838 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
2839 link->speed.forced_speed = 50000;
2841 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
2842 link->speed.forced_speed = 100000;
2845 DP_NOTICE(p_hwfn, true, "Unknown Speed in 0x%08x\n", link_temp);
2848 p_hwfn->mcp_info->link_capabilities.default_speed =
2849 link->speed.forced_speed;
2850 p_hwfn->mcp_info->link_capabilities.default_speed_autoneg =
2851 link->speed.autoneg;
2853 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
2854 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
2855 link->pause.autoneg = !!(link_temp &
2856 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
2857 link->pause.forced_rx = !!(link_temp &
2858 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
2859 link->pause.forced_tx = !!(link_temp &
2860 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
2861 link->loopback_mode = 0;
2863 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
2864 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
2865 link->speed.forced_speed, link->speed.advertised_speeds,
2866 link->speed.autoneg, link->pause.autoneg);
2868 /* Read Multi-function information from shmem */
2869 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2870 OFFSETOF(struct nvm_cfg1, glob) +
2871 OFFSETOF(struct nvm_cfg1_glob, generic_cont0);
2873 generic_cont0 = ecore_rd(p_hwfn, p_ptt, addr);
2875 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
2876 NVM_CFG1_GLOB_MF_MODE_OFFSET;
2879 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
2880 p_hwfn->p_dev->mf_mode = ECORE_MF_OVLAN;
2882 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
2883 p_hwfn->p_dev->mf_mode = ECORE_MF_NPAR;
2885 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
2886 p_hwfn->p_dev->mf_mode = ECORE_MF_DEFAULT;
2889 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
2890 p_hwfn->p_dev->mf_mode);
2892 /* Read Multi-function information from shmem */
2893 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2894 OFFSETOF(struct nvm_cfg1, glob) +
2895 OFFSETOF(struct nvm_cfg1_glob, device_capabilities);
2897 device_capabilities = ecore_rd(p_hwfn, p_ptt, addr);
2898 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
2899 OSAL_SET_BIT(ECORE_DEV_CAP_ETH,
2900 &p_hwfn->hw_info.device_capabilities);
2901 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
2902 OSAL_SET_BIT(ECORE_DEV_CAP_FCOE,
2903 &p_hwfn->hw_info.device_capabilities);
2904 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
2905 OSAL_SET_BIT(ECORE_DEV_CAP_ISCSI,
2906 &p_hwfn->hw_info.device_capabilities);
2907 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
2908 OSAL_SET_BIT(ECORE_DEV_CAP_ROCE,
2909 &p_hwfn->hw_info.device_capabilities);
2910 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_IWARP)
2911 OSAL_SET_BIT(ECORE_DEV_CAP_IWARP,
2912 &p_hwfn->hw_info.device_capabilities);
2914 rc = ecore_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
2915 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
2917 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
2923 static void ecore_get_num_funcs(struct ecore_hwfn *p_hwfn,
2924 struct ecore_ptt *p_ptt)
2926 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
2927 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
2928 struct ecore_dev *p_dev = p_hwfn->p_dev;
2930 num_funcs = ECORE_IS_AH(p_dev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
2932 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
2933 * in the other bits are selected.
2934 * Bits 1-15 are for functions 1-15, respectively, and their value is
2935 * '0' only for enabled functions (function 0 always exists and
2937 * In case of CMT in BB, only the "even" functions are enabled, and thus
2938 * the number of functions for both hwfns is learnt from the same bits.
2940 if (ECORE_IS_BB(p_dev) || ECORE_IS_AH(p_dev)) {
2941 reg_function_hide = ecore_rd(p_hwfn, p_ptt,
2942 MISCS_REG_FUNCTION_HIDE_BB_K2);
2944 reg_function_hide = 0;
2947 if (reg_function_hide & 0x1) {
2948 if (ECORE_IS_BB(p_dev)) {
2949 if (ECORE_PATH_ID(p_hwfn) && p_dev->num_hwfns == 1) {
2961 /* Get the number of the enabled functions on the engine */
2962 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
2969 /* Get the PF index within the enabled functions */
2970 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
2971 tmp = reg_function_hide & eng_mask & low_pfs_mask;
2979 p_hwfn->num_funcs_on_engine = num_funcs;
2980 p_hwfn->enabled_func_idx = enabled_func_idx;
2983 if (CHIP_REV_IS_FPGA(p_dev)) {
2984 DP_NOTICE(p_hwfn, false,
2985 "FPGA: Limit number of PFs to 4 [would affect resource allocation, needed for IOV]\n");
2986 p_hwfn->num_funcs_on_engine = 4;
2990 DP_VERBOSE(p_hwfn, ECORE_MSG_PROBE,
2991 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
2992 p_hwfn->rel_pf_id, p_hwfn->abs_pf_id,
2993 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
2996 static void ecore_hw_info_port_num_bb(struct ecore_hwfn *p_hwfn,
2997 struct ecore_ptt *p_ptt)
3002 /* Read the port mode */
3003 if (CHIP_REV_IS_FPGA(p_hwfn->p_dev))
3005 else if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) &&
3006 (p_hwfn->p_dev->num_hwfns > 1))
3007 /* In CMT on emulation, assume 1 port */
3011 port_mode = ecore_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
3013 if (port_mode < 3) {
3014 p_hwfn->p_dev->num_ports_in_engines = 1;
3015 } else if (port_mode <= 5) {
3016 p_hwfn->p_dev->num_ports_in_engines = 2;
3018 DP_NOTICE(p_hwfn, true, "PORT MODE: %d not supported\n",
3019 p_hwfn->p_dev->num_ports_in_engines);
3021 /* Default num_ports_in_engines to something */
3022 p_hwfn->p_dev->num_ports_in_engines = 1;
3026 static void ecore_hw_info_port_num_ah_e5(struct ecore_hwfn *p_hwfn,
3027 struct ecore_ptt *p_ptt)
3032 p_hwfn->p_dev->num_ports_in_engines = 0;
3035 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev)) {
3036 port = ecore_rd(p_hwfn, p_ptt, MISCS_REG_ECO_RESERVED);
3037 switch ((port & 0xf000) >> 12) {
3039 p_hwfn->p_dev->num_ports_in_engines = 1;
3042 p_hwfn->p_dev->num_ports_in_engines = 2;
3045 p_hwfn->p_dev->num_ports_in_engines = 4;
3048 DP_NOTICE(p_hwfn, false,
3049 "Unknown port mode in ECO_RESERVED %08x\n",
3054 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
3055 port = ecore_rd(p_hwfn, p_ptt,
3056 CNIG_REG_NIG_PORT0_CONF_K2_E5 +
3059 p_hwfn->p_dev->num_ports_in_engines++;
3063 static void ecore_hw_info_port_num(struct ecore_hwfn *p_hwfn,
3064 struct ecore_ptt *p_ptt)
3066 if (ECORE_IS_BB(p_hwfn->p_dev))
3067 ecore_hw_info_port_num_bb(p_hwfn, p_ptt);
3069 ecore_hw_info_port_num_ah_e5(p_hwfn, p_ptt);
3072 static enum _ecore_status_t
3073 ecore_get_hw_info(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
3074 enum ecore_pci_personality personality,
3075 struct ecore_hw_prepare_params *p_params)
3077 bool drv_resc_alloc = p_params->drv_resc_alloc;
3078 enum _ecore_status_t rc;
3080 /* Since all information is common, only first hwfns should do this */
3081 if (IS_LEAD_HWFN(p_hwfn)) {
3082 rc = ecore_iov_hw_info(p_hwfn);
3083 if (rc != ECORE_SUCCESS) {
3084 if (p_params->b_relaxed_probe)
3085 p_params->p_relaxed_res =
3086 ECORE_HW_PREPARE_BAD_IOV;
3092 /* TODO In get_hw_info, amoungst others:
3093 * Get MCP FW revision and determine according to it the supported
3094 * featrues (e.g. DCB)
3096 * ecore_get_pcie_width_speed, WOL capability.
3097 * Number of global CQ-s (for storage
3099 ecore_hw_info_port_num(p_hwfn, p_ptt);
3102 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev)) {
3104 rc = ecore_hw_get_nvm_info(p_hwfn, p_ptt, p_params);
3105 if (rc != ECORE_SUCCESS)
3111 rc = ecore_int_igu_read_cam(p_hwfn, p_ptt);
3112 if (rc != ECORE_SUCCESS) {
3113 if (p_params->b_relaxed_probe)
3114 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_IGU;
3120 if (CHIP_REV_IS_ASIC(p_hwfn->p_dev) && ecore_mcp_is_init(p_hwfn)) {
3122 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr,
3123 p_hwfn->mcp_info->func_info.mac, ETH_ALEN);
3126 static u8 mcp_hw_mac[6] = { 0, 2, 3, 4, 5, 6 };
3128 OSAL_MEMCPY(p_hwfn->hw_info.hw_mac_addr, mcp_hw_mac, ETH_ALEN);
3129 p_hwfn->hw_info.hw_mac_addr[5] = p_hwfn->abs_pf_id;
3133 if (ecore_mcp_is_init(p_hwfn)) {
3134 if (p_hwfn->mcp_info->func_info.ovlan != ECORE_MCP_VLAN_UNSET)
3135 p_hwfn->hw_info.ovlan =
3136 p_hwfn->mcp_info->func_info.ovlan;
3138 ecore_mcp_cmd_port_init(p_hwfn, p_ptt);
3141 if (personality != ECORE_PCI_DEFAULT) {
3142 p_hwfn->hw_info.personality = personality;
3143 } else if (ecore_mcp_is_init(p_hwfn)) {
3144 enum ecore_pci_personality protocol;
3146 protocol = p_hwfn->mcp_info->func_info.protocol;
3147 p_hwfn->hw_info.personality = protocol;
3151 /* To overcome ILT lack for emulation, until at least until we'll have
3152 * a definite answer from system about it, allow only PF0 to be RoCE.
3154 if (CHIP_REV_IS_EMUL(p_hwfn->p_dev) && ECORE_IS_AH(p_hwfn->p_dev)) {
3155 if (!p_hwfn->rel_pf_id)
3156 p_hwfn->hw_info.personality = ECORE_PCI_ETH_ROCE;
3158 p_hwfn->hw_info.personality = ECORE_PCI_ETH;
3162 /* although in BB some constellations may support more than 4 tcs,
3163 * that can result in performance penalty in some cases. 4
3164 * represents a good tradeoff between performance and flexibility.
3166 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
3168 /* start out with a single active tc. This can be increased either
3169 * by dcbx negotiation or by upper layer driver
3171 p_hwfn->hw_info.num_active_tc = 1;
3173 ecore_get_num_funcs(p_hwfn, p_ptt);
3175 if (ecore_mcp_is_init(p_hwfn))
3176 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
3178 /* In case of forcing the driver's default resource allocation, calling
3179 * ecore_hw_get_resc() should come after initializing the personality
3180 * and after getting the number of functions, since the calculation of
3181 * the resources/features depends on them.
3182 * This order is not harmful if not forcing.
3184 rc = ecore_hw_get_resc(p_hwfn, drv_resc_alloc);
3185 if (rc != ECORE_SUCCESS && p_params->b_relaxed_probe) {
3187 p_params->p_relaxed_res = ECORE_HW_PREPARE_BAD_MCP;
3193 static enum _ecore_status_t ecore_get_dev_info(struct ecore_dev *p_dev)
3195 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3198 /* Read Vendor Id / Device Id */
3199 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_VENDOR_ID_OFFSET,
3201 OSAL_PCI_READ_CONFIG_WORD(p_dev, PCICFG_DEVICE_ID_OFFSET,
3204 /* Determine type */
3205 if ((p_dev->device_id & ECORE_DEV_ID_MASK) == ECORE_DEV_ID_MASK_AH)
3206 p_dev->type = ECORE_DEV_TYPE_AH;
3208 p_dev->type = ECORE_DEV_TYPE_BB;
3210 p_dev->chip_num = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3211 MISCS_REG_CHIP_NUM);
3212 p_dev->chip_rev = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3213 MISCS_REG_CHIP_REV);
3215 MASK_FIELD(CHIP_REV, p_dev->chip_rev);
3217 /* Learn number of HW-functions */
3218 tmp = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3219 MISCS_REG_CMT_ENABLED_FOR_PAIR);
3221 if (tmp & (1 << p_hwfn->rel_pf_id)) {
3222 DP_NOTICE(p_dev->hwfns, false, "device in CMT mode\n");
3223 p_dev->num_hwfns = 2;
3225 p_dev->num_hwfns = 1;
3229 if (CHIP_REV_IS_EMUL(p_dev)) {
3230 /* For some reason we have problems with this register
3231 * in B0 emulation; Simply assume no CMT
3233 DP_NOTICE(p_dev->hwfns, false,
3234 "device on emul - assume no CMT\n");
3235 p_dev->num_hwfns = 1;
3239 p_dev->chip_bond_id = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3240 MISCS_REG_CHIP_TEST_REG) >> 4;
3241 MASK_FIELD(CHIP_BOND_ID, p_dev->chip_bond_id);
3242 p_dev->chip_metal = (u16)ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3243 MISCS_REG_CHIP_METAL);
3244 MASK_FIELD(CHIP_METAL, p_dev->chip_metal);
3245 DP_INFO(p_dev->hwfns,
3246 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
3247 ECORE_IS_BB(p_dev) ? "BB" : "AH",
3248 'A' + p_dev->chip_rev, (int)p_dev->chip_metal,
3249 p_dev->chip_num, p_dev->chip_rev, p_dev->chip_bond_id,
3252 if (ECORE_IS_BB(p_dev) && CHIP_REV_IS_A0(p_dev)) {
3253 DP_NOTICE(p_dev->hwfns, false,
3254 "The chip type/rev (BB A0) is not supported!\n");
3255 return ECORE_ABORTED;
3258 if (CHIP_REV_IS_EMUL(p_dev) && ECORE_IS_AH(p_dev))
3259 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
3260 MISCS_REG_PLL_MAIN_CTRL_4, 0x1);
3262 if (CHIP_REV_IS_EMUL(p_dev)) {
3263 tmp = ecore_rd(p_hwfn, p_hwfn->p_main_ptt,
3264 MISCS_REG_ECO_RESERVED);
3265 if (tmp & (1 << 29)) {
3266 DP_NOTICE(p_hwfn, false,
3267 "Emulation: Running on a FULL build\n");
3268 p_dev->b_is_emul_full = true;
3270 DP_NOTICE(p_hwfn, false,
3271 "Emulation: Running on a REDUCED build\n");
3276 return ECORE_SUCCESS;
3279 #ifndef LINUX_REMOVE
3280 void ecore_prepare_hibernate(struct ecore_dev *p_dev)
3287 for_each_hwfn(p_dev, j) {
3288 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[j];
3290 DP_VERBOSE(p_hwfn, ECORE_MSG_IFDOWN,
3291 "Mark hw/fw uninitialized\n");
3293 p_hwfn->hw_init_done = false;
3294 p_hwfn->first_on_engine = false;
3296 ecore_ptt_invalidate(p_hwfn);
3301 static enum _ecore_status_t
3302 ecore_hw_prepare_single(struct ecore_hwfn *p_hwfn,
3303 void OSAL_IOMEM * p_regview,
3304 void OSAL_IOMEM * p_doorbells,
3305 struct ecore_hw_prepare_params *p_params)
3307 struct ecore_dev *p_dev = p_hwfn->p_dev;
3308 struct ecore_mdump_info mdump_info;
3309 enum _ecore_status_t rc = ECORE_SUCCESS;
3311 /* Split PCI bars evenly between hwfns */
3312 p_hwfn->regview = p_regview;
3313 p_hwfn->doorbells = p_doorbells;
3316 return ecore_vf_hw_prepare(p_hwfn);
3318 /* Validate that chip access is feasible */
3319 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
3321 "Reading the ME register returns all Fs; Preventing further chip access\n");
3322 if (p_params->b_relaxed_probe)
3323 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_ME;
3327 get_function_id(p_hwfn);
3329 /* Allocate PTT pool */
3330 rc = ecore_ptt_pool_alloc(p_hwfn);
3332 DP_NOTICE(p_hwfn, true, "Failed to prepare hwfn's hw\n");
3333 if (p_params->b_relaxed_probe)
3334 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3338 /* Allocate the main PTT */
3339 p_hwfn->p_main_ptt = ecore_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
3341 /* First hwfn learns basic information, e.g., number of hwfns */
3342 if (!p_hwfn->my_id) {
3343 rc = ecore_get_dev_info(p_dev);
3344 if (rc != ECORE_SUCCESS) {
3345 if (p_params->b_relaxed_probe)
3346 p_params->p_relaxed_res =
3347 ECORE_HW_PREPARE_FAILED_DEV;
3352 ecore_hw_hwfn_prepare(p_hwfn);
3354 /* Initialize MCP structure */
3355 rc = ecore_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
3357 DP_NOTICE(p_hwfn, true, "Failed initializing mcp command\n");
3358 if (p_params->b_relaxed_probe)
3359 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3363 /* Read the device configuration information from the HW and SHMEM */
3364 rc = ecore_get_hw_info(p_hwfn, p_hwfn->p_main_ptt,
3365 p_params->personality, p_params);
3367 DP_NOTICE(p_hwfn, true, "Failed to get HW information\n");
3371 /* Sending a mailbox to the MFW should be after ecore_get_hw_info() is
3372 * called, since among others it sets the ports number in an engine.
3374 if (p_params->initiate_pf_flr && p_hwfn == ECORE_LEADING_HWFN(p_dev) &&
3375 !p_dev->recov_in_prog) {
3376 rc = ecore_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
3377 if (rc != ECORE_SUCCESS)
3378 DP_NOTICE(p_hwfn, false, "Failed to initiate PF FLR\n");
3381 /* Check if mdump logs are present and update the epoch value */
3382 if (p_hwfn == ECORE_LEADING_HWFN(p_hwfn->p_dev)) {
3383 rc = ecore_mcp_mdump_get_info(p_hwfn, p_hwfn->p_main_ptt,
3385 if (rc == ECORE_SUCCESS && mdump_info.num_of_logs > 0) {
3386 DP_NOTICE(p_hwfn, false,
3387 "* * * IMPORTANT - HW ERROR register dump captured by device * * *\n");
3390 ecore_mcp_mdump_set_values(p_hwfn, p_hwfn->p_main_ptt,
3394 /* Allocate the init RT array and initialize the init-ops engine */
3395 rc = ecore_init_alloc(p_hwfn);
3397 DP_NOTICE(p_hwfn, true, "Failed to allocate the init array\n");
3398 if (p_params->b_relaxed_probe)
3399 p_params->p_relaxed_res = ECORE_HW_PREPARE_FAILED_MEM;
3403 if (CHIP_REV_IS_FPGA(p_dev)) {
3404 DP_NOTICE(p_hwfn, false,
3405 "FPGA: workaround; Prevent DMAE parities\n");
3406 ecore_wr(p_hwfn, p_hwfn->p_main_ptt, PCIE_REG_PRTY_MASK_K2_E5,
3409 DP_NOTICE(p_hwfn, false,
3410 "FPGA: workaround: Set VF bar0 size\n");
3411 ecore_wr(p_hwfn, p_hwfn->p_main_ptt,
3412 PGLUE_B_REG_VF_BAR0_SIZE_K2_E5, 4);
3418 if (IS_LEAD_HWFN(p_hwfn))
3419 ecore_iov_free_hw_info(p_dev);
3420 ecore_mcp_free(p_hwfn);
3422 ecore_hw_hwfn_free(p_hwfn);
3427 enum _ecore_status_t ecore_hw_prepare(struct ecore_dev *p_dev,
3428 struct ecore_hw_prepare_params *p_params)
3430 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3431 enum _ecore_status_t rc;
3433 p_dev->chk_reg_fifo = p_params->chk_reg_fifo;
3435 if (p_params->b_relaxed_probe)
3436 p_params->p_relaxed_res = ECORE_HW_PREPARE_SUCCESS;
3438 /* Store the precompiled init data ptrs */
3440 ecore_init_iro_array(p_dev);
3442 /* Initialize the first hwfn - will learn number of hwfns */
3443 rc = ecore_hw_prepare_single(p_hwfn,
3445 p_dev->doorbells, p_params);
3446 if (rc != ECORE_SUCCESS)
3449 p_params->personality = p_hwfn->hw_info.personality;
3451 /* initilalize 2nd hwfn if necessary */
3452 if (p_dev->num_hwfns > 1) {
3453 void OSAL_IOMEM *p_regview, *p_doorbell;
3454 u8 OSAL_IOMEM *addr;
3456 /* adjust bar offset for second engine */
3457 addr = (u8 OSAL_IOMEM *)p_dev->regview +
3458 ecore_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
3459 p_regview = (void OSAL_IOMEM *)addr;
3461 addr = (u8 OSAL_IOMEM *)p_dev->doorbells +
3462 ecore_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
3463 p_doorbell = (void OSAL_IOMEM *)addr;
3465 /* prepare second hw function */
3466 rc = ecore_hw_prepare_single(&p_dev->hwfns[1], p_regview,
3467 p_doorbell, p_params);
3469 /* in case of error, need to free the previously
3470 * initiliazed hwfn 0.
3472 if (rc != ECORE_SUCCESS) {
3473 if (p_params->b_relaxed_probe)
3474 p_params->p_relaxed_res =
3475 ECORE_HW_PREPARE_FAILED_ENG2;
3478 ecore_init_free(p_hwfn);
3479 ecore_mcp_free(p_hwfn);
3480 ecore_hw_hwfn_free(p_hwfn);
3482 DP_NOTICE(p_dev, true,
3483 "What do we need to free when VF hwfn1 init fails\n");
3492 void ecore_hw_remove(struct ecore_dev *p_dev)
3494 struct ecore_hwfn *p_hwfn = ECORE_LEADING_HWFN(p_dev);
3498 ecore_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
3499 ECORE_OV_DRIVER_STATE_NOT_LOADED);
3501 for_each_hwfn(p_dev, i) {
3502 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
3505 ecore_vf_pf_release(p_hwfn);
3509 ecore_init_free(p_hwfn);
3510 ecore_hw_hwfn_free(p_hwfn);
3511 ecore_mcp_free(p_hwfn);
3513 OSAL_MUTEX_DEALLOC(&p_hwfn->dmae_info.mutex);
3516 ecore_iov_free_hw_info(p_dev);
3519 static void ecore_chain_free_next_ptr(struct ecore_dev *p_dev,
3520 struct ecore_chain *p_chain)
3522 void *p_virt = p_chain->p_virt_addr, *p_virt_next = OSAL_NULL;
3523 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3524 struct ecore_chain_next *p_next;
3530 size = p_chain->elem_size * p_chain->usable_per_page;
3532 for (i = 0; i < p_chain->page_cnt; i++) {
3536 p_next = (struct ecore_chain_next *)((u8 *)p_virt + size);
3537 p_virt_next = p_next->next_virt;
3538 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3540 OSAL_DMA_FREE_COHERENT(p_dev, p_virt, p_phys,
3541 ECORE_CHAIN_PAGE_SIZE);
3543 p_virt = p_virt_next;
3544 p_phys = p_phys_next;
3548 static void ecore_chain_free_single(struct ecore_dev *p_dev,
3549 struct ecore_chain *p_chain)
3551 if (!p_chain->p_virt_addr)
3554 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->p_virt_addr,
3555 p_chain->p_phys_addr, ECORE_CHAIN_PAGE_SIZE);
3558 static void ecore_chain_free_pbl(struct ecore_dev *p_dev,
3559 struct ecore_chain *p_chain)
3561 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3562 u8 *p_pbl_virt = (u8 *)p_chain->pbl_sp.p_virt_table;
3563 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
3565 if (!pp_virt_addr_tbl)
3571 for (i = 0; i < page_cnt; i++) {
3572 if (!pp_virt_addr_tbl[i])
3575 OSAL_DMA_FREE_COHERENT(p_dev, pp_virt_addr_tbl[i],
3576 *(dma_addr_t *)p_pbl_virt,
3577 ECORE_CHAIN_PAGE_SIZE);
3579 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
3582 pbl_size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
3584 if (!p_chain->b_external_pbl)
3585 OSAL_DMA_FREE_COHERENT(p_dev, p_chain->pbl_sp.p_virt_table,
3586 p_chain->pbl_sp.p_phys_table, pbl_size);
3588 OSAL_VFREE(p_dev, p_chain->pbl.pp_virt_addr_tbl);
3591 void ecore_chain_free(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3593 switch (p_chain->mode) {
3594 case ECORE_CHAIN_MODE_NEXT_PTR:
3595 ecore_chain_free_next_ptr(p_dev, p_chain);
3597 case ECORE_CHAIN_MODE_SINGLE:
3598 ecore_chain_free_single(p_dev, p_chain);
3600 case ECORE_CHAIN_MODE_PBL:
3601 ecore_chain_free_pbl(p_dev, p_chain);
3606 static enum _ecore_status_t
3607 ecore_chain_alloc_sanity_check(struct ecore_dev *p_dev,
3608 enum ecore_chain_cnt_type cnt_type,
3609 osal_size_t elem_size, u32 page_cnt)
3611 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3613 /* The actual chain size can be larger than the maximal possible value
3614 * after rounding up the requested elements number to pages, and after
3615 * taking into acount the unusuable elements (next-ptr elements).
3616 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3617 * size/capacity fields are of a u32 type.
3619 if ((cnt_type == ECORE_CHAIN_CNT_TYPE_U16 &&
3620 chain_size > ((u32)ECORE_U16_MAX + 1)) ||
3621 (cnt_type == ECORE_CHAIN_CNT_TYPE_U32 &&
3622 chain_size > ECORE_U32_MAX)) {
3623 DP_NOTICE(p_dev, true,
3624 "The actual chain size (0x%lx) is larger than the maximal possible value\n",
3625 (unsigned long)chain_size);
3629 return ECORE_SUCCESS;
3632 static enum _ecore_status_t
3633 ecore_chain_alloc_next_ptr(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3635 void *p_virt = OSAL_NULL, *p_virt_prev = OSAL_NULL;
3636 dma_addr_t p_phys = 0;
3639 for (i = 0; i < p_chain->page_cnt; i++) {
3640 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
3641 ECORE_CHAIN_PAGE_SIZE);
3643 DP_NOTICE(p_dev, true,
3644 "Failed to allocate chain memory\n");
3649 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3650 ecore_chain_reset(p_chain);
3652 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3656 p_virt_prev = p_virt;
3658 /* Last page's next element should point to the beginning of the
3661 ecore_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3662 p_chain->p_virt_addr,
3663 p_chain->p_phys_addr);
3665 return ECORE_SUCCESS;
3668 static enum _ecore_status_t
3669 ecore_chain_alloc_single(struct ecore_dev *p_dev, struct ecore_chain *p_chain)
3671 dma_addr_t p_phys = 0;
3672 void *p_virt = OSAL_NULL;
3674 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys, ECORE_CHAIN_PAGE_SIZE);
3676 DP_NOTICE(p_dev, true, "Failed to allocate chain memory\n");
3680 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3681 ecore_chain_reset(p_chain);
3683 return ECORE_SUCCESS;
3686 static enum _ecore_status_t
3687 ecore_chain_alloc_pbl(struct ecore_dev *p_dev,
3688 struct ecore_chain *p_chain,
3689 struct ecore_chain_ext_pbl *ext_pbl)
3691 void *p_virt = OSAL_NULL;
3692 u8 *p_pbl_virt = OSAL_NULL;
3693 void **pp_virt_addr_tbl = OSAL_NULL;
3694 dma_addr_t p_phys = 0, p_pbl_phys = 0;
3695 u32 page_cnt = p_chain->page_cnt, size, i;
3697 size = page_cnt * sizeof(*pp_virt_addr_tbl);
3698 pp_virt_addr_tbl = (void **)OSAL_VALLOC(p_dev, size);
3699 if (!pp_virt_addr_tbl) {
3700 DP_NOTICE(p_dev, true,
3701 "Failed to allocate memory for the chain virtual addresses table\n");
3704 OSAL_MEM_ZERO(pp_virt_addr_tbl, size);
3706 /* The allocation of the PBL table is done with its full size, since it
3707 * is expected to be successive.
3708 * ecore_chain_init_pbl_mem() is called even in a case of an allocation
3709 * failure, since pp_virt_addr_tbl was previously allocated, and it
3710 * should be saved to allow its freeing during the error flow.
3712 size = page_cnt * ECORE_CHAIN_PBL_ENTRY_SIZE;
3714 if (ext_pbl == OSAL_NULL) {
3715 p_pbl_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_pbl_phys, size);
3717 p_pbl_virt = ext_pbl->p_pbl_virt;
3718 p_pbl_phys = ext_pbl->p_pbl_phys;
3719 p_chain->b_external_pbl = true;
3722 ecore_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
3725 DP_NOTICE(p_dev, true, "Failed to allocate chain pbl memory\n");
3729 for (i = 0; i < page_cnt; i++) {
3730 p_virt = OSAL_DMA_ALLOC_COHERENT(p_dev, &p_phys,
3731 ECORE_CHAIN_PAGE_SIZE);
3733 DP_NOTICE(p_dev, true,
3734 "Failed to allocate chain memory\n");
3739 ecore_chain_init_mem(p_chain, p_virt, p_phys);
3740 ecore_chain_reset(p_chain);
3743 /* Fill the PBL table with the physical address of the page */
3744 *(dma_addr_t *)p_pbl_virt = p_phys;
3745 /* Keep the virtual address of the page */
3746 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
3748 p_pbl_virt += ECORE_CHAIN_PBL_ENTRY_SIZE;
3751 return ECORE_SUCCESS;
3754 enum _ecore_status_t ecore_chain_alloc(struct ecore_dev *p_dev,
3755 enum ecore_chain_use_mode intended_use,
3756 enum ecore_chain_mode mode,
3757 enum ecore_chain_cnt_type cnt_type,
3758 u32 num_elems, osal_size_t elem_size,
3759 struct ecore_chain *p_chain,
3760 struct ecore_chain_ext_pbl *ext_pbl)
3763 enum _ecore_status_t rc = ECORE_SUCCESS;
3765 if (mode == ECORE_CHAIN_MODE_SINGLE)
3768 page_cnt = ECORE_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
3770 rc = ecore_chain_alloc_sanity_check(p_dev, cnt_type, elem_size,
3773 DP_NOTICE(p_dev, true,
3774 "Cannot allocate a chain with the given arguments:\n"
3775 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
3776 intended_use, mode, cnt_type, num_elems, elem_size);
3780 ecore_chain_init_params(p_chain, page_cnt, (u8)elem_size, intended_use,
3781 mode, cnt_type, p_dev->dp_ctx);
3784 case ECORE_CHAIN_MODE_NEXT_PTR:
3785 rc = ecore_chain_alloc_next_ptr(p_dev, p_chain);
3787 case ECORE_CHAIN_MODE_SINGLE:
3788 rc = ecore_chain_alloc_single(p_dev, p_chain);
3790 case ECORE_CHAIN_MODE_PBL:
3791 rc = ecore_chain_alloc_pbl(p_dev, p_chain, ext_pbl);
3797 return ECORE_SUCCESS;
3800 ecore_chain_free(p_dev, p_chain);
3804 enum _ecore_status_t ecore_fw_l2_queue(struct ecore_hwfn *p_hwfn,
3805 u16 src_id, u16 *dst_id)
3807 if (src_id >= RESC_NUM(p_hwfn, ECORE_L2_QUEUE)) {
3810 min = (u16)RESC_START(p_hwfn, ECORE_L2_QUEUE);
3811 max = min + RESC_NUM(p_hwfn, ECORE_L2_QUEUE);
3812 DP_NOTICE(p_hwfn, true,
3813 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
3819 *dst_id = RESC_START(p_hwfn, ECORE_L2_QUEUE) + src_id;
3821 return ECORE_SUCCESS;
3824 enum _ecore_status_t ecore_fw_vport(struct ecore_hwfn *p_hwfn,
3825 u8 src_id, u8 *dst_id)
3827 if (src_id >= RESC_NUM(p_hwfn, ECORE_VPORT)) {
3830 min = (u8)RESC_START(p_hwfn, ECORE_VPORT);
3831 max = min + RESC_NUM(p_hwfn, ECORE_VPORT);
3832 DP_NOTICE(p_hwfn, true,
3833 "vport id [%d] is not valid, available indices [%d - %d]\n",
3839 *dst_id = RESC_START(p_hwfn, ECORE_VPORT) + src_id;
3841 return ECORE_SUCCESS;
3844 enum _ecore_status_t ecore_fw_rss_eng(struct ecore_hwfn *p_hwfn,
3845 u8 src_id, u8 *dst_id)
3847 if (src_id >= RESC_NUM(p_hwfn, ECORE_RSS_ENG)) {
3850 min = (u8)RESC_START(p_hwfn, ECORE_RSS_ENG);
3851 max = min + RESC_NUM(p_hwfn, ECORE_RSS_ENG);
3852 DP_NOTICE(p_hwfn, true,
3853 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
3859 *dst_id = RESC_START(p_hwfn, ECORE_RSS_ENG) + src_id;
3861 return ECORE_SUCCESS;
3864 enum _ecore_status_t ecore_llh_add_mac_filter(struct ecore_hwfn *p_hwfn,
3865 struct ecore_ptt *p_ptt,
3871 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3872 return ECORE_SUCCESS;
3874 high = p_filter[1] | (p_filter[0] << 8);
3875 low = p_filter[5] | (p_filter[4] << 8) |
3876 (p_filter[3] << 16) | (p_filter[2] << 24);
3878 /* Find a free entry and utilize it */
3879 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3880 en = ecore_rd(p_hwfn, p_ptt,
3881 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3884 ecore_wr(p_hwfn, p_ptt,
3885 NIG_REG_LLH_FUNC_FILTER_VALUE +
3886 2 * i * sizeof(u32), low);
3887 ecore_wr(p_hwfn, p_ptt,
3888 NIG_REG_LLH_FUNC_FILTER_VALUE +
3889 (2 * i + 1) * sizeof(u32), high);
3890 ecore_wr(p_hwfn, p_ptt,
3891 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3892 ecore_wr(p_hwfn, p_ptt,
3893 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3894 i * sizeof(u32), 0);
3895 ecore_wr(p_hwfn, p_ptt,
3896 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3899 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3900 DP_NOTICE(p_hwfn, false,
3901 "Failed to find an empty LLH filter to utilize\n");
3905 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
3906 "MAC: %x:%x:%x:%x:%x:%x is added at %d\n",
3907 p_filter[0], p_filter[1], p_filter[2],
3908 p_filter[3], p_filter[4], p_filter[5], i);
3910 return ECORE_SUCCESS;
3913 void ecore_llh_remove_mac_filter(struct ecore_hwfn *p_hwfn,
3914 struct ecore_ptt *p_ptt, u8 *p_filter)
3919 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3922 high = p_filter[1] | (p_filter[0] << 8);
3923 low = p_filter[5] | (p_filter[4] << 8) |
3924 (p_filter[3] << 16) | (p_filter[2] << 24);
3926 /* Find the entry and clean it */
3927 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3928 if (ecore_rd(p_hwfn, p_ptt,
3929 NIG_REG_LLH_FUNC_FILTER_VALUE +
3930 2 * i * sizeof(u32)) != low)
3932 if (ecore_rd(p_hwfn, p_ptt,
3933 NIG_REG_LLH_FUNC_FILTER_VALUE +
3934 (2 * i + 1) * sizeof(u32)) != high)
3937 ecore_wr(p_hwfn, p_ptt,
3938 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3939 ecore_wr(p_hwfn, p_ptt,
3940 NIG_REG_LLH_FUNC_FILTER_VALUE +
3941 2 * i * sizeof(u32), 0);
3942 ecore_wr(p_hwfn, p_ptt,
3943 NIG_REG_LLH_FUNC_FILTER_VALUE +
3944 (2 * i + 1) * sizeof(u32), 0);
3947 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3948 DP_NOTICE(p_hwfn, false,
3949 "Tried to remove a non-configured filter\n");
3952 enum _ecore_status_t
3953 ecore_llh_add_protocol_filter(struct ecore_hwfn *p_hwfn,
3954 struct ecore_ptt *p_ptt,
3955 u16 source_port_or_eth_type,
3957 enum ecore_llh_port_filter_type_t type)
3962 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3963 return ECORE_SUCCESS;
3968 case ECORE_LLH_FILTER_ETHERTYPE:
3969 high = source_port_or_eth_type;
3971 case ECORE_LLH_FILTER_TCP_SRC_PORT:
3972 case ECORE_LLH_FILTER_UDP_SRC_PORT:
3973 low = source_port_or_eth_type << 16;
3975 case ECORE_LLH_FILTER_TCP_DEST_PORT:
3976 case ECORE_LLH_FILTER_UDP_DEST_PORT:
3979 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3980 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3981 low = (source_port_or_eth_type << 16) | dest_port;
3984 DP_NOTICE(p_hwfn, true,
3985 "Non valid LLH protocol filter type %d\n", type);
3988 /* Find a free entry and utilize it */
3989 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3990 en = ecore_rd(p_hwfn, p_ptt,
3991 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3994 ecore_wr(p_hwfn, p_ptt,
3995 NIG_REG_LLH_FUNC_FILTER_VALUE +
3996 2 * i * sizeof(u32), low);
3997 ecore_wr(p_hwfn, p_ptt,
3998 NIG_REG_LLH_FUNC_FILTER_VALUE +
3999 (2 * i + 1) * sizeof(u32), high);
4000 ecore_wr(p_hwfn, p_ptt,
4001 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1);
4002 ecore_wr(p_hwfn, p_ptt,
4003 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
4004 i * sizeof(u32), 1 << type);
4005 ecore_wr(p_hwfn, p_ptt,
4006 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
4009 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
4010 DP_NOTICE(p_hwfn, false,
4011 "Failed to find an empty LLH filter to utilize\n");
4012 return ECORE_NORESOURCES;
4015 case ECORE_LLH_FILTER_ETHERTYPE:
4016 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4017 "ETH type %x is added at %d\n",
4018 source_port_or_eth_type, i);
4020 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4021 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4022 "TCP src port %x is added at %d\n",
4023 source_port_or_eth_type, i);
4025 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4026 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4027 "UDP src port %x is added at %d\n",
4028 source_port_or_eth_type, i);
4030 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4031 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4032 "TCP dst port %x is added at %d\n", dest_port, i);
4034 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4035 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4036 "UDP dst port %x is added at %d\n", dest_port, i);
4038 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4039 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4040 "TCP src/dst ports %x/%x are added at %d\n",
4041 source_port_or_eth_type, dest_port, i);
4043 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4044 DP_VERBOSE(p_hwfn, ECORE_MSG_HW,
4045 "UDP src/dst ports %x/%x are added at %d\n",
4046 source_port_or_eth_type, dest_port, i);
4049 return ECORE_SUCCESS;
4053 ecore_llh_remove_protocol_filter(struct ecore_hwfn *p_hwfn,
4054 struct ecore_ptt *p_ptt,
4055 u16 source_port_or_eth_type,
4057 enum ecore_llh_port_filter_type_t type)
4062 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4068 case ECORE_LLH_FILTER_ETHERTYPE:
4069 high = source_port_or_eth_type;
4071 case ECORE_LLH_FILTER_TCP_SRC_PORT:
4072 case ECORE_LLH_FILTER_UDP_SRC_PORT:
4073 low = source_port_or_eth_type << 16;
4075 case ECORE_LLH_FILTER_TCP_DEST_PORT:
4076 case ECORE_LLH_FILTER_UDP_DEST_PORT:
4079 case ECORE_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
4080 case ECORE_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
4081 low = (source_port_or_eth_type << 16) | dest_port;
4084 DP_NOTICE(p_hwfn, true,
4085 "Non valid LLH protocol filter type %d\n", type);
4089 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4090 if (!ecore_rd(p_hwfn, p_ptt,
4091 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)))
4093 if (!ecore_rd(p_hwfn, p_ptt,
4094 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32)))
4096 if (!(ecore_rd(p_hwfn, p_ptt,
4097 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
4098 i * sizeof(u32)) & (1 << type)))
4100 if (ecore_rd(p_hwfn, p_ptt,
4101 NIG_REG_LLH_FUNC_FILTER_VALUE +
4102 2 * i * sizeof(u32)) != low)
4104 if (ecore_rd(p_hwfn, p_ptt,
4105 NIG_REG_LLH_FUNC_FILTER_VALUE +
4106 (2 * i + 1) * sizeof(u32)) != high)
4109 ecore_wr(p_hwfn, p_ptt,
4110 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
4111 ecore_wr(p_hwfn, p_ptt,
4112 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
4113 ecore_wr(p_hwfn, p_ptt,
4114 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
4115 i * sizeof(u32), 0);
4116 ecore_wr(p_hwfn, p_ptt,
4117 NIG_REG_LLH_FUNC_FILTER_VALUE +
4118 2 * i * sizeof(u32), 0);
4119 ecore_wr(p_hwfn, p_ptt,
4120 NIG_REG_LLH_FUNC_FILTER_VALUE +
4121 (2 * i + 1) * sizeof(u32), 0);
4125 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
4126 DP_NOTICE(p_hwfn, false,
4127 "Tried to remove a non-configured filter\n");
4130 void ecore_llh_clear_all_filters(struct ecore_hwfn *p_hwfn,
4131 struct ecore_ptt *p_ptt)
4135 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
4138 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
4139 ecore_wr(p_hwfn, p_ptt,
4140 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
4141 ecore_wr(p_hwfn, p_ptt,
4142 NIG_REG_LLH_FUNC_FILTER_VALUE +
4143 2 * i * sizeof(u32), 0);
4144 ecore_wr(p_hwfn, p_ptt,
4145 NIG_REG_LLH_FUNC_FILTER_VALUE +
4146 (2 * i + 1) * sizeof(u32), 0);
4150 enum _ecore_status_t
4151 ecore_llh_set_function_as_default(struct ecore_hwfn *p_hwfn,
4152 struct ecore_ptt *p_ptt)
4154 if (IS_MF_DEFAULT(p_hwfn) && ECORE_IS_BB(p_hwfn->p_dev)) {
4155 ecore_wr(p_hwfn, p_ptt,
4156 NIG_REG_LLH_TAGMAC_DEF_PF_VECTOR,
4157 1 << p_hwfn->abs_pf_id / 2);
4158 ecore_wr(p_hwfn, p_ptt, PRS_REG_MSG_INFO, 0);
4159 return ECORE_SUCCESS;
4162 DP_NOTICE(p_hwfn, false,
4163 "This function can't be set as default\n");
4167 static enum _ecore_status_t ecore_set_coalesce(struct ecore_hwfn *p_hwfn,
4168 struct ecore_ptt *p_ptt,
4169 u32 hw_addr, void *p_eth_qzone,
4170 osal_size_t eth_qzone_size,
4173 struct coalescing_timeset *p_coal_timeset;
4175 if (IS_VF(p_hwfn->p_dev)) {
4176 DP_NOTICE(p_hwfn, true, "VF coalescing config not supported\n");
4180 if (p_hwfn->p_dev->int_coalescing_mode != ECORE_COAL_MODE_ENABLE) {
4181 DP_NOTICE(p_hwfn, true,
4182 "Coalescing configuration not enabled\n");
4186 p_coal_timeset = p_eth_qzone;
4187 OSAL_MEMSET(p_eth_qzone, 0, eth_qzone_size);
4188 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
4189 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
4190 ecore_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
4192 return ECORE_SUCCESS;
4195 enum _ecore_status_t ecore_set_rxq_coalesce(struct ecore_hwfn *p_hwfn,
4196 struct ecore_ptt *p_ptt,
4197 u16 coalesce, u16 qid, u16 sb_id)
4199 struct ustorm_eth_queue_zone eth_qzone;
4200 u8 timeset, timer_res;
4203 enum _ecore_status_t rc;
4205 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4206 if (coalesce <= 0x7F) {
4208 } else if (coalesce <= 0xFF) {
4210 } else if (coalesce <= 0x1FF) {
4213 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4216 timeset = (u8)(coalesce >> timer_res);
4218 rc = ecore_fw_l2_queue(p_hwfn, qid, &fw_qid);
4219 if (rc != ECORE_SUCCESS)
4222 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false);
4223 if (rc != ECORE_SUCCESS)
4226 address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
4228 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4229 sizeof(struct ustorm_eth_queue_zone), timeset);
4230 if (rc != ECORE_SUCCESS)
4233 p_hwfn->p_dev->rx_coalesce_usecs = coalesce;
4238 enum _ecore_status_t ecore_set_txq_coalesce(struct ecore_hwfn *p_hwfn,
4239 struct ecore_ptt *p_ptt,
4240 u16 coalesce, u16 qid, u16 sb_id)
4242 struct xstorm_eth_queue_zone eth_qzone;
4243 u8 timeset, timer_res;
4246 enum _ecore_status_t rc;
4248 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
4249 if (coalesce <= 0x7F) {
4251 } else if (coalesce <= 0xFF) {
4253 } else if (coalesce <= 0x1FF) {
4256 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
4260 timeset = (u8)(coalesce >> timer_res);
4262 rc = ecore_fw_l2_queue(p_hwfn, qid, &fw_qid);
4263 if (rc != ECORE_SUCCESS)
4266 rc = ecore_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true);
4267 if (rc != ECORE_SUCCESS)
4270 address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
4272 rc = ecore_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4273 sizeof(struct xstorm_eth_queue_zone), timeset);
4274 if (rc != ECORE_SUCCESS)
4277 p_hwfn->p_dev->tx_coalesce_usecs = coalesce;
4282 /* Calculate final WFQ values for all vports and configure it.
4283 * After this configuration each vport must have
4284 * approx min rate = vport_wfq * min_pf_rate / ECORE_WFQ_UNIT
4286 static void ecore_configure_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4287 struct ecore_ptt *p_ptt,
4290 struct init_qm_vport_params *vport_params;
4293 vport_params = p_hwfn->qm_info.qm_vport_params;
4295 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4296 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4298 vport_params[i].vport_wfq = (wfq_speed * ECORE_WFQ_UNIT) /
4300 ecore_init_vport_wfq(p_hwfn, p_ptt,
4301 vport_params[i].first_tx_pq_id,
4302 vport_params[i].vport_wfq);
4307 ecore_init_wfq_default_param(struct ecore_hwfn *p_hwfn, u32 min_pf_rate)
4311 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
4312 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
4315 static void ecore_disable_wfq_for_all_vports(struct ecore_hwfn *p_hwfn,
4316 struct ecore_ptt *p_ptt,
4319 struct init_qm_vport_params *vport_params;
4322 vport_params = p_hwfn->qm_info.qm_vport_params;
4324 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4325 ecore_init_wfq_default_param(p_hwfn, min_pf_rate);
4326 ecore_init_vport_wfq(p_hwfn, p_ptt,
4327 vport_params[i].first_tx_pq_id,
4328 vport_params[i].vport_wfq);
4332 /* This function performs several validations for WFQ
4333 * configuration and required min rate for a given vport
4334 * 1. req_rate must be greater than one percent of min_pf_rate.
4335 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
4336 * rates to get less than one percent of min_pf_rate.
4337 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
4339 static enum _ecore_status_t ecore_init_wfq_param(struct ecore_hwfn *p_hwfn,
4340 u16 vport_id, u32 req_rate,
4343 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
4344 int non_requested_count = 0, req_count = 0, i, num_vports;
4346 num_vports = p_hwfn->qm_info.num_vports;
4348 /* Accounting for the vports which are configured for WFQ explicitly */
4350 for (i = 0; i < num_vports; i++) {
4353 if ((i != vport_id) && p_hwfn->qm_info.wfq_data[i].configured) {
4355 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4356 total_req_min_rate += tmp_speed;
4360 /* Include current vport data as well */
4362 total_req_min_rate += req_rate;
4363 non_requested_count = num_vports - req_count;
4365 /* validate possible error cases */
4366 if (req_rate > min_pf_rate) {
4367 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4368 "Vport [%d] - Requested rate[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4369 vport_id, req_rate, min_pf_rate);
4373 if (req_rate < min_pf_rate / ECORE_WFQ_UNIT) {
4374 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4375 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4376 vport_id, req_rate, min_pf_rate);
4380 /* TBD - for number of vports greater than 100 */
4381 if (num_vports > ECORE_WFQ_UNIT) {
4382 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4383 "Number of vports is greater than %d\n",
4388 if (total_req_min_rate > min_pf_rate) {
4389 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4390 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4391 total_req_min_rate, min_pf_rate);
4395 /* Data left for non requested vports */
4396 total_left_rate = min_pf_rate - total_req_min_rate;
4397 left_rate_per_vp = total_left_rate / non_requested_count;
4399 /* validate if non requested get < 1% of min bw */
4400 if (left_rate_per_vp < min_pf_rate / ECORE_WFQ_UNIT) {
4401 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4402 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4403 left_rate_per_vp, min_pf_rate);
4407 /* now req_rate for given vport passes all scenarios.
4408 * assign final wfq rates to all vports.
4410 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
4411 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
4413 for (i = 0; i < num_vports; i++) {
4414 if (p_hwfn->qm_info.wfq_data[i].configured)
4417 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
4420 return ECORE_SUCCESS;
4423 static int __ecore_configure_vport_wfq(struct ecore_hwfn *p_hwfn,
4424 struct ecore_ptt *p_ptt,
4425 u16 vp_id, u32 rate)
4427 struct ecore_mcp_link_state *p_link;
4428 int rc = ECORE_SUCCESS;
4430 p_link = &p_hwfn->p_dev->hwfns[0].mcp_info->link_output;
4432 if (!p_link->min_pf_rate) {
4433 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
4434 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
4438 rc = ecore_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
4440 if (rc == ECORE_SUCCESS)
4441 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt,
4442 p_link->min_pf_rate);
4444 DP_NOTICE(p_hwfn, false,
4445 "Validation failed while configuring min rate\n");
4450 static int __ecore_configure_vp_wfq_on_link_change(struct ecore_hwfn *p_hwfn,
4451 struct ecore_ptt *p_ptt,
4454 bool use_wfq = false;
4455 int rc = ECORE_SUCCESS;
4458 /* Validate all pre configured vports for wfq */
4459 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4462 if (!p_hwfn->qm_info.wfq_data[i].configured)
4465 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
4468 rc = ecore_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
4469 if (rc != ECORE_SUCCESS) {
4470 DP_NOTICE(p_hwfn, false,
4471 "WFQ validation failed while configuring min rate\n");
4476 if (rc == ECORE_SUCCESS && use_wfq)
4477 ecore_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4479 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4484 /* Main API for ecore clients to configure vport min rate.
4485 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
4486 * rate - Speed in Mbps needs to be assigned to a given vport.
4488 int ecore_configure_vport_wfq(struct ecore_dev *p_dev, u16 vp_id, u32 rate)
4490 int i, rc = ECORE_INVAL;
4492 /* TBD - for multiple hardware functions - that is 100 gig */
4493 if (p_dev->num_hwfns > 1) {
4494 DP_NOTICE(p_dev, false,
4495 "WFQ configuration is not supported for this device\n");
4499 for_each_hwfn(p_dev, i) {
4500 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4501 struct ecore_ptt *p_ptt;
4503 p_ptt = ecore_ptt_acquire(p_hwfn);
4505 return ECORE_TIMEOUT;
4507 rc = __ecore_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
4509 if (rc != ECORE_SUCCESS) {
4510 ecore_ptt_release(p_hwfn, p_ptt);
4514 ecore_ptt_release(p_hwfn, p_ptt);
4520 /* API to configure WFQ from mcp link change */
4521 void ecore_configure_vp_wfq_on_link_change(struct ecore_dev *p_dev,
4526 /* TBD - for multiple hardware functions - that is 100 gig */
4527 if (p_dev->num_hwfns > 1) {
4528 DP_VERBOSE(p_dev, ECORE_MSG_LINK,
4529 "WFQ configuration is not supported for this device\n");
4533 for_each_hwfn(p_dev, i) {
4534 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4536 __ecore_configure_vp_wfq_on_link_change(p_hwfn,
4542 int __ecore_configure_pf_max_bandwidth(struct ecore_hwfn *p_hwfn,
4543 struct ecore_ptt *p_ptt,
4544 struct ecore_mcp_link_state *p_link,
4547 int rc = ECORE_SUCCESS;
4549 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
4551 if (!p_link->line_speed && (max_bw != 100))
4554 p_link->speed = (p_link->line_speed * max_bw) / 100;
4555 p_hwfn->qm_info.pf_rl = p_link->speed;
4557 /* Since the limiter also affects Tx-switched traffic, we don't want it
4558 * to limit such traffic in case there's no actual limit.
4559 * In that case, set limit to imaginary high boundary.
4562 p_hwfn->qm_info.pf_rl = 100000;
4564 rc = ecore_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
4565 p_hwfn->qm_info.pf_rl);
4567 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4568 "Configured MAX bandwidth to be %08x Mb/sec\n",
4574 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
4575 int ecore_configure_pf_max_bandwidth(struct ecore_dev *p_dev, u8 max_bw)
4577 int i, rc = ECORE_INVAL;
4579 if (max_bw < 1 || max_bw > 100) {
4580 DP_NOTICE(p_dev, false, "PF max bw valid range is [1-100]\n");
4584 for_each_hwfn(p_dev, i) {
4585 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4586 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
4587 struct ecore_mcp_link_state *p_link;
4588 struct ecore_ptt *p_ptt;
4590 p_link = &p_lead->mcp_info->link_output;
4592 p_ptt = ecore_ptt_acquire(p_hwfn);
4594 return ECORE_TIMEOUT;
4596 rc = __ecore_configure_pf_max_bandwidth(p_hwfn, p_ptt,
4599 ecore_ptt_release(p_hwfn, p_ptt);
4601 if (rc != ECORE_SUCCESS)
4608 int __ecore_configure_pf_min_bandwidth(struct ecore_hwfn *p_hwfn,
4609 struct ecore_ptt *p_ptt,
4610 struct ecore_mcp_link_state *p_link,
4613 int rc = ECORE_SUCCESS;
4615 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
4616 p_hwfn->qm_info.pf_wfq = min_bw;
4618 if (!p_link->line_speed)
4621 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
4623 rc = ecore_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
4625 DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
4626 "Configured MIN bandwidth to be %d Mb/sec\n",
4627 p_link->min_pf_rate);
4632 /* Main API to configure PF min bandwidth where bw range is [1-100] */
4633 int ecore_configure_pf_min_bandwidth(struct ecore_dev *p_dev, u8 min_bw)
4635 int i, rc = ECORE_INVAL;
4637 if (min_bw < 1 || min_bw > 100) {
4638 DP_NOTICE(p_dev, false, "PF min bw valid range is [1-100]\n");
4642 for_each_hwfn(p_dev, i) {
4643 struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
4644 struct ecore_hwfn *p_lead = ECORE_LEADING_HWFN(p_dev);
4645 struct ecore_mcp_link_state *p_link;
4646 struct ecore_ptt *p_ptt;
4648 p_link = &p_lead->mcp_info->link_output;
4650 p_ptt = ecore_ptt_acquire(p_hwfn);
4652 return ECORE_TIMEOUT;
4654 rc = __ecore_configure_pf_min_bandwidth(p_hwfn, p_ptt,
4656 if (rc != ECORE_SUCCESS) {
4657 ecore_ptt_release(p_hwfn, p_ptt);
4661 if (p_link->min_pf_rate) {
4662 u32 min_rate = p_link->min_pf_rate;
4664 rc = __ecore_configure_vp_wfq_on_link_change(p_hwfn,
4669 ecore_ptt_release(p_hwfn, p_ptt);
4675 void ecore_clean_wfq_db(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
4677 struct ecore_mcp_link_state *p_link;
4679 p_link = &p_hwfn->mcp_info->link_output;
4681 if (p_link->min_pf_rate)
4682 ecore_disable_wfq_for_all_vports(p_hwfn, p_ptt,
4683 p_link->min_pf_rate);
4685 OSAL_MEMSET(p_hwfn->qm_info.wfq_data, 0,
4686 sizeof(*p_hwfn->qm_info.wfq_data) *
4687 p_hwfn->qm_info.num_vports);
4690 int ecore_device_num_engines(struct ecore_dev *p_dev)
4692 return ECORE_IS_BB(p_dev) ? 2 : 1;
4695 int ecore_device_num_ports(struct ecore_dev *p_dev)
4697 /* in CMT always only one port */
4698 if (p_dev->num_hwfns > 1)
4701 return p_dev->num_ports_in_engines * ecore_device_num_engines(p_dev);
4704 void ecore_set_fw_mac_addr(__le16 *fw_msb,
4709 ((u8 *)fw_msb)[0] = mac[1];
4710 ((u8 *)fw_msb)[1] = mac[0];
4711 ((u8 *)fw_mid)[0] = mac[3];
4712 ((u8 *)fw_mid)[1] = mac[2];
4713 ((u8 *)fw_lsb)[0] = mac[5];
4714 ((u8 *)fw_lsb)[1] = mac[4];