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 static void qed_dbg_user_data_free(struct qed_hwfn *p_hwfn)
149 kfree(p_hwfn->dbg_user_info);
150 p_hwfn->dbg_user_info = NULL;
153 void qed_resc_free(struct qed_dev *cdev)
158 for_each_hwfn(cdev, i)
159 qed_l2_free(&cdev->hwfns[i]);
163 kfree(cdev->fw_data);
164 cdev->fw_data = NULL;
166 kfree(cdev->reset_stats);
167 cdev->reset_stats = NULL;
169 for_each_hwfn(cdev, i) {
170 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
172 qed_cxt_mngr_free(p_hwfn);
173 qed_qm_info_free(p_hwfn);
174 qed_spq_free(p_hwfn);
176 qed_consq_free(p_hwfn);
177 qed_int_free(p_hwfn);
178 #ifdef CONFIG_QED_LL2
179 qed_ll2_free(p_hwfn);
181 if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
182 qed_fcoe_free(p_hwfn);
184 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
185 qed_iscsi_free(p_hwfn);
186 qed_ooo_free(p_hwfn);
189 if (QED_IS_RDMA_PERSONALITY(p_hwfn))
190 qed_rdma_info_free(p_hwfn);
192 qed_iov_free(p_hwfn);
194 qed_dmae_info_free(p_hwfn);
195 qed_dcbx_info_free(p_hwfn);
196 qed_dbg_user_data_free(p_hwfn);
200 /******************** QM initialization *******************/
201 #define ACTIVE_TCS_BMAP 0x9f
202 #define ACTIVE_TCS_BMAP_4PORT_K2 0xf
204 /* determines the physical queue flags for a given PF. */
205 static u32 qed_get_pq_flags(struct qed_hwfn *p_hwfn)
213 if (IS_QED_SRIOV(p_hwfn->cdev))
214 flags |= PQ_FLAGS_VFS;
217 switch (p_hwfn->hw_info.personality) {
219 flags |= PQ_FLAGS_MCOS;
222 flags |= PQ_FLAGS_OFLD;
225 flags |= PQ_FLAGS_ACK | PQ_FLAGS_OOO | PQ_FLAGS_OFLD;
227 case QED_PCI_ETH_ROCE:
228 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_OFLD | PQ_FLAGS_LLT;
229 if (IS_QED_MULTI_TC_ROCE(p_hwfn))
230 flags |= PQ_FLAGS_MTC;
232 case QED_PCI_ETH_IWARP:
233 flags |= PQ_FLAGS_MCOS | PQ_FLAGS_ACK | PQ_FLAGS_OOO |
238 "unknown personality %d\n", p_hwfn->hw_info.personality);
245 /* Getters for resource amounts necessary for qm initialization */
246 static u8 qed_init_qm_get_num_tcs(struct qed_hwfn *p_hwfn)
248 return p_hwfn->hw_info.num_hw_tc;
251 static u16 qed_init_qm_get_num_vfs(struct qed_hwfn *p_hwfn)
253 return IS_QED_SRIOV(p_hwfn->cdev) ?
254 p_hwfn->cdev->p_iov_info->total_vfs : 0;
257 static u8 qed_init_qm_get_num_mtc_tcs(struct qed_hwfn *p_hwfn)
259 u32 pq_flags = qed_get_pq_flags(p_hwfn);
261 if (!(PQ_FLAGS_MTC & pq_flags))
264 return qed_init_qm_get_num_tcs(p_hwfn);
267 #define NUM_DEFAULT_RLS 1
269 static u16 qed_init_qm_get_num_pf_rls(struct qed_hwfn *p_hwfn)
271 u16 num_pf_rls, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
273 /* num RLs can't exceed resource amount of rls or vports */
274 num_pf_rls = (u16) min_t(u32, RESC_NUM(p_hwfn, QED_RL),
275 RESC_NUM(p_hwfn, QED_VPORT));
277 /* Make sure after we reserve there's something left */
278 if (num_pf_rls < num_vfs + NUM_DEFAULT_RLS)
281 /* subtract rls necessary for VFs and one default one for the PF */
282 num_pf_rls -= num_vfs + NUM_DEFAULT_RLS;
287 static u16 qed_init_qm_get_num_vports(struct qed_hwfn *p_hwfn)
289 u32 pq_flags = qed_get_pq_flags(p_hwfn);
291 /* all pqs share the same vport, except for vfs and pf_rl pqs */
292 return (!!(PQ_FLAGS_RLS & pq_flags)) *
293 qed_init_qm_get_num_pf_rls(p_hwfn) +
294 (!!(PQ_FLAGS_VFS & pq_flags)) *
295 qed_init_qm_get_num_vfs(p_hwfn) + 1;
298 /* calc amount of PQs according to the requested flags */
299 static u16 qed_init_qm_get_num_pqs(struct qed_hwfn *p_hwfn)
301 u32 pq_flags = qed_get_pq_flags(p_hwfn);
303 return (!!(PQ_FLAGS_RLS & pq_flags)) *
304 qed_init_qm_get_num_pf_rls(p_hwfn) +
305 (!!(PQ_FLAGS_MCOS & pq_flags)) *
306 qed_init_qm_get_num_tcs(p_hwfn) +
307 (!!(PQ_FLAGS_LB & pq_flags)) + (!!(PQ_FLAGS_OOO & pq_flags)) +
308 (!!(PQ_FLAGS_ACK & pq_flags)) +
309 (!!(PQ_FLAGS_OFLD & pq_flags)) *
310 qed_init_qm_get_num_mtc_tcs(p_hwfn) +
311 (!!(PQ_FLAGS_LLT & pq_flags)) *
312 qed_init_qm_get_num_mtc_tcs(p_hwfn) +
313 (!!(PQ_FLAGS_VFS & pq_flags)) * qed_init_qm_get_num_vfs(p_hwfn);
316 /* initialize the top level QM params */
317 static void qed_init_qm_params(struct qed_hwfn *p_hwfn)
319 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
322 /* pq and vport bases for this PF */
323 qm_info->start_pq = (u16) RESC_START(p_hwfn, QED_PQ);
324 qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
326 /* rate limiting and weighted fair queueing are always enabled */
327 qm_info->vport_rl_en = true;
328 qm_info->vport_wfq_en = true;
330 /* TC config is different for AH 4 port */
331 four_port = p_hwfn->cdev->num_ports_in_engine == MAX_NUM_PORTS_K2;
333 /* in AH 4 port we have fewer TCs per port */
334 qm_info->max_phys_tcs_per_port = four_port ? NUM_PHYS_TCS_4PORT_K2 :
337 /* unless MFW indicated otherwise, ooo_tc == 3 for
338 * AH 4-port and 4 otherwise.
340 if (!qm_info->ooo_tc)
341 qm_info->ooo_tc = four_port ? DCBX_TCP_OOO_K2_4PORT_TC :
345 /* initialize qm vport params */
346 static void qed_init_qm_vport_params(struct qed_hwfn *p_hwfn)
348 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
351 /* all vports participate in weighted fair queueing */
352 for (i = 0; i < qed_init_qm_get_num_vports(p_hwfn); i++)
353 qm_info->qm_vport_params[i].vport_wfq = 1;
356 /* initialize qm port params */
357 static void qed_init_qm_port_params(struct qed_hwfn *p_hwfn)
359 /* Initialize qm port parameters */
360 u8 i, active_phys_tcs, num_ports = p_hwfn->cdev->num_ports_in_engine;
362 /* indicate how ooo and high pri traffic is dealt with */
363 active_phys_tcs = num_ports == MAX_NUM_PORTS_K2 ?
364 ACTIVE_TCS_BMAP_4PORT_K2 :
367 for (i = 0; i < num_ports; i++) {
368 struct init_qm_port_params *p_qm_port =
369 &p_hwfn->qm_info.qm_port_params[i];
371 p_qm_port->active = 1;
372 p_qm_port->active_phys_tcs = active_phys_tcs;
373 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
374 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
378 /* Reset the params which must be reset for qm init. QM init may be called as
379 * a result of flows other than driver load (e.g. dcbx renegotiation). Other
380 * params may be affected by the init but would simply recalculate to the same
381 * values. The allocations made for QM init, ports, vports, pqs and vfqs are not
382 * affected as these amounts stay the same.
384 static void qed_init_qm_reset_params(struct qed_hwfn *p_hwfn)
386 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
388 qm_info->num_pqs = 0;
389 qm_info->num_vports = 0;
390 qm_info->num_pf_rls = 0;
391 qm_info->num_vf_pqs = 0;
392 qm_info->first_vf_pq = 0;
393 qm_info->first_mcos_pq = 0;
394 qm_info->first_rl_pq = 0;
397 static void qed_init_qm_advance_vport(struct qed_hwfn *p_hwfn)
399 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
401 qm_info->num_vports++;
403 if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
405 "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
406 qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
409 /* initialize a single pq and manage qm_info resources accounting.
410 * The pq_init_flags param determines whether the PQ is rate limited
411 * (for VF or PF) and whether a new vport is allocated to the pq or not
412 * (i.e. vport will be shared).
415 /* flags for pq init */
416 #define PQ_INIT_SHARE_VPORT (1 << 0)
417 #define PQ_INIT_PF_RL (1 << 1)
418 #define PQ_INIT_VF_RL (1 << 2)
420 /* defines for pq init */
421 #define PQ_INIT_DEFAULT_WRR_GROUP 1
422 #define PQ_INIT_DEFAULT_TC 0
424 void qed_hw_info_set_offload_tc(struct qed_hw_info *p_info, u8 tc)
426 p_info->offload_tc = tc;
427 p_info->offload_tc_set = true;
430 static bool qed_is_offload_tc_set(struct qed_hwfn *p_hwfn)
432 return p_hwfn->hw_info.offload_tc_set;
435 static u32 qed_get_offload_tc(struct qed_hwfn *p_hwfn)
437 if (qed_is_offload_tc_set(p_hwfn))
438 return p_hwfn->hw_info.offload_tc;
440 return PQ_INIT_DEFAULT_TC;
443 static void qed_init_qm_pq(struct qed_hwfn *p_hwfn,
444 struct qed_qm_info *qm_info,
445 u8 tc, u32 pq_init_flags)
447 u16 pq_idx = qm_info->num_pqs, max_pq = qed_init_qm_get_num_pqs(p_hwfn);
451 "pq overflow! pq %d, max pq %d\n", pq_idx, max_pq);
454 qm_info->qm_pq_params[pq_idx].port_id = p_hwfn->port_id;
455 qm_info->qm_pq_params[pq_idx].vport_id = qm_info->start_vport +
457 qm_info->qm_pq_params[pq_idx].tc_id = tc;
458 qm_info->qm_pq_params[pq_idx].wrr_group = PQ_INIT_DEFAULT_WRR_GROUP;
459 qm_info->qm_pq_params[pq_idx].rl_valid =
460 (pq_init_flags & PQ_INIT_PF_RL || pq_init_flags & PQ_INIT_VF_RL);
462 /* qm params accounting */
464 if (!(pq_init_flags & PQ_INIT_SHARE_VPORT))
465 qm_info->num_vports++;
467 if (pq_init_flags & PQ_INIT_PF_RL)
468 qm_info->num_pf_rls++;
470 if (qm_info->num_vports > qed_init_qm_get_num_vports(p_hwfn))
472 "vport overflow! qm_info->num_vports %d, qm_init_get_num_vports() %d\n",
473 qm_info->num_vports, qed_init_qm_get_num_vports(p_hwfn));
475 if (qm_info->num_pf_rls > qed_init_qm_get_num_pf_rls(p_hwfn))
477 "rl overflow! qm_info->num_pf_rls %d, qm_init_get_num_pf_rls() %d\n",
478 qm_info->num_pf_rls, qed_init_qm_get_num_pf_rls(p_hwfn));
481 /* get pq index according to PQ_FLAGS */
482 static u16 *qed_init_qm_get_idx_from_flags(struct qed_hwfn *p_hwfn,
485 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
487 /* Can't have multiple flags set here */
488 if (bitmap_weight((unsigned long *)&pq_flags,
489 sizeof(pq_flags) * BITS_PER_BYTE) > 1) {
490 DP_ERR(p_hwfn, "requested multiple pq flags 0x%x\n", pq_flags);
494 if (!(qed_get_pq_flags(p_hwfn) & pq_flags)) {
495 DP_ERR(p_hwfn, "pq flag 0x%x is not set\n", pq_flags);
501 return &qm_info->first_rl_pq;
503 return &qm_info->first_mcos_pq;
505 return &qm_info->pure_lb_pq;
507 return &qm_info->ooo_pq;
509 return &qm_info->pure_ack_pq;
511 return &qm_info->first_ofld_pq;
513 return &qm_info->first_llt_pq;
515 return &qm_info->first_vf_pq;
521 return &qm_info->start_pq;
524 /* save pq index in qm info */
525 static void qed_init_qm_set_idx(struct qed_hwfn *p_hwfn,
526 u32 pq_flags, u16 pq_val)
528 u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
530 *base_pq_idx = p_hwfn->qm_info.start_pq + pq_val;
533 /* get tx pq index, with the PQ TX base already set (ready for context init) */
534 u16 qed_get_cm_pq_idx(struct qed_hwfn *p_hwfn, u32 pq_flags)
536 u16 *base_pq_idx = qed_init_qm_get_idx_from_flags(p_hwfn, pq_flags);
538 return *base_pq_idx + CM_TX_PQ_BASE;
541 u16 qed_get_cm_pq_idx_mcos(struct qed_hwfn *p_hwfn, u8 tc)
543 u8 max_tc = qed_init_qm_get_num_tcs(p_hwfn);
546 DP_ERR(p_hwfn, "pq with flag 0x%lx do not exist\n",
548 return p_hwfn->qm_info.start_pq;
552 DP_ERR(p_hwfn, "tc %d must be smaller than %d\n", tc, max_tc);
554 return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_MCOS) + (tc % max_tc);
557 u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf)
559 u16 max_vf = qed_init_qm_get_num_vfs(p_hwfn);
562 DP_ERR(p_hwfn, "pq with flag 0x%lx do not exist\n",
564 return p_hwfn->qm_info.start_pq;
568 DP_ERR(p_hwfn, "vf %d must be smaller than %d\n", vf, max_vf);
570 return qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_VFS) + (vf % max_vf);
573 u16 qed_get_cm_pq_idx_ofld_mtc(struct qed_hwfn *p_hwfn, u8 tc)
575 u16 first_ofld_pq, pq_offset;
577 first_ofld_pq = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
578 pq_offset = (tc < qed_init_qm_get_num_mtc_tcs(p_hwfn)) ?
579 tc : PQ_INIT_DEFAULT_TC;
581 return first_ofld_pq + pq_offset;
584 u16 qed_get_cm_pq_idx_llt_mtc(struct qed_hwfn *p_hwfn, u8 tc)
586 u16 first_llt_pq, pq_offset;
588 first_llt_pq = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LLT);
589 pq_offset = (tc < qed_init_qm_get_num_mtc_tcs(p_hwfn)) ?
590 tc : PQ_INIT_DEFAULT_TC;
592 return first_llt_pq + pq_offset;
595 /* Functions for creating specific types of pqs */
596 static void qed_init_qm_lb_pq(struct qed_hwfn *p_hwfn)
598 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
600 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LB))
603 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LB, qm_info->num_pqs);
604 qed_init_qm_pq(p_hwfn, qm_info, PURE_LB_TC, PQ_INIT_SHARE_VPORT);
607 static void qed_init_qm_ooo_pq(struct qed_hwfn *p_hwfn)
609 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
611 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OOO))
614 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OOO, qm_info->num_pqs);
615 qed_init_qm_pq(p_hwfn, qm_info, qm_info->ooo_tc, PQ_INIT_SHARE_VPORT);
618 static void qed_init_qm_pure_ack_pq(struct qed_hwfn *p_hwfn)
620 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
622 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_ACK))
625 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_ACK, qm_info->num_pqs);
626 qed_init_qm_pq(p_hwfn, qm_info, qed_get_offload_tc(p_hwfn),
627 PQ_INIT_SHARE_VPORT);
630 static void qed_init_qm_mtc_pqs(struct qed_hwfn *p_hwfn)
632 u8 num_tcs = qed_init_qm_get_num_mtc_tcs(p_hwfn);
633 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
636 /* override pq's TC if offload TC is set */
637 for (tc = 0; tc < num_tcs; tc++)
638 qed_init_qm_pq(p_hwfn, qm_info,
639 qed_is_offload_tc_set(p_hwfn) ?
640 p_hwfn->hw_info.offload_tc : tc,
641 PQ_INIT_SHARE_VPORT);
644 static void qed_init_qm_offload_pq(struct qed_hwfn *p_hwfn)
646 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
648 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_OFLD))
651 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_OFLD, qm_info->num_pqs);
652 qed_init_qm_mtc_pqs(p_hwfn);
655 static void qed_init_qm_low_latency_pq(struct qed_hwfn *p_hwfn)
657 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
659 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_LLT))
662 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_LLT, qm_info->num_pqs);
663 qed_init_qm_mtc_pqs(p_hwfn);
666 static void qed_init_qm_mcos_pqs(struct qed_hwfn *p_hwfn)
668 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
671 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_MCOS))
674 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_MCOS, qm_info->num_pqs);
675 for (tc_idx = 0; tc_idx < qed_init_qm_get_num_tcs(p_hwfn); tc_idx++)
676 qed_init_qm_pq(p_hwfn, qm_info, tc_idx, PQ_INIT_SHARE_VPORT);
679 static void qed_init_qm_vf_pqs(struct qed_hwfn *p_hwfn)
681 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
682 u16 vf_idx, num_vfs = qed_init_qm_get_num_vfs(p_hwfn);
684 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_VFS))
687 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_VFS, qm_info->num_pqs);
688 qm_info->num_vf_pqs = num_vfs;
689 for (vf_idx = 0; vf_idx < num_vfs; vf_idx++)
690 qed_init_qm_pq(p_hwfn,
691 qm_info, PQ_INIT_DEFAULT_TC, PQ_INIT_VF_RL);
694 static void qed_init_qm_rl_pqs(struct qed_hwfn *p_hwfn)
696 u16 pf_rls_idx, num_pf_rls = qed_init_qm_get_num_pf_rls(p_hwfn);
697 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
699 if (!(qed_get_pq_flags(p_hwfn) & PQ_FLAGS_RLS))
702 qed_init_qm_set_idx(p_hwfn, PQ_FLAGS_RLS, qm_info->num_pqs);
703 for (pf_rls_idx = 0; pf_rls_idx < num_pf_rls; pf_rls_idx++)
704 qed_init_qm_pq(p_hwfn, qm_info, qed_get_offload_tc(p_hwfn),
708 static void qed_init_qm_pq_params(struct qed_hwfn *p_hwfn)
710 /* rate limited pqs, must come first (FW assumption) */
711 qed_init_qm_rl_pqs(p_hwfn);
713 /* pqs for multi cos */
714 qed_init_qm_mcos_pqs(p_hwfn);
716 /* pure loopback pq */
717 qed_init_qm_lb_pq(p_hwfn);
719 /* out of order pq */
720 qed_init_qm_ooo_pq(p_hwfn);
723 qed_init_qm_pure_ack_pq(p_hwfn);
725 /* pq for offloaded protocol */
726 qed_init_qm_offload_pq(p_hwfn);
729 qed_init_qm_low_latency_pq(p_hwfn);
731 /* done sharing vports */
732 qed_init_qm_advance_vport(p_hwfn);
735 qed_init_qm_vf_pqs(p_hwfn);
738 /* compare values of getters against resources amounts */
739 static int qed_init_qm_sanity(struct qed_hwfn *p_hwfn)
741 if (qed_init_qm_get_num_vports(p_hwfn) > RESC_NUM(p_hwfn, QED_VPORT)) {
742 DP_ERR(p_hwfn, "requested amount of vports exceeds resource\n");
746 if (qed_init_qm_get_num_pqs(p_hwfn) <= RESC_NUM(p_hwfn, QED_PQ))
749 if (QED_IS_ROCE_PERSONALITY(p_hwfn)) {
750 p_hwfn->hw_info.multi_tc_roce_en = 0;
752 "multi-tc roce was disabled to reduce requested amount of pqs\n");
753 if (qed_init_qm_get_num_pqs(p_hwfn) <= RESC_NUM(p_hwfn, QED_PQ))
757 DP_ERR(p_hwfn, "requested amount of pqs exceeds resource\n");
761 static void qed_dp_init_qm_params(struct qed_hwfn *p_hwfn)
763 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
764 struct init_qm_vport_params *vport;
765 struct init_qm_port_params *port;
766 struct init_qm_pq_params *pq;
769 /* top level params */
772 "qm init top level params: start_pq %d, start_vport %d, pure_lb_pq %d, offload_pq %d, llt_pq %d, pure_ack_pq %d\n",
774 qm_info->start_vport,
776 qm_info->first_ofld_pq,
777 qm_info->first_llt_pq,
778 qm_info->pure_ack_pq);
781 "ooo_pq %d, first_vf_pq %d, num_pqs %d, num_vf_pqs %d, num_vports %d, max_phys_tcs_per_port %d\n",
783 qm_info->first_vf_pq,
786 qm_info->num_vports, qm_info->max_phys_tcs_per_port);
789 "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",
792 qm_info->vport_rl_en,
793 qm_info->vport_wfq_en,
796 qm_info->num_pf_rls, qed_get_pq_flags(p_hwfn));
799 for (i = 0; i < p_hwfn->cdev->num_ports_in_engine; i++) {
800 port = &(qm_info->qm_port_params[i]);
803 "port idx %d, active %d, active_phys_tcs %d, num_pbf_cmd_lines %d, num_btb_blocks %d, reserved %d\n",
806 port->active_phys_tcs,
807 port->num_pbf_cmd_lines,
808 port->num_btb_blocks, port->reserved);
812 for (i = 0; i < qm_info->num_vports; i++) {
813 vport = &(qm_info->qm_vport_params[i]);
816 "vport idx %d, vport_rl %d, wfq %d, first_tx_pq_id [ ",
817 qm_info->start_vport + i,
818 vport->vport_rl, vport->vport_wfq);
819 for (tc = 0; tc < NUM_OF_TCS; tc++)
822 "%d ", vport->first_tx_pq_id[tc]);
823 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "]\n");
827 for (i = 0; i < qm_info->num_pqs; i++) {
828 pq = &(qm_info->qm_pq_params[i]);
831 "pq idx %d, port %d, vport_id %d, tc %d, wrr_grp %d, rl_valid %d\n",
832 qm_info->start_pq + i,
835 pq->tc_id, pq->wrr_group, pq->rl_valid);
839 static void qed_init_qm_info(struct qed_hwfn *p_hwfn)
841 /* reset params required for init run */
842 qed_init_qm_reset_params(p_hwfn);
844 /* init QM top level params */
845 qed_init_qm_params(p_hwfn);
847 /* init QM port params */
848 qed_init_qm_port_params(p_hwfn);
850 /* init QM vport params */
851 qed_init_qm_vport_params(p_hwfn);
853 /* init QM physical queue params */
854 qed_init_qm_pq_params(p_hwfn);
856 /* display all that init */
857 qed_dp_init_qm_params(p_hwfn);
860 /* This function reconfigures the QM pf on the fly.
861 * For this purpose we:
862 * 1. reconfigure the QM database
863 * 2. set new values to runtime array
864 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
865 * 4. activate init tool in QM_PF stage
866 * 5. send an sdm_qm_cmd through rbc interface to release the QM
868 int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
870 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
874 /* initialize qed's qm data structure */
875 qed_init_qm_info(p_hwfn);
877 /* stop PF's qm queues */
878 spin_lock_bh(&qm_lock);
879 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
880 qm_info->start_pq, qm_info->num_pqs);
881 spin_unlock_bh(&qm_lock);
885 /* clear the QM_PF runtime phase leftovers from previous init */
886 qed_init_clear_rt_data(p_hwfn);
888 /* prepare QM portion of runtime array */
889 qed_qm_init_pf(p_hwfn, p_ptt, false);
891 /* activate init tool on runtime array */
892 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
893 p_hwfn->hw_info.hw_mode);
897 /* start PF's qm queues */
898 spin_lock_bh(&qm_lock);
899 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
900 qm_info->start_pq, qm_info->num_pqs);
901 spin_unlock_bh(&qm_lock);
908 static int qed_alloc_qm_data(struct qed_hwfn *p_hwfn)
910 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
913 rc = qed_init_qm_sanity(p_hwfn);
917 qm_info->qm_pq_params = kcalloc(qed_init_qm_get_num_pqs(p_hwfn),
918 sizeof(*qm_info->qm_pq_params),
920 if (!qm_info->qm_pq_params)
923 qm_info->qm_vport_params = kcalloc(qed_init_qm_get_num_vports(p_hwfn),
924 sizeof(*qm_info->qm_vport_params),
926 if (!qm_info->qm_vport_params)
929 qm_info->qm_port_params = kcalloc(p_hwfn->cdev->num_ports_in_engine,
930 sizeof(*qm_info->qm_port_params),
932 if (!qm_info->qm_port_params)
935 qm_info->wfq_data = kcalloc(qed_init_qm_get_num_vports(p_hwfn),
936 sizeof(*qm_info->wfq_data),
938 if (!qm_info->wfq_data)
944 DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
945 qed_qm_info_free(p_hwfn);
949 int qed_resc_alloc(struct qed_dev *cdev)
951 u32 rdma_tasks, excess_tasks;
956 for_each_hwfn(cdev, i) {
957 rc = qed_l2_alloc(&cdev->hwfns[i]);
964 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
968 for_each_hwfn(cdev, i) {
969 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
970 u32 n_eqes, num_cons;
972 /* First allocate the context manager structure */
973 rc = qed_cxt_mngr_alloc(p_hwfn);
977 /* Set the HW cid/tid numbers (in the contest manager)
978 * Must be done prior to any further computations.
980 rc = qed_cxt_set_pf_params(p_hwfn, RDMA_MAX_TIDS);
984 rc = qed_alloc_qm_data(p_hwfn);
989 qed_init_qm_info(p_hwfn);
991 /* Compute the ILT client partition */
992 rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
995 "too many ILT lines; re-computing with less lines\n");
996 /* In case there are not enough ILT lines we reduce the
997 * number of RDMA tasks and re-compute.
1000 qed_cxt_cfg_ilt_compute_excess(p_hwfn, line_count);
1004 rdma_tasks = RDMA_MAX_TIDS - excess_tasks;
1005 rc = qed_cxt_set_pf_params(p_hwfn, rdma_tasks);
1009 rc = qed_cxt_cfg_ilt_compute(p_hwfn, &line_count);
1012 "failed ILT compute. Requested too many lines: %u\n",
1019 /* CID map / ILT shadow table / T2
1020 * The talbes sizes are determined by the computations above
1022 rc = qed_cxt_tables_alloc(p_hwfn);
1026 /* SPQ, must follow ILT because initializes SPQ context */
1027 rc = qed_spq_alloc(p_hwfn);
1031 /* SP status block allocation */
1032 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
1035 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
1039 rc = qed_iov_alloc(p_hwfn);
1044 n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
1045 if (QED_IS_RDMA_PERSONALITY(p_hwfn)) {
1046 enum protocol_type rdma_proto;
1048 if (QED_IS_ROCE_PERSONALITY(p_hwfn))
1049 rdma_proto = PROTOCOLID_ROCE;
1051 rdma_proto = PROTOCOLID_IWARP;
1053 num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
1056 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
1057 } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
1059 qed_cxt_get_proto_cid_count(p_hwfn,
1062 n_eqes += 2 * num_cons;
1065 if (n_eqes > 0xFFFF) {
1067 "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
1072 rc = qed_eq_alloc(p_hwfn, (u16) n_eqes);
1076 rc = qed_consq_alloc(p_hwfn);
1080 rc = qed_l2_alloc(p_hwfn);
1084 #ifdef CONFIG_QED_LL2
1085 if (p_hwfn->using_ll2) {
1086 rc = qed_ll2_alloc(p_hwfn);
1092 if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
1093 rc = qed_fcoe_alloc(p_hwfn);
1098 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
1099 rc = qed_iscsi_alloc(p_hwfn);
1102 rc = qed_ooo_alloc(p_hwfn);
1107 if (QED_IS_RDMA_PERSONALITY(p_hwfn)) {
1108 rc = qed_rdma_info_alloc(p_hwfn);
1113 /* DMA info initialization */
1114 rc = qed_dmae_info_alloc(p_hwfn);
1118 /* DCBX initialization */
1119 rc = qed_dcbx_info_alloc(p_hwfn);
1123 rc = qed_dbg_alloc_user_data(p_hwfn);
1128 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
1129 if (!cdev->reset_stats)
1137 qed_resc_free(cdev);
1141 void qed_resc_setup(struct qed_dev *cdev)
1146 for_each_hwfn(cdev, i)
1147 qed_l2_setup(&cdev->hwfns[i]);
1151 for_each_hwfn(cdev, i) {
1152 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1154 qed_cxt_mngr_setup(p_hwfn);
1155 qed_spq_setup(p_hwfn);
1156 qed_eq_setup(p_hwfn);
1157 qed_consq_setup(p_hwfn);
1159 /* Read shadow of current MFW mailbox */
1160 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
1161 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
1162 p_hwfn->mcp_info->mfw_mb_cur,
1163 p_hwfn->mcp_info->mfw_mb_length);
1165 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
1167 qed_l2_setup(p_hwfn);
1168 qed_iov_setup(p_hwfn);
1169 #ifdef CONFIG_QED_LL2
1170 if (p_hwfn->using_ll2)
1171 qed_ll2_setup(p_hwfn);
1173 if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
1174 qed_fcoe_setup(p_hwfn);
1176 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
1177 qed_iscsi_setup(p_hwfn);
1178 qed_ooo_setup(p_hwfn);
1183 #define FINAL_CLEANUP_POLL_CNT (100)
1184 #define FINAL_CLEANUP_POLL_TIME (10)
1185 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
1186 struct qed_ptt *p_ptt, u16 id, bool is_vf)
1188 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
1191 addr = GTT_BAR0_MAP_REG_USDM_RAM +
1192 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
1197 command |= X_FINAL_CLEANUP_AGG_INT <<
1198 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
1199 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
1200 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
1201 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
1203 /* Make sure notification is not set before initiating final cleanup */
1204 if (REG_RD(p_hwfn, addr)) {
1206 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
1207 REG_WR(p_hwfn, addr, 0);
1210 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1211 "Sending final cleanup for PFVF[%d] [Command %08x]\n",
1214 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
1216 /* Poll until completion */
1217 while (!REG_RD(p_hwfn, addr) && count--)
1218 msleep(FINAL_CLEANUP_POLL_TIME);
1220 if (REG_RD(p_hwfn, addr))
1224 "Failed to receive FW final cleanup notification\n");
1226 /* Cleanup afterwards */
1227 REG_WR(p_hwfn, addr, 0);
1232 static int qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
1236 if (QED_IS_BB_B0(p_hwfn->cdev)) {
1237 hw_mode |= 1 << MODE_BB;
1238 } else if (QED_IS_AH(p_hwfn->cdev)) {
1239 hw_mode |= 1 << MODE_K2;
1241 DP_NOTICE(p_hwfn, "Unknown chip type %#x\n",
1242 p_hwfn->cdev->type);
1246 switch (p_hwfn->cdev->num_ports_in_engine) {
1248 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
1251 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
1254 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
1257 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
1258 p_hwfn->cdev->num_ports_in_engine);
1262 if (test_bit(QED_MF_OVLAN_CLSS, &p_hwfn->cdev->mf_bits))
1263 hw_mode |= 1 << MODE_MF_SD;
1265 hw_mode |= 1 << MODE_MF_SI;
1267 hw_mode |= 1 << MODE_ASIC;
1269 if (p_hwfn->cdev->num_hwfns > 1)
1270 hw_mode |= 1 << MODE_100G;
1272 p_hwfn->hw_info.hw_mode = hw_mode;
1274 DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
1275 "Configuring function for hw_mode: 0x%08x\n",
1276 p_hwfn->hw_info.hw_mode);
1281 /* Init run time data for all PFs on an engine. */
1282 static void qed_init_cau_rt_data(struct qed_dev *cdev)
1284 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
1287 for_each_hwfn(cdev, i) {
1288 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1289 struct qed_igu_info *p_igu_info;
1290 struct qed_igu_block *p_block;
1291 struct cau_sb_entry sb_entry;
1293 p_igu_info = p_hwfn->hw_info.p_igu_info;
1296 igu_sb_id < QED_MAPPING_MEMORY_SIZE(cdev); igu_sb_id++) {
1297 p_block = &p_igu_info->entry[igu_sb_id];
1299 if (!p_block->is_pf)
1302 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
1303 p_block->function_id, 0, 0);
1304 STORE_RT_REG_AGG(p_hwfn, offset + igu_sb_id * 2,
1310 static void qed_init_cache_line_size(struct qed_hwfn *p_hwfn,
1311 struct qed_ptt *p_ptt)
1313 u32 val, wr_mbs, cache_line_size;
1315 val = qed_rd(p_hwfn, p_ptt, PSWRQ2_REG_WR_MBS0);
1328 "Unexpected value of PSWRQ2_REG_WR_MBS0 [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1333 cache_line_size = min_t(u32, L1_CACHE_BYTES, wr_mbs);
1334 switch (cache_line_size) {
1349 "Unexpected value of cache line size [0x%x]. Avoid configuring PGLUE_B_REG_CACHE_LINE_SIZE.\n",
1353 if (L1_CACHE_BYTES > wr_mbs)
1355 "The cache line size for padding is suboptimal for performance [OS cache line size 0x%x, wr mbs 0x%x]\n",
1356 L1_CACHE_BYTES, wr_mbs);
1358 STORE_RT_REG(p_hwfn, PGLUE_REG_B_CACHE_LINE_SIZE_RT_OFFSET, val);
1360 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_WR_RT_OFFSET, val);
1361 STORE_RT_REG(p_hwfn, PSWRQ2_REG_DRAM_ALIGN_RD_RT_OFFSET, val);
1365 static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
1366 struct qed_ptt *p_ptt, int hw_mode)
1368 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
1369 struct qed_qm_common_rt_init_params params;
1370 struct qed_dev *cdev = p_hwfn->cdev;
1371 u8 vf_id, max_num_vfs;
1376 qed_init_cau_rt_data(cdev);
1378 /* Program GTT windows */
1379 qed_gtt_init(p_hwfn);
1381 if (p_hwfn->mcp_info) {
1382 if (p_hwfn->mcp_info->func_info.bandwidth_max)
1383 qm_info->pf_rl_en = true;
1384 if (p_hwfn->mcp_info->func_info.bandwidth_min)
1385 qm_info->pf_wfq_en = true;
1388 memset(¶ms, 0, sizeof(params));
1389 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engine;
1390 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
1391 params.pf_rl_en = qm_info->pf_rl_en;
1392 params.pf_wfq_en = qm_info->pf_wfq_en;
1393 params.vport_rl_en = qm_info->vport_rl_en;
1394 params.vport_wfq_en = qm_info->vport_wfq_en;
1395 params.port_params = qm_info->qm_port_params;
1397 qed_qm_common_rt_init(p_hwfn, ¶ms);
1399 qed_cxt_hw_init_common(p_hwfn);
1401 qed_init_cache_line_size(p_hwfn, p_ptt);
1403 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
1407 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
1408 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
1410 if (QED_IS_BB(p_hwfn->cdev)) {
1411 num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
1412 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
1413 qed_fid_pretend(p_hwfn, p_ptt, pf_id);
1414 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1415 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1417 /* pretend to original PF */
1418 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1421 max_num_vfs = QED_IS_AH(cdev) ? MAX_NUM_VFS_K2 : MAX_NUM_VFS_BB;
1422 for (vf_id = 0; vf_id < max_num_vfs; vf_id++) {
1423 concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
1424 qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
1425 qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
1426 qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
1427 qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
1428 qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
1430 /* pretend to original PF */
1431 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
1437 qed_hw_init_dpi_size(struct qed_hwfn *p_hwfn,
1438 struct qed_ptt *p_ptt, u32 pwm_region_size, u32 n_cpus)
1440 u32 dpi_bit_shift, dpi_count, dpi_page_size;
1444 /* Calculate DPI size */
1445 n_wids = max_t(u32, QED_MIN_WIDS, n_cpus);
1446 dpi_page_size = QED_WID_SIZE * roundup_pow_of_two(n_wids);
1447 dpi_page_size = (dpi_page_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
1448 dpi_bit_shift = ilog2(dpi_page_size / 4096);
1449 dpi_count = pwm_region_size / dpi_page_size;
1451 min_dpis = p_hwfn->pf_params.rdma_pf_params.min_dpis;
1452 min_dpis = max_t(u32, QED_MIN_DPIS, min_dpis);
1454 p_hwfn->dpi_size = dpi_page_size;
1455 p_hwfn->dpi_count = dpi_count;
1457 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPI_BIT_SHIFT, dpi_bit_shift);
1459 if (dpi_count < min_dpis)
1465 enum QED_ROCE_EDPM_MODE {
1466 QED_ROCE_EDPM_MODE_ENABLE = 0,
1467 QED_ROCE_EDPM_MODE_FORCE_ON = 1,
1468 QED_ROCE_EDPM_MODE_DISABLE = 2,
1472 qed_hw_init_pf_doorbell_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1474 u32 pwm_regsize, norm_regsize;
1475 u32 non_pwm_conn, min_addr_reg1;
1476 u32 db_bar_size, n_cpus = 1;
1482 db_bar_size = qed_hw_bar_size(p_hwfn, p_ptt, BAR_ID_1);
1483 if (p_hwfn->cdev->num_hwfns > 1)
1486 /* Calculate doorbell regions */
1487 non_pwm_conn = qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_CORE) +
1488 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_CORE,
1490 qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
1492 norm_regsize = roundup(QED_PF_DEMS_SIZE * non_pwm_conn, PAGE_SIZE);
1493 min_addr_reg1 = norm_regsize / 4096;
1494 pwm_regsize = db_bar_size - norm_regsize;
1496 /* Check that the normal and PWM sizes are valid */
1497 if (db_bar_size < norm_regsize) {
1498 DP_ERR(p_hwfn->cdev,
1499 "Doorbell BAR size 0x%x is too small (normal region is 0x%0x )\n",
1500 db_bar_size, norm_regsize);
1504 if (pwm_regsize < QED_MIN_PWM_REGION) {
1505 DP_ERR(p_hwfn->cdev,
1506 "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",
1508 QED_MIN_PWM_REGION, db_bar_size, norm_regsize);
1512 /* Calculate number of DPIs */
1513 roce_edpm_mode = p_hwfn->pf_params.rdma_pf_params.roce_edpm_mode;
1514 if ((roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE) ||
1515 ((roce_edpm_mode == QED_ROCE_EDPM_MODE_FORCE_ON))) {
1516 /* Either EDPM is mandatory, or we are attempting to allocate a
1519 n_cpus = num_present_cpus();
1520 rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1523 cond = (rc && (roce_edpm_mode == QED_ROCE_EDPM_MODE_ENABLE)) ||
1524 (roce_edpm_mode == QED_ROCE_EDPM_MODE_DISABLE);
1525 if (cond || p_hwfn->dcbx_no_edpm) {
1526 /* Either EDPM is disabled from user configuration, or it is
1527 * disabled via DCBx, or it is not mandatory and we failed to
1528 * allocated a WID per CPU.
1531 rc = qed_hw_init_dpi_size(p_hwfn, p_ptt, pwm_regsize, n_cpus);
1534 qed_rdma_dpm_bar(p_hwfn, p_ptt);
1537 p_hwfn->wid_count = (u16) n_cpus;
1540 "doorbell bar: normal_region_size=%d, pwm_region_size=%d, dpi_size=%d, dpi_count=%d, roce_edpm=%s\n",
1545 ((p_hwfn->dcbx_no_edpm) || (p_hwfn->db_bar_no_edpm)) ?
1546 "disabled" : "enabled");
1550 "Failed to allocate enough DPIs. Allocated %d but the current minimum is %d.\n",
1552 p_hwfn->pf_params.rdma_pf_params.min_dpis);
1556 p_hwfn->dpi_start_offset = norm_regsize;
1558 /* DEMS size is configured log2 of DWORDs, hence the division by 4 */
1559 pf_dems_shift = ilog2(QED_PF_DEMS_SIZE / 4);
1560 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_ICID_BIT_SHIFT_NORM, pf_dems_shift);
1561 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_MIN_ADDR_REG1, min_addr_reg1);
1566 static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
1567 struct qed_ptt *p_ptt, int hw_mode)
1571 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id, hw_mode);
1575 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_MASTER_WRITE_PAD_ENABLE, 0);
1580 static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
1581 struct qed_ptt *p_ptt,
1582 struct qed_tunnel_info *p_tunn,
1585 enum qed_int_mode int_mode,
1586 bool allow_npar_tx_switch)
1588 u8 rel_pf_id = p_hwfn->rel_pf_id;
1591 if (p_hwfn->mcp_info) {
1592 struct qed_mcp_function_info *p_info;
1594 p_info = &p_hwfn->mcp_info->func_info;
1595 if (p_info->bandwidth_min)
1596 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
1598 /* Update rate limit once we'll actually have a link */
1599 p_hwfn->qm_info.pf_rl = 100000;
1602 qed_cxt_hw_init_pf(p_hwfn, p_ptt);
1604 qed_int_igu_init_rt(p_hwfn);
1606 /* Set VLAN in NIG if needed */
1607 if (hw_mode & BIT(MODE_MF_SD)) {
1608 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
1609 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
1610 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
1611 p_hwfn->hw_info.ovlan);
1613 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
1614 "Configuring LLH_FUNC_FILTER_HDR_SEL\n");
1615 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_FILTER_HDR_SEL_RT_OFFSET,
1619 /* Enable classification by MAC if needed */
1620 if (hw_mode & BIT(MODE_MF_SI)) {
1621 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
1622 "Configuring TAGMAC_CLS_TYPE\n");
1623 STORE_RT_REG(p_hwfn,
1624 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
1627 /* Protocol Configuration */
1628 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
1629 (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
1630 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET,
1631 (p_hwfn->hw_info.personality == QED_PCI_FCOE) ? 1 : 0);
1632 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
1634 /* Cleanup chip from previous driver if such remains exist */
1635 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
1639 /* Sanity check before the PF init sequence that uses DMAE */
1640 rc = qed_dmae_sanity(p_hwfn, p_ptt, "pf_phase");
1644 /* PF Init sequence */
1645 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
1649 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
1650 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
1654 /* Pure runtime initializations - directly to the HW */
1655 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
1657 rc = qed_hw_init_pf_doorbell_bar(p_hwfn, p_ptt);
1662 /* enable interrupts */
1663 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
1665 /* send function start command */
1666 rc = qed_sp_pf_start(p_hwfn, p_ptt, p_tunn,
1667 allow_npar_tx_switch);
1669 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
1672 if (p_hwfn->hw_info.personality == QED_PCI_FCOE) {
1673 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TAG1, BIT(2));
1674 qed_wr(p_hwfn, p_ptt,
1675 PRS_REG_PKT_LEN_STAT_TAGS_NOT_COUNTED_FIRST,
1682 static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
1683 struct qed_ptt *p_ptt,
1686 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
1688 /* Change PF in PXP */
1689 qed_wr(p_hwfn, p_ptt,
1690 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
1692 /* wait until value is set - try for 1 second every 50us */
1693 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
1694 val = qed_rd(p_hwfn, p_ptt,
1695 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
1699 usleep_range(50, 60);
1702 if (val != set_val) {
1704 "PFID_ENABLE_MASTER wasn't changed after a second\n");
1711 static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
1712 struct qed_ptt *p_main_ptt)
1714 /* Read shadow of current MFW mailbox */
1715 qed_mcp_read_mb(p_hwfn, p_main_ptt);
1716 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
1717 p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
1721 qed_fill_load_req_params(struct qed_load_req_params *p_load_req,
1722 struct qed_drv_load_params *p_drv_load)
1724 memset(p_load_req, 0, sizeof(*p_load_req));
1726 p_load_req->drv_role = p_drv_load->is_crash_kernel ?
1727 QED_DRV_ROLE_KDUMP : QED_DRV_ROLE_OS;
1728 p_load_req->timeout_val = p_drv_load->mfw_timeout_val;
1729 p_load_req->avoid_eng_reset = p_drv_load->avoid_eng_reset;
1730 p_load_req->override_force_load = p_drv_load->override_force_load;
1733 static int qed_vf_start(struct qed_hwfn *p_hwfn,
1734 struct qed_hw_init_params *p_params)
1736 if (p_params->p_tunn) {
1737 qed_vf_set_vf_start_tunn_update_param(p_params->p_tunn);
1738 qed_vf_pf_tunnel_param_update(p_hwfn, p_params->p_tunn);
1741 p_hwfn->b_int_enabled = true;
1746 int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params)
1748 struct qed_load_req_params load_req_params;
1749 u32 load_code, resp, param, drv_mb_param;
1750 bool b_default_mtu = true;
1751 struct qed_hwfn *p_hwfn;
1752 int rc = 0, mfw_rc, i;
1755 if ((p_params->int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
1756 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
1761 rc = qed_init_fw_data(cdev, p_params->bin_fw_data);
1766 for_each_hwfn(cdev, i) {
1767 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1769 /* If management didn't provide a default, set one of our own */
1770 if (!p_hwfn->hw_info.mtu) {
1771 p_hwfn->hw_info.mtu = 1500;
1772 b_default_mtu = false;
1776 qed_vf_start(p_hwfn, p_params);
1780 /* Enable DMAE in PXP */
1781 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
1783 rc = qed_calc_hw_mode(p_hwfn);
1787 if (IS_PF(cdev) && (test_bit(QED_MF_8021Q_TAGGING,
1789 test_bit(QED_MF_8021AD_TAGGING,
1791 if (test_bit(QED_MF_8021Q_TAGGING, &cdev->mf_bits))
1792 ether_type = ETH_P_8021Q;
1794 ether_type = ETH_P_8021AD;
1795 STORE_RT_REG(p_hwfn, PRS_REG_TAG_ETHERTYPE_0_RT_OFFSET,
1797 STORE_RT_REG(p_hwfn, NIG_REG_TAG_ETHERTYPE_0_RT_OFFSET,
1799 STORE_RT_REG(p_hwfn, PBF_REG_TAG_ETHERTYPE_0_RT_OFFSET,
1801 STORE_RT_REG(p_hwfn, DORQ_REG_TAG1_ETHERTYPE_RT_OFFSET,
1805 qed_fill_load_req_params(&load_req_params,
1806 p_params->p_drv_load_params);
1807 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
1810 DP_NOTICE(p_hwfn, "Failed sending a LOAD_REQ command\n");
1814 load_code = load_req_params.load_code;
1815 DP_VERBOSE(p_hwfn, QED_MSG_SP,
1816 "Load request was sent. Load code: 0x%x\n",
1819 qed_mcp_set_capabilities(p_hwfn, p_hwfn->p_main_ptt);
1821 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
1823 p_hwfn->first_on_engine = (load_code ==
1824 FW_MSG_CODE_DRV_LOAD_ENGINE);
1826 switch (load_code) {
1827 case FW_MSG_CODE_DRV_LOAD_ENGINE:
1828 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
1829 p_hwfn->hw_info.hw_mode);
1833 case FW_MSG_CODE_DRV_LOAD_PORT:
1834 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
1835 p_hwfn->hw_info.hw_mode);
1840 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
1841 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
1843 p_hwfn->hw_info.hw_mode,
1844 p_params->b_hw_start,
1846 p_params->allow_npar_tx_switch);
1850 "Unexpected load code [0x%08x]", load_code);
1857 "init phase failed for loadcode 0x%x (rc %d)\n",
1860 /* ACK mfw regardless of success or failure of initialization */
1861 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1862 DRV_MSG_CODE_LOAD_DONE,
1863 0, &load_code, ¶m);
1867 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
1871 /* Check if there is a DID mismatch between nvm-cfg/efuse */
1872 if (param & FW_MB_PARAM_LOAD_DONE_DID_EFUSE_ERROR)
1874 "warning: device configuration is not supported on this board type. The device may not function as expected.\n");
1876 /* send DCBX attention request command */
1879 "sending phony dcbx set command to trigger DCBx attention handling\n");
1880 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1881 DRV_MSG_CODE_SET_DCBX,
1882 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
1883 &load_code, ¶m);
1886 "Failed to send DCBX attention request\n");
1890 p_hwfn->hw_init_done = true;
1894 p_hwfn = QED_LEADING_HWFN(cdev);
1896 /* Get pre-negotiated values for stag, bandwidth etc. */
1899 "Sending GET_OEM_UPDATES command to trigger stag/bandwidth attention handling\n");
1900 drv_mb_param = 1 << DRV_MB_PARAM_DUMMY_OEM_UPDATES_OFFSET;
1901 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1902 DRV_MSG_CODE_GET_OEM_UPDATES,
1903 drv_mb_param, &resp, ¶m);
1906 "Failed to send GET_OEM_UPDATES attention request\n");
1908 drv_mb_param = STORM_FW_VERSION;
1909 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1910 DRV_MSG_CODE_OV_UPDATE_STORM_FW_VER,
1911 drv_mb_param, &load_code, ¶m);
1913 DP_INFO(p_hwfn, "Failed to update firmware version\n");
1915 if (!b_default_mtu) {
1916 rc = qed_mcp_ov_update_mtu(p_hwfn, p_hwfn->p_main_ptt,
1917 p_hwfn->hw_info.mtu);
1920 "Failed to update default mtu\n");
1923 rc = qed_mcp_ov_update_driver_state(p_hwfn,
1925 QED_OV_DRIVER_STATE_DISABLED);
1927 DP_INFO(p_hwfn, "Failed to update driver state\n");
1929 rc = qed_mcp_ov_update_eswitch(p_hwfn, p_hwfn->p_main_ptt,
1930 QED_OV_ESWITCH_NONE);
1932 DP_INFO(p_hwfn, "Failed to update eswitch mode\n");
1938 #define QED_HW_STOP_RETRY_LIMIT (10)
1939 static void qed_hw_timers_stop(struct qed_dev *cdev,
1940 struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1945 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
1946 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
1948 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
1949 if ((!qed_rd(p_hwfn, p_ptt,
1950 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
1951 (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
1954 /* Dependent on number of connection/tasks, possibly
1955 * 1ms sleep is required between polls
1957 usleep_range(1000, 2000);
1960 if (i < QED_HW_STOP_RETRY_LIMIT)
1964 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
1965 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
1966 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
1969 void qed_hw_timers_stop_all(struct qed_dev *cdev)
1973 for_each_hwfn(cdev, j) {
1974 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1975 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1977 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
1981 int qed_hw_stop(struct qed_dev *cdev)
1983 struct qed_hwfn *p_hwfn;
1984 struct qed_ptt *p_ptt;
1988 for_each_hwfn(cdev, j) {
1989 p_hwfn = &cdev->hwfns[j];
1990 p_ptt = p_hwfn->p_main_ptt;
1992 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
1995 qed_vf_pf_int_cleanup(p_hwfn);
1996 rc = qed_vf_pf_reset(p_hwfn);
1999 "qed_vf_pf_reset failed. rc = %d.\n",
2006 /* mark the hw as uninitialized... */
2007 p_hwfn->hw_init_done = false;
2009 /* Send unload command to MCP */
2010 rc = qed_mcp_unload_req(p_hwfn, p_ptt);
2013 "Failed sending a UNLOAD_REQ command. rc = %d.\n",
2018 qed_slowpath_irq_sync(p_hwfn);
2020 /* After this point no MFW attentions are expected, e.g. prevent
2021 * race between pf stop and dcbx pf update.
2023 rc = qed_sp_pf_stop(p_hwfn);
2026 "Failed to close PF against FW [rc = %d]. Continue to stop HW to prevent illegal host access by the device.\n",
2031 qed_wr(p_hwfn, p_ptt,
2032 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2034 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2035 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2036 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2037 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2038 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2040 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
2042 /* Disable Attention Generation */
2043 qed_int_igu_disable_int(p_hwfn, p_ptt);
2045 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
2046 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
2048 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
2050 /* Need to wait 1ms to guarantee SBs are cleared */
2051 usleep_range(1000, 2000);
2053 /* Disable PF in HW blocks */
2054 qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DB_ENABLE, 0);
2055 qed_wr(p_hwfn, p_ptt, QM_REG_PF_EN, 0);
2057 qed_mcp_unload_done(p_hwfn, p_ptt);
2060 "Failed sending a UNLOAD_DONE command. rc = %d.\n",
2067 p_hwfn = QED_LEADING_HWFN(cdev);
2068 p_ptt = QED_LEADING_HWFN(cdev)->p_main_ptt;
2070 /* Disable DMAE in PXP - in CMT, this should only be done for
2071 * first hw-function, and only after all transactions have
2072 * stopped for all active hw-functions.
2074 rc = qed_change_pci_hwfn(p_hwfn, p_ptt, false);
2077 "qed_change_pci_hwfn failed. rc = %d.\n", rc);
2085 int qed_hw_stop_fastpath(struct qed_dev *cdev)
2089 for_each_hwfn(cdev, j) {
2090 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
2091 struct qed_ptt *p_ptt;
2094 qed_vf_pf_int_cleanup(p_hwfn);
2097 p_ptt = qed_ptt_acquire(p_hwfn);
2102 NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
2104 qed_wr(p_hwfn, p_ptt,
2105 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
2107 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
2108 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
2109 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
2110 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
2111 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
2113 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
2115 /* Need to wait 1ms to guarantee SBs are cleared */
2116 usleep_range(1000, 2000);
2117 qed_ptt_release(p_hwfn, p_ptt);
2123 int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
2125 struct qed_ptt *p_ptt;
2127 if (IS_VF(p_hwfn->cdev))
2130 p_ptt = qed_ptt_acquire(p_hwfn);
2134 if (p_hwfn->p_rdma_info &&
2135 p_hwfn->p_rdma_info->active && p_hwfn->b_rdma_enabled_in_prs)
2136 qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0x1);
2138 /* Re-open incoming traffic */
2139 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
2140 qed_ptt_release(p_hwfn, p_ptt);
2145 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
2146 static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
2148 qed_ptt_pool_free(p_hwfn);
2149 kfree(p_hwfn->hw_info.p_igu_info);
2150 p_hwfn->hw_info.p_igu_info = NULL;
2153 /* Setup bar access */
2154 static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
2156 /* clear indirect access */
2157 if (QED_IS_AH(p_hwfn->cdev)) {
2158 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2159 PGLUE_B_REG_PGL_ADDR_E8_F0_K2, 0);
2160 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2161 PGLUE_B_REG_PGL_ADDR_EC_F0_K2, 0);
2162 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2163 PGLUE_B_REG_PGL_ADDR_F0_F0_K2, 0);
2164 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2165 PGLUE_B_REG_PGL_ADDR_F4_F0_K2, 0);
2167 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2168 PGLUE_B_REG_PGL_ADDR_88_F0_BB, 0);
2169 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2170 PGLUE_B_REG_PGL_ADDR_8C_F0_BB, 0);
2171 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2172 PGLUE_B_REG_PGL_ADDR_90_F0_BB, 0);
2173 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2174 PGLUE_B_REG_PGL_ADDR_94_F0_BB, 0);
2177 /* Clean Previous errors if such exist */
2178 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2179 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
2181 /* enable internal target-read */
2182 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
2183 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
2186 static void get_function_id(struct qed_hwfn *p_hwfn)
2189 p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
2190 PXP_PF_ME_OPAQUE_ADDR);
2192 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
2194 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
2195 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2196 PXP_CONCRETE_FID_PFID);
2197 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
2198 PXP_CONCRETE_FID_PORT);
2200 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
2201 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
2202 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
2205 static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
2207 u32 *feat_num = p_hwfn->hw_info.feat_num;
2208 struct qed_sb_cnt_info sb_cnt;
2211 memset(&sb_cnt, 0, sizeof(sb_cnt));
2212 qed_int_get_num_sbs(p_hwfn, &sb_cnt);
2214 if (IS_ENABLED(CONFIG_QED_RDMA) &&
2215 QED_IS_RDMA_PERSONALITY(p_hwfn)) {
2216 /* Roce CNQ each requires: 1 status block + 1 CNQ. We divide
2217 * the status blocks equally between L2 / RoCE but with
2218 * consideration as to how many l2 queues / cnqs we have.
2220 feat_num[QED_RDMA_CNQ] =
2221 min_t(u32, sb_cnt.cnt / 2,
2222 RESC_NUM(p_hwfn, QED_RDMA_CNQ_RAM));
2224 non_l2_sbs = feat_num[QED_RDMA_CNQ];
2226 if (QED_IS_L2_PERSONALITY(p_hwfn)) {
2227 /* Start by allocating VF queues, then PF's */
2228 feat_num[QED_VF_L2_QUE] = min_t(u32,
2229 RESC_NUM(p_hwfn, QED_L2_QUEUE),
2231 feat_num[QED_PF_L2_QUE] = min_t(u32,
2232 sb_cnt.cnt - non_l2_sbs,
2239 if (QED_IS_FCOE_PERSONALITY(p_hwfn))
2240 feat_num[QED_FCOE_CQ] = min_t(u32, sb_cnt.cnt,
2244 if (QED_IS_ISCSI_PERSONALITY(p_hwfn))
2245 feat_num[QED_ISCSI_CQ] = min_t(u32, sb_cnt.cnt,
2250 "#PF_L2_QUEUES=%d VF_L2_QUEUES=%d #ROCE_CNQ=%d FCOE_CQ=%d ISCSI_CQ=%d #SBS=%d\n",
2251 (int)FEAT_NUM(p_hwfn, QED_PF_L2_QUE),
2252 (int)FEAT_NUM(p_hwfn, QED_VF_L2_QUE),
2253 (int)FEAT_NUM(p_hwfn, QED_RDMA_CNQ),
2254 (int)FEAT_NUM(p_hwfn, QED_FCOE_CQ),
2255 (int)FEAT_NUM(p_hwfn, QED_ISCSI_CQ),
2259 const char *qed_hw_get_resc_name(enum qed_resources res_id)
2276 case QED_RDMA_CNQ_RAM:
2277 return "RDMA_CNQ_RAM";
2284 case QED_RDMA_STATS_QUEUE:
2285 return "RDMA_STATS_QUEUE";
2291 return "UNKNOWN_RESOURCE";
2296 __qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn,
2297 struct qed_ptt *p_ptt,
2298 enum qed_resources res_id,
2299 u32 resc_max_val, u32 *p_mcp_resp)
2303 rc = qed_mcp_set_resc_max_val(p_hwfn, p_ptt, res_id,
2304 resc_max_val, p_mcp_resp);
2307 "MFW response failure for a max value setting of resource %d [%s]\n",
2308 res_id, qed_hw_get_resc_name(res_id));
2312 if (*p_mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK)
2314 "Failed to set the max value of resource %d [%s]. mcp_resp = 0x%08x.\n",
2315 res_id, qed_hw_get_resc_name(res_id), *p_mcp_resp);
2321 qed_hw_set_soft_resc_size(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2323 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2324 u32 resc_max_val, mcp_resp;
2328 for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
2331 resc_max_val = MAX_NUM_LL2_RX_QUEUES;
2333 case QED_RDMA_CNQ_RAM:
2334 /* No need for a case for QED_CMDQS_CQS since
2335 * CNQ/CMDQS are the same resource.
2337 resc_max_val = NUM_OF_GLOBAL_QUEUES;
2339 case QED_RDMA_STATS_QUEUE:
2340 resc_max_val = b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2
2341 : RDMA_NUM_STATISTIC_COUNTERS_BB;
2344 resc_max_val = BDQ_NUM_RESOURCES;
2350 rc = __qed_hw_set_soft_resc_size(p_hwfn, p_ptt, res_id,
2351 resc_max_val, &mcp_resp);
2355 /* There's no point to continue to the next resource if the
2356 * command is not supported by the MFW.
2357 * We do continue if the command is supported but the resource
2358 * is unknown to the MFW. Such a resource will be later
2359 * configured with the default allocation values.
2361 if (mcp_resp == FW_MSG_CODE_UNSUPPORTED)
2369 int qed_hw_get_dflt_resc(struct qed_hwfn *p_hwfn,
2370 enum qed_resources res_id,
2371 u32 *p_resc_num, u32 *p_resc_start)
2373 u8 num_funcs = p_hwfn->num_funcs_on_engine;
2374 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2378 *p_resc_num = (b_ah ? MAX_NUM_L2_QUEUES_K2 :
2379 MAX_NUM_L2_QUEUES_BB) / num_funcs;
2382 *p_resc_num = (b_ah ? MAX_NUM_VPORTS_K2 :
2383 MAX_NUM_VPORTS_BB) / num_funcs;
2386 *p_resc_num = (b_ah ? ETH_RSS_ENGINE_NUM_K2 :
2387 ETH_RSS_ENGINE_NUM_BB) / num_funcs;
2390 *p_resc_num = (b_ah ? MAX_QM_TX_QUEUES_K2 :
2391 MAX_QM_TX_QUEUES_BB) / num_funcs;
2392 *p_resc_num &= ~0x7; /* The granularity of the PQs is 8 */
2395 *p_resc_num = MAX_QM_GLOBAL_RLS / num_funcs;
2399 /* Each VFC resource can accommodate both a MAC and a VLAN */
2400 *p_resc_num = ETH_NUM_MAC_FILTERS / num_funcs;
2403 *p_resc_num = (b_ah ? PXP_NUM_ILT_RECORDS_K2 :
2404 PXP_NUM_ILT_RECORDS_BB) / num_funcs;
2407 *p_resc_num = MAX_NUM_LL2_RX_QUEUES / num_funcs;
2409 case QED_RDMA_CNQ_RAM:
2411 /* CNQ/CMDQS are the same resource */
2412 *p_resc_num = NUM_OF_GLOBAL_QUEUES / num_funcs;
2414 case QED_RDMA_STATS_QUEUE:
2415 *p_resc_num = (b_ah ? RDMA_NUM_STATISTIC_COUNTERS_K2 :
2416 RDMA_NUM_STATISTIC_COUNTERS_BB) / num_funcs;
2419 if (p_hwfn->hw_info.personality != QED_PCI_ISCSI &&
2420 p_hwfn->hw_info.personality != QED_PCI_FCOE)
2426 /* Since we want its value to reflect whether MFW supports
2427 * the new scheme, have a default of 0.
2439 else if (p_hwfn->cdev->num_ports_in_engine == 4)
2440 *p_resc_start = p_hwfn->port_id;
2441 else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
2442 *p_resc_start = p_hwfn->port_id;
2443 else if (p_hwfn->hw_info.personality == QED_PCI_FCOE)
2444 *p_resc_start = p_hwfn->port_id + 2;
2447 *p_resc_start = *p_resc_num * p_hwfn->enabled_func_idx;
2454 static int __qed_hw_set_resc_info(struct qed_hwfn *p_hwfn,
2455 enum qed_resources res_id)
2457 u32 dflt_resc_num = 0, dflt_resc_start = 0;
2458 u32 mcp_resp, *p_resc_num, *p_resc_start;
2461 p_resc_num = &RESC_NUM(p_hwfn, res_id);
2462 p_resc_start = &RESC_START(p_hwfn, res_id);
2464 rc = qed_hw_get_dflt_resc(p_hwfn, res_id, &dflt_resc_num,
2468 "Failed to get default amount for resource %d [%s]\n",
2469 res_id, qed_hw_get_resc_name(res_id));
2473 rc = qed_mcp_get_resc_info(p_hwfn, p_hwfn->p_main_ptt, res_id,
2474 &mcp_resp, p_resc_num, p_resc_start);
2477 "MFW response failure for an allocation request for resource %d [%s]\n",
2478 res_id, qed_hw_get_resc_name(res_id));
2482 /* Default driver values are applied in the following cases:
2483 * - The resource allocation MB command is not supported by the MFW
2484 * - There is an internal error in the MFW while processing the request
2485 * - The resource ID is unknown to the MFW
2487 if (mcp_resp != FW_MSG_CODE_RESOURCE_ALLOC_OK) {
2489 "Failed to receive allocation info for resource %d [%s]. mcp_resp = 0x%x. Applying default values [%d,%d].\n",
2491 qed_hw_get_resc_name(res_id),
2492 mcp_resp, dflt_resc_num, dflt_resc_start);
2493 *p_resc_num = dflt_resc_num;
2494 *p_resc_start = dflt_resc_start;
2499 /* PQs have to divide by 8 [that's the HW granularity].
2500 * Reduce number so it would fit.
2502 if ((res_id == QED_PQ) && ((*p_resc_num % 8) || (*p_resc_start % 8))) {
2504 "PQs need to align by 8; Number %08x --> %08x, Start %08x --> %08x\n",
2506 (*p_resc_num) & ~0x7,
2507 *p_resc_start, (*p_resc_start) & ~0x7);
2508 *p_resc_num &= ~0x7;
2509 *p_resc_start &= ~0x7;
2515 static int qed_hw_set_resc_info(struct qed_hwfn *p_hwfn)
2520 for (res_id = 0; res_id < QED_MAX_RESC; res_id++) {
2521 rc = __qed_hw_set_resc_info(p_hwfn, res_id);
2529 static int qed_hw_get_resc(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2531 struct qed_resc_unlock_params resc_unlock_params;
2532 struct qed_resc_lock_params resc_lock_params;
2533 bool b_ah = QED_IS_AH(p_hwfn->cdev);
2537 /* Setting the max values of the soft resources and the following
2538 * resources allocation queries should be atomic. Since several PFs can
2539 * run in parallel - a resource lock is needed.
2540 * If either the resource lock or resource set value commands are not
2541 * supported - skip the the max values setting, release the lock if
2542 * needed, and proceed to the queries. Other failures, including a
2543 * failure to acquire the lock, will cause this function to fail.
2545 qed_mcp_resc_lock_default_init(&resc_lock_params, &resc_unlock_params,
2546 QED_RESC_LOCK_RESC_ALLOC, false);
2548 rc = qed_mcp_resc_lock(p_hwfn, p_ptt, &resc_lock_params);
2549 if (rc && rc != -EINVAL) {
2551 } else if (rc == -EINVAL) {
2553 "Skip the max values setting of the soft resources since the resource lock is not supported by the MFW\n");
2554 } else if (!rc && !resc_lock_params.b_granted) {
2556 "Failed to acquire the resource lock for the resource allocation commands\n");
2559 rc = qed_hw_set_soft_resc_size(p_hwfn, p_ptt);
2560 if (rc && rc != -EINVAL) {
2562 "Failed to set the max values of the soft resources\n");
2563 goto unlock_and_exit;
2564 } else if (rc == -EINVAL) {
2566 "Skip the max values setting of the soft resources since it is not supported by the MFW\n");
2567 rc = qed_mcp_resc_unlock(p_hwfn, p_ptt,
2568 &resc_unlock_params);
2571 "Failed to release the resource lock for the resource allocation commands\n");
2575 rc = qed_hw_set_resc_info(p_hwfn);
2577 goto unlock_and_exit;
2579 if (resc_lock_params.b_granted && !resc_unlock_params.b_released) {
2580 rc = qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
2583 "Failed to release the resource lock for the resource allocation commands\n");
2586 /* Sanity for ILT */
2587 if ((b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_K2)) ||
2588 (!b_ah && (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB))) {
2589 DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
2590 RESC_START(p_hwfn, QED_ILT),
2591 RESC_END(p_hwfn, QED_ILT) - 1);
2595 /* This will also learn the number of SBs from MFW */
2596 if (qed_int_igu_reset_cam(p_hwfn, p_ptt))
2599 qed_hw_set_feat(p_hwfn);
2601 for (res_id = 0; res_id < QED_MAX_RESC; res_id++)
2602 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE, "%s = %d start = %d\n",
2603 qed_hw_get_resc_name(res_id),
2604 RESC_NUM(p_hwfn, res_id),
2605 RESC_START(p_hwfn, res_id));
2610 if (resc_lock_params.b_granted && !resc_unlock_params.b_released)
2611 qed_mcp_resc_unlock(p_hwfn, p_ptt, &resc_unlock_params);
2615 static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2617 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
2618 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
2619 struct qed_mcp_link_capabilities *p_caps;
2620 struct qed_mcp_link_params *link;
2622 /* Read global nvm_cfg address */
2623 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
2625 /* Verify MCP has initialized it */
2626 if (!nvm_cfg_addr) {
2627 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
2631 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
2632 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
2634 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2635 offsetof(struct nvm_cfg1, glob) +
2636 offsetof(struct nvm_cfg1_glob, core_cfg);
2638 core_cfg = qed_rd(p_hwfn, p_ptt, addr);
2640 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
2641 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
2642 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
2643 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
2645 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
2646 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
2648 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
2649 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
2651 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
2652 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
2654 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
2655 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
2657 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
2658 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
2660 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
2661 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
2663 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
2664 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
2666 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X10G:
2667 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X10G;
2669 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
2670 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
2672 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X25G:
2673 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X25G;
2676 DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
2680 /* Read default link configuration */
2681 link = &p_hwfn->mcp_info->link_input;
2682 p_caps = &p_hwfn->mcp_info->link_capabilities;
2683 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2684 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
2685 link_temp = qed_rd(p_hwfn, p_ptt,
2687 offsetof(struct nvm_cfg1_port, speed_cap_mask));
2688 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
2689 link->speed.advertised_speeds = link_temp;
2691 link_temp = link->speed.advertised_speeds;
2692 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
2694 link_temp = qed_rd(p_hwfn, p_ptt,
2696 offsetof(struct nvm_cfg1_port, link_settings));
2697 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
2698 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
2699 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
2700 link->speed.autoneg = true;
2702 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
2703 link->speed.forced_speed = 1000;
2705 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
2706 link->speed.forced_speed = 10000;
2708 case NVM_CFG1_PORT_DRV_LINK_SPEED_20G:
2709 link->speed.forced_speed = 20000;
2711 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
2712 link->speed.forced_speed = 25000;
2714 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
2715 link->speed.forced_speed = 40000;
2717 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
2718 link->speed.forced_speed = 50000;
2720 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
2721 link->speed.forced_speed = 100000;
2724 DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
2727 p_hwfn->mcp_info->link_capabilities.default_speed_autoneg =
2728 link->speed.autoneg;
2730 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
2731 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
2732 link->pause.autoneg = !!(link_temp &
2733 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
2734 link->pause.forced_rx = !!(link_temp &
2735 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
2736 link->pause.forced_tx = !!(link_temp &
2737 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
2738 link->loopback_mode = 0;
2740 if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE) {
2741 link_temp = qed_rd(p_hwfn, p_ptt, port_cfg_addr +
2742 offsetof(struct nvm_cfg1_port, ext_phy));
2743 link_temp &= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_MASK;
2744 link_temp >>= NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_OFFSET;
2745 p_caps->default_eee = QED_MCP_EEE_ENABLED;
2746 link->eee.enable = true;
2747 switch (link_temp) {
2748 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_DISABLED:
2749 p_caps->default_eee = QED_MCP_EEE_DISABLED;
2750 link->eee.enable = false;
2752 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_BALANCED:
2753 p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_BALANCED_TIME;
2755 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_AGGRESSIVE:
2756 p_caps->eee_lpi_timer =
2757 EEE_TX_TIMER_USEC_AGGRESSIVE_TIME;
2759 case NVM_CFG1_PORT_EEE_POWER_SAVING_MODE_LOW_LATENCY:
2760 p_caps->eee_lpi_timer = EEE_TX_TIMER_USEC_LATENCY_TIME;
2764 link->eee.tx_lpi_timer = p_caps->eee_lpi_timer;
2765 link->eee.tx_lpi_enable = link->eee.enable;
2766 link->eee.adv_caps = QED_EEE_1G_ADV | QED_EEE_10G_ADV;
2768 p_caps->default_eee = QED_MCP_EEE_UNSUPPORTED;
2773 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x EEE: %02x [%08x usec]\n",
2774 link->speed.forced_speed,
2775 link->speed.advertised_speeds,
2776 link->speed.autoneg,
2777 link->pause.autoneg,
2778 p_caps->default_eee, p_caps->eee_lpi_timer);
2780 if (IS_LEAD_HWFN(p_hwfn)) {
2781 struct qed_dev *cdev = p_hwfn->cdev;
2783 /* Read Multi-function information from shmem */
2784 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2785 offsetof(struct nvm_cfg1, glob) +
2786 offsetof(struct nvm_cfg1_glob, generic_cont0);
2788 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
2790 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
2791 NVM_CFG1_GLOB_MF_MODE_OFFSET;
2794 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
2795 cdev->mf_bits = BIT(QED_MF_OVLAN_CLSS);
2797 case NVM_CFG1_GLOB_MF_MODE_UFP:
2798 cdev->mf_bits = BIT(QED_MF_OVLAN_CLSS) |
2799 BIT(QED_MF_LLH_PROTO_CLSS) |
2800 BIT(QED_MF_UFP_SPECIFIC) |
2801 BIT(QED_MF_8021Q_TAGGING);
2803 case NVM_CFG1_GLOB_MF_MODE_BD:
2804 cdev->mf_bits = BIT(QED_MF_OVLAN_CLSS) |
2805 BIT(QED_MF_LLH_PROTO_CLSS) |
2806 BIT(QED_MF_8021AD_TAGGING);
2808 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
2809 cdev->mf_bits = BIT(QED_MF_LLH_MAC_CLSS) |
2810 BIT(QED_MF_LLH_PROTO_CLSS) |
2811 BIT(QED_MF_LL2_NON_UNICAST) |
2812 BIT(QED_MF_INTER_PF_SWITCH);
2814 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
2815 cdev->mf_bits = BIT(QED_MF_LLH_MAC_CLSS) |
2816 BIT(QED_MF_LLH_PROTO_CLSS) |
2817 BIT(QED_MF_LL2_NON_UNICAST);
2818 if (QED_IS_BB(p_hwfn->cdev))
2819 cdev->mf_bits |= BIT(QED_MF_NEED_DEF_PF);
2823 DP_INFO(p_hwfn, "Multi function mode is 0x%lx\n",
2827 DP_INFO(p_hwfn, "Multi function mode is 0x%lx\n",
2828 p_hwfn->cdev->mf_bits);
2830 /* Read device capabilities information from shmem */
2831 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
2832 offsetof(struct nvm_cfg1, glob) +
2833 offsetof(struct nvm_cfg1_glob, device_capabilities);
2835 device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
2836 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
2837 __set_bit(QED_DEV_CAP_ETH,
2838 &p_hwfn->hw_info.device_capabilities);
2839 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_FCOE)
2840 __set_bit(QED_DEV_CAP_FCOE,
2841 &p_hwfn->hw_info.device_capabilities);
2842 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
2843 __set_bit(QED_DEV_CAP_ISCSI,
2844 &p_hwfn->hw_info.device_capabilities);
2845 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
2846 __set_bit(QED_DEV_CAP_ROCE,
2847 &p_hwfn->hw_info.device_capabilities);
2849 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
2852 static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2854 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
2855 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
2856 struct qed_dev *cdev = p_hwfn->cdev;
2858 num_funcs = QED_IS_AH(cdev) ? MAX_NUM_PFS_K2 : MAX_NUM_PFS_BB;
2860 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
2861 * in the other bits are selected.
2862 * Bits 1-15 are for functions 1-15, respectively, and their value is
2863 * '0' only for enabled functions (function 0 always exists and
2865 * In case of CMT, only the "even" functions are enabled, and thus the
2866 * number of functions for both hwfns is learnt from the same bits.
2868 reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
2870 if (reg_function_hide & 0x1) {
2871 if (QED_IS_BB(cdev)) {
2872 if (QED_PATH_ID(p_hwfn) && cdev->num_hwfns == 1) {
2884 /* Get the number of the enabled functions on the engine */
2885 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
2892 /* Get the PF index within the enabled functions */
2893 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
2894 tmp = reg_function_hide & eng_mask & low_pfs_mask;
2902 p_hwfn->num_funcs_on_engine = num_funcs;
2903 p_hwfn->enabled_func_idx = enabled_func_idx;
2907 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
2910 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
2913 static void qed_hw_info_port_num_bb(struct qed_hwfn *p_hwfn,
2914 struct qed_ptt *p_ptt)
2918 port_mode = qed_rd(p_hwfn, p_ptt, CNIG_REG_NW_PORT_MODE_BB);
2920 if (port_mode < 3) {
2921 p_hwfn->cdev->num_ports_in_engine = 1;
2922 } else if (port_mode <= 5) {
2923 p_hwfn->cdev->num_ports_in_engine = 2;
2925 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
2926 p_hwfn->cdev->num_ports_in_engine);
2928 /* Default num_ports_in_engine to something */
2929 p_hwfn->cdev->num_ports_in_engine = 1;
2933 static void qed_hw_info_port_num_ah(struct qed_hwfn *p_hwfn,
2934 struct qed_ptt *p_ptt)
2939 p_hwfn->cdev->num_ports_in_engine = 0;
2941 for (i = 0; i < MAX_NUM_PORTS_K2; i++) {
2942 port = qed_rd(p_hwfn, p_ptt,
2943 CNIG_REG_NIG_PORT0_CONF_K2 + (i * 4));
2945 p_hwfn->cdev->num_ports_in_engine++;
2948 if (!p_hwfn->cdev->num_ports_in_engine) {
2949 DP_NOTICE(p_hwfn, "All NIG ports are inactive\n");
2951 /* Default num_ports_in_engine to something */
2952 p_hwfn->cdev->num_ports_in_engine = 1;
2956 static void qed_hw_info_port_num(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2958 if (QED_IS_BB(p_hwfn->cdev))
2959 qed_hw_info_port_num_bb(p_hwfn, p_ptt);
2961 qed_hw_info_port_num_ah(p_hwfn, p_ptt);
2964 static void qed_get_eee_caps(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2966 struct qed_mcp_link_capabilities *p_caps;
2969 p_caps = &p_hwfn->mcp_info->link_capabilities;
2970 if (p_caps->default_eee == QED_MCP_EEE_UNSUPPORTED)
2973 p_caps->eee_speed_caps = 0;
2974 eee_status = qed_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
2975 offsetof(struct public_port, eee_status));
2976 eee_status = (eee_status & EEE_SUPPORTED_SPEED_MASK) >>
2977 EEE_SUPPORTED_SPEED_OFFSET;
2979 if (eee_status & EEE_1G_SUPPORTED)
2980 p_caps->eee_speed_caps |= QED_EEE_1G_ADV;
2981 if (eee_status & EEE_10G_ADV)
2982 p_caps->eee_speed_caps |= QED_EEE_10G_ADV;
2986 qed_get_hw_info(struct qed_hwfn *p_hwfn,
2987 struct qed_ptt *p_ptt,
2988 enum qed_pci_personality personality)
2992 /* Since all information is common, only first hwfns should do this */
2993 if (IS_LEAD_HWFN(p_hwfn)) {
2994 rc = qed_iov_hw_info(p_hwfn);
2999 qed_hw_info_port_num(p_hwfn, p_ptt);
3001 qed_mcp_get_capabilities(p_hwfn, p_ptt);
3003 qed_hw_get_nvm_info(p_hwfn, p_ptt);
3005 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
3009 if (qed_mcp_is_init(p_hwfn))
3010 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
3011 p_hwfn->mcp_info->func_info.mac);
3013 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
3015 if (qed_mcp_is_init(p_hwfn)) {
3016 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
3017 p_hwfn->hw_info.ovlan =
3018 p_hwfn->mcp_info->func_info.ovlan;
3020 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
3022 qed_get_eee_caps(p_hwfn, p_ptt);
3024 qed_mcp_read_ufp_config(p_hwfn, p_ptt);
3027 if (qed_mcp_is_init(p_hwfn)) {
3028 enum qed_pci_personality protocol;
3030 protocol = p_hwfn->mcp_info->func_info.protocol;
3031 p_hwfn->hw_info.personality = protocol;
3034 if (QED_IS_ROCE_PERSONALITY(p_hwfn))
3035 p_hwfn->hw_info.multi_tc_roce_en = 1;
3037 p_hwfn->hw_info.num_hw_tc = NUM_PHYS_TCS_4PORT_K2;
3038 p_hwfn->hw_info.num_active_tc = 1;
3040 qed_get_num_funcs(p_hwfn, p_ptt);
3042 if (qed_mcp_is_init(p_hwfn))
3043 p_hwfn->hw_info.mtu = p_hwfn->mcp_info->func_info.mtu;
3045 return qed_hw_get_resc(p_hwfn, p_ptt);
3048 static int qed_get_dev_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
3050 struct qed_dev *cdev = p_hwfn->cdev;
3054 /* Read Vendor Id / Device Id */
3055 pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
3056 pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
3058 /* Determine type */
3059 device_id_mask = cdev->device_id & QED_DEV_ID_MASK;
3060 switch (device_id_mask) {
3061 case QED_DEV_ID_MASK_BB:
3062 cdev->type = QED_DEV_TYPE_BB;
3064 case QED_DEV_ID_MASK_AH:
3065 cdev->type = QED_DEV_TYPE_AH;
3068 DP_NOTICE(p_hwfn, "Unknown device id 0x%x\n", cdev->device_id);
3072 cdev->chip_num = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_NUM);
3073 cdev->chip_rev = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_REV);
3075 MASK_FIELD(CHIP_REV, cdev->chip_rev);
3077 /* Learn number of HW-functions */
3078 tmp = qed_rd(p_hwfn, p_ptt, MISCS_REG_CMT_ENABLED_FOR_PAIR);
3080 if (tmp & (1 << p_hwfn->rel_pf_id)) {
3081 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
3082 cdev->num_hwfns = 2;
3084 cdev->num_hwfns = 1;
3087 cdev->chip_bond_id = qed_rd(p_hwfn, p_ptt,
3088 MISCS_REG_CHIP_TEST_REG) >> 4;
3089 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
3090 cdev->chip_metal = (u16)qed_rd(p_hwfn, p_ptt, MISCS_REG_CHIP_METAL);
3091 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
3093 DP_INFO(cdev->hwfns,
3094 "Chip details - %s %c%d, Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
3095 QED_IS_BB(cdev) ? "BB" : "AH",
3096 'A' + cdev->chip_rev,
3097 (int)cdev->chip_metal,
3098 cdev->chip_num, cdev->chip_rev,
3099 cdev->chip_bond_id, cdev->chip_metal);
3104 static void qed_nvm_info_free(struct qed_hwfn *p_hwfn)
3106 kfree(p_hwfn->nvm_info.image_att);
3107 p_hwfn->nvm_info.image_att = NULL;
3110 static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
3111 void __iomem *p_regview,
3112 void __iomem *p_doorbells,
3113 enum qed_pci_personality personality)
3117 /* Split PCI bars evenly between hwfns */
3118 p_hwfn->regview = p_regview;
3119 p_hwfn->doorbells = p_doorbells;
3121 if (IS_VF(p_hwfn->cdev))
3122 return qed_vf_hw_prepare(p_hwfn);
3124 /* Validate that chip access is feasible */
3125 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
3127 "Reading the ME register returns all Fs; Preventing further chip access\n");
3131 get_function_id(p_hwfn);
3133 /* Allocate PTT pool */
3134 rc = qed_ptt_pool_alloc(p_hwfn);
3138 /* Allocate the main PTT */
3139 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
3141 /* First hwfn learns basic information, e.g., number of hwfns */
3142 if (!p_hwfn->my_id) {
3143 rc = qed_get_dev_info(p_hwfn, p_hwfn->p_main_ptt);
3148 qed_hw_hwfn_prepare(p_hwfn);
3150 /* Initialize MCP structure */
3151 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
3153 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
3157 /* Read the device configuration information from the HW and SHMEM */
3158 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
3160 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
3164 /* Sending a mailbox to the MFW should be done after qed_get_hw_info()
3165 * is called as it sets the ports number in an engine.
3167 if (IS_LEAD_HWFN(p_hwfn)) {
3168 rc = qed_mcp_initiate_pf_flr(p_hwfn, p_hwfn->p_main_ptt);
3170 DP_NOTICE(p_hwfn, "Failed to initiate PF FLR\n");
3173 /* NVRAM info initialization and population */
3174 if (IS_LEAD_HWFN(p_hwfn)) {
3175 rc = qed_mcp_nvm_info_populate(p_hwfn);
3178 "Failed to populate nvm info shadow\n");
3183 /* Allocate the init RT array and initialize the init-ops engine */
3184 rc = qed_init_alloc(p_hwfn);
3190 if (IS_LEAD_HWFN(p_hwfn))
3191 qed_nvm_info_free(p_hwfn);
3193 if (IS_LEAD_HWFN(p_hwfn))
3194 qed_iov_free_hw_info(p_hwfn->cdev);
3195 qed_mcp_free(p_hwfn);
3197 qed_hw_hwfn_free(p_hwfn);
3202 int qed_hw_prepare(struct qed_dev *cdev,
3205 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
3208 /* Store the precompiled init data ptrs */
3210 qed_init_iro_array(cdev);
3212 /* Initialize the first hwfn - will learn number of hwfns */
3213 rc = qed_hw_prepare_single(p_hwfn,
3215 cdev->doorbells, personality);
3219 personality = p_hwfn->hw_info.personality;
3221 /* Initialize the rest of the hwfns */
3222 if (cdev->num_hwfns > 1) {
3223 void __iomem *p_regview, *p_doorbell;
3226 /* adjust bar offset for second engine */
3227 addr = cdev->regview +
3228 qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
3232 addr = cdev->doorbells +
3233 qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
3237 /* prepare second hw function */
3238 rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
3239 p_doorbell, personality);
3241 /* in case of error, need to free the previously
3242 * initiliazed hwfn 0.
3246 qed_init_free(p_hwfn);
3247 qed_nvm_info_free(p_hwfn);
3248 qed_mcp_free(p_hwfn);
3249 qed_hw_hwfn_free(p_hwfn);
3257 void qed_hw_remove(struct qed_dev *cdev)
3259 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
3263 qed_mcp_ov_update_driver_state(p_hwfn, p_hwfn->p_main_ptt,
3264 QED_OV_DRIVER_STATE_NOT_LOADED);
3266 for_each_hwfn(cdev, i) {
3267 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
3270 qed_vf_pf_release(p_hwfn);
3274 qed_init_free(p_hwfn);
3275 qed_hw_hwfn_free(p_hwfn);
3276 qed_mcp_free(p_hwfn);
3279 qed_iov_free_hw_info(cdev);
3281 qed_nvm_info_free(p_hwfn);
3284 static void qed_chain_free_next_ptr(struct qed_dev *cdev,
3285 struct qed_chain *p_chain)
3287 void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
3288 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
3289 struct qed_chain_next *p_next;
3295 size = p_chain->elem_size * p_chain->usable_per_page;
3297 for (i = 0; i < p_chain->page_cnt; i++) {
3301 p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
3302 p_virt_next = p_next->next_virt;
3303 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
3305 dma_free_coherent(&cdev->pdev->dev,
3306 QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
3308 p_virt = p_virt_next;
3309 p_phys = p_phys_next;
3313 static void qed_chain_free_single(struct qed_dev *cdev,
3314 struct qed_chain *p_chain)
3316 if (!p_chain->p_virt_addr)
3319 dma_free_coherent(&cdev->pdev->dev,
3320 QED_CHAIN_PAGE_SIZE,
3321 p_chain->p_virt_addr, p_chain->p_phys_addr);
3324 static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
3326 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
3327 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
3328 u8 *p_pbl_virt = p_chain->pbl_sp.p_virt_table;
3330 if (!pp_virt_addr_tbl)
3336 for (i = 0; i < page_cnt; i++) {
3337 if (!pp_virt_addr_tbl[i])
3340 dma_free_coherent(&cdev->pdev->dev,
3341 QED_CHAIN_PAGE_SIZE,
3342 pp_virt_addr_tbl[i],
3343 *(dma_addr_t *)p_pbl_virt);
3345 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
3348 pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
3350 if (!p_chain->b_external_pbl)
3351 dma_free_coherent(&cdev->pdev->dev,
3353 p_chain->pbl_sp.p_virt_table,
3354 p_chain->pbl_sp.p_phys_table);
3356 vfree(p_chain->pbl.pp_virt_addr_tbl);
3357 p_chain->pbl.pp_virt_addr_tbl = NULL;
3360 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
3362 switch (p_chain->mode) {
3363 case QED_CHAIN_MODE_NEXT_PTR:
3364 qed_chain_free_next_ptr(cdev, p_chain);
3366 case QED_CHAIN_MODE_SINGLE:
3367 qed_chain_free_single(cdev, p_chain);
3369 case QED_CHAIN_MODE_PBL:
3370 qed_chain_free_pbl(cdev, p_chain);
3376 qed_chain_alloc_sanity_check(struct qed_dev *cdev,
3377 enum qed_chain_cnt_type cnt_type,
3378 size_t elem_size, u32 page_cnt)
3380 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
3382 /* The actual chain size can be larger than the maximal possible value
3383 * after rounding up the requested elements number to pages, and after
3384 * taking into acount the unusuable elements (next-ptr elements).
3385 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
3386 * size/capacity fields are of a u32 type.
3388 if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
3389 chain_size > ((u32)U16_MAX + 1)) ||
3390 (cnt_type == QED_CHAIN_CNT_TYPE_U32 && chain_size > U32_MAX)) {
3392 "The actual chain size (0x%llx) is larger than the maximal possible value\n",
3401 qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
3403 void *p_virt = NULL, *p_virt_prev = NULL;
3404 dma_addr_t p_phys = 0;
3407 for (i = 0; i < p_chain->page_cnt; i++) {
3408 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3409 QED_CHAIN_PAGE_SIZE,
3410 &p_phys, GFP_KERNEL);
3415 qed_chain_init_mem(p_chain, p_virt, p_phys);
3416 qed_chain_reset(p_chain);
3418 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3422 p_virt_prev = p_virt;
3424 /* Last page's next element should point to the beginning of the
3427 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
3428 p_chain->p_virt_addr,
3429 p_chain->p_phys_addr);
3435 qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
3437 dma_addr_t p_phys = 0;
3438 void *p_virt = NULL;
3440 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3441 QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
3445 qed_chain_init_mem(p_chain, p_virt, p_phys);
3446 qed_chain_reset(p_chain);
3452 qed_chain_alloc_pbl(struct qed_dev *cdev,
3453 struct qed_chain *p_chain,
3454 struct qed_chain_ext_pbl *ext_pbl)
3456 u32 page_cnt = p_chain->page_cnt, size, i;
3457 dma_addr_t p_phys = 0, p_pbl_phys = 0;
3458 void **pp_virt_addr_tbl = NULL;
3459 u8 *p_pbl_virt = NULL;
3460 void *p_virt = NULL;
3462 size = page_cnt * sizeof(*pp_virt_addr_tbl);
3463 pp_virt_addr_tbl = vzalloc(size);
3464 if (!pp_virt_addr_tbl)
3467 /* The allocation of the PBL table is done with its full size, since it
3468 * is expected to be successive.
3469 * qed_chain_init_pbl_mem() is called even in a case of an allocation
3470 * failure, since pp_virt_addr_tbl was previously allocated, and it
3471 * should be saved to allow its freeing during the error flow.
3473 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
3476 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
3477 size, &p_pbl_phys, GFP_KERNEL);
3479 p_pbl_virt = ext_pbl->p_pbl_virt;
3480 p_pbl_phys = ext_pbl->p_pbl_phys;
3481 p_chain->b_external_pbl = true;
3484 qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
3489 for (i = 0; i < page_cnt; i++) {
3490 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
3491 QED_CHAIN_PAGE_SIZE,
3492 &p_phys, GFP_KERNEL);
3497 qed_chain_init_mem(p_chain, p_virt, p_phys);
3498 qed_chain_reset(p_chain);
3501 /* Fill the PBL table with the physical address of the page */
3502 *(dma_addr_t *)p_pbl_virt = p_phys;
3503 /* Keep the virtual address of the page */
3504 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
3506 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
3512 int qed_chain_alloc(struct qed_dev *cdev,
3513 enum qed_chain_use_mode intended_use,
3514 enum qed_chain_mode mode,
3515 enum qed_chain_cnt_type cnt_type,
3518 struct qed_chain *p_chain,
3519 struct qed_chain_ext_pbl *ext_pbl)
3524 if (mode == QED_CHAIN_MODE_SINGLE)
3527 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
3529 rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
3532 "Cannot allocate a chain with the given arguments:\n");
3534 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
3535 intended_use, mode, cnt_type, num_elems, elem_size);
3539 qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
3543 case QED_CHAIN_MODE_NEXT_PTR:
3544 rc = qed_chain_alloc_next_ptr(cdev, p_chain);
3546 case QED_CHAIN_MODE_SINGLE:
3547 rc = qed_chain_alloc_single(cdev, p_chain);
3549 case QED_CHAIN_MODE_PBL:
3550 rc = qed_chain_alloc_pbl(cdev, p_chain, ext_pbl);
3559 qed_chain_free(cdev, p_chain);
3563 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
3565 if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
3568 min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
3569 max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
3571 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
3577 *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
3582 int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
3584 if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
3587 min = (u8)RESC_START(p_hwfn, QED_VPORT);
3588 max = min + RESC_NUM(p_hwfn, QED_VPORT);
3590 "vport id [%d] is not valid, available indices [%d - %d]\n",
3596 *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
3601 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
3603 if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
3606 min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
3607 max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
3609 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
3615 *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
3620 static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low,
3623 *p_high = p_filter[1] | (p_filter[0] << 8);
3624 *p_low = p_filter[5] | (p_filter[4] << 8) |
3625 (p_filter[3] << 16) | (p_filter[2] << 24);
3628 int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
3629 struct qed_ptt *p_ptt, u8 *p_filter)
3631 u32 high = 0, low = 0, en;
3634 if (!test_bit(QED_MF_LLH_MAC_CLSS, &p_hwfn->cdev->mf_bits))
3637 qed_llh_mac_to_filter(&high, &low, p_filter);
3639 /* Find a free entry and utilize it */
3640 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3641 en = qed_rd(p_hwfn, p_ptt,
3642 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3645 qed_wr(p_hwfn, p_ptt,
3646 NIG_REG_LLH_FUNC_FILTER_VALUE +
3647 2 * i * sizeof(u32), low);
3648 qed_wr(p_hwfn, p_ptt,
3649 NIG_REG_LLH_FUNC_FILTER_VALUE +
3650 (2 * i + 1) * sizeof(u32), high);
3651 qed_wr(p_hwfn, p_ptt,
3652 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3653 qed_wr(p_hwfn, p_ptt,
3654 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3655 i * sizeof(u32), 0);
3656 qed_wr(p_hwfn, p_ptt,
3657 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3660 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3662 "Failed to find an empty LLH filter to utilize\n");
3666 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3667 "mac: %pM is added at %d\n",
3673 void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
3674 struct qed_ptt *p_ptt, u8 *p_filter)
3676 u32 high = 0, low = 0;
3679 if (!test_bit(QED_MF_LLH_MAC_CLSS, &p_hwfn->cdev->mf_bits))
3682 qed_llh_mac_to_filter(&high, &low, p_filter);
3684 /* Find the entry and clean it */
3685 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3686 if (qed_rd(p_hwfn, p_ptt,
3687 NIG_REG_LLH_FUNC_FILTER_VALUE +
3688 2 * i * sizeof(u32)) != low)
3690 if (qed_rd(p_hwfn, p_ptt,
3691 NIG_REG_LLH_FUNC_FILTER_VALUE +
3692 (2 * i + 1) * sizeof(u32)) != high)
3695 qed_wr(p_hwfn, p_ptt,
3696 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3697 qed_wr(p_hwfn, p_ptt,
3698 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
3699 qed_wr(p_hwfn, p_ptt,
3700 NIG_REG_LLH_FUNC_FILTER_VALUE +
3701 (2 * i + 1) * sizeof(u32), 0);
3703 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3704 "mac: %pM is removed from %d\n",
3708 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3709 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
3713 qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn,
3714 struct qed_ptt *p_ptt,
3715 u16 source_port_or_eth_type,
3716 u16 dest_port, enum qed_llh_port_filter_type_t type)
3718 u32 high = 0, low = 0, en;
3721 if (!test_bit(QED_MF_LLH_PROTO_CLSS, &p_hwfn->cdev->mf_bits))
3725 case QED_LLH_FILTER_ETHERTYPE:
3726 high = source_port_or_eth_type;
3728 case QED_LLH_FILTER_TCP_SRC_PORT:
3729 case QED_LLH_FILTER_UDP_SRC_PORT:
3730 low = source_port_or_eth_type << 16;
3732 case QED_LLH_FILTER_TCP_DEST_PORT:
3733 case QED_LLH_FILTER_UDP_DEST_PORT:
3736 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3737 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3738 low = (source_port_or_eth_type << 16) | dest_port;
3742 "Non valid LLH protocol filter type %d\n", type);
3745 /* Find a free entry and utilize it */
3746 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3747 en = qed_rd(p_hwfn, p_ptt,
3748 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
3751 qed_wr(p_hwfn, p_ptt,
3752 NIG_REG_LLH_FUNC_FILTER_VALUE +
3753 2 * i * sizeof(u32), low);
3754 qed_wr(p_hwfn, p_ptt,
3755 NIG_REG_LLH_FUNC_FILTER_VALUE +
3756 (2 * i + 1) * sizeof(u32), high);
3757 qed_wr(p_hwfn, p_ptt,
3758 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 1);
3759 qed_wr(p_hwfn, p_ptt,
3760 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3761 i * sizeof(u32), 1 << type);
3762 qed_wr(p_hwfn, p_ptt,
3763 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
3766 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
3768 "Failed to find an empty LLH filter to utilize\n");
3772 case QED_LLH_FILTER_ETHERTYPE:
3773 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3774 "ETH type %x is added at %d\n",
3775 source_port_or_eth_type, i);
3777 case QED_LLH_FILTER_TCP_SRC_PORT:
3778 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3779 "TCP src port %x is added at %d\n",
3780 source_port_or_eth_type, i);
3782 case QED_LLH_FILTER_UDP_SRC_PORT:
3783 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3784 "UDP src port %x is added at %d\n",
3785 source_port_or_eth_type, i);
3787 case QED_LLH_FILTER_TCP_DEST_PORT:
3788 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3789 "TCP dst port %x is added at %d\n", dest_port, i);
3791 case QED_LLH_FILTER_UDP_DEST_PORT:
3792 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3793 "UDP dst port %x is added at %d\n", dest_port, i);
3795 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3796 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3797 "TCP src/dst ports %x/%x are added at %d\n",
3798 source_port_or_eth_type, dest_port, i);
3800 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3801 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
3802 "UDP src/dst ports %x/%x are added at %d\n",
3803 source_port_or_eth_type, dest_port, i);
3810 qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn,
3811 struct qed_ptt *p_ptt,
3812 u16 source_port_or_eth_type,
3814 enum qed_llh_port_filter_type_t type)
3816 u32 high = 0, low = 0;
3819 if (!test_bit(QED_MF_LLH_PROTO_CLSS, &p_hwfn->cdev->mf_bits))
3823 case QED_LLH_FILTER_ETHERTYPE:
3824 high = source_port_or_eth_type;
3826 case QED_LLH_FILTER_TCP_SRC_PORT:
3827 case QED_LLH_FILTER_UDP_SRC_PORT:
3828 low = source_port_or_eth_type << 16;
3830 case QED_LLH_FILTER_TCP_DEST_PORT:
3831 case QED_LLH_FILTER_UDP_DEST_PORT:
3834 case QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT:
3835 case QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT:
3836 low = (source_port_or_eth_type << 16) | dest_port;
3840 "Non valid LLH protocol filter type %d\n", type);
3844 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
3845 if (!qed_rd(p_hwfn, p_ptt,
3846 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32)))
3848 if (!qed_rd(p_hwfn, p_ptt,
3849 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32)))
3851 if (!(qed_rd(p_hwfn, p_ptt,
3852 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3853 i * sizeof(u32)) & BIT(type)))
3855 if (qed_rd(p_hwfn, p_ptt,
3856 NIG_REG_LLH_FUNC_FILTER_VALUE +
3857 2 * i * sizeof(u32)) != low)
3859 if (qed_rd(p_hwfn, p_ptt,
3860 NIG_REG_LLH_FUNC_FILTER_VALUE +
3861 (2 * i + 1) * sizeof(u32)) != high)
3864 qed_wr(p_hwfn, p_ptt,
3865 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
3866 qed_wr(p_hwfn, p_ptt,
3867 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
3868 qed_wr(p_hwfn, p_ptt,
3869 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
3870 i * sizeof(u32), 0);
3871 qed_wr(p_hwfn, p_ptt,
3872 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
3873 qed_wr(p_hwfn, p_ptt,
3874 NIG_REG_LLH_FUNC_FILTER_VALUE +
3875 (2 * i + 1) * sizeof(u32), 0);
3879 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
3880 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
3883 static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
3884 u32 hw_addr, void *p_eth_qzone,
3885 size_t eth_qzone_size, u8 timeset)
3887 struct coalescing_timeset *p_coal_timeset;
3889 if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
3890 DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
3894 p_coal_timeset = p_eth_qzone;
3895 memset(p_eth_qzone, 0, eth_qzone_size);
3896 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
3897 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
3898 qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
3903 int qed_set_queue_coalesce(u16 rx_coal, u16 tx_coal, void *p_handle)
3905 struct qed_queue_cid *p_cid = p_handle;
3906 struct qed_hwfn *p_hwfn;
3907 struct qed_ptt *p_ptt;
3910 p_hwfn = p_cid->p_owner;
3912 if (IS_VF(p_hwfn->cdev))
3913 return qed_vf_pf_set_coalesce(p_hwfn, rx_coal, tx_coal, p_cid);
3915 p_ptt = qed_ptt_acquire(p_hwfn);
3920 rc = qed_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
3923 p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
3927 rc = qed_set_txq_coalesce(p_hwfn, p_ptt, tx_coal, p_cid);
3930 p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
3933 qed_ptt_release(p_hwfn, p_ptt);
3937 int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn,
3938 struct qed_ptt *p_ptt,
3939 u16 coalesce, struct qed_queue_cid *p_cid)
3941 struct ustorm_eth_queue_zone eth_qzone;
3942 u8 timeset, timer_res;
3946 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
3947 if (coalesce <= 0x7F) {
3949 } else if (coalesce <= 0xFF) {
3951 } else if (coalesce <= 0x1FF) {
3954 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
3957 timeset = (u8)(coalesce >> timer_res);
3959 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res,
3960 p_cid->sb_igu_id, false);
3964 address = BAR0_MAP_REG_USDM_RAM +
3965 USTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
3967 rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
3968 sizeof(struct ustorm_eth_queue_zone), timeset);
3976 int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn,
3977 struct qed_ptt *p_ptt,
3978 u16 coalesce, struct qed_queue_cid *p_cid)
3980 struct xstorm_eth_queue_zone eth_qzone;
3981 u8 timeset, timer_res;
3985 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
3986 if (coalesce <= 0x7F) {
3988 } else if (coalesce <= 0xFF) {
3990 } else if (coalesce <= 0x1FF) {
3993 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
3996 timeset = (u8)(coalesce >> timer_res);
3998 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res,
3999 p_cid->sb_igu_id, true);
4003 address = BAR0_MAP_REG_XSDM_RAM +
4004 XSTORM_ETH_QUEUE_ZONE_OFFSET(p_cid->abs.queue_id);
4006 rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
4007 sizeof(struct xstorm_eth_queue_zone), timeset);
4012 /* Calculate final WFQ values for all vports and configure them.
4013 * After this configuration each vport will have
4014 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
4016 static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
4017 struct qed_ptt *p_ptt,
4020 struct init_qm_vport_params *vport_params;
4023 vport_params = p_hwfn->qm_info.qm_vport_params;
4025 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4026 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4028 vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
4030 qed_init_vport_wfq(p_hwfn, p_ptt,
4031 vport_params[i].first_tx_pq_id,
4032 vport_params[i].vport_wfq);
4036 static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
4042 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
4043 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
4046 static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
4047 struct qed_ptt *p_ptt,
4050 struct init_qm_vport_params *vport_params;
4053 vport_params = p_hwfn->qm_info.qm_vport_params;
4055 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4056 qed_init_wfq_default_param(p_hwfn, min_pf_rate);
4057 qed_init_vport_wfq(p_hwfn, p_ptt,
4058 vport_params[i].first_tx_pq_id,
4059 vport_params[i].vport_wfq);
4063 /* This function performs several validations for WFQ
4064 * configuration and required min rate for a given vport
4065 * 1. req_rate must be greater than one percent of min_pf_rate.
4066 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
4067 * rates to get less than one percent of min_pf_rate.
4068 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
4070 static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
4071 u16 vport_id, u32 req_rate, u32 min_pf_rate)
4073 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
4074 int non_requested_count = 0, req_count = 0, i, num_vports;
4076 num_vports = p_hwfn->qm_info.num_vports;
4078 /* Accounting for the vports which are configured for WFQ explicitly */
4079 for (i = 0; i < num_vports; i++) {
4082 if ((i != vport_id) &&
4083 p_hwfn->qm_info.wfq_data[i].configured) {
4085 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
4086 total_req_min_rate += tmp_speed;
4090 /* Include current vport data as well */
4092 total_req_min_rate += req_rate;
4093 non_requested_count = num_vports - req_count;
4095 if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
4096 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4097 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4098 vport_id, req_rate, min_pf_rate);
4102 if (num_vports > QED_WFQ_UNIT) {
4103 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4104 "Number of vports is greater than %d\n",
4109 if (total_req_min_rate > min_pf_rate) {
4110 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4111 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
4112 total_req_min_rate, min_pf_rate);
4116 total_left_rate = min_pf_rate - total_req_min_rate;
4118 left_rate_per_vp = total_left_rate / non_requested_count;
4119 if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
4120 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4121 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
4122 left_rate_per_vp, min_pf_rate);
4126 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
4127 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
4129 for (i = 0; i < num_vports; i++) {
4130 if (p_hwfn->qm_info.wfq_data[i].configured)
4133 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
4139 static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
4140 struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
4142 struct qed_mcp_link_state *p_link;
4145 p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
4147 if (!p_link->min_pf_rate) {
4148 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
4149 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
4153 rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
4156 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
4157 p_link->min_pf_rate);
4160 "Validation failed while configuring min rate\n");
4165 static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
4166 struct qed_ptt *p_ptt,
4169 bool use_wfq = false;
4173 /* Validate all pre configured vports for wfq */
4174 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
4177 if (!p_hwfn->qm_info.wfq_data[i].configured)
4180 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
4183 rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
4186 "WFQ validation failed while configuring min rate\n");
4192 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4194 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
4199 /* Main API for qed clients to configure vport min rate.
4200 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
4201 * rate - Speed in Mbps needs to be assigned to a given vport.
4203 int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
4205 int i, rc = -EINVAL;
4207 /* Currently not supported; Might change in future */
4208 if (cdev->num_hwfns > 1) {
4210 "WFQ configuration is not supported for this device\n");
4214 for_each_hwfn(cdev, i) {
4215 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4216 struct qed_ptt *p_ptt;
4218 p_ptt = qed_ptt_acquire(p_hwfn);
4222 rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
4225 qed_ptt_release(p_hwfn, p_ptt);
4229 qed_ptt_release(p_hwfn, p_ptt);
4235 /* API to configure WFQ from mcp link change */
4236 void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev,
4237 struct qed_ptt *p_ptt, u32 min_pf_rate)
4241 if (cdev->num_hwfns > 1) {
4244 "WFQ configuration is not supported for this device\n");
4248 for_each_hwfn(cdev, i) {
4249 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4251 __qed_configure_vp_wfq_on_link_change(p_hwfn, p_ptt,
4256 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
4257 struct qed_ptt *p_ptt,
4258 struct qed_mcp_link_state *p_link,
4263 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
4265 if (!p_link->line_speed && (max_bw != 100))
4268 p_link->speed = (p_link->line_speed * max_bw) / 100;
4269 p_hwfn->qm_info.pf_rl = p_link->speed;
4271 /* Since the limiter also affects Tx-switched traffic, we don't want it
4272 * to limit such traffic in case there's no actual limit.
4273 * In that case, set limit to imaginary high boundary.
4276 p_hwfn->qm_info.pf_rl = 100000;
4278 rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
4279 p_hwfn->qm_info.pf_rl);
4281 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4282 "Configured MAX bandwidth to be %08x Mb/sec\n",
4288 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
4289 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
4291 int i, rc = -EINVAL;
4293 if (max_bw < 1 || max_bw > 100) {
4294 DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
4298 for_each_hwfn(cdev, i) {
4299 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4300 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
4301 struct qed_mcp_link_state *p_link;
4302 struct qed_ptt *p_ptt;
4304 p_link = &p_lead->mcp_info->link_output;
4306 p_ptt = qed_ptt_acquire(p_hwfn);
4310 rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
4313 qed_ptt_release(p_hwfn, p_ptt);
4322 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
4323 struct qed_ptt *p_ptt,
4324 struct qed_mcp_link_state *p_link,
4329 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
4330 p_hwfn->qm_info.pf_wfq = min_bw;
4332 if (!p_link->line_speed)
4335 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
4337 rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
4339 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
4340 "Configured MIN bandwidth to be %d Mb/sec\n",
4341 p_link->min_pf_rate);
4346 /* Main API to configure PF min bandwidth where bw range is [1-100] */
4347 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
4349 int i, rc = -EINVAL;
4351 if (min_bw < 1 || min_bw > 100) {
4352 DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
4356 for_each_hwfn(cdev, i) {
4357 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
4358 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
4359 struct qed_mcp_link_state *p_link;
4360 struct qed_ptt *p_ptt;
4362 p_link = &p_lead->mcp_info->link_output;
4364 p_ptt = qed_ptt_acquire(p_hwfn);
4368 rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
4371 qed_ptt_release(p_hwfn, p_ptt);
4375 if (p_link->min_pf_rate) {
4376 u32 min_rate = p_link->min_pf_rate;
4378 rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
4383 qed_ptt_release(p_hwfn, p_ptt);
4389 void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
4391 struct qed_mcp_link_state *p_link;
4393 p_link = &p_hwfn->mcp_info->link_output;
4395 if (p_link->min_pf_rate)
4396 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
4397 p_link->min_pf_rate);
4399 memset(p_hwfn->qm_info.wfq_data, 0,
4400 sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);
4403 int qed_device_num_engines(struct qed_dev *cdev)
4405 return QED_IS_BB(cdev) ? 2 : 1;
4408 static int qed_device_num_ports(struct qed_dev *cdev)
4410 /* in CMT always only one port */
4411 if (cdev->num_hwfns > 1)
4414 return cdev->num_ports_in_engine * qed_device_num_engines(cdev);
4417 int qed_device_get_port_id(struct qed_dev *cdev)
4419 return (QED_LEADING_HWFN(cdev)->abs_pf_id) % qed_device_num_ports(cdev);
4422 void qed_set_fw_mac_addr(__le16 *fw_msb,
4423 __le16 *fw_mid, __le16 *fw_lsb, u8 *mac)
4425 ((u8 *)fw_msb)[0] = mac[1];
4426 ((u8 *)fw_msb)[1] = mac[0];
4427 ((u8 *)fw_mid)[0] = mac[3];
4428 ((u8 *)fw_mid)[1] = mac[2];
4429 ((u8 *)fw_lsb)[0] = mac[5];
4430 ((u8 *)fw_lsb)[1] = mac[4];