1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/types.h>
34 #include <asm/byteorder.h>
36 #include <linux/delay.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/errno.h>
39 #include <linux/kernel.h>
40 #include <linux/mutex.h>
41 #include <linux/pci.h>
42 #include <linux/slab.h>
43 #include <linux/string.h>
44 #include <linux/vmalloc.h>
45 #include <linux/etherdevice.h>
46 #include <linux/qed/qed_chain.h>
47 #include <linux/qed/qed_if.h>
51 #include "qed_dev_api.h"
55 #include "qed_init_ops.h"
57 #include "qed_iscsi.h"
61 #include "qed_reg_addr.h"
63 #include "qed_sriov.h"
67 static DEFINE_SPINLOCK(qm_lock);
69 #define QED_MIN_DPIS (4)
70 #define QED_MIN_PWM_REGION (QED_WID_SIZE * QED_MIN_DPIS)
72 static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
73 struct qed_ptt *p_ptt, enum BAR_ID bar_id)
75 u32 bar_reg = (bar_id == BAR_ID_0 ?
76 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
79 if (IS_VF(p_hwfn->cdev))
80 return qed_vf_hw_bar_size(p_hwfn, bar_id);
82 val = qed_rd(p_hwfn, p_ptt, bar_reg);
84 return 1 << (val + 15);
86 /* Old MFW initialized above registered only conditionally */
87 if (p_hwfn->cdev->num_hwfns > 1) {
89 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
90 return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
93 "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
98 void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level)
102 cdev->dp_level = dp_level;
103 cdev->dp_module = dp_module;
104 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
105 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
107 p_hwfn->dp_level = dp_level;
108 p_hwfn->dp_module = dp_module;
112 void qed_init_struct(struct qed_dev *cdev)
116 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
117 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
121 p_hwfn->b_active = false;
123 mutex_init(&p_hwfn->dmae_info.mutex);
126 /* hwfn 0 is always active */
127 cdev->hwfns[0].b_active = true;
129 /* set the default cache alignment to 128 */
130 cdev->cache_shift = 7;
133 static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
135 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
137 kfree(qm_info->qm_pq_params);
138 qm_info->qm_pq_params = NULL;
139 kfree(qm_info->qm_vport_params);
140 qm_info->qm_vport_params = NULL;
141 kfree(qm_info->qm_port_params);
142 qm_info->qm_port_params = NULL;
143 kfree(qm_info->wfq_data);
144 qm_info->wfq_data = NULL;
147 void qed_resc_free(struct qed_dev *cdev)
152 for_each_hwfn(cdev, i)
153 qed_l2_free(&cdev->hwfns[i]);
157 kfree(cdev->fw_data);
158 cdev->fw_data = NULL;
160 kfree(cdev->reset_stats);
161 cdev->reset_stats = NULL;
163 for_each_hwfn(cdev, i) {
164 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
166 qed_cxt_mngr_free(p_hwfn);
167 qed_qm_info_free(p_hwfn);
168 qed_spq_free(p_hwfn);
170 qed_consq_free(p_hwfn);
171 qed_int_free(p_hwfn);
172 #ifdef CONFIG_QED_LL2
173 qed_ll2_free(p_hwfn);
175 if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
176 qed_fcoe_free(p_hwfn);
178 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
179 qed_iscsi_free(p_hwfn);
180 qed_ooo_free(p_hwfn);
182 qed_iov_free(p_hwfn);
184 qed_dmae_info_free(p_hwfn);
185 qed_dcbx_info_free(p_hwfn);
189 /******************** QM initialization *******************/
190 #define ACTIVE_TCS_BMAP 0x9f
191 #define ACTIVE_TCS_BMAP_4PORT_K2 0xf
193 /* determines the physical queue flags for a given PF. */
194 static u32 qed_get_pq_flags(struct qed_hwfn *p_hwfn)
202 if (IS_QED_SRIOV(p_hwfn->cdev))
203 flags |= PQ_FLAGS_VFS;
206 switch (p_hwfn->hw_info.personality) {
208 flags |= PQ_FLAGS_MCOS;
211 flags |= PQ_FLAGS_OFLD;
214 flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
216 case QED_PCI_ETH_ROCE:
217 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD | PQ_FLAGS_LLT;
221 "unknown personality %d\n", p_hwfn->hw_info.personality);
228 /* Getters for resource amounts necessary for qm initialization */
229 u8 qed_init_qm_get_num_tcs(struct qed_hwfn *p_hwfn)
231 return p_hwfn->hw_info.num_hw_tc;
234 u16 qed_init_qm_get_num_vfs(struct qed_hwfn *p_hwfn)
236 return IS_QED_SRIOV(p_hwfn->cdev) ?
237 p_hwfn->cdev->p_iov_info->total_vfs : 0;
240 #define NUM_DEFAULT_RLS 1
242 u16 qed_init_qm_get_num_pf_rls(struct qed_hwfn *p_hwfn)
244 u16 num_pf_rls, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
246 /* num RLs can't exceed resource amount of rls or vports */
247 num_pf_rls = (u16) min_t(u32, RESC_NUM(p_hwfn, QED_RL),
248 RESC_NUM(p_hwfn, QED_VPORT));
250 /* Make sure after we reserve there's something left */
251 if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS)
254 /* subtract rls necessary for VFs and one default one for the PF */
255 num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
260 u16 qed_init_qm_get_num_vports(struct qed_hwfn *p_hwfn)
262 u32 pq_flags = qed_get_pq_flags(p_hwfn);
264 /* all pqs share the same vport, except for vfs and pf_rl pqs */
265 return (!!(PQ_FLAGS_RLS & pq_flags)) *
266 qed_init_qm_get_num_pf_rls(p_hwfn) +
267 (!!(PQ_FLAGS_VFS & pq_flags)) *
268 qed_init_qm_get_num_vfs(p_hwfn) + 1;
271 /* calc amount of PQs according to the requested flags */
272 u16 qed_init_qm_get_num_pqs(struct qed_hwfn *p_hwfn)
274 u32 pq_flags = qed_get_pq_flags(p_hwfn);
276 return (!!(PQ_FLAGS_RLS & pq_flags)) *
277 qed_init_qm_get_num_pf_rls(p_hwfn) +
278 (!!(PQ_FLAGS_MCOS & pq_flags)) *
279 qed_init_qm_get_num_tcs(p_hwfn) +
280 (!!(PQ_FLAGS_LB & pq_flags)) + (!!(PQ_FLAGS_OOO & pq_flags)) +
281 (!!(PQ_FLAGS_ACK & pq_flags)) + (!!(PQ_FLAGS_OFLD & pq_flags)) +
282 (!!(PQ_FLAGS_LLT & pq_flags)) +
283 (!!(PQ_FLAGS_VFS & pq_flags)) * qed_init_qm_get_num_vfs(p_hwfn);
286 /* initialize the top level QM params */
287 static void qed_init_qm_params(struct qed_hwfn *p_hwfn)
289 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
292 /* pq and vport bases for this PF */
293 qm_info->start_pq = (u16) RESC_START(p_hwfn, QED_PQ);
294 qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
296 /* rate limiting and weighted fair queueing are always enabled */
297 qm_info->vport_rl_en = 1;
298 qm_info->vport_wfq_en = 1;
300 /* TC config is different for AH 4 port */
301 four_port = p_hwfn->cdev->num_ports_in_engine == MAX_NUM_PORTS_K2;
303 /* in AH 4 port we have fewer TCs per port */
304 qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 :
307 /* unless MFW indicated otherwise, ooo_tc == 3 for
308 * AH 4-port and 4 otherwise.
310 if (!qm_info->ooo_tc)
311 qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC :
315 /* initialize qm vport params */
316 static void qed_init_qm_vport_params(struct qed_hwfn *p_hwfn)
318 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
321 /* all vports participate in weighted fair queueing */
322 for (i = 0; i < qed_init_qm_get_num_vports(p_hwfn); i++)
323 qm_info->qm_vport_params[i].vport_wfq = 1;
326 /* initialize qm port params */
327 static void qed_init_qm_port_params(struct qed_hwfn *p_hwfn)
329 /* Initialize qm port parameters */
330 u8 i, active_phys_tcs, num_ports = p_hwfn->cdev->num_ports_in_engine;
332 /* indicate how ooo and high pri traffic is dealt with */
333 active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
334 ACTIVE_TCS_BMAP_4PORT_K2 :
337 for (i = 0; i < num_ports; i++) {
338 struct init_qm_port_params *p_qm_port =
339 &p_hwfn->qm_info.qm_port_params[i];
341 p_qm_port->active = 1;
342 p_qm_port->active_phys_tcs = active_phys_tcs;
343 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
344 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
348 /* Reset the params which must be reset for qm init. QM init may be called as
349 * a result of flows other than driver load (e.g. dcbx renegotiation). Other
350 * params may be affected by the init but would simply recalculate to the same
351 * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
352 * affected as these amounts stay the same.
354 static void qed_init_qm_reset_params(struct qed_hwfn *p_hwfn)
356 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
358 qm_info->num_pqs = 0;
359 qm_info->num_vports = 0;
360 qm_info->num_pf_rls = 0;
361 qm_info->num_vf_pqs = 0;
362 qm_info->first_vf_pq = 0;
363 qm_info->first_mcos_pq = 0;
364 qm_info->first_rl_pq = 0;
367 static void qed_init_qm_advance_vport(struct qed_hwfn *p_hwfn)
369 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
371 qm_info->num_vports++;
373 if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
375 "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
376 qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
379 /* initialize a single pq and manage qm_info resources accounting.
380 * The pq_init_flags param determines whether the PQ is rate limited
381 * (for VF or PF) and whether a new vport is allocated to the pq or not
382 * (i.e. vport will be shared).
385 /* flags for pq init */
386 #define PQ_INIT_SHARE_VPORT (1 << 0)
387 #define PQ_INIT_PF_RL (1 << 1)
388 #define PQ_INIT_VF_RL (1 << 2)
390 /* defines for pq init */
391 #define PQ_INIT_DEFAULT_WRR_GROUP 1
392 #define PQ_INIT_DEFAULT_TC 0
393 #define PQ_INIT_OFLD_TC (p_hwfn->hw_info.offload_tc)
395 static void qed_init_qm_pq(struct qed_hwfn *p_hwfn,
396 struct qed_qm_info *qm_info,
397 u8 tc, u32 pq_init_flags)
399 u16 pq_idx = qm_info->num_pqs, max_pq = qed_init_qm_get_num_pqs(p_hwfn);
403 "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
406 qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
408 qm_info->qm_pq_params[pq_idx].tc_id = tc;
409 qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
410 qm_info->qm_pq_params[pq_idx].rl_valid =
411 (pq_init_flags & PQ_INIT_PF_RL || pq_init_flags & PQ_INIT_VF_RL);
413 /* qm params accounting */
415 if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
416 qm_info->num_vports++;
418 if (pq_init_flags & PQ_INIT_PF_RL)
419 qm_info->num_pf_rls++;
421 if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
423 "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
424 qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
426 if (qm_info->num_pf_rls > qed_init_qm_get_num_pf_rls(p_hwfn))
428 "rl overflow! qm_info->num_pf_rls %d, qm_init_get_num_pf_rls() %d\n",
429 qm_info->num_pf_rls, qed_init_qm_get_num_pf_rls(p_hwfn));
432 /* get pq index according to PQ_FLAGS */
433 static u16 *qed_init_qm_get_idx_from_flags(struct qed_hwfn *p_hwfn,
436 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
438 /* Can't have multiple flags set here */
439 if (bitmap_weight((unsigned long *)&pq_flags, sizeof(pq_flags)) > 1)
444 return &qm_info->first_rl_pq;
446 return &qm_info->first_mcos_pq;
448 return &qm_info->pure_lb_pq;
450 return &qm_info->ooo_pq;
452 return &qm_info->pure_ack_pq;
454 return &qm_info->offload_pq;
456 return &qm_info->low_latency_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 qed_init_qm_set_idx(struct qed_hwfn *p_hwfn,
470 u32 pq_flags, u16 pq_val)
472 u16 *base_pq_idx = qed_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 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags)
480 u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
482 return *base_pq_idx + CM_TX_PQ_BASE;
485 u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc)
487 u8 max_tc = qed_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 qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + tc;
495 u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf)
497 u16 max_vf = qed_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 qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + vf;
505 u16 qed_get_cm_pq_idx_rl(struct qed_hwfn *p_hwfn, u8 rl)
507 u16 max_rl = qed_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 qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_RLS) + rl;
515 /* Functions for creating specific types of pqs */
516 static void qed_init_qm_lb_pq(struct qed_hwfn *p_hwfn)
518 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
520 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
523 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
524 qed_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
527 static void qed_init_qm_ooo_pq(struct qed_hwfn *p_hwfn)
529 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
531 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
534 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
535 qed_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
538 static void qed_init_qm_pure_ack_pq(struct qed_hwfn *p_hwfn)
540 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
542 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
545 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
546 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
549 static void qed_init_qm_offload_pq(struct qed_hwfn *p_hwfn)
551 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
553 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
556 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
557 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
560 static void qed_init_qm_low_latency_pq(struct qed_hwfn *p_hwfn)
562 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
564 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LLT))
567 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LLT, qm_info->num_pqs);
568 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_SHARE_VPORT);
571 static void qed_init_qm_mcos_pqs(struct qed_hwfn *p_hwfn)
573 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
576 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
579 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
580 for (tc_idx = 0; tc_idx < qed_init_qm_get_num_tcs(p_hwfn); tc_idx++)
581 qed_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
584 static void qed_init_qm_vf_pqs(struct qed_hwfn *p_hwfn)
586 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
587 u16 vf_idx, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
589 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
592 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
593 qm_info->num_vf_pqs = num_vfs;
594 for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
595 qed_init_qm_pq(p_hwfn,
596 qm_info, PQ_INIT_DEFAULT_TC, PQ_INIT_VF_RL);
599 static void qed_init_qm_rl_pqs(struct qed_hwfn *p_hwfn)
601 u16 pf_rls_idx, num_pf_rls = qed_init_qm_get_num_pf_rls(p_hwfn);
602 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
604 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
607 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
608 for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
609 qed_init_qm_pq(p_hwfn, qm_info, PQ_INIT_OFLD_TC, PQ_INIT_PF_RL);
612 static void qed_init_qm_pq_params(struct qed_hwfn *p_hwfn)
614 /* rate limited pqs, must come first (FW assumption) */
615 qed_init_qm_rl_pqs(p_hwfn);
617 /* pqs for multi cos */
618 qed_init_qm_mcos_pqs(p_hwfn);
620 /* pure loopback pq */
621 qed_init_qm_lb_pq(p_hwfn);
623 /* out of order pq */
624 qed_init_qm_ooo_pq(p_hwfn);
627 qed_init_qm_pure_ack_pq(p_hwfn);
629 /* pq for offloaded protocol */
630 qed_init_qm_offload_pq(p_hwfn);
633 qed_init_qm_low_latency_pq(p_hwfn);
635 /* done sharing vports */
636 qed_init_qm_advance_vport(p_hwfn);
639 qed_init_qm_vf_pqs(p_hwfn);
642 /* compare values of getters against resources amounts */
643 static int qed_init_qm_sanity(struct qed_hwfn *p_hwfn)
645 if (qed_init_qm_get_num_vports(p_hwfn) > RESC_NUM(p_hwfn, QED_VPORT)) {
646 DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
650 if (qed_init_qm_get_num_pqs(p_hwfn) > RESC_NUM(p_hwfn, QED_PQ)) {
651 DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
658 static void qed_dp_init_qm_params(struct qed_hwfn *p_hwfn)
660 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
661 struct init_qm_vport_params *vport;
662 struct init_qm_port_params *port;
663 struct init_qm_pq_params *pq;
666 /* top level params */
669 "qm init top level params: start_pq %d, start_vport %d, pure_lb_pq %d, offload_pq %d, pure_ack_pq %d\n",
671 qm_info->start_vport,
673 qm_info->offload_pq, qm_info->pure_ack_pq);
676 "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d, num_vports %d, max_phys_tcs_per_port %d\n",
678 qm_info->first_vf_pq,
681 qm_info->num_vports, qm_info->max_phys_tcs_per_port);
684 "pf_rl_en %d, pf_wfq_en %d, vport_rl_en %d, vport_wfq_en %d, pf_wfq %d, pf_rl %d, num_pf_rls %d, pq_flags %x\n",
687 qm_info->vport_rl_en,
688 qm_info->vport_wfq_en,
691 qm_info->num_pf_rls, qed_get_pq_flags(p_hwfn));
694 for (i = 0; i < p_hwfn->cdev->num_ports_in_engine; i++) {
695 port = &(qm_info->qm_port_params[i]);
698 "port idx %d, active %d, active_phys_tcs %d, num_pbf_cmd_lines %d, num_btb_blocks %d, reserved %d\n",
701 port->active_phys_tcs,
702 port->num_pbf_cmd_lines,
703 port->num_btb_blocks, port->reserved);
707 for (i = 0; i < qm_info->num_vports; i++) {
708 vport = &(qm_info->qm_vport_params[i]);
711 "vport idx %d, vport_rl %d, wfq %d, first_tx_pq_id [ ",
712 qm_info->start_vport + i,
713 vport->vport_rl, vport->vport_wfq);
714 for (tc = 0; tc < NUM_OF_TCS; tc++)
717 "%d ", vport->first_tx_pq_id[tc]);
718 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "]\n");
722 for (i = 0; i < qm_info->num_pqs; i++) {
723 pq = &(qm_info->qm_pq_params[i]);
726 "pq idx %d, vport_id %d, tc %d, wrr_grp %d, rl_valid %d\n",
727 qm_info->start_pq + i,
729 pq->tc_id, pq->wrr_group, pq->rl_valid);
733 static void qed_init_qm_info(struct qed_hwfn *p_hwfn)
735 /* reset params required for init run */
736 qed_init_qm_reset_params(p_hwfn);
738 /* init QM top level params */
739 qed_init_qm_params(p_hwfn);
741 /* init QM port params */
742 qed_init_qm_port_params(p_hwfn);
744 /* init QM vport params */
745 qed_init_qm_vport_params(p_hwfn);
747 /* init QM physical queue params */
748 qed_init_qm_pq_params(p_hwfn);
750 /* display all that init */
751 qed_dp_init_qm_params(p_hwfn);
754 /* This function reconfigures the QM pf on the fly.
755 * For this purpose we:
756 * 1. reconfigure the QM database
757 * 2. set new values to runtime arrat
758 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
759 * 4. activate init tool in QM_PF stage
760 * 5. send an sdm_qm_cmd through rbc interface to release the QM
762 int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
764 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
768 /* initialize qed's qm data structure */
769 qed_init_qm_info(p_hwfn);
771 /* stop PF's qm queues */
772 spin_lock_bh(&qm_lock);
773 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
774 qm_info->start_pq, qm_info->num_pqs);
775 spin_unlock_bh(&qm_lock);
779 /* clear the QM_PF runtime phase leftovers from previous init */
780 qed_init_clear_rt_data(p_hwfn);
782 /* prepare QM portion of runtime array */
783 qed_qm_init_pf(p_hwfn, p_ptt);
785 /* activate init tool on runtime array */
786 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
787 p_hwfn->hw_info.hw_mode);
791 /* start PF's qm queues */
792 spin_lock_bh(&qm_lock);
793 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
794 qm_info->start_pq, qm_info->num_pqs);
795 spin_unlock_bh(&qm_lock);
802 static int qed_alloc_qm_data(struct qed_hwfn *p_hwfn)
804 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
807 rc = qed_init_qm_sanity(p_hwfn);
811 qm_info->qm_pq_params = kzalloc(sizeof(*qm_info->qm_pq_params) *
812 qed_init_qm_get_num_pqs(p_hwfn),
814 if (!qm_info->qm_pq_params)
817 qm_info->qm_vport_params = kzalloc(sizeof(*qm_info->qm_vport_params) *
818 qed_init_qm_get_num_vports(p_hwfn),
820 if (!qm_info->qm_vport_params)
823 qm_info->qm_port_params = kzalloc(sizeof(*qm_info->qm_port_params) *
824 p_hwfn->cdev->num_ports_in_engine,
826 if (!qm_info->qm_port_params)
829 qm_info->wfq_data = kzalloc(sizeof(*qm_info->wfq_data) *
830 qed_init_qm_get_num_vports(p_hwfn),
832 if (!qm_info->wfq_data)
838 DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
839 qed_qm_info_free(p_hwfn);
843 int qed_resc_alloc(struct qed_dev *cdev)
845 u32 rdma_tasks, excess_tasks;
850 for_each_hwfn(cdev, i) {
851 rc = qed_l2_alloc(&cdev->hwfns[i]);
858 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
862 for_each_hwfn(cdev, i) {
863 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
864 u32 n_eqes, num_cons;
866 /* First allocate the context manager structure */
867 rc = qed_cxt_mngr_alloc(p_hwfn);
871 /* Set the HW cid/tid numbers (in the contest manager)
872 * Must be done prior to any further computations.
874 rc = qed_cxt_set_pf_params(p_hwfn, RDMA_MAX_TIDS);
878 rc = qed_alloc_qm_data(p_hwfn);
883 qed_init_qm_info(p_hwfn);
885 /* Compute the ILT client partition */
886 rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
889 "too many ILT lines; re-computing with less lines\n");
890 /* In case there are not enough ILT lines we reduce the
891 * number of RDMA tasks and re-compute.
894 qed_cxt_cfg_ilt_compute_excess(p_hwfn, line_count);
898 rdma_tasks = RDMA_MAX_TIDS - excess_tasks;
899 rc = qed_cxt_set_pf_params(p_hwfn, rdma_tasks);
903 rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
906 "failed ILT compute. Requested too many lines: %u\n",
913 /* CID map / ILT shadow table / T2
914 * The talbes sizes are determined by the computations above
916 rc = qed_cxt_tables_alloc(p_hwfn);
920 /* SPQ, must follow ILT because initializes SPQ context */
921 rc = qed_spq_alloc(p_hwfn);
925 /* SP status block allocation */
926 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
929 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
933 rc = qed_iov_alloc(p_hwfn);
938 n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
939 if (QED_IS_RDMA_PERSONALITY(p_hwfn)) {
940 enum protocol_type rdma_proto;
942 if (QED_IS_ROCE_PERSONALITY(p_hwfn))
943 rdma_proto = PROTOCOLID_ROCE;
945 rdma_proto = PROTOCOLID_IWARP;
947 num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
950 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
951 } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
953 qed_cxt_get_proto_cid_count(p_hwfn,
956 n_eqes += 2 * num_cons;
959 if (n_eqes > 0xFFFF) {
961 "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
966 rc = qed_eq_alloc(p_hwfn, (u16) n_eqes);
970 rc = qed_consq_alloc(p_hwfn);
974 rc = qed_l2_alloc(p_hwfn);
978 #ifdef CONFIG_QED_LL2
979 if (p_hwfn->using_ll2) {
980 rc = qed_ll2_alloc(p_hwfn);
986 if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
987 rc = qed_fcoe_alloc(p_hwfn);
992 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
993 rc = qed_iscsi_alloc(p_hwfn);
996 rc = qed_ooo_alloc(p_hwfn);
1001 /* DMA info initialization */
1002 rc = qed_dmae_info_alloc(p_hwfn);
1006 /* DCBX initialization */
1007 rc = qed_dcbx_info_alloc(p_hwfn);
1012 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
1013 if (!cdev->reset_stats)
1021 qed_resc_free(cdev);
1025 void qed_resc_setup(struct qed_dev *cdev)
1030 for_each_hwfn(cdev, i)
1031 qed_l2_setup(&cdev->hwfns[i]);
1035 for_each_hwfn(cdev, i) {
1036 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1038 qed_cxt_mngr_setup(p_hwfn);
1039 qed_spq_setup(p_hwfn);
1040 qed_eq_setup(p_hwfn);
1041 qed_consq_setup(p_hwfn);
1043 /* Read shadow of current MFW mailbox */
1044 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
1045 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
1046 p_hwfn->mcp_info->mfw_mb_cur,
1047 p_hwfn->mcp_info->mfw_mb_length);
1049 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
1051 qed_l2_setup(p_hwfn);
1052 qed_iov_setup(p_hwfn);
1053 #ifdef CONFIG_QED_LL2
1054 if (p_hwfn->using_ll2)
1055 qed_ll2_setup(p_hwfn);
1057 if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
1058 qed_fcoe_setup(p_hwfn);
1060 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
1061 qed_iscsi_setup(p_hwfn);
1062 qed_ooo_setup(p_hwfn);
1067 #define FINAL_CLEANUP_POLL_CNT (100)
1068 #define FINAL_CLEANUP_POLL_TIME (10)
1069 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
1070 struct qed_ptt *p_ptt, u16 id, bool is_vf)
1072 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
1075 addr = GTT_BAR0_MAP_REG_USDM_RAM +
1076 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
1081 command |= X_FINAL_CLEANUP_AGG_INT <<
1082 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
1083 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
1084 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
1085 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
1087 /* Make sure notification is not set before initiating final cleanup */
1088 if (REG_RD(p_hwfn, addr)) {
1090 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
1091 REG_WR(p_hwfn, addr, 0);
1094 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1095 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
1098 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
1100 /* Poll until completion */
1101 while (!REG_RD(p_hwfn, addr) && count--)
1102 msleep(FINAL_CLEANUP_POLL_TIME);
1104 if (REG_RD(p_hwfn, addr))
1108 "Failed to receive FW final cleanup notification\n");
1110 /* Cleanup afterwards */
1111 REG_WR(p_hwfn, addr, 0);
1116 static int qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
1120 if (QED_IS_BB_B0(p_hwfn->cdev)) {
1121 hw_mode |= 1 << MODE_BB;
1122 } else if (QED_IS_AH(p_hwfn->cdev)) {
1123 hw_mode |= 1 << MODE_K2;
1125 DP_NOTICE(p_hwfn, "Unknown chip type %#x\n",
1126 p_hwfn->cdev->type);
1130 switch (p_hwfn->cdev->num_ports_in_engine) {
1132 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
1135 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
1138 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
1141 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
1142 p_hwfn->cdev->num_ports_in_engine);
1146 switch (p_hwfn->cdev->mf_mode) {
1147 case QED_MF_DEFAULT:
1149 hw_mode |= 1 << MODE_MF_SI;
1152 hw_mode |= 1 << MODE_MF_SD;
1155 DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
1156 hw_mode |= 1 << MODE_MF_SI;
1159 hw_mode |= 1 << MODE_ASIC;
1161 if (p_hwfn->cdev->num_hwfns > 1)
1162 hw_mode |= 1 << MODE_100G;
1164 p_hwfn->hw_info.hw_mode = hw_mode;
1166 DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
1167 "Configuring function for hw_mode: 0x%08x\n",
1168 p_hwfn->hw_info.hw_mode);
1173 /* Init run time data for all PFs on an engine. */
1174 static void qed_init_cau_rt_data(struct qed_dev *cdev)
1176 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
1179 for_each_hwfn(cdev, i) {
1180 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1181 struct qed_igu_info *p_igu_info;
1182 struct qed_igu_block *p_block;
1183 struct cau_sb_entry sb_entry;
1185 p_igu_info = p_hwfn->hw_info.p_igu_info;
1188 igu_sb_id < QED_MAPPING_MEMORY_SIZE(cdev); igu_sb_id++) {
1189 p_block = &p_igu_info->entry[igu_sb_id];
1191 if (!p_block->is_pf)
1194 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
1195 p_block->function_id, 0, 0);
1196 STORE_RT_REG_AGG(p_hwfn, offset + igu_sb_id * 2,
1202 static void qed_init_cache_line_size(struct qed_hwfn *p_hwfn,
1203 struct qed_ptt *p_ptt)
1205 u32 val, wr_mbs, cache_line_size;
1207 val = qed_rd(p_hwfn, p_ptt, PSWRQ2_REG_WR_MBS0);
1220 "Unexpected value of PSWRQ2_REG_WR_MBS0 [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1225 cache_line_size = min_t(u32, L1_CACHE_BYTES, wr_mbs);
1226 switch (cache_line_size) {
1241 "Unexpected value of cache line size [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1245 if (L1_CACHE_BYTES > wr_mbs)
1247 "The cache line size for padding is suboptimal for performance [OS cache line size 0x%x, wr mbs 0x%x]\n",
1248 L1_CACHE_BYTES, wr_mbs);
1250 STORE_RT_REG(p_hwfn, PGLUE_REG_B_CACHE_LINE_SIZE_RT_OFFSET, val);
1252 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_WR_RT_OFFSET, val);
1253 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_RD_RT_OFFSET, val);
1257 static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
1258 struct qed_ptt *p_ptt, int hw_mode)
1260 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
1261 struct qed_qm_common_rt_init_params params;
1262 struct qed_dev *cdev = p_hwfn->cdev;
1263 u8 vf_id, max_num_vfs;
1268 qed_init_cau_rt_data(cdev);
1270 /* Program GTT windows */
1271 qed_gtt_init(p_hwfn);
1273 if (p_hwfn->mcp_info) {
1274 if (p_hwfn->mcp_info->func_info.bandwidth_max)
1275 qm_info->pf_rl_en = 1;
1276 if (p_hwfn->mcp_info->func_info.bandwidth_min)
1277 qm_info->pf_wfq_en = 1;
1280 memset(¶ms, 0, sizeof(params));
1281 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engine;
1282 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
1283 params.pf_rl_en = qm_info->pf_rl_en;
1284 params.pf_wfq_en = qm_info->pf_wfq_en;
1285 params.vport_rl_en = qm_info->vport_rl_en;
1286 params.vport_wfq_en = qm_info->vport_wfq_en;
1287 params.port_params = qm_info->qm_port_params;
1289 qed_qm_common_rt_init(p_hwfn, ¶ms);
1291 qed_cxt_hw_init_common(p_hwfn);
1293 qed_init_cache_line_size(p_hwfn, p_ptt);
1295 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
1299 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
1300 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
1302 if (QED_IS_BB(p_hwfn->cdev)) {
1303 num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
1304 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
1305 qed_fid_pretend(p_hwfn, p_ptt, pf_id);
1306 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1307 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1309 /* pretend to original PF */
1310 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1313 max_num_vfs = QED_IS_AH(cdev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
1314 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
1315 concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
1316 qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
1317 qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
1318 qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
1319 qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
1320 qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
1322 /* pretend to original PF */
1323 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1329 qed_hw_init_dpi_size(struct qed_hwfn *p_hwfn,
1330 struct qed_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
1332 u32 dpi_bit_shift, dpi_count, dpi_page_size;
1336 /* Calculate DPI size */
1337 n_wids = max_t(u32, QED_MIN_WIDS, n_cpus);
1338 dpi_page_size = QED_WID_SIZE * roundup_pow_of_two(n_wids);
1339 dpi_page_size = (dpi_page_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
1340 dpi_bit_shift = ilog2(dpi_page_size / 4096);
1341 dpi_count = pwm_region_size / dpi_page_size;
1343 min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
1344 min_dpis = max_t(u32, QED_MIN_DPIS, min_dpis);
1346 p_hwfn->dpi_size = dpi_page_size;
1347 p_hwfn->dpi_count = dpi_count;
1349 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
1351 if (dpi_count < min_dpis)
1357 enum QED_ROCE_EDPM_MODE {
1358 QED_ROCE_EDPM_MODE_ENABLE = 0,
1359 QED_ROCE_EDPM_MODE_FORCE_ON = 1,
1360 QED_ROCE_EDPM_MODE_DISABLE = 2,
1364 qed_hw_init_pf_doorbell_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1366 u32 pwm_regsize, norm_regsize;
1367 u32 non_pwm_conn, min_addr_reg1;
1368 u32 db_bar_size, n_cpus = 1;
1374 db_bar_size = qed_hw_bar_size(p_hwfn, p_ptt, BAR_ID_1);
1375 if (p_hwfn->cdev->num_hwfns > 1)
1378 /* Calculate doorbell regions */
1379 non_pwm_conn = qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1380 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1382 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
1384 norm_regsize = roundup(QED_PF_DEMS_SIZE * non_pwm_conn, PAGE_SIZE);
1385 min_addr_reg1 = norm_regsize / 4096;
1386 pwm_regsize = db_bar_size - norm_regsize;
1388 /* Check that the normal and PWM sizes are valid */
1389 if (db_bar_size < norm_regsize) {
1390 DP_ERR(p_hwfn->cdev,
1391 "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
1392 db_bar_size, norm_regsize);
1396 if (pwm_regsize < QED_MIN_PWM_REGION) {
1397 DP_ERR(p_hwfn->cdev,
1398 "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",
1400 QED_MIN_PWM_REGION, db_bar_size, norm_regsize);
1404 /* Calculate number of DPIs */
1405 roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
1406 if ((roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE) ||
1407 ((roce_edpm_mode == QED_ROCE_EDPM_MODE_FORCE_ON))) {
1408 /* Either EDPM is mandatory, or we are attempting to allocate a
1411 n_cpus = num_present_cpus();
1412 rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1415 cond = (rc && (roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE)) ||
1416 (roce_edpm_mode == QED_ROCE_EDPM_MODE_DISABLE);
1417 if (cond || p_hwfn->dcbx_no_edpm) {
1418 /* Either EDPM is disabled from user configuration, or it is
1419 * disabled via DCBx, or it is not mandatory and we failed to
1420 * allocated a WID per CPU.
1423 rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1426 qed_rdma_dpm_bar(p_hwfn, p_ptt);
1429 p_hwfn->wid_count = (u16) n_cpus;
1432 "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
1437 ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
1438 "disabled" : "enabled");
1442 "Failed to allocate enough DPIs. Allocated %d but the current minimum is %d.\n",
1444 p_hwfn->pf_params.rdma_pf_params.min_dpis);
1448 p_hwfn->dpi_start_offset = norm_regsize;
1450 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1451 pf_dems_shift = ilog2(QED_PF_DEMS_SIZE / 4);
1452 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1453 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1458 static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
1459 struct qed_ptt *p_ptt, int hw_mode)
1463 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id, hw_mode);
1467 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_MASTER_WRITE_PAD_ENABLE, 0);
1472 static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
1473 struct qed_ptt *p_ptt,
1474 struct qed_tunnel_info *p_tunn,
1477 enum qed_int_mode int_mode,
1478 bool allow_npar_tx_switch)
1480 u8 rel_pf_id = p_hwfn->rel_pf_id;
1483 if (p_hwfn->mcp_info) {
1484 struct qed_mcp_function_info *p_info;
1486 p_info = &p_hwfn->mcp_info->func_info;
1487 if (p_info->bandwidth_min)
1488 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1490 /* Update rate limit once we'll actually have a link */
1491 p_hwfn->qm_info.pf_rl = 100000;
1494 qed_cxt_hw_init_pf(p_hwfn, p_ptt);
1496 qed_int_igu_init_rt(p_hwfn);
1498 /* Set VLAN in NIG if needed */
1499 if (hw_mode & BIT(MODE_MF_SD)) {
1500 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1501 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1502 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1503 p_hwfn->hw_info.ovlan);
1506 /* Enable classification by MAC if needed */
1507 if (hw_mode & BIT(MODE_MF_SI)) {
1508 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
1509 "Configuring TAGMAC_CLS_TYPE\n");
1510 STORE_RT_REG(p_hwfn,
1511 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
1514 /* Protocl Configuration */
1515 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
1516 (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
1517 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
1518 (p_hwfn->hw_info.personality == QED_PCI_FCOE) ? 1 : 0);
1519 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
1521 /* Cleanup chip from previous driver if such remains exist */
1522 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
1526 /* PF Init sequence */
1527 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1531 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1532 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1536 /* Pure runtime initializations - directly to the HW */
1537 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1539 rc = qed_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1544 /* enable interrupts */
1545 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
1547 /* send function start command */
1548 rc = qed_sp_pf_start(p_hwfn, p_ptt, p_tunn,
1549 p_hwfn->cdev->mf_mode,
1550 allow_npar_tx_switch);
1552 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
1555 if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
1556 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1, BIT(2));
1557 qed_wr(p_hwfn, p_ptt,
1558 PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
1565 static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
1566 struct qed_ptt *p_ptt,
1569 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
1571 /* Change PF in PXP */
1572 qed_wr(p_hwfn, p_ptt,
1573 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1575 /* wait until value is set - try for 1 second every 50us */
1576 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1577 val = qed_rd(p_hwfn, p_ptt,
1578 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1582 usleep_range(50, 60);
1585 if (val != set_val) {
1587 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1594 static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
1595 struct qed_ptt *p_main_ptt)
1597 /* Read shadow of current MFW mailbox */
1598 qed_mcp_read_mb(p_hwfn, p_main_ptt);
1599 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
1600 p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
1604 qed_fill_load_req_params(struct qed_load_req_params *p_load_req,
1605 struct qed_drv_load_params *p_drv_load)
1607 memset(p_load_req, 0, sizeof(*p_load_req));
1609 p_load_req->drv_role = p_drv_load->is_crash_kernel ?
1610 QED_DRV_ROLE_KDUMP : QED_DRV_ROLE_OS;
1611 p_load_req->timeout_val = p_drv_load->mfw_timeout_val;
1612 p_load_req->avoid_eng_reset = p_drv_load->avoid_eng_reset;
1613 p_load_req->override_force_load = p_drv_load->override_force_load;
1616 static int qed_vf_start(struct qed_hwfn *p_hwfn,
1617 struct qed_hw_init_params *p_params)
1619 if (p_params->p_tunn) {
1620 qed_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
1621 qed_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
1624 p_hwfn->b_int_enabled = 1;
1629 int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params)
1631 struct qed_load_req_params load_req_params;
1632 u32 load_code, param, drv_mb_param;
1633 bool b_default_mtu = true;
1634 struct qed_hwfn *p_hwfn;
1635 int rc = 0, mfw_rc, i;
1637 if ((p_params->int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
1638 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
1643 rc = qed_init_fw_data(cdev, p_params->bin_fw_data);
1648 for_each_hwfn(cdev, i) {
1649 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1651 /* If management didn't provide a default, set one of our own */
1652 if (!p_hwfn->hw_info.mtu) {
1653 p_hwfn->hw_info.mtu = 1500;
1654 b_default_mtu = false;
1658 qed_vf_start(p_hwfn, p_params);
1662 /* Enable DMAE in PXP */
1663 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
1665 rc = qed_calc_hw_mode(p_hwfn);
1669 qed_fill_load_req_params(&load_req_params,
1670 p_params->p_drv_load_params);
1671 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
1674 DP_NOTICE(p_hwfn, "Failed sending a LOAD_REQ command\n");
1678 load_code = load_req_params.load_code;
1679 DP_VERBOSE(p_hwfn, QED_MSG_SP,
1680 "Load request was sent. Load code: 0x%x\n",
1683 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
1685 p_hwfn->first_on_engine = (load_code ==
1686 FW_MSG_CODE_DRV_LOAD_ENGINE);
1688 switch (load_code) {
1689 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1690 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
1691 p_hwfn->hw_info.hw_mode);
1695 case FW_MSG_CODE_DRV_LOAD_PORT:
1696 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
1697 p_hwfn->hw_info.hw_mode);
1702 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1703 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
1705 p_hwfn->hw_info.hw_mode,
1706 p_params->b_hw_start,
1708 p_params->allow_npar_tx_switch);
1712 "Unexpected load code [0x%08x]", load_code);
1719 "init phase failed for loadcode 0x%x (rc %d)\n",
1722 /* ACK mfw regardless of success or failure of initialization */
1723 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1724 DRV_MSG_CODE_LOAD_DONE,
1725 0, &load_code, ¶m);
1729 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
1733 /* Check if there is a DID mismatch between nvm-cfg/efuse */
1734 if (param & FW_MB_PARAM_LOAD_DONE_DID_EFUSE_ERROR)
1736 "warning: device configuration is not supported on this board type. The device may not function as expected.\n");
1738 /* send DCBX attention request command */
1741 "sending phony dcbx set command to trigger DCBx attention handling\n");
1742 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1743 DRV_MSG_CODE_SET_DCBX,
1744 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
1745 &load_code, ¶m);
1748 "Failed to send DCBX attention request\n");
1752 p_hwfn->hw_init_done = true;
1756 p_hwfn = QED_LEADING_HWFN(cdev);
1757 drv_mb_param = STORM_FW_VERSION;
1758 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1759 DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
1760 drv_mb_param, &load_code, ¶m);
1762 DP_INFO(p_hwfn, "Failed to update firmware version\n");
1764 if (!b_default_mtu) {
1765 rc = qed_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
1766 p_hwfn->hw_info.mtu);
1769 "Failed to update default mtu\n");
1772 rc = qed_mcp_ov_update_driver_state(p_hwfn,
1774 QED_OV_DRIVER_STATE_DISABLED);
1776 DP_INFO(p_hwfn, "Failed to update driver state\n");
1778 rc = qed_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt,
1779 QED_OV_ESWITCH_VEB);
1781 DP_INFO(p_hwfn, "Failed to update eswitch mode\n");
1787 #define QED_HW_STOP_RETRY_LIMIT (10)
1788 static void qed_hw_timers_stop(struct qed_dev *cdev,
1789 struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1794 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
1795 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
1797 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
1798 if ((!qed_rd(p_hwfn, p_ptt,
1799 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
1800 (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
1803 /* Dependent on number of connection/tasks, possibly
1804 * 1ms sleep is required between polls
1806 usleep_range(1000, 2000);
1809 if (i < QED_HW_STOP_RETRY_LIMIT)
1813 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
1814 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
1815 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
1818 void qed_hw_timers_stop_all(struct qed_dev *cdev)
1822 for_each_hwfn(cdev, j) {
1823 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1824 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1826 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
1830 int qed_hw_stop(struct qed_dev *cdev)
1832 struct qed_hwfn *p_hwfn;
1833 struct qed_ptt *p_ptt;
1837 for_each_hwfn(cdev, j) {
1838 p_hwfn = &cdev->hwfns[j];
1839 p_ptt = p_hwfn->p_main_ptt;
1841 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
1844 qed_vf_pf_int_cleanup(p_hwfn);
1845 rc = qed_vf_pf_reset(p_hwfn);
1848 "qed_vf_pf_reset failed. rc = %d.\n",
1855 /* mark the hw as uninitialized... */
1856 p_hwfn->hw_init_done = false;
1858 /* Send unload command to MCP */
1859 rc = qed_mcp_unload_req(p_hwfn, p_ptt);
1862 "Failed sending a UNLOAD_REQ command. rc = %d.\n",
1867 qed_slowpath_irq_sync(p_hwfn);
1869 /* After this point no MFW attentions are expected, e.g. prevent
1870 * race between pf stop and dcbx pf update.
1872 rc = qed_sp_pf_stop(p_hwfn);
1875 "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
1880 qed_wr(p_hwfn, p_ptt,
1881 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1883 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1884 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1885 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1886 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1887 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1889 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
1891 /* Disable Attention Generation */
1892 qed_int_igu_disable_int(p_hwfn, p_ptt);
1894 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
1895 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
1897 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
1899 /* Need to wait 1ms to guarantee SBs are cleared */
1900 usleep_range(1000, 2000);
1902 /* Disable PF in HW blocks */
1903 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
1904 qed_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
1906 qed_mcp_unload_done(p_hwfn, p_ptt);
1909 "Failed sending a UNLOAD_DONE command. rc = %d.\n",
1916 p_hwfn = QED_LEADING_HWFN(cdev);
1917 p_ptt = QED_LEADING_HWFN(cdev)->p_main_ptt;
1919 /* Disable DMAE in PXP - in CMT, this should only be done for
1920 * first hw-function, and only after all transactions have
1921 * stopped for all active hw-functions.
1923 rc = qed_change_pci_hwfn(p_hwfn, p_ptt, false);
1926 "qed_change_pci_hwfn failed. rc = %d.\n", rc);
1934 int qed_hw_stop_fastpath(struct qed_dev *cdev)
1938 for_each_hwfn(cdev, j) {
1939 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1940 struct qed_ptt *p_ptt;
1943 qed_vf_pf_int_cleanup(p_hwfn);
1946 p_ptt = qed_ptt_acquire(p_hwfn);
1951 NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
1953 qed_wr(p_hwfn, p_ptt,
1954 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1956 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1957 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1958 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1959 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1960 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1962 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
1964 /* Need to wait 1ms to guarantee SBs are cleared */
1965 usleep_range(1000, 2000);
1966 qed_ptt_release(p_hwfn, p_ptt);
1972 int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
1974 struct qed_ptt *p_ptt;
1976 if (IS_VF(p_hwfn->cdev))
1979 p_ptt = qed_ptt_acquire(p_hwfn);
1983 /* If roce info is allocated it means roce is initialized and should
1984 * be enabled in searcher.
1986 if (p_hwfn->p_rdma_info &&
1987 p_hwfn->b_rdma_enabled_in_prs)
1988 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0x1);
1990 /* Re-open incoming traffic */
1991 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
1992 qed_ptt_release(p_hwfn, p_ptt);
1997 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
1998 static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
2000 qed_ptt_pool_free(p_hwfn);
2001 kfree(p_hwfn->hw_info.p_igu_info);
2002 p_hwfn->hw_info.p_igu_info = NULL;
2005 /* Setup bar access */
2006 static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
2008 /* clear indirect access */
2009 if (QED_IS_AH(p_hwfn->cdev)) {
2010 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2011 PGLUE_B_REG_PGL_ADDR_E8_F0_K2, 0);
2012 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2013 PGLUE_B_REG_PGL_ADDR_EC_F0_K2, 0);
2014 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2015 PGLUE_B_REG_PGL_ADDR_F0_F0_K2, 0);
2016 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2017 PGLUE_B_REG_PGL_ADDR_F4_F0_K2, 0);
2019 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2020 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
2021 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2022 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
2023 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2024 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
2025 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2026 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
2029 /* Clean Previous errors if such exist */
2030 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2031 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
2033 /* enable internal target-read */
2034 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2035 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
2038 static void get_function_id(struct qed_hwfn *p_hwfn)
2041 p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
2042 PXP_PF_ME_OPAQUE_ADDR);
2044 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
2046 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
2047 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2048 PXP_CONCRETE_FID_PFID);
2049 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2050 PXP_CONCRETE_FID_PORT);
2052 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
2053 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
2054 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
2057 static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
2059 u32 *feat_num = p_hwfn->hw_info.feat_num;
2060 struct qed_sb_cnt_info sb_cnt;
2063 memset(&sb_cnt, 0, sizeof(sb_cnt));
2064 qed_int_get_num_sbs(p_hwfn, &sb_cnt);
2066 if (IS_ENABLED(CONFIG_QED_RDMA) &&
2067 QED_IS_RDMA_PERSONALITY(p_hwfn)) {
2068 /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide
2069 * the status blocks equally between L2 / RoCE but with
2070 * consideration as to how many l2 queues / cnqs we have.
2072 feat_num[QED_RDMA_CNQ] =
2073 min_t(u32, sb_cnt.cnt / 2,
2074 RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM));
2076 non_l2_sbs = feat_num[QED_RDMA_CNQ];
2078 if (QED_IS_L2_PERSONALITY(p_hwfn)) {
2079 /* Start by allocating VF queues, then PF's */
2080 feat_num[QED_VF_L2_QUE] = min_t(u32,
2081 RESC_NUM(p_hwfn, QED_L2_QUEUE),
2083 feat_num[QED_PF_L2_QUE] = min_t(u32,
2084 sb_cnt.cnt - non_l2_sbs,
2091 if (QED_IS_FCOE_PERSONALITY(p_hwfn))
2092 feat_num[QED_FCOE_CQ] = min_t(u32, sb_cnt.cnt,
2096 if (QED_IS_ISCSI_PERSONALITY(p_hwfn))
2097 feat_num[QED_ISCSI_CQ] = min_t(u32, sb_cnt.cnt,
2102 "#PF_L2_QUEUES=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d FCOE_CQ=%d ISCSI_CQ=%d #SBS=%d\n",
2103 (int)FEAT_NUM(p_hwfn, QED_PF_L2_QUE),
2104 (int)FEAT_NUM(p_hwfn, QED_VF_L2_QUE),
2105 (int)FEAT_NUM(p_hwfn, QED_RDMA_CNQ),
2106 (int)FEAT_NUM(p_hwfn, QED_FCOE_CQ),
2107 (int)FEAT_NUM(p_hwfn, QED_ISCSI_CQ),
2111 const char *qed_hw_get_resc_name(enum qed_resources res_id)
2128 case QED_RDMA_CNQ_RAM:
2129 return "RDMA_CNQ_RAM";
2136 case QED_RDMA_STATS_QUEUE:
2137 return "RDMA_STATS_QUEUE";
2143 return "UNKNOWN_RESOURCE";
2148 __qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn,
2149 struct qed_ptt *p_ptt,
2150 enum qed_resources res_id,
2151 u32 resc_max_val, u32 *p_mcp_resp)
2155 rc = qed_mcp_set_resc_max_val(p_hwfn, p_ptt, res_id,
2156 resc_max_val, p_mcp_resp);
2159 "MFW response failure for a max value setting of resource %d [%s]\n",
2160 res_id, qed_hw_get_resc_name(res_id));
2164 if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
2166 "Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
2167 res_id, qed_hw_get_resc_name(res_id), *p_mcp_resp);
2173 qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2175 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2176 u32 resc_max_val, mcp_resp;
2180 for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
2183 resc_max_val = MAX_NUM_LL2_RX_QUEUES;
2185 case QED_RDMA_CNQ_RAM:
2186 /* No need for a case for QED_CMDQS_CQS since
2187 * CNQ/CMDQS are the same resource.
2189 resc_max_val = NUM_OF_CMDQS_CQS;
2191 case QED_RDMA_STATS_QUEUE:
2192 resc_max_val = b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2
2193 : RDMA_NUM_STATISTIC_COUNTERS_BB;
2196 resc_max_val = BDQ_NUM_RESOURCES;
2202 rc = __qed_hw_set_soft_resc_size(p_hwfn, p_ptt, res_id,
2203 resc_max_val, &mcp_resp);
2207 /* There's no point to continue to the next resource if the
2208 * command is not supported by the MFW.
2209 * We do continue if the command is supported but the resource
2210 * is unknown to the MFW. Such a resource will be later
2211 * configured with the default allocation values.
2213 if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
2221 int qed_hw_get_dflt_resc(struct qed_hwfn *p_hwfn,
2222 enum qed_resources res_id,
2223 u32 *p_resc_num, u32 *p_resc_start)
2225 u8 num_funcs = p_hwfn->num_funcs_on_engine;
2226 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2230 *p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
2231 MAX_NUM_L2_QUEUES_BB) / num_funcs;
2234 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2235 MAX_NUM_VPORTS_BB) / num_funcs;
2238 *p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
2239 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
2242 *p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
2243 MAX_QM_TX_QUEUES_BB) / num_funcs;
2244 *p_resc_num &= ~0x7; /* The granularity of the PQs is 8 */
2247 *p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
2251 /* Each VFC resource can accommodate both a MAC and a VLAN */
2252 *p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
2255 *p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
2256 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
2259 *p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
2261 case QED_RDMA_CNQ_RAM:
2263 /* CNQ/CMDQS are the same resource */
2264 *p_resc_num = NUM_OF_CMDQS_CQS / num_funcs;
2266 case QED_RDMA_STATS_QUEUE:
2267 *p_resc_num = (b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2 :
2268 RDMA_NUM_STATISTIC_COUNTERS_BB) / num_funcs;
2271 if (p_hwfn->hw_info.personality != QED_PCI_ISCSI &&
2272 p_hwfn->hw_info.personality != QED_PCI_FCOE)
2278 /* Since we want its value to reflect whether MFW supports
2279 * the new scheme, have a default of 0.
2291 else if (p_hwfn->cdev->num_ports_in_engine == 4)
2292 *p_resc_start = p_hwfn->port_id;
2293 else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
2294 *p_resc_start = p_hwfn->port_id;
2295 else if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
2296 *p_resc_start = p_hwfn->port_id + 2;
2299 *p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
2306 static int __qed_hw_set_resc_info(struct qed_hwfn *p_hwfn,
2307 enum qed_resources res_id)
2309 u32 dflt_resc_num = 0, dflt_resc_start = 0;
2310 u32 mcp_resp, *p_resc_num, *p_resc_start;
2313 p_resc_num = &RESC_NUM(p_hwfn, res_id);
2314 p_resc_start = &RESC_START(p_hwfn, res_id);
2316 rc = qed_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
2320 "Failed to get default amount for resource %d [%s]\n",
2321 res_id, qed_hw_get_resc_name(res_id));
2325 rc = qed_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
2326 &mcp_resp, p_resc_num, p_resc_start);
2329 "MFW response failure for an allocation request for resource %d [%s]\n",
2330 res_id, qed_hw_get_resc_name(res_id));
2334 /* Default driver values are applied in the following cases:
2335 * - The resource allocation MB command is not supported by the MFW
2336 * - There is an internal error in the MFW while processing the request
2337 * - The resource ID is unknown to the MFW
2339 if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
2341 "Failed to receive allocation info for resource %d [%s]. mcp_resp = 0x%x. Applying default values [%d,%d].\n",
2343 qed_hw_get_resc_name(res_id),
2344 mcp_resp, dflt_resc_num, dflt_resc_start);
2345 *p_resc_num = dflt_resc_num;
2346 *p_resc_start = dflt_resc_start;
2351 /* PQs have to divide by 8 [that's the HW granularity].
2352 * Reduce number so it would fit.
2354 if ((res_id == QED_PQ) && ((*p_resc_num % 8) || (*p_resc_start % 8))) {
2356 "PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n",
2358 (*p_resc_num) & ~0x7,
2359 *p_resc_start, (*p_resc_start) & ~0x7);
2360 *p_resc_num &= ~0x7;
2361 *p_resc_start &= ~0x7;
2367 static int qed_hw_set_resc_info(struct qed_hwfn *p_hwfn)
2372 for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
2373 rc = __qed_hw_set_resc_info(p_hwfn, res_id);
2381 static int qed_hw_get_resc(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2383 struct qed_resc_unlock_params resc_unlock_params;
2384 struct qed_resc_lock_params resc_lock_params;
2385 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2389 /* Setting the max values of the soft resources and the following
2390 * resources allocation queries should be atomic. Since several PFs can
2391 * run in parallel - a resource lock is needed.
2392 * If either the resource lock or resource set value commands are not
2393 * supported - skip the the max values setting, release the lock if
2394 * needed, and proceed to the queries. Other failures, including a
2395 * failure to acquire the lock, will cause this function to fail.
2397 qed_mcp_resc_lock_default_init(&resc_lock_params, &resc_unlock_params,
2398 QED_RESC_LOCK_RESC_ALLOC, false);
2400 rc = qed_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
2401 if (rc && rc != -EINVAL) {
2403 } else if (rc == -EINVAL) {
2405 "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
2406 } else if (!rc && !resc_lock_params.b_granted) {
2408 "Failed to acquire the resource lock for the resource allocation commands\n");
2411 rc = qed_hw_set_soft_resc_size(p_hwfn, p_ptt);
2412 if (rc && rc != -EINVAL) {
2414 "Failed to set the max values of the soft resources\n");
2415 goto unlock_and_exit;
2416 } else if (rc == -EINVAL) {
2418 "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
2419 rc = qed_mcp_resc_unlock(p_hwfn, p_ptt,
2420 &resc_unlock_params);
2423 "Failed to release the resource lock for the resource allocation commands\n");
2427 rc = qed_hw_set_resc_info(p_hwfn);
2429 goto unlock_and_exit;
2431 if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
2432 rc = qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
2435 "Failed to release the resource lock for the resource allocation commands\n");
2438 /* Sanity for ILT */
2439 if ((b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2440 (!b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
2441 DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
2442 RESC_START(p_hwfn, QED_ILT),
2443 RESC_END(p_hwfn, QED_ILT) - 1);
2447 /* This will also learn the number of SBs from MFW */
2448 if (qed_int_igu_reset_cam(p_hwfn, p_ptt))
2451 qed_hw_set_feat(p_hwfn);
2453 for (res_id = 0; res_id < QED_MAX_RESC; res_id++)
2454 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, "%s = %d start = %d\n",
2455 qed_hw_get_resc_name(res_id),
2456 RESC_NUM(p_hwfn, res_id),
2457 RESC_START(p_hwfn, res_id));
2462 if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
2463 qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
2467 static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2469 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
2470 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
2471 struct qed_mcp_link_params *link;
2473 /* Read global nvm_cfg address */
2474 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2476 /* Verify MCP has initialized it */
2477 if (!nvm_cfg_addr) {
2478 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
2482 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
2483 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2485 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2486 offsetof(struct nvm_cfg1, glob) +
2487 offsetof(struct nvm_cfg1_glob, core_cfg);
2489 core_cfg = qed_rd(p_hwfn, p_ptt, addr);
2491 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
2492 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
2493 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
2494 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
2496 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
2497 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
2499 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
2500 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
2502 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
2503 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
2505 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
2506 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
2508 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
2509 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
2511 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
2512 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
2514 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
2515 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
2517 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
2518 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X10G;
2520 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
2521 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
2523 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
2524 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X25G;
2527 DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
2531 /* Read default link configuration */
2532 link = &p_hwfn->mcp_info->link_input;
2533 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2534 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2535 link_temp = qed_rd(p_hwfn, p_ptt,
2537 offsetof(struct nvm_cfg1_port, speed_cap_mask));
2538 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
2539 link->speed.advertised_speeds = link_temp;
2541 link_temp = link->speed.advertised_speeds;
2542 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
2544 link_temp = qed_rd(p_hwfn, p_ptt,
2546 offsetof(struct nvm_cfg1_port, link_settings));
2547 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
2548 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
2549 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
2550 link->speed.autoneg = true;
2552 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
2553 link->speed.forced_speed = 1000;
2555 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
2556 link->speed.forced_speed = 10000;
2558 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
2559 link->speed.forced_speed = 25000;
2561 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
2562 link->speed.forced_speed = 40000;
2564 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
2565 link->speed.forced_speed = 50000;
2567 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
2568 link->speed.forced_speed = 100000;
2571 DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
2574 p_hwfn->mcp_info->link_capabilities.default_speed_autoneg =
2575 link->speed.autoneg;
2577 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
2578 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
2579 link->pause.autoneg = !!(link_temp &
2580 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
2581 link->pause.forced_rx = !!(link_temp &
2582 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
2583 link->pause.forced_tx = !!(link_temp &
2584 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
2585 link->loopback_mode = 0;
2587 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2588 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
2589 link->speed.forced_speed, link->speed.advertised_speeds,
2590 link->speed.autoneg, link->pause.autoneg);
2592 /* Read Multi-function information from shmem */
2593 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2594 offsetof(struct nvm_cfg1, glob) +
2595 offsetof(struct nvm_cfg1_glob, generic_cont0);
2597 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
2599 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
2600 NVM_CFG1_GLOB_MF_MODE_OFFSET;
2603 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
2604 p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
2606 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
2607 p_hwfn->cdev->mf_mode = QED_MF_NPAR;
2609 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
2610 p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
2613 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
2614 p_hwfn->cdev->mf_mode);
2616 /* Read Multi-function information from shmem */
2617 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2618 offsetof(struct nvm_cfg1, glob) +
2619 offsetof(struct nvm_cfg1_glob, device_capabilities);
2621 device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
2622 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
2623 __set_bit(QED_DEV_CAP_ETH,
2624 &p_hwfn->hw_info.device_capabilities);
2625 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
2626 __set_bit(QED_DEV_CAP_FCOE,
2627 &p_hwfn->hw_info.device_capabilities);
2628 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
2629 __set_bit(QED_DEV_CAP_ISCSI,
2630 &p_hwfn->hw_info.device_capabilities);
2631 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
2632 __set_bit(QED_DEV_CAP_ROCE,
2633 &p_hwfn->hw_info.device_capabilities);
2635 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
2638 static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2640 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
2641 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
2642 struct qed_dev *cdev = p_hwfn->cdev;
2644 num_funcs = QED_IS_AH(cdev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
2646 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
2647 * in the other bits are selected.
2648 * Bits 1-15 are for functions 1-15, respectively, and their value is
2649 * '0' only for enabled functions (function 0 always exists and
2651 * In case of CMT, only the "even" functions are enabled, and thus the
2652 * number of functions for both hwfns is learnt from the same bits.
2654 reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
2656 if (reg_function_hide & 0x1) {
2657 if (QED_IS_BB(cdev)) {
2658 if (QED_PATH_ID(p_hwfn) && cdev->num_hwfns == 1) {
2670 /* Get the number of the enabled functions on the engine */
2671 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
2678 /* Get the PF index within the enabled functions */
2679 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
2680 tmp = reg_function_hide & eng_mask & low_pfs_mask;
2688 p_hwfn->num_funcs_on_engine = num_funcs;
2689 p_hwfn->enabled_func_idx = enabled_func_idx;
2693 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
2696 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
2699 static void qed_hw_info_port_num_bb(struct qed_hwfn *p_hwfn,
2700 struct qed_ptt *p_ptt)
2704 port_mode = qed_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB_B0);
2706 if (port_mode < 3) {
2707 p_hwfn->cdev->num_ports_in_engine = 1;
2708 } else if (port_mode <= 5) {
2709 p_hwfn->cdev->num_ports_in_engine = 2;
2711 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
2712 p_hwfn->cdev->num_ports_in_engine);
2714 /* Default num_ports_in_engine to something */
2715 p_hwfn->cdev->num_ports_in_engine = 1;
2719 static void qed_hw_info_port_num_ah(struct qed_hwfn *p_hwfn,
2720 struct qed_ptt *p_ptt)
2725 p_hwfn->cdev->num_ports_in_engine = 0;
2727 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
2728 port = qed_rd(p_hwfn, p_ptt,
2729 CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4));
2731 p_hwfn->cdev->num_ports_in_engine++;
2734 if (!p_hwfn->cdev->num_ports_in_engine) {
2735 DP_NOTICE(p_hwfn, "All NIG ports are inactive\n");
2737 /* Default num_ports_in_engine to something */
2738 p_hwfn->cdev->num_ports_in_engine = 1;
2742 static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2744 if (QED_IS_BB(p_hwfn->cdev))
2745 qed_hw_info_port_num_bb(p_hwfn, p_ptt);
2747 qed_hw_info_port_num_ah(p_hwfn, p_ptt);
2751 qed_get_hw_info(struct qed_hwfn *p_hwfn,
2752 struct qed_ptt *p_ptt,
2753 enum qed_pci_personality personality)
2757 /* Since all information is common, only first hwfns should do this */
2758 if (IS_LEAD_HWFN(p_hwfn)) {
2759 rc = qed_iov_hw_info(p_hwfn);
2764 qed_hw_info_port_num(p_hwfn, p_ptt);
2766 qed_hw_get_nvm_info(p_hwfn, p_ptt);
2768 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
2772 if (qed_mcp_is_init(p_hwfn))
2773 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
2774 p_hwfn->mcp_info->func_info.mac);
2776 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
2778 if (qed_mcp_is_init(p_hwfn)) {
2779 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
2780 p_hwfn->hw_info.ovlan =
2781 p_hwfn->mcp_info->func_info.ovlan;
2783 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
2786 if (qed_mcp_is_init(p_hwfn)) {
2787 enum qed_pci_personality protocol;
2789 protocol = p_hwfn->mcp_info->func_info.protocol;
2790 p_hwfn->hw_info.personality = protocol;
2793 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
2794 p_hwfn->hw_info.num_active_tc = 1;
2796 qed_get_num_funcs(p_hwfn, p_ptt);
2798 if (qed_mcp_is_init(p_hwfn))
2799 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
2801 return qed_hw_get_resc(p_hwfn, p_ptt);
2804 static int qed_get_dev_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2806 struct qed_dev *cdev = p_hwfn->cdev;
2810 /* Read Vendor Id / Device Id */
2811 pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
2812 pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
2814 /* Determine type */
2815 device_id_mask = cdev->device_id & QED_DEV_ID_MASK;
2816 switch (device_id_mask) {
2817 case QED_DEV_ID_MASK_BB:
2818 cdev->type = QED_DEV_TYPE_BB;
2820 case QED_DEV_ID_MASK_AH:
2821 cdev->type = QED_DEV_TYPE_AH;
2824 DP_NOTICE(p_hwfn, "Unknown device id 0x%x\n", cdev->device_id);
2828 cdev->chip_num = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_NUM);
2829 cdev->chip_rev = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
2831 MASK_FIELD(CHIP_REV, cdev->chip_rev);
2833 /* Learn number of HW-functions */
2834 tmp = qed_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
2836 if (tmp & (1 << p_hwfn->rel_pf_id)) {
2837 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
2838 cdev->num_hwfns = 2;
2840 cdev->num_hwfns = 1;
2843 cdev->chip_bond_id = qed_rd(p_hwfn, p_ptt,
2844 MISCS_REG_CHIP_TEST_REG) >> 4;
2845 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
2846 cdev->chip_metal = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
2847 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
2849 DP_INFO(cdev->hwfns,
2850 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
2851 QED_IS_BB(cdev) ? "BB" : "AH",
2852 'A' + cdev->chip_rev,
2853 (int)cdev->chip_metal,
2854 cdev->chip_num, cdev->chip_rev,
2855 cdev->chip_bond_id, cdev->chip_metal);
2860 static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
2861 void __iomem *p_regview,
2862 void __iomem *p_doorbells,
2863 enum qed_pci_personality personality)
2867 /* Split PCI bars evenly between hwfns */
2868 p_hwfn->regview = p_regview;
2869 p_hwfn->doorbells = p_doorbells;
2871 if (IS_VF(p_hwfn->cdev))
2872 return qed_vf_hw_prepare(p_hwfn);
2874 /* Validate that chip access is feasible */
2875 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
2877 "Reading the ME register returns all Fs; Preventing further chip access\n");
2881 get_function_id(p_hwfn);
2883 /* Allocate PTT pool */
2884 rc = qed_ptt_pool_alloc(p_hwfn);
2888 /* Allocate the main PTT */
2889 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
2891 /* First hwfn learns basic information, e.g., number of hwfns */
2892 if (!p_hwfn->my_id) {
2893 rc = qed_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
2898 qed_hw_hwfn_prepare(p_hwfn);
2900 /* Initialize MCP structure */
2901 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
2903 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
2907 /* Read the device configuration information from the HW and SHMEM */
2908 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
2910 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
2914 /* Sending a mailbox to the MFW should be done after qed_get_hw_info()
2915 * is called as it sets the ports number in an engine.
2917 if (IS_LEAD_HWFN(p_hwfn)) {
2918 rc = qed_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
2920 DP_NOTICE(p_hwfn, "Failed to initiate PF FLR\n");
2923 /* Allocate the init RT array and initialize the init-ops engine */
2924 rc = qed_init_alloc(p_hwfn);
2930 if (IS_LEAD_HWFN(p_hwfn))
2931 qed_iov_free_hw_info(p_hwfn->cdev);
2932 qed_mcp_free(p_hwfn);
2934 qed_hw_hwfn_free(p_hwfn);
2939 int qed_hw_prepare(struct qed_dev *cdev,
2942 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2945 /* Store the precompiled init data ptrs */
2947 qed_init_iro_array(cdev);
2949 /* Initialize the first hwfn - will learn number of hwfns */
2950 rc = qed_hw_prepare_single(p_hwfn,
2952 cdev->doorbells, personality);
2956 personality = p_hwfn->hw_info.personality;
2958 /* Initialize the rest of the hwfns */
2959 if (cdev->num_hwfns > 1) {
2960 void __iomem *p_regview, *p_doorbell;
2963 /* adjust bar offset for second engine */
2964 addr = cdev->regview +
2965 qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
2969 addr = cdev->doorbells +
2970 qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
2974 /* prepare second hw function */
2975 rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
2976 p_doorbell, personality);
2978 /* in case of error, need to free the previously
2979 * initiliazed hwfn 0.
2983 qed_init_free(p_hwfn);
2984 qed_mcp_free(p_hwfn);
2985 qed_hw_hwfn_free(p_hwfn);
2993 void qed_hw_remove(struct qed_dev *cdev)
2995 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
2999 qed_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
3000 QED_OV_DRIVER_STATE_NOT_LOADED);
3002 for_each_hwfn(cdev, i) {
3003 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3006 qed_vf_pf_release(p_hwfn);
3010 qed_init_free(p_hwfn);
3011 qed_hw_hwfn_free(p_hwfn);
3012 qed_mcp_free(p_hwfn);
3015 qed_iov_free_hw_info(cdev);
3018 static void qed_chain_free_next_ptr(struct qed_dev *cdev,
3019 struct qed_chain *p_chain)
3021 void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
3022 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3023 struct qed_chain_next *p_next;
3029 size = p_chain->elem_size * p_chain->usable_per_page;
3031 for (i = 0; i < p_chain->page_cnt; i++) {
3035 p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
3036 p_virt_next = p_next->next_virt;
3037 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3039 dma_free_coherent(&cdev->pdev->dev,
3040 QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
3042 p_virt = p_virt_next;
3043 p_phys = p_phys_next;
3047 static void qed_chain_free_single(struct qed_dev *cdev,
3048 struct qed_chain *p_chain)
3050 if (!p_chain->p_virt_addr)
3053 dma_free_coherent(&cdev->pdev->dev,
3054 QED_CHAIN_PAGE_SIZE,
3055 p_chain->p_virt_addr, p_chain->p_phys_addr);
3058 static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
3060 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3061 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
3062 u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table;
3064 if (!pp_virt_addr_tbl)
3070 for (i = 0; i < page_cnt; i++) {
3071 if (!pp_virt_addr_tbl[i])
3074 dma_free_coherent(&cdev->pdev->dev,
3075 QED_CHAIN_PAGE_SIZE,
3076 pp_virt_addr_tbl[i],
3077 *(dma_addr_t *)p_pbl_virt);
3079 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
3082 pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
3084 if (!p_chain->b_external_pbl)
3085 dma_free_coherent(&cdev->pdev->dev,
3087 p_chain->pbl_sp.p_virt_table,
3088 p_chain->pbl_sp.p_phys_table);
3090 vfree(p_chain->pbl.pp_virt_addr_tbl);
3091 p_chain->pbl.pp_virt_addr_tbl = NULL;
3094 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
3096 switch (p_chain->mode) {
3097 case QED_CHAIN_MODE_NEXT_PTR:
3098 qed_chain_free_next_ptr(cdev, p_chain);
3100 case QED_CHAIN_MODE_SINGLE:
3101 qed_chain_free_single(cdev, p_chain);
3103 case QED_CHAIN_MODE_PBL:
3104 qed_chain_free_pbl(cdev, p_chain);
3110 qed_chain_alloc_sanity_check(struct qed_dev *cdev,
3111 enum qed_chain_cnt_type cnt_type,
3112 size_t elem_size, u32 page_cnt)
3114 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3116 /* The actual chain size can be larger than the maximal possible value
3117 * after rounding up the requested elements number to pages, and after
3118 * taking into acount the unusuable elements (next-ptr elements).
3119 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3120 * size/capacity fields are of a u32 type.
3122 if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
3123 chain_size > ((u32)U16_MAX + 1)) ||
3124 (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) {
3126 "The actual chain size (0x%llx) is larger than the maximal possible value\n",
3135 qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
3137 void *p_virt = NULL, *p_virt_prev = NULL;
3138 dma_addr_t p_phys = 0;
3141 for (i = 0; i < p_chain->page_cnt; i++) {
3142 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3143 QED_CHAIN_PAGE_SIZE,
3144 &p_phys, GFP_KERNEL);
3149 qed_chain_init_mem(p_chain, p_virt, p_phys);
3150 qed_chain_reset(p_chain);
3152 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3156 p_virt_prev = p_virt;
3158 /* Last page's next element should point to the beginning of the
3161 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3162 p_chain->p_virt_addr,
3163 p_chain->p_phys_addr);
3169 qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
3171 dma_addr_t p_phys = 0;
3172 void *p_virt = NULL;
3174 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3175 QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
3179 qed_chain_init_mem(p_chain, p_virt, p_phys);
3180 qed_chain_reset(p_chain);
3186 qed_chain_alloc_pbl(struct qed_dev *cdev,
3187 struct qed_chain *p_chain,
3188 struct qed_chain_ext_pbl *ext_pbl)
3190 u32 page_cnt = p_chain->page_cnt, size, i;
3191 dma_addr_t p_phys = 0, p_pbl_phys = 0;
3192 void **pp_virt_addr_tbl = NULL;
3193 u8 *p_pbl_virt = NULL;
3194 void *p_virt = NULL;
3196 size = page_cnt * sizeof(*pp_virt_addr_tbl);
3197 pp_virt_addr_tbl = vzalloc(size);
3198 if (!pp_virt_addr_tbl)
3201 /* The allocation of the PBL table is done with its full size, since it
3202 * is expected to be successive.
3203 * qed_chain_init_pbl_mem() is called even in a case of an allocation
3204 * failure, since pp_virt_addr_tbl was previously allocated, and it
3205 * should be saved to allow its freeing during the error flow.
3207 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
3210 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
3211 size, &p_pbl_phys, GFP_KERNEL);
3213 p_pbl_virt = ext_pbl->p_pbl_virt;
3214 p_pbl_phys = ext_pbl->p_pbl_phys;
3215 p_chain->b_external_pbl = true;
3218 qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
3223 for (i = 0; i < page_cnt; i++) {
3224 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3225 QED_CHAIN_PAGE_SIZE,
3226 &p_phys, GFP_KERNEL);
3231 qed_chain_init_mem(p_chain, p_virt, p_phys);
3232 qed_chain_reset(p_chain);
3235 /* Fill the PBL table with the physical address of the page */
3236 *(dma_addr_t *)p_pbl_virt = p_phys;
3237 /* Keep the virtual address of the page */
3238 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
3240 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
3246 int qed_chain_alloc(struct qed_dev *cdev,
3247 enum qed_chain_use_mode intended_use,
3248 enum qed_chain_mode mode,
3249 enum qed_chain_cnt_type cnt_type,
3252 struct qed_chain *p_chain,
3253 struct qed_chain_ext_pbl *ext_pbl)
3258 if (mode == QED_CHAIN_MODE_SINGLE)
3261 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
3263 rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
3266 "Cannot allocate a chain with the given arguments:\n");
3268 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
3269 intended_use, mode, cnt_type, num_elems, elem_size);
3273 qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
3277 case QED_CHAIN_MODE_NEXT_PTR:
3278 rc = qed_chain_alloc_next_ptr(cdev, p_chain);
3280 case QED_CHAIN_MODE_SINGLE:
3281 rc = qed_chain_alloc_single(cdev, p_chain);
3283 case QED_CHAIN_MODE_PBL:
3284 rc = qed_chain_alloc_pbl(cdev, p_chain, ext_pbl);
3293 qed_chain_free(cdev, p_chain);
3297 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
3299 if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
3302 min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
3303 max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
3305 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
3311 *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
3316 int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
3318 if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
3321 min = (u8)RESC_START(p_hwfn, QED_VPORT);
3322 max = min + RESC_NUM(p_hwfn, QED_VPORT);
3324 "vport id [%d] is not valid, available indices [%d - %d]\n",
3330 *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
3335 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
3337 if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
3340 min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
3341 max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
3343 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
3349 *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
3354 static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low,
3357 *p_high = p_filter[1] | (p_filter[0] << 8);
3358 *p_low = p_filter[5] | (p_filter[4] << 8) |
3359 (p_filter[3] << 16) | (p_filter[2] << 24);
3362 int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
3363 struct qed_ptt *p_ptt, u8 *p_filter)
3365 u32 high = 0, low = 0, en;
3368 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3371 qed_llh_mac_to_filter(&high, &low, p_filter);
3373 /* Find a free entry and utilize it */
3374 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3375 en = qed_rd(p_hwfn, p_ptt,
3376 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3379 qed_wr(p_hwfn, p_ptt,
3380 NIG_REG_LLH_FUNC_FILTER_VALUE +
3381 2 * i * sizeof(u32), low);
3382 qed_wr(p_hwfn, p_ptt,
3383 NIG_REG_LLH_FUNC_FILTER_VALUE +
3384 (2 * i + 1) * sizeof(u32), high);
3385 qed_wr(p_hwfn, p_ptt,
3386 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3387 qed_wr(p_hwfn, p_ptt,
3388 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3389 i * sizeof(u32), 0);
3390 qed_wr(p_hwfn, p_ptt,
3391 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3394 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3396 "Failed to find an empty LLH filter to utilize\n");
3400 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3401 "mac: %pM is added at %d\n",
3407 void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
3408 struct qed_ptt *p_ptt, u8 *p_filter)
3410 u32 high = 0, low = 0;
3413 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3416 qed_llh_mac_to_filter(&high, &low, p_filter);
3418 /* Find the entry and clean it */
3419 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3420 if (qed_rd(p_hwfn, p_ptt,
3421 NIG_REG_LLH_FUNC_FILTER_VALUE +
3422 2 * i * sizeof(u32)) != low)
3424 if (qed_rd(p_hwfn, p_ptt,
3425 NIG_REG_LLH_FUNC_FILTER_VALUE +
3426 (2 * i + 1) * sizeof(u32)) != high)
3429 qed_wr(p_hwfn, p_ptt,
3430 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3431 qed_wr(p_hwfn, p_ptt,
3432 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
3433 qed_wr(p_hwfn, p_ptt,
3434 NIG_REG_LLH_FUNC_FILTER_VALUE +
3435 (2 * i + 1) * sizeof(u32), 0);
3437 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3438 "mac: %pM is removed from %d\n",
3442 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3443 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
3447 qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
3448 struct qed_ptt *p_ptt,
3449 u16 source_port_or_eth_type,
3450 u16 dest_port, enum qed_llh_port_filter_type_t type)
3452 u32 high = 0, low = 0, en;
3455 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3459 case QED_LLH_FILTER_ETHERTYPE:
3460 high = source_port_or_eth_type;
3462 case QED_LLH_FILTER_TCP_SRC_PORT:
3463 case QED_LLH_FILTER_UDP_SRC_PORT:
3464 low = source_port_or_eth_type << 16;
3466 case QED_LLH_FILTER_TCP_DEST_PORT:
3467 case QED_LLH_FILTER_UDP_DEST_PORT:
3470 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3471 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3472 low = (source_port_or_eth_type << 16) | dest_port;
3476 "Non valid LLH protocol filter type %d\n", type);
3479 /* Find a free entry and utilize it */
3480 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3481 en = qed_rd(p_hwfn, p_ptt,
3482 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3485 qed_wr(p_hwfn, p_ptt,
3486 NIG_REG_LLH_FUNC_FILTER_VALUE +
3487 2 * i * sizeof(u32), low);
3488 qed_wr(p_hwfn, p_ptt,
3489 NIG_REG_LLH_FUNC_FILTER_VALUE +
3490 (2 * i + 1) * sizeof(u32), high);
3491 qed_wr(p_hwfn, p_ptt,
3492 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1);
3493 qed_wr(p_hwfn, p_ptt,
3494 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3495 i * sizeof(u32), 1 << type);
3496 qed_wr(p_hwfn, p_ptt,
3497 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3500 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3502 "Failed to find an empty LLH filter to utilize\n");
3506 case QED_LLH_FILTER_ETHERTYPE:
3507 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3508 "ETH type %x is added at %d\n",
3509 source_port_or_eth_type, i);
3511 case QED_LLH_FILTER_TCP_SRC_PORT:
3512 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3513 "TCP src port %x is added at %d\n",
3514 source_port_or_eth_type, i);
3516 case QED_LLH_FILTER_UDP_SRC_PORT:
3517 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3518 "UDP src port %x is added at %d\n",
3519 source_port_or_eth_type, i);
3521 case QED_LLH_FILTER_TCP_DEST_PORT:
3522 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3523 "TCP dst port %x is added at %d\n", dest_port, i);
3525 case QED_LLH_FILTER_UDP_DEST_PORT:
3526 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3527 "UDP dst port %x is added at %d\n", dest_port, i);
3529 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3530 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3531 "TCP src/dst ports %x/%x are added at %d\n",
3532 source_port_or_eth_type, dest_port, i);
3534 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3535 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3536 "UDP src/dst ports %x/%x are added at %d\n",
3537 source_port_or_eth_type, dest_port, i);
3544 qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
3545 struct qed_ptt *p_ptt,
3546 u16 source_port_or_eth_type,
3548 enum qed_llh_port_filter_type_t type)
3550 u32 high = 0, low = 0;
3553 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
3557 case QED_LLH_FILTER_ETHERTYPE:
3558 high = source_port_or_eth_type;
3560 case QED_LLH_FILTER_TCP_SRC_PORT:
3561 case QED_LLH_FILTER_UDP_SRC_PORT:
3562 low = source_port_or_eth_type << 16;
3564 case QED_LLH_FILTER_TCP_DEST_PORT:
3565 case QED_LLH_FILTER_UDP_DEST_PORT:
3568 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3569 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3570 low = (source_port_or_eth_type << 16) | dest_port;
3574 "Non valid LLH protocol filter type %d\n", type);
3578 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3579 if (!qed_rd(p_hwfn, p_ptt,
3580 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)))
3582 if (!qed_rd(p_hwfn, p_ptt,
3583 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32)))
3585 if (!(qed_rd(p_hwfn, p_ptt,
3586 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3587 i * sizeof(u32)) & BIT(type)))
3589 if (qed_rd(p_hwfn, p_ptt,
3590 NIG_REG_LLH_FUNC_FILTER_VALUE +
3591 2 * i * sizeof(u32)) != low)
3593 if (qed_rd(p_hwfn, p_ptt,
3594 NIG_REG_LLH_FUNC_FILTER_VALUE +
3595 (2 * i + 1) * sizeof(u32)) != high)
3598 qed_wr(p_hwfn, p_ptt,
3599 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3600 qed_wr(p_hwfn, p_ptt,
3601 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3602 qed_wr(p_hwfn, p_ptt,
3603 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3604 i * sizeof(u32), 0);
3605 qed_wr(p_hwfn, p_ptt,
3606 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
3607 qed_wr(p_hwfn, p_ptt,
3608 NIG_REG_LLH_FUNC_FILTER_VALUE +
3609 (2 * i + 1) * sizeof(u32), 0);
3613 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3614 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
3617 static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
3618 u32 hw_addr, void *p_eth_qzone,
3619 size_t eth_qzone_size, u8 timeset)
3621 struct coalescing_timeset *p_coal_timeset;
3623 if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
3624 DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
3628 p_coal_timeset = p_eth_qzone;
3629 memset(p_coal_timeset, 0, eth_qzone_size);
3630 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
3631 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
3632 qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
3637 int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
3638 u16 coalesce, u16 qid, u16 sb_id)
3640 struct ustorm_eth_queue_zone eth_qzone;
3641 u8 timeset, timer_res;
3646 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
3647 if (coalesce <= 0x7F) {
3649 } else if (coalesce <= 0xFF) {
3651 } else if (coalesce <= 0x1FF) {
3654 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
3657 timeset = (u8)(coalesce >> timer_res);
3659 rc = qed_fw_l2_queue(p_hwfn, qid, &fw_qid);
3663 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false);
3667 address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
3669 rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
3670 sizeof(struct ustorm_eth_queue_zone), timeset);
3674 p_hwfn->cdev->rx_coalesce_usecs = coalesce;
3679 int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
3680 u16 coalesce, u16 qid, u16 sb_id)
3682 struct xstorm_eth_queue_zone eth_qzone;
3683 u8 timeset, timer_res;
3688 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
3689 if (coalesce <= 0x7F) {
3691 } else if (coalesce <= 0xFF) {
3693 } else if (coalesce <= 0x1FF) {
3696 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
3699 timeset = (u8)(coalesce >> timer_res);
3701 rc = qed_fw_l2_queue(p_hwfn, qid, &fw_qid);
3705 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true);
3709 address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
3711 rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
3712 sizeof(struct xstorm_eth_queue_zone), timeset);
3716 p_hwfn->cdev->tx_coalesce_usecs = coalesce;
3721 /* Calculate final WFQ values for all vports and configure them.
3722 * After this configuration each vport will have
3723 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
3725 static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
3726 struct qed_ptt *p_ptt,
3729 struct init_qm_vport_params *vport_params;
3732 vport_params = p_hwfn->qm_info.qm_vport_params;
3734 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
3735 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
3737 vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
3739 qed_init_vport_wfq(p_hwfn, p_ptt,
3740 vport_params[i].first_tx_pq_id,
3741 vport_params[i].vport_wfq);
3745 static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
3751 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
3752 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
3755 static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
3756 struct qed_ptt *p_ptt,
3759 struct init_qm_vport_params *vport_params;
3762 vport_params = p_hwfn->qm_info.qm_vport_params;
3764 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
3765 qed_init_wfq_default_param(p_hwfn, min_pf_rate);
3766 qed_init_vport_wfq(p_hwfn, p_ptt,
3767 vport_params[i].first_tx_pq_id,
3768 vport_params[i].vport_wfq);
3772 /* This function performs several validations for WFQ
3773 * configuration and required min rate for a given vport
3774 * 1. req_rate must be greater than one percent of min_pf_rate.
3775 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
3776 * rates to get less than one percent of min_pf_rate.
3777 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
3779 static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
3780 u16 vport_id, u32 req_rate, u32 min_pf_rate)
3782 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
3783 int non_requested_count = 0, req_count = 0, i, num_vports;
3785 num_vports = p_hwfn->qm_info.num_vports;
3787 /* Accounting for the vports which are configured for WFQ explicitly */
3788 for (i = 0; i < num_vports; i++) {
3791 if ((i != vport_id) &&
3792 p_hwfn->qm_info.wfq_data[i].configured) {
3794 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
3795 total_req_min_rate += tmp_speed;
3799 /* Include current vport data as well */
3801 total_req_min_rate += req_rate;
3802 non_requested_count = num_vports - req_count;
3804 if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
3805 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3806 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
3807 vport_id, req_rate, min_pf_rate);
3811 if (num_vports > QED_WFQ_UNIT) {
3812 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3813 "Number of vports is greater than %d\n",
3818 if (total_req_min_rate > min_pf_rate) {
3819 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3820 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
3821 total_req_min_rate, min_pf_rate);
3825 total_left_rate = min_pf_rate - total_req_min_rate;
3827 left_rate_per_vp = total_left_rate / non_requested_count;
3828 if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
3829 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3830 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
3831 left_rate_per_vp, min_pf_rate);
3835 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
3836 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
3838 for (i = 0; i < num_vports; i++) {
3839 if (p_hwfn->qm_info.wfq_data[i].configured)
3842 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
3848 static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
3849 struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
3851 struct qed_mcp_link_state *p_link;
3854 p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
3856 if (!p_link->min_pf_rate) {
3857 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
3858 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
3862 rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
3865 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
3866 p_link->min_pf_rate);
3869 "Validation failed while configuring min rate\n");
3874 static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
3875 struct qed_ptt *p_ptt,
3878 bool use_wfq = false;
3882 /* Validate all pre configured vports for wfq */
3883 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
3886 if (!p_hwfn->qm_info.wfq_data[i].configured)
3889 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
3892 rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
3895 "WFQ validation failed while configuring min rate\n");
3901 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
3903 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
3908 /* Main API for qed clients to configure vport min rate.
3909 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
3910 * rate - Speed in Mbps needs to be assigned to a given vport.
3912 int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
3914 int i, rc = -EINVAL;
3916 /* Currently not supported; Might change in future */
3917 if (cdev->num_hwfns > 1) {
3919 "WFQ configuration is not supported for this device\n");
3923 for_each_hwfn(cdev, i) {
3924 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3925 struct qed_ptt *p_ptt;
3927 p_ptt = qed_ptt_acquire(p_hwfn);
3931 rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
3934 qed_ptt_release(p_hwfn, p_ptt);
3938 qed_ptt_release(p_hwfn, p_ptt);
3944 /* API to configure WFQ from mcp link change */
3945 void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
3946 struct qed_ptt *p_ptt, u32 min_pf_rate)
3950 if (cdev->num_hwfns > 1) {
3953 "WFQ configuration is not supported for this device\n");
3957 for_each_hwfn(cdev, i) {
3958 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3960 __qed_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
3965 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
3966 struct qed_ptt *p_ptt,
3967 struct qed_mcp_link_state *p_link,
3972 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
3974 if (!p_link->line_speed && (max_bw != 100))
3977 p_link->speed = (p_link->line_speed * max_bw) / 100;
3978 p_hwfn->qm_info.pf_rl = p_link->speed;
3980 /* Since the limiter also affects Tx-switched traffic, we don't want it
3981 * to limit such traffic in case there's no actual limit.
3982 * In that case, set limit to imaginary high boundary.
3985 p_hwfn->qm_info.pf_rl = 100000;
3987 rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
3988 p_hwfn->qm_info.pf_rl);
3990 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
3991 "Configured MAX bandwidth to be %08x Mb/sec\n",
3997 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
3998 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
4000 int i, rc = -EINVAL;
4002 if (max_bw < 1 || max_bw > 100) {
4003 DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
4007 for_each_hwfn(cdev, i) {
4008 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4009 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
4010 struct qed_mcp_link_state *p_link;
4011 struct qed_ptt *p_ptt;
4013 p_link = &p_lead->mcp_info->link_output;
4015 p_ptt = qed_ptt_acquire(p_hwfn);
4019 rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
4022 qed_ptt_release(p_hwfn, p_ptt);
4031 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
4032 struct qed_ptt *p_ptt,
4033 struct qed_mcp_link_state *p_link,
4038 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
4039 p_hwfn->qm_info.pf_wfq = min_bw;
4041 if (!p_link->line_speed)
4044 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
4046 rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
4048 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4049 "Configured MIN bandwidth to be %d Mb/sec\n",
4050 p_link->min_pf_rate);
4055 /* Main API to configure PF min bandwidth where bw range is [1-100] */
4056 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
4058 int i, rc = -EINVAL;
4060 if (min_bw < 1 || min_bw > 100) {
4061 DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
4065 for_each_hwfn(cdev, i) {
4066 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4067 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
4068 struct qed_mcp_link_state *p_link;
4069 struct qed_ptt *p_ptt;
4071 p_link = &p_lead->mcp_info->link_output;
4073 p_ptt = qed_ptt_acquire(p_hwfn);
4077 rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
4080 qed_ptt_release(p_hwfn, p_ptt);
4084 if (p_link->min_pf_rate) {
4085 u32 min_rate = p_link->min_pf_rate;
4087 rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
4092 qed_ptt_release(p_hwfn, p_ptt);
4098 void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
4100 struct qed_mcp_link_state *p_link;
4102 p_link = &p_hwfn->mcp_info->link_output;
4104 if (p_link->min_pf_rate)
4105 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
4106 p_link->min_pf_rate);
4108 memset(p_hwfn->qm_info.wfq_data, 0,
4109 sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
4112 int qed_device_num_engines(struct qed_dev *cdev)
4114 return QED_IS_BB(cdev) ? 2 : 1;
4117 static int qed_device_num_ports(struct qed_dev *cdev)
4119 /* in CMT always only one port */
4120 if (cdev->num_hwfns > 1)
4123 return cdev->num_ports_in_engine * qed_device_num_engines(cdev);
4126 int qed_device_get_port_id(struct qed_dev *cdev)
4128 return (QED_LEADING_HWFN(cdev)->abs_pf_id) % qed_device_num_ports(cdev);
4131 void qed_set_fw_mac_addr(__le16 *fw_msb,
4132 __le16 *fw_mid, __le16 *fw_lsb, u8 *mac)
4134 ((u8 *)fw_msb)[0] = mac[1];
4135 ((u8 *)fw_msb)[1] = mac[0];
4136 ((u8 *)fw_mid)[0] = mac[3];
4137 ((u8 *)fw_mid)[1] = mac[2];
4138 ((u8 *)fw_lsb)[0] = mac[5];
4139 ((u8 *)fw_lsb)[1] = mac[4];