1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/types.h>
10 #include <asm/byteorder.h>
12 #include <linux/delay.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/mutex.h>
17 #include <linux/pci.h>
18 #include <linux/slab.h>
19 #include <linux/string.h>
20 #include <linux/vmalloc.h>
21 #include <linux/etherdevice.h>
22 #include <linux/qed/qed_chain.h>
23 #include <linux/qed/qed_if.h>
27 #include "qed_dev_api.h"
30 #include "qed_init_ops.h"
34 #include "qed_reg_addr.h"
36 #include "qed_sriov.h"
39 static DEFINE_SPINLOCK(qm_lock);
41 /* API common to all protocols */
43 BAR_ID_0, /* used for GRC */
44 BAR_ID_1 /* Used for doorbells */
47 static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
49 u32 bar_reg = (bar_id == BAR_ID_0 ?
50 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
53 if (IS_VF(p_hwfn->cdev))
56 val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
58 return 1 << (val + 15);
60 /* Old MFW initialized above registered only conditionally */
61 if (p_hwfn->cdev->num_hwfns > 1) {
63 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
64 return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
67 "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
72 void qed_init_dp(struct qed_dev *cdev, u32 dp_module, u8 dp_level)
76 cdev->dp_level = dp_level;
77 cdev->dp_module = dp_module;
78 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
79 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
81 p_hwfn->dp_level = dp_level;
82 p_hwfn->dp_module = dp_module;
86 void qed_init_struct(struct qed_dev *cdev)
90 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
91 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
95 p_hwfn->b_active = false;
97 mutex_init(&p_hwfn->dmae_info.mutex);
100 /* hwfn 0 is always active */
101 cdev->hwfns[0].b_active = true;
103 /* set the default cache alignment to 128 */
104 cdev->cache_shift = 7;
107 static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
109 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
111 kfree(qm_info->qm_pq_params);
112 qm_info->qm_pq_params = NULL;
113 kfree(qm_info->qm_vport_params);
114 qm_info->qm_vport_params = NULL;
115 kfree(qm_info->qm_port_params);
116 qm_info->qm_port_params = NULL;
117 kfree(qm_info->wfq_data);
118 qm_info->wfq_data = NULL;
121 void qed_resc_free(struct qed_dev *cdev)
128 kfree(cdev->fw_data);
129 cdev->fw_data = NULL;
131 kfree(cdev->reset_stats);
133 for_each_hwfn(cdev, i) {
134 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
136 kfree(p_hwfn->p_tx_cids);
137 p_hwfn->p_tx_cids = NULL;
138 kfree(p_hwfn->p_rx_cids);
139 p_hwfn->p_rx_cids = NULL;
142 for_each_hwfn(cdev, i) {
143 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
145 qed_cxt_mngr_free(p_hwfn);
146 qed_qm_info_free(p_hwfn);
147 qed_spq_free(p_hwfn);
148 qed_eq_free(p_hwfn, p_hwfn->p_eq);
149 qed_consq_free(p_hwfn, p_hwfn->p_consq);
150 qed_int_free(p_hwfn);
151 #ifdef CONFIG_QED_LL2
152 qed_ll2_free(p_hwfn, p_hwfn->p_ll2_info);
154 qed_iov_free(p_hwfn);
155 qed_dmae_info_free(p_hwfn);
156 qed_dcbx_info_free(p_hwfn, p_hwfn->p_dcbx_info);
160 static int qed_init_qm_info(struct qed_hwfn *p_hwfn, bool b_sleepable)
162 u8 num_vports, vf_offset = 0, i, vport_id, num_ports, curr_queue = 0;
163 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
164 struct init_qm_port_params *p_qm_port;
165 bool init_rdma_offload_pq = false;
166 bool init_pure_ack_pq = false;
167 bool init_ooo_pq = false;
168 u16 num_pqs, multi_cos_tcs = 1;
169 u8 pf_wfq = qm_info->pf_wfq;
170 u32 pf_rl = qm_info->pf_rl;
174 #ifdef CONFIG_QED_SRIOV
175 if (p_hwfn->cdev->p_iov_info)
176 num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
178 memset(qm_info, 0, sizeof(*qm_info));
180 num_pqs = multi_cos_tcs + num_vfs + 1; /* The '1' is for pure-LB */
181 num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
183 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
184 num_pqs++; /* for RoCE queue */
185 init_rdma_offload_pq = true;
186 /* we subtract num_vfs because each require a rate limiter,
187 * and one default rate limiter
189 if (p_hwfn->pf_params.rdma_pf_params.enable_dcqcn)
190 num_pf_rls = RESC_NUM(p_hwfn, QED_RL) - num_vfs - 1;
192 num_pqs += num_pf_rls;
193 qm_info->num_pf_rls = (u8) num_pf_rls;
196 if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
197 num_pqs += 2; /* for iSCSI pure-ACK / OOO queue */
198 init_pure_ack_pq = true;
202 /* Sanity checking that setup requires legal number of resources */
203 if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
205 "Need too many Physical queues - 0x%04x when only %04x are available\n",
206 num_pqs, RESC_NUM(p_hwfn, QED_PQ));
210 /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
212 qm_info->qm_pq_params = kcalloc(num_pqs,
213 sizeof(struct init_qm_pq_params),
214 b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
215 if (!qm_info->qm_pq_params)
218 qm_info->qm_vport_params = kcalloc(num_vports,
219 sizeof(struct init_qm_vport_params),
220 b_sleepable ? GFP_KERNEL
222 if (!qm_info->qm_vport_params)
225 qm_info->qm_port_params = kcalloc(MAX_NUM_PORTS,
226 sizeof(struct init_qm_port_params),
227 b_sleepable ? GFP_KERNEL
229 if (!qm_info->qm_port_params)
232 qm_info->wfq_data = kcalloc(num_vports, sizeof(struct qed_wfq_data),
233 b_sleepable ? GFP_KERNEL : GFP_ATOMIC);
234 if (!qm_info->wfq_data)
237 vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
239 /* First init rate limited queues */
240 for (curr_queue = 0; curr_queue < num_pf_rls; curr_queue++) {
241 qm_info->qm_pq_params[curr_queue].vport_id = vport_id++;
242 qm_info->qm_pq_params[curr_queue].tc_id =
243 p_hwfn->hw_info.non_offload_tc;
244 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
245 qm_info->qm_pq_params[curr_queue].rl_valid = 1;
248 /* First init per-TC PQs */
249 for (i = 0; i < multi_cos_tcs; i++) {
250 struct init_qm_pq_params *params =
251 &qm_info->qm_pq_params[curr_queue++];
253 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE ||
254 p_hwfn->hw_info.personality == QED_PCI_ETH) {
255 params->vport_id = vport_id;
256 params->tc_id = p_hwfn->hw_info.non_offload_tc;
257 params->wrr_group = 1;
259 params->vport_id = vport_id;
260 params->tc_id = p_hwfn->hw_info.offload_tc;
261 params->wrr_group = 1;
265 /* Then init pure-LB PQ */
266 qm_info->pure_lb_pq = curr_queue;
267 qm_info->qm_pq_params[curr_queue].vport_id =
268 (u8) RESC_START(p_hwfn, QED_VPORT);
269 qm_info->qm_pq_params[curr_queue].tc_id = PURE_LB_TC;
270 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
273 qm_info->offload_pq = 0;
274 if (init_rdma_offload_pq) {
275 qm_info->offload_pq = curr_queue;
276 qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
277 qm_info->qm_pq_params[curr_queue].tc_id =
278 p_hwfn->hw_info.offload_tc;
279 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
283 if (init_pure_ack_pq) {
284 qm_info->pure_ack_pq = curr_queue;
285 qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
286 qm_info->qm_pq_params[curr_queue].tc_id =
287 p_hwfn->hw_info.offload_tc;
288 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
293 qm_info->ooo_pq = curr_queue;
294 qm_info->qm_pq_params[curr_queue].vport_id = vport_id;
295 qm_info->qm_pq_params[curr_queue].tc_id = DCBX_ISCSI_OOO_TC;
296 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
300 /* Then init per-VF PQs */
301 vf_offset = curr_queue;
302 for (i = 0; i < num_vfs; i++) {
303 /* First vport is used by the PF */
304 qm_info->qm_pq_params[curr_queue].vport_id = vport_id + i + 1;
305 qm_info->qm_pq_params[curr_queue].tc_id =
306 p_hwfn->hw_info.non_offload_tc;
307 qm_info->qm_pq_params[curr_queue].wrr_group = 1;
308 qm_info->qm_pq_params[curr_queue].rl_valid = 1;
312 qm_info->vf_queues_offset = vf_offset;
313 qm_info->num_pqs = num_pqs;
314 qm_info->num_vports = num_vports;
316 /* Initialize qm port parameters */
317 num_ports = p_hwfn->cdev->num_ports_in_engines;
318 for (i = 0; i < num_ports; i++) {
319 p_qm_port = &qm_info->qm_port_params[i];
320 p_qm_port->active = 1;
322 p_qm_port->active_phys_tcs = 0x7;
324 p_qm_port->active_phys_tcs = 0x9f;
325 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
326 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
329 qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
331 qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
333 qm_info->num_vf_pqs = num_vfs;
334 qm_info->start_vport = (u8) RESC_START(p_hwfn, QED_VPORT);
336 for (i = 0; i < qm_info->num_vports; i++)
337 qm_info->qm_vport_params[i].vport_wfq = 1;
339 qm_info->vport_rl_en = 1;
340 qm_info->vport_wfq_en = 1;
341 qm_info->pf_rl = pf_rl;
342 qm_info->pf_wfq = pf_wfq;
347 qed_qm_info_free(p_hwfn);
351 /* This function reconfigures the QM pf on the fly.
352 * For this purpose we:
353 * 1. reconfigure the QM database
354 * 2. set new values to runtime arrat
355 * 3. send an sdm_qm_cmd through the rbc interface to stop the QM
356 * 4. activate init tool in QM_PF stage
357 * 5. send an sdm_qm_cmd through rbc interface to release the QM
359 int qed_qm_reconf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
361 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
365 /* qm_info is allocated in qed_init_qm_info() which is already called
366 * from qed_resc_alloc() or previous call of qed_qm_reconf().
367 * The allocated size may change each init, so we free it before next
370 qed_qm_info_free(p_hwfn);
372 /* initialize qed's qm data structure */
373 rc = qed_init_qm_info(p_hwfn, false);
377 /* stop PF's qm queues */
378 spin_lock_bh(&qm_lock);
379 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, false, true,
380 qm_info->start_pq, qm_info->num_pqs);
381 spin_unlock_bh(&qm_lock);
385 /* clear the QM_PF runtime phase leftovers from previous init */
386 qed_init_clear_rt_data(p_hwfn);
388 /* prepare QM portion of runtime array */
389 qed_qm_init_pf(p_hwfn);
391 /* activate init tool on runtime array */
392 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, p_hwfn->rel_pf_id,
393 p_hwfn->hw_info.hw_mode);
397 /* start PF's qm queues */
398 spin_lock_bh(&qm_lock);
399 b_rc = qed_send_qm_stop_cmd(p_hwfn, p_ptt, true, true,
400 qm_info->start_pq, qm_info->num_pqs);
401 spin_unlock_bh(&qm_lock);
408 int qed_resc_alloc(struct qed_dev *cdev)
410 #ifdef CONFIG_QED_LL2
411 struct qed_ll2_info *p_ll2_info;
413 struct qed_consq *p_consq;
420 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
424 /* Allocate Memory for the Queue->CID mapping */
425 for_each_hwfn(cdev, i) {
426 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
427 int tx_size = sizeof(struct qed_hw_cid_data) *
428 RESC_NUM(p_hwfn, QED_L2_QUEUE);
429 int rx_size = sizeof(struct qed_hw_cid_data) *
430 RESC_NUM(p_hwfn, QED_L2_QUEUE);
432 p_hwfn->p_tx_cids = kzalloc(tx_size, GFP_KERNEL);
433 if (!p_hwfn->p_tx_cids)
436 p_hwfn->p_rx_cids = kzalloc(rx_size, GFP_KERNEL);
437 if (!p_hwfn->p_rx_cids)
441 for_each_hwfn(cdev, i) {
442 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
443 u32 n_eqes, num_cons;
445 /* First allocate the context manager structure */
446 rc = qed_cxt_mngr_alloc(p_hwfn);
450 /* Set the HW cid/tid numbers (in the contest manager)
451 * Must be done prior to any further computations.
453 rc = qed_cxt_set_pf_params(p_hwfn);
457 /* Prepare and process QM requirements */
458 rc = qed_init_qm_info(p_hwfn, true);
462 /* Compute the ILT client partition */
463 rc = qed_cxt_cfg_ilt_compute(p_hwfn);
467 /* CID map / ILT shadow table / T2
468 * The talbes sizes are determined by the computations above
470 rc = qed_cxt_tables_alloc(p_hwfn);
474 /* SPQ, must follow ILT because initializes SPQ context */
475 rc = qed_spq_alloc(p_hwfn);
479 /* SP status block allocation */
480 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
483 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
487 rc = qed_iov_alloc(p_hwfn);
492 n_eqes = qed_chain_get_capacity(&p_hwfn->p_spq->chain);
493 if (p_hwfn->hw_info.personality == QED_PCI_ETH_ROCE) {
494 num_cons = qed_cxt_get_proto_cid_count(p_hwfn,
497 n_eqes += num_cons + 2 * MAX_NUM_VFS_BB;
498 } else if (p_hwfn->hw_info.personality == QED_PCI_ISCSI) {
500 qed_cxt_get_proto_cid_count(p_hwfn,
501 PROTOCOLID_ISCSI, 0);
502 n_eqes += 2 * num_cons;
505 if (n_eqes > 0xFFFF) {
507 "Cannot allocate 0x%x EQ elements. The maximum of a u16 chain is 0x%x\n",
513 p_eq = qed_eq_alloc(p_hwfn, (u16) n_eqes);
518 p_consq = qed_consq_alloc(p_hwfn);
521 p_hwfn->p_consq = p_consq;
523 #ifdef CONFIG_QED_LL2
524 if (p_hwfn->using_ll2) {
525 p_ll2_info = qed_ll2_alloc(p_hwfn);
528 p_hwfn->p_ll2_info = p_ll2_info;
532 /* DMA info initialization */
533 rc = qed_dmae_info_alloc(p_hwfn);
537 /* DCBX initialization */
538 rc = qed_dcbx_info_alloc(p_hwfn);
543 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
544 if (!cdev->reset_stats)
556 void qed_resc_setup(struct qed_dev *cdev)
563 for_each_hwfn(cdev, i) {
564 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
566 qed_cxt_mngr_setup(p_hwfn);
567 qed_spq_setup(p_hwfn);
568 qed_eq_setup(p_hwfn, p_hwfn->p_eq);
569 qed_consq_setup(p_hwfn, p_hwfn->p_consq);
571 /* Read shadow of current MFW mailbox */
572 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
573 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
574 p_hwfn->mcp_info->mfw_mb_cur,
575 p_hwfn->mcp_info->mfw_mb_length);
577 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
579 qed_iov_setup(p_hwfn, p_hwfn->p_main_ptt);
580 #ifdef CONFIG_QED_LL2
581 if (p_hwfn->using_ll2)
582 qed_ll2_setup(p_hwfn, p_hwfn->p_ll2_info);
587 #define FINAL_CLEANUP_POLL_CNT (100)
588 #define FINAL_CLEANUP_POLL_TIME (10)
589 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
590 struct qed_ptt *p_ptt, u16 id, bool is_vf)
592 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
595 addr = GTT_BAR0_MAP_REG_USDM_RAM +
596 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
601 command |= X_FINAL_CLEANUP_AGG_INT <<
602 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
603 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
604 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
605 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
607 /* Make sure notification is not set before initiating final cleanup */
608 if (REG_RD(p_hwfn, addr)) {
610 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
611 REG_WR(p_hwfn, addr, 0);
614 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
615 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
618 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
620 /* Poll until completion */
621 while (!REG_RD(p_hwfn, addr) && count--)
622 msleep(FINAL_CLEANUP_POLL_TIME);
624 if (REG_RD(p_hwfn, addr))
628 "Failed to receive FW final cleanup notification\n");
630 /* Cleanup afterwards */
631 REG_WR(p_hwfn, addr, 0);
636 static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
640 hw_mode = (1 << MODE_BB_B0);
642 switch (p_hwfn->cdev->num_ports_in_engines) {
644 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
647 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
650 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
653 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
654 p_hwfn->cdev->num_ports_in_engines);
658 switch (p_hwfn->cdev->mf_mode) {
661 hw_mode |= 1 << MODE_MF_SI;
664 hw_mode |= 1 << MODE_MF_SD;
667 DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
668 hw_mode |= 1 << MODE_MF_SI;
671 hw_mode |= 1 << MODE_ASIC;
673 if (p_hwfn->cdev->num_hwfns > 1)
674 hw_mode |= 1 << MODE_100G;
676 p_hwfn->hw_info.hw_mode = hw_mode;
678 DP_VERBOSE(p_hwfn, (NETIF_MSG_PROBE | NETIF_MSG_IFUP),
679 "Configuring function for hw_mode: 0x%08x\n",
680 p_hwfn->hw_info.hw_mode);
683 /* Init run time data for all PFs on an engine. */
684 static void qed_init_cau_rt_data(struct qed_dev *cdev)
686 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
689 for_each_hwfn(cdev, i) {
690 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
691 struct qed_igu_info *p_igu_info;
692 struct qed_igu_block *p_block;
693 struct cau_sb_entry sb_entry;
695 p_igu_info = p_hwfn->hw_info.p_igu_info;
697 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
699 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
703 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
704 p_block->function_id, 0, 0);
705 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2, sb_entry);
710 static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
711 struct qed_ptt *p_ptt, int hw_mode)
713 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
714 struct qed_qm_common_rt_init_params params;
715 struct qed_dev *cdev = p_hwfn->cdev;
721 qed_init_cau_rt_data(cdev);
723 /* Program GTT windows */
724 qed_gtt_init(p_hwfn);
726 if (p_hwfn->mcp_info) {
727 if (p_hwfn->mcp_info->func_info.bandwidth_max)
728 qm_info->pf_rl_en = 1;
729 if (p_hwfn->mcp_info->func_info.bandwidth_min)
730 qm_info->pf_wfq_en = 1;
733 memset(¶ms, 0, sizeof(params));
734 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
735 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
736 params.pf_rl_en = qm_info->pf_rl_en;
737 params.pf_wfq_en = qm_info->pf_wfq_en;
738 params.vport_rl_en = qm_info->vport_rl_en;
739 params.vport_wfq_en = qm_info->vport_wfq_en;
740 params.port_params = qm_info->qm_port_params;
742 qed_qm_common_rt_init(p_hwfn, ¶ms);
744 qed_cxt_hw_init_common(p_hwfn);
746 /* Close gate from NIG to BRB/Storm; By default they are open, but
747 * we close them to prevent NIG from passing data to reset blocks.
748 * Should have been done in the ENGINE phase, but init-tool lacks
749 * proper port-pretend capabilities.
751 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
752 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
753 qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
754 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
755 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
756 qed_port_unpretend(p_hwfn, p_ptt);
758 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
762 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
763 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
765 if (QED_IS_BB(p_hwfn->cdev)) {
766 num_pfs = NUM_OF_ENG_PFS(p_hwfn->cdev);
767 for (pf_id = 0; pf_id < num_pfs; pf_id++) {
768 qed_fid_pretend(p_hwfn, p_ptt, pf_id);
769 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
770 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
772 /* pretend to original PF */
773 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
776 for (vf_id = 0; vf_id < MAX_NUM_VFS_BB; vf_id++) {
777 concrete_fid = qed_vfid_to_concrete(p_hwfn, vf_id);
778 qed_fid_pretend(p_hwfn, p_ptt, (u16) concrete_fid);
779 qed_wr(p_hwfn, p_ptt, CCFC_REG_STRONG_ENABLE_VF, 0x1);
780 qed_wr(p_hwfn, p_ptt, CCFC_REG_WEAK_ENABLE_VF, 0x0);
781 qed_wr(p_hwfn, p_ptt, TCFC_REG_STRONG_ENABLE_VF, 0x1);
782 qed_wr(p_hwfn, p_ptt, TCFC_REG_WEAK_ENABLE_VF, 0x0);
784 /* pretend to original PF */
785 qed_fid_pretend(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
790 static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
791 struct qed_ptt *p_ptt, int hw_mode)
793 return qed_init_run(p_hwfn, p_ptt, PHASE_PORT,
794 p_hwfn->port_id, hw_mode);
797 static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
798 struct qed_ptt *p_ptt,
799 struct qed_tunn_start_params *p_tunn,
802 enum qed_int_mode int_mode,
803 bool allow_npar_tx_switch)
805 u8 rel_pf_id = p_hwfn->rel_pf_id;
808 if (p_hwfn->mcp_info) {
809 struct qed_mcp_function_info *p_info;
811 p_info = &p_hwfn->mcp_info->func_info;
812 if (p_info->bandwidth_min)
813 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
815 /* Update rate limit once we'll actually have a link */
816 p_hwfn->qm_info.pf_rl = 100000;
819 qed_cxt_hw_init_pf(p_hwfn);
821 qed_int_igu_init_rt(p_hwfn);
823 /* Set VLAN in NIG if needed */
824 if (hw_mode & BIT(MODE_MF_SD)) {
825 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
826 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
827 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
828 p_hwfn->hw_info.ovlan);
831 /* Enable classification by MAC if needed */
832 if (hw_mode & BIT(MODE_MF_SI)) {
833 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
834 "Configuring TAGMAC_CLS_TYPE\n");
836 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
839 /* Protocl Configuration */
840 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET,
841 (p_hwfn->hw_info.personality == QED_PCI_ISCSI) ? 1 : 0);
842 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
843 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
845 /* Cleanup chip from previous driver if such remains exist */
846 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id, false);
850 /* PF Init sequence */
851 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
855 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
856 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
860 /* Pure runtime initializations - directly to the HW */
861 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
864 /* enable interrupts */
865 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
867 /* send function start command */
868 rc = qed_sp_pf_start(p_hwfn, p_tunn, p_hwfn->cdev->mf_mode,
869 allow_npar_tx_switch);
871 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
876 static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
877 struct qed_ptt *p_ptt,
880 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
882 /* Change PF in PXP */
883 qed_wr(p_hwfn, p_ptt,
884 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
886 /* wait until value is set - try for 1 second every 50us */
887 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
888 val = qed_rd(p_hwfn, p_ptt,
889 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
893 usleep_range(50, 60);
896 if (val != set_val) {
898 "PFID_ENABLE_MASTER wasn't changed after a second\n");
905 static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
906 struct qed_ptt *p_main_ptt)
908 /* Read shadow of current MFW mailbox */
909 qed_mcp_read_mb(p_hwfn, p_main_ptt);
910 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
911 p_hwfn->mcp_info->mfw_mb_cur, p_hwfn->mcp_info->mfw_mb_length);
914 int qed_hw_init(struct qed_dev *cdev,
915 struct qed_tunn_start_params *p_tunn,
917 enum qed_int_mode int_mode,
918 bool allow_npar_tx_switch,
919 const u8 *bin_fw_data)
921 u32 load_code, param;
924 if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
925 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
930 rc = qed_init_fw_data(cdev, bin_fw_data);
935 for_each_hwfn(cdev, i) {
936 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
939 p_hwfn->b_int_enabled = 1;
943 /* Enable DMAE in PXP */
944 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
946 qed_calc_hw_mode(p_hwfn);
948 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt, &load_code);
950 DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
954 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
956 DP_VERBOSE(p_hwfn, QED_MSG_SP,
957 "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
960 p_hwfn->first_on_engine = (load_code ==
961 FW_MSG_CODE_DRV_LOAD_ENGINE);
964 case FW_MSG_CODE_DRV_LOAD_ENGINE:
965 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
966 p_hwfn->hw_info.hw_mode);
970 case FW_MSG_CODE_DRV_LOAD_PORT:
971 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
972 p_hwfn->hw_info.hw_mode);
977 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
978 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
979 p_tunn, p_hwfn->hw_info.hw_mode,
980 b_hw_start, int_mode,
981 allow_npar_tx_switch);
990 "init phase failed for loadcode 0x%x (rc %d)\n",
993 /* ACK mfw regardless of success or failure of initialization */
994 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
995 DRV_MSG_CODE_LOAD_DONE,
996 0, &load_code, ¶m);
1000 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
1004 /* send DCBX attention request command */
1007 "sending phony dcbx set command to trigger DCBx attention handling\n");
1008 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1009 DRV_MSG_CODE_SET_DCBX,
1010 1 << DRV_MB_PARAM_DCBX_NOTIFY_SHIFT,
1011 &load_code, ¶m);
1014 "Failed to send DCBX attention request\n");
1018 p_hwfn->hw_init_done = true;
1024 #define QED_HW_STOP_RETRY_LIMIT (10)
1025 static void qed_hw_timers_stop(struct qed_dev *cdev,
1026 struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1031 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
1032 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
1034 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
1035 if ((!qed_rd(p_hwfn, p_ptt,
1036 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
1037 (!qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK)))
1040 /* Dependent on number of connection/tasks, possibly
1041 * 1ms sleep is required between polls
1043 usleep_range(1000, 2000);
1046 if (i < QED_HW_STOP_RETRY_LIMIT)
1050 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
1051 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
1052 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
1055 void qed_hw_timers_stop_all(struct qed_dev *cdev)
1059 for_each_hwfn(cdev, j) {
1060 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1061 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1063 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
1067 int qed_hw_stop(struct qed_dev *cdev)
1072 for_each_hwfn(cdev, j) {
1073 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1074 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1076 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
1079 qed_vf_pf_int_cleanup(p_hwfn);
1083 /* mark the hw as uninitialized... */
1084 p_hwfn->hw_init_done = false;
1086 rc = qed_sp_pf_stop(p_hwfn);
1089 "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
1091 qed_wr(p_hwfn, p_ptt,
1092 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1094 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1095 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1096 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1097 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1098 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1100 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
1102 /* Disable Attention Generation */
1103 qed_int_igu_disable_int(p_hwfn, p_ptt);
1105 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
1106 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
1108 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
1110 /* Need to wait 1ms to guarantee SBs are cleared */
1111 usleep_range(1000, 2000);
1115 /* Disable DMAE in PXP - in CMT, this should only be done for
1116 * first hw-function, and only after all transactions have
1117 * stopped for all active hw-functions.
1119 t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
1120 cdev->hwfns[0].p_main_ptt, false);
1128 void qed_hw_stop_fastpath(struct qed_dev *cdev)
1132 for_each_hwfn(cdev, j) {
1133 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
1134 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
1137 qed_vf_pf_int_cleanup(p_hwfn);
1142 NETIF_MSG_IFDOWN, "Shutting down the fastpath\n");
1144 qed_wr(p_hwfn, p_ptt,
1145 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
1147 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
1148 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
1149 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
1150 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
1151 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
1153 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
1155 /* Need to wait 1ms to guarantee SBs are cleared */
1156 usleep_range(1000, 2000);
1160 void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
1162 if (IS_VF(p_hwfn->cdev))
1165 /* Re-open incoming traffic */
1166 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1167 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
1170 static int qed_reg_assert(struct qed_hwfn *p_hwfn,
1171 struct qed_ptt *p_ptt, u32 reg, bool expected)
1173 u32 assert_val = qed_rd(p_hwfn, p_ptt, reg);
1175 if (assert_val != expected) {
1176 DP_NOTICE(p_hwfn, "Value at address 0x%08x != 0x%08x\n",
1184 int qed_hw_reset(struct qed_dev *cdev)
1187 u32 unload_resp, unload_param;
1190 for_each_hwfn(cdev, i) {
1191 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1194 rc = qed_vf_pf_reset(p_hwfn);
1200 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
1202 /* Check for incorrect states */
1203 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
1204 QM_REG_USG_CNT_PF_TX, 0);
1205 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
1206 QM_REG_USG_CNT_PF_OTHER, 0);
1208 /* Disable PF in HW blocks */
1209 qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
1210 qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
1211 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1212 TCFC_REG_STRONG_ENABLE_PF, 0);
1213 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1214 CCFC_REG_STRONG_ENABLE_PF, 0);
1216 /* Send unload command to MCP */
1217 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1218 DRV_MSG_CODE_UNLOAD_REQ,
1219 DRV_MB_PARAM_UNLOAD_WOL_MCP,
1220 &unload_resp, &unload_param);
1222 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
1223 unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
1226 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
1227 DRV_MSG_CODE_UNLOAD_DONE,
1228 0, &unload_resp, &unload_param);
1230 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
1238 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
1239 static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
1241 qed_ptt_pool_free(p_hwfn);
1242 kfree(p_hwfn->hw_info.p_igu_info);
1245 /* Setup bar access */
1246 static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
1248 /* clear indirect access */
1249 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
1250 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
1251 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
1252 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
1254 /* Clean Previous errors if such exist */
1255 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1256 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR, 1 << p_hwfn->abs_pf_id);
1258 /* enable internal target-read */
1259 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
1260 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
1263 static void get_function_id(struct qed_hwfn *p_hwfn)
1266 p_hwfn->hw_info.opaque_fid = (u16) REG_RD(p_hwfn,
1267 PXP_PF_ME_OPAQUE_ADDR);
1269 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
1271 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
1272 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
1273 PXP_CONCRETE_FID_PFID);
1274 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
1275 PXP_CONCRETE_FID_PORT);
1277 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1278 "Read ME register: Concrete 0x%08x Opaque 0x%04x\n",
1279 p_hwfn->hw_info.concrete_fid, p_hwfn->hw_info.opaque_fid);
1282 static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
1284 u32 *feat_num = p_hwfn->hw_info.feat_num;
1285 int num_features = 1;
1287 feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
1289 RESC_NUM(p_hwfn, QED_L2_QUEUE));
1290 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1291 "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
1292 feat_num[QED_PF_L2_QUE], RESC_NUM(p_hwfn, QED_SB),
1296 static int qed_hw_get_resc(struct qed_hwfn *p_hwfn)
1298 u8 enabled_func_idx = p_hwfn->enabled_func_idx;
1299 u32 *resc_start = p_hwfn->hw_info.resc_start;
1300 u8 num_funcs = p_hwfn->num_funcs_on_engine;
1301 u32 *resc_num = p_hwfn->hw_info.resc_num;
1302 struct qed_sb_cnt_info sb_cnt_info;
1303 int i, max_vf_vlan_filters;
1305 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
1307 #ifdef CONFIG_QED_SRIOV
1308 max_vf_vlan_filters = QED_ETH_MAX_VF_NUM_VLAN_FILTERS;
1310 max_vf_vlan_filters = 0;
1313 qed_int_get_num_sbs(p_hwfn, &sb_cnt_info);
1315 resc_num[QED_SB] = min_t(u32,
1316 (MAX_SB_PER_PATH_BB / num_funcs),
1317 sb_cnt_info.sb_cnt);
1318 resc_num[QED_L2_QUEUE] = MAX_NUM_L2_QUEUES_BB / num_funcs;
1319 resc_num[QED_VPORT] = MAX_NUM_VPORTS_BB / num_funcs;
1320 resc_num[QED_RSS_ENG] = ETH_RSS_ENGINE_NUM_BB / num_funcs;
1321 resc_num[QED_PQ] = MAX_QM_TX_QUEUES_BB / num_funcs;
1322 resc_num[QED_RL] = min_t(u32, 64, resc_num[QED_VPORT]);
1323 resc_num[QED_MAC] = ETH_NUM_MAC_FILTERS / num_funcs;
1324 resc_num[QED_VLAN] = (ETH_NUM_VLAN_FILTERS - 1 /*For vlan0*/) /
1326 resc_num[QED_ILT] = PXP_NUM_ILT_RECORDS_BB / num_funcs;
1327 resc_num[QED_LL2_QUEUE] = MAX_NUM_LL2_RX_QUEUES / num_funcs;
1329 for (i = 0; i < QED_MAX_RESC; i++)
1330 resc_start[i] = resc_num[i] * enabled_func_idx;
1332 /* Sanity for ILT */
1333 if (RESC_END(p_hwfn, QED_ILT) > PXP_NUM_ILT_RECORDS_BB) {
1334 DP_NOTICE(p_hwfn, "Can't assign ILT pages [%08x,...,%08x]\n",
1335 RESC_START(p_hwfn, QED_ILT),
1336 RESC_END(p_hwfn, QED_ILT) - 1);
1340 qed_hw_set_feat(p_hwfn);
1342 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1343 "The numbers for each resource are:\n"
1344 "SB = %d start = %d\n"
1345 "L2_QUEUE = %d start = %d\n"
1346 "VPORT = %d start = %d\n"
1347 "PQ = %d start = %d\n"
1348 "RL = %d start = %d\n"
1349 "MAC = %d start = %d\n"
1350 "VLAN = %d start = %d\n"
1351 "ILT = %d start = %d\n"
1352 "LL2_QUEUE = %d start = %d\n",
1353 p_hwfn->hw_info.resc_num[QED_SB],
1354 p_hwfn->hw_info.resc_start[QED_SB],
1355 p_hwfn->hw_info.resc_num[QED_L2_QUEUE],
1356 p_hwfn->hw_info.resc_start[QED_L2_QUEUE],
1357 p_hwfn->hw_info.resc_num[QED_VPORT],
1358 p_hwfn->hw_info.resc_start[QED_VPORT],
1359 p_hwfn->hw_info.resc_num[QED_PQ],
1360 p_hwfn->hw_info.resc_start[QED_PQ],
1361 p_hwfn->hw_info.resc_num[QED_RL],
1362 p_hwfn->hw_info.resc_start[QED_RL],
1363 p_hwfn->hw_info.resc_num[QED_MAC],
1364 p_hwfn->hw_info.resc_start[QED_MAC],
1365 p_hwfn->hw_info.resc_num[QED_VLAN],
1366 p_hwfn->hw_info.resc_start[QED_VLAN],
1367 p_hwfn->hw_info.resc_num[QED_ILT],
1368 p_hwfn->hw_info.resc_start[QED_ILT],
1369 RESC_NUM(p_hwfn, QED_LL2_QUEUE),
1370 RESC_START(p_hwfn, QED_LL2_QUEUE));
1375 static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1377 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
1378 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
1379 struct qed_mcp_link_params *link;
1381 /* Read global nvm_cfg address */
1382 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
1384 /* Verify MCP has initialized it */
1385 if (!nvm_cfg_addr) {
1386 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
1390 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
1391 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
1393 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1394 offsetof(struct nvm_cfg1, glob) +
1395 offsetof(struct nvm_cfg1_glob, core_cfg);
1397 core_cfg = qed_rd(p_hwfn, p_ptt, addr);
1399 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
1400 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
1401 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_2X40G:
1402 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
1404 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X50G:
1405 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
1407 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_1X100G:
1408 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
1410 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_4X10G_F:
1411 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
1413 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X10G_E:
1414 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
1416 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_BB_4X20G:
1417 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
1419 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X40G:
1420 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
1422 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_2X25G:
1423 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
1425 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_1X25G:
1426 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
1429 DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n", core_cfg);
1433 /* Read default link configuration */
1434 link = &p_hwfn->mcp_info->link_input;
1435 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1436 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
1437 link_temp = qed_rd(p_hwfn, p_ptt,
1439 offsetof(struct nvm_cfg1_port, speed_cap_mask));
1440 link_temp &= NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
1441 link->speed.advertised_speeds = link_temp;
1443 link_temp = link->speed.advertised_speeds;
1444 p_hwfn->mcp_info->link_capabilities.speed_capabilities = link_temp;
1446 link_temp = qed_rd(p_hwfn, p_ptt,
1448 offsetof(struct nvm_cfg1_port, link_settings));
1449 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
1450 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
1451 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
1452 link->speed.autoneg = true;
1454 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
1455 link->speed.forced_speed = 1000;
1457 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
1458 link->speed.forced_speed = 10000;
1460 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
1461 link->speed.forced_speed = 25000;
1463 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
1464 link->speed.forced_speed = 40000;
1466 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
1467 link->speed.forced_speed = 50000;
1469 case NVM_CFG1_PORT_DRV_LINK_SPEED_BB_100G:
1470 link->speed.forced_speed = 100000;
1473 DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n", link_temp);
1476 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
1477 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
1478 link->pause.autoneg = !!(link_temp &
1479 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
1480 link->pause.forced_rx = !!(link_temp &
1481 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
1482 link->pause.forced_tx = !!(link_temp &
1483 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
1484 link->loopback_mode = 0;
1486 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1487 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
1488 link->speed.forced_speed, link->speed.advertised_speeds,
1489 link->speed.autoneg, link->pause.autoneg);
1491 /* Read Multi-function information from shmem */
1492 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1493 offsetof(struct nvm_cfg1, glob) +
1494 offsetof(struct nvm_cfg1_glob, generic_cont0);
1496 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
1498 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
1499 NVM_CFG1_GLOB_MF_MODE_OFFSET;
1502 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
1503 p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
1505 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
1506 p_hwfn->cdev->mf_mode = QED_MF_NPAR;
1508 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
1509 p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
1512 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
1513 p_hwfn->cdev->mf_mode);
1515 /* Read Multi-function information from shmem */
1516 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1517 offsetof(struct nvm_cfg1, glob) +
1518 offsetof(struct nvm_cfg1_glob, device_capabilities);
1520 device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
1521 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
1522 __set_bit(QED_DEV_CAP_ETH,
1523 &p_hwfn->hw_info.device_capabilities);
1524 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ISCSI)
1525 __set_bit(QED_DEV_CAP_ISCSI,
1526 &p_hwfn->hw_info.device_capabilities);
1527 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ROCE)
1528 __set_bit(QED_DEV_CAP_ROCE,
1529 &p_hwfn->hw_info.device_capabilities);
1531 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
1534 static void qed_get_num_funcs(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
1536 u8 num_funcs, enabled_func_idx = p_hwfn->rel_pf_id;
1537 u32 reg_function_hide, tmp, eng_mask, low_pfs_mask;
1539 num_funcs = MAX_NUM_PFS_BB;
1541 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
1542 * in the other bits are selected.
1543 * Bits 1-15 are for functions 1-15, respectively, and their value is
1544 * '0' only for enabled functions (function 0 always exists and
1546 * In case of CMT, only the "even" functions are enabled, and thus the
1547 * number of functions for both hwfns is learnt from the same bits.
1549 reg_function_hide = qed_rd(p_hwfn, p_ptt, MISCS_REG_FUNCTION_HIDE);
1551 if (reg_function_hide & 0x1) {
1552 if (QED_PATH_ID(p_hwfn) && p_hwfn->cdev->num_hwfns == 1) {
1560 /* Get the number of the enabled functions on the engine */
1561 tmp = (reg_function_hide ^ 0xffffffff) & eng_mask;
1568 /* Get the PF index within the enabled functions */
1569 low_pfs_mask = (0x1 << p_hwfn->abs_pf_id) - 1;
1570 tmp = reg_function_hide & eng_mask & low_pfs_mask;
1578 p_hwfn->num_funcs_on_engine = num_funcs;
1579 p_hwfn->enabled_func_idx = enabled_func_idx;
1583 "PF [rel_id %d, abs_id %d] occupies index %d within the %d enabled functions on the engine\n",
1586 p_hwfn->enabled_func_idx, p_hwfn->num_funcs_on_engine);
1590 qed_get_hw_info(struct qed_hwfn *p_hwfn,
1591 struct qed_ptt *p_ptt,
1592 enum qed_pci_personality personality)
1597 /* Since all information is common, only first hwfns should do this */
1598 if (IS_LEAD_HWFN(p_hwfn)) {
1599 rc = qed_iov_hw_info(p_hwfn);
1604 /* Read the port mode */
1605 port_mode = qed_rd(p_hwfn, p_ptt,
1606 CNIG_REG_NW_PORT_MODE_BB_B0);
1608 if (port_mode < 3) {
1609 p_hwfn->cdev->num_ports_in_engines = 1;
1610 } else if (port_mode <= 5) {
1611 p_hwfn->cdev->num_ports_in_engines = 2;
1613 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
1614 p_hwfn->cdev->num_ports_in_engines);
1616 /* Default num_ports_in_engines to something */
1617 p_hwfn->cdev->num_ports_in_engines = 1;
1620 qed_hw_get_nvm_info(p_hwfn, p_ptt);
1622 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
1626 if (qed_mcp_is_init(p_hwfn))
1627 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
1628 p_hwfn->mcp_info->func_info.mac);
1630 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
1632 if (qed_mcp_is_init(p_hwfn)) {
1633 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
1634 p_hwfn->hw_info.ovlan =
1635 p_hwfn->mcp_info->func_info.ovlan;
1637 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
1640 if (qed_mcp_is_init(p_hwfn)) {
1641 enum qed_pci_personality protocol;
1643 protocol = p_hwfn->mcp_info->func_info.protocol;
1644 p_hwfn->hw_info.personality = protocol;
1647 qed_get_num_funcs(p_hwfn, p_ptt);
1649 return qed_hw_get_resc(p_hwfn);
1652 static int qed_get_dev_info(struct qed_dev *cdev)
1654 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
1657 /* Read Vendor Id / Device Id */
1658 pci_read_config_word(cdev->pdev, PCI_VENDOR_ID, &cdev->vendor_id);
1659 pci_read_config_word(cdev->pdev, PCI_DEVICE_ID, &cdev->device_id);
1661 cdev->chip_num = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1662 MISCS_REG_CHIP_NUM);
1663 cdev->chip_rev = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1664 MISCS_REG_CHIP_REV);
1665 MASK_FIELD(CHIP_REV, cdev->chip_rev);
1667 cdev->type = QED_DEV_TYPE_BB;
1668 /* Learn number of HW-functions */
1669 tmp = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1670 MISCS_REG_CMT_ENABLED_FOR_PAIR);
1672 if (tmp & (1 << p_hwfn->rel_pf_id)) {
1673 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
1674 cdev->num_hwfns = 2;
1676 cdev->num_hwfns = 1;
1679 cdev->chip_bond_id = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1680 MISCS_REG_CHIP_TEST_REG) >> 4;
1681 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
1682 cdev->chip_metal = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1683 MISCS_REG_CHIP_METAL);
1684 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
1686 DP_INFO(cdev->hwfns,
1687 "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
1688 cdev->chip_num, cdev->chip_rev,
1689 cdev->chip_bond_id, cdev->chip_metal);
1691 if (QED_IS_BB(cdev) && CHIP_REV_IS_A0(cdev)) {
1692 DP_NOTICE(cdev->hwfns,
1693 "The chip type/rev (BB A0) is not supported!\n");
1700 static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
1701 void __iomem *p_regview,
1702 void __iomem *p_doorbells,
1703 enum qed_pci_personality personality)
1707 /* Split PCI bars evenly between hwfns */
1708 p_hwfn->regview = p_regview;
1709 p_hwfn->doorbells = p_doorbells;
1711 if (IS_VF(p_hwfn->cdev))
1712 return qed_vf_hw_prepare(p_hwfn);
1714 /* Validate that chip access is feasible */
1715 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
1717 "Reading the ME register returns all Fs; Preventing further chip access\n");
1721 get_function_id(p_hwfn);
1723 /* Allocate PTT pool */
1724 rc = qed_ptt_pool_alloc(p_hwfn);
1728 /* Allocate the main PTT */
1729 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
1731 /* First hwfn learns basic information, e.g., number of hwfns */
1732 if (!p_hwfn->my_id) {
1733 rc = qed_get_dev_info(p_hwfn->cdev);
1738 qed_hw_hwfn_prepare(p_hwfn);
1740 /* Initialize MCP structure */
1741 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
1743 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
1747 /* Read the device configuration information from the HW and SHMEM */
1748 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
1750 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
1754 /* Allocate the init RT array and initialize the init-ops engine */
1755 rc = qed_init_alloc(p_hwfn);
1761 if (IS_LEAD_HWFN(p_hwfn))
1762 qed_iov_free_hw_info(p_hwfn->cdev);
1763 qed_mcp_free(p_hwfn);
1765 qed_hw_hwfn_free(p_hwfn);
1770 int qed_hw_prepare(struct qed_dev *cdev,
1773 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
1776 /* Store the precompiled init data ptrs */
1778 qed_init_iro_array(cdev);
1780 /* Initialize the first hwfn - will learn number of hwfns */
1781 rc = qed_hw_prepare_single(p_hwfn,
1783 cdev->doorbells, personality);
1787 personality = p_hwfn->hw_info.personality;
1789 /* Initialize the rest of the hwfns */
1790 if (cdev->num_hwfns > 1) {
1791 void __iomem *p_regview, *p_doorbell;
1794 /* adjust bar offset for second engine */
1795 addr = cdev->regview + qed_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
1798 /* adjust doorbell bar offset for second engine */
1799 addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
1802 /* prepare second hw function */
1803 rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
1804 p_doorbell, personality);
1806 /* in case of error, need to free the previously
1807 * initiliazed hwfn 0.
1811 qed_init_free(p_hwfn);
1812 qed_mcp_free(p_hwfn);
1813 qed_hw_hwfn_free(p_hwfn);
1821 void qed_hw_remove(struct qed_dev *cdev)
1825 for_each_hwfn(cdev, i) {
1826 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1829 qed_vf_pf_release(p_hwfn);
1833 qed_init_free(p_hwfn);
1834 qed_hw_hwfn_free(p_hwfn);
1835 qed_mcp_free(p_hwfn);
1838 qed_iov_free_hw_info(cdev);
1841 static void qed_chain_free_next_ptr(struct qed_dev *cdev,
1842 struct qed_chain *p_chain)
1844 void *p_virt = p_chain->p_virt_addr, *p_virt_next = NULL;
1845 dma_addr_t p_phys = p_chain->p_phys_addr, p_phys_next = 0;
1846 struct qed_chain_next *p_next;
1852 size = p_chain->elem_size * p_chain->usable_per_page;
1854 for (i = 0; i < p_chain->page_cnt; i++) {
1858 p_next = (struct qed_chain_next *)((u8 *)p_virt + size);
1859 p_virt_next = p_next->next_virt;
1860 p_phys_next = HILO_DMA_REGPAIR(p_next->next_phys);
1862 dma_free_coherent(&cdev->pdev->dev,
1863 QED_CHAIN_PAGE_SIZE, p_virt, p_phys);
1865 p_virt = p_virt_next;
1866 p_phys = p_phys_next;
1870 static void qed_chain_free_single(struct qed_dev *cdev,
1871 struct qed_chain *p_chain)
1873 if (!p_chain->p_virt_addr)
1876 dma_free_coherent(&cdev->pdev->dev,
1877 QED_CHAIN_PAGE_SIZE,
1878 p_chain->p_virt_addr, p_chain->p_phys_addr);
1881 static void qed_chain_free_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
1883 void **pp_virt_addr_tbl = p_chain->pbl.pp_virt_addr_tbl;
1884 u32 page_cnt = p_chain->page_cnt, i, pbl_size;
1885 u8 *p_pbl_virt = p_chain->pbl.p_virt_table;
1887 if (!pp_virt_addr_tbl)
1890 if (!p_chain->pbl.p_virt_table)
1893 for (i = 0; i < page_cnt; i++) {
1894 if (!pp_virt_addr_tbl[i])
1897 dma_free_coherent(&cdev->pdev->dev,
1898 QED_CHAIN_PAGE_SIZE,
1899 pp_virt_addr_tbl[i],
1900 *(dma_addr_t *)p_pbl_virt);
1902 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
1905 pbl_size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1906 dma_free_coherent(&cdev->pdev->dev,
1908 p_chain->pbl.p_virt_table, p_chain->pbl.p_phys_table);
1910 vfree(p_chain->pbl.pp_virt_addr_tbl);
1913 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain)
1915 switch (p_chain->mode) {
1916 case QED_CHAIN_MODE_NEXT_PTR:
1917 qed_chain_free_next_ptr(cdev, p_chain);
1919 case QED_CHAIN_MODE_SINGLE:
1920 qed_chain_free_single(cdev, p_chain);
1922 case QED_CHAIN_MODE_PBL:
1923 qed_chain_free_pbl(cdev, p_chain);
1929 qed_chain_alloc_sanity_check(struct qed_dev *cdev,
1930 enum qed_chain_cnt_type cnt_type,
1931 size_t elem_size, u32 page_cnt)
1933 u64 chain_size = ELEMS_PER_PAGE(elem_size) * page_cnt;
1935 /* The actual chain size can be larger than the maximal possible value
1936 * after rounding up the requested elements number to pages, and after
1937 * taking into acount the unusuable elements (next-ptr elements).
1938 * The size of a "u16" chain can be (U16_MAX + 1) since the chain
1939 * size/capacity fields are of a u32 type.
1941 if ((cnt_type == QED_CHAIN_CNT_TYPE_U16 &&
1942 chain_size > 0x10000) ||
1943 (cnt_type == QED_CHAIN_CNT_TYPE_U32 &&
1944 chain_size > 0x100000000ULL)) {
1946 "The actual chain size (0x%llx) is larger than the maximal possible value\n",
1955 qed_chain_alloc_next_ptr(struct qed_dev *cdev, struct qed_chain *p_chain)
1957 void *p_virt = NULL, *p_virt_prev = NULL;
1958 dma_addr_t p_phys = 0;
1961 for (i = 0; i < p_chain->page_cnt; i++) {
1962 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
1963 QED_CHAIN_PAGE_SIZE,
1964 &p_phys, GFP_KERNEL);
1969 qed_chain_init_mem(p_chain, p_virt, p_phys);
1970 qed_chain_reset(p_chain);
1972 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
1976 p_virt_prev = p_virt;
1978 /* Last page's next element should point to the beginning of the
1981 qed_chain_init_next_ptr_elem(p_chain, p_virt_prev,
1982 p_chain->p_virt_addr,
1983 p_chain->p_phys_addr);
1989 qed_chain_alloc_single(struct qed_dev *cdev, struct qed_chain *p_chain)
1991 dma_addr_t p_phys = 0;
1992 void *p_virt = NULL;
1994 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
1995 QED_CHAIN_PAGE_SIZE, &p_phys, GFP_KERNEL);
1999 qed_chain_init_mem(p_chain, p_virt, p_phys);
2000 qed_chain_reset(p_chain);
2005 static int qed_chain_alloc_pbl(struct qed_dev *cdev, struct qed_chain *p_chain)
2007 u32 page_cnt = p_chain->page_cnt, size, i;
2008 dma_addr_t p_phys = 0, p_pbl_phys = 0;
2009 void **pp_virt_addr_tbl = NULL;
2010 u8 *p_pbl_virt = NULL;
2011 void *p_virt = NULL;
2013 size = page_cnt * sizeof(*pp_virt_addr_tbl);
2014 pp_virt_addr_tbl = vzalloc(size);
2015 if (!pp_virt_addr_tbl)
2018 /* The allocation of the PBL table is done with its full size, since it
2019 * is expected to be successive.
2020 * qed_chain_init_pbl_mem() is called even in a case of an allocation
2021 * failure, since pp_virt_addr_tbl was previously allocated, and it
2022 * should be saved to allow its freeing during the error flow.
2024 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
2025 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
2026 size, &p_pbl_phys, GFP_KERNEL);
2027 qed_chain_init_pbl_mem(p_chain, p_pbl_virt, p_pbl_phys,
2032 for (i = 0; i < page_cnt; i++) {
2033 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
2034 QED_CHAIN_PAGE_SIZE,
2035 &p_phys, GFP_KERNEL);
2040 qed_chain_init_mem(p_chain, p_virt, p_phys);
2041 qed_chain_reset(p_chain);
2044 /* Fill the PBL table with the physical address of the page */
2045 *(dma_addr_t *)p_pbl_virt = p_phys;
2046 /* Keep the virtual address of the page */
2047 p_chain->pbl.pp_virt_addr_tbl[i] = p_virt;
2049 p_pbl_virt += QED_CHAIN_PBL_ENTRY_SIZE;
2055 int qed_chain_alloc(struct qed_dev *cdev,
2056 enum qed_chain_use_mode intended_use,
2057 enum qed_chain_mode mode,
2058 enum qed_chain_cnt_type cnt_type,
2059 u32 num_elems, size_t elem_size, struct qed_chain *p_chain)
2064 if (mode == QED_CHAIN_MODE_SINGLE)
2067 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
2069 rc = qed_chain_alloc_sanity_check(cdev, cnt_type, elem_size, page_cnt);
2072 "Cannot allocate a chain with the given arguments:\n");
2074 "[use_mode %d, mode %d, cnt_type %d, num_elems %d, elem_size %zu]\n",
2075 intended_use, mode, cnt_type, num_elems, elem_size);
2079 qed_chain_init_params(p_chain, page_cnt, (u8) elem_size, intended_use,
2083 case QED_CHAIN_MODE_NEXT_PTR:
2084 rc = qed_chain_alloc_next_ptr(cdev, p_chain);
2086 case QED_CHAIN_MODE_SINGLE:
2087 rc = qed_chain_alloc_single(cdev, p_chain);
2089 case QED_CHAIN_MODE_PBL:
2090 rc = qed_chain_alloc_pbl(cdev, p_chain);
2099 qed_chain_free(cdev, p_chain);
2103 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, u16 src_id, u16 *dst_id)
2105 if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
2108 min = (u16) RESC_START(p_hwfn, QED_L2_QUEUE);
2109 max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
2111 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
2117 *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
2122 int qed_fw_vport(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
2124 if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
2127 min = (u8)RESC_START(p_hwfn, QED_VPORT);
2128 max = min + RESC_NUM(p_hwfn, QED_VPORT);
2130 "vport id [%d] is not valid, available indices [%d - %d]\n",
2136 *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
2141 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, u8 src_id, u8 *dst_id)
2143 if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
2146 min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
2147 max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
2149 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
2155 *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
2160 static void qed_llh_mac_to_filter(u32 *p_high, u32 *p_low,
2163 *p_high = p_filter[1] | (p_filter[0] << 8);
2164 *p_low = p_filter[5] | (p_filter[4] << 8) |
2165 (p_filter[3] << 16) | (p_filter[2] << 24);
2168 int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn,
2169 struct qed_ptt *p_ptt, u8 *p_filter)
2171 u32 high = 0, low = 0, en;
2174 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2177 qed_llh_mac_to_filter(&high, &low, p_filter);
2179 /* Find a free entry and utilize it */
2180 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2181 en = qed_rd(p_hwfn, p_ptt,
2182 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32));
2185 qed_wr(p_hwfn, p_ptt,
2186 NIG_REG_LLH_FUNC_FILTER_VALUE +
2187 2 * i * sizeof(u32), low);
2188 qed_wr(p_hwfn, p_ptt,
2189 NIG_REG_LLH_FUNC_FILTER_VALUE +
2190 (2 * i + 1) * sizeof(u32), high);
2191 qed_wr(p_hwfn, p_ptt,
2192 NIG_REG_LLH_FUNC_FILTER_MODE + i * sizeof(u32), 0);
2193 qed_wr(p_hwfn, p_ptt,
2194 NIG_REG_LLH_FUNC_FILTER_PROTOCOL_TYPE +
2195 i * sizeof(u32), 0);
2196 qed_wr(p_hwfn, p_ptt,
2197 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 1);
2200 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE) {
2202 "Failed to find an empty LLH filter to utilize\n");
2206 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
2207 "mac: %pM is added at %d\n",
2213 void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn,
2214 struct qed_ptt *p_ptt, u8 *p_filter)
2216 u32 high = 0, low = 0;
2219 if (!(IS_MF_SI(p_hwfn) || IS_MF_DEFAULT(p_hwfn)))
2222 qed_llh_mac_to_filter(&high, &low, p_filter);
2224 /* Find the entry and clean it */
2225 for (i = 0; i < NIG_REG_LLH_FUNC_FILTER_EN_SIZE; i++) {
2226 if (qed_rd(p_hwfn, p_ptt,
2227 NIG_REG_LLH_FUNC_FILTER_VALUE +
2228 2 * i * sizeof(u32)) != low)
2230 if (qed_rd(p_hwfn, p_ptt,
2231 NIG_REG_LLH_FUNC_FILTER_VALUE +
2232 (2 * i + 1) * sizeof(u32)) != high)
2235 qed_wr(p_hwfn, p_ptt,
2236 NIG_REG_LLH_FUNC_FILTER_EN + i * sizeof(u32), 0);
2237 qed_wr(p_hwfn, p_ptt,
2238 NIG_REG_LLH_FUNC_FILTER_VALUE + 2 * i * sizeof(u32), 0);
2239 qed_wr(p_hwfn, p_ptt,
2240 NIG_REG_LLH_FUNC_FILTER_VALUE +
2241 (2 * i + 1) * sizeof(u32), 0);
2243 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
2244 "mac: %pM is removed from %d\n",
2248 if (i >= NIG_REG_LLH_FUNC_FILTER_EN_SIZE)
2249 DP_NOTICE(p_hwfn, "Tried to remove a non-configured filter\n");
2252 static int qed_set_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2253 u32 hw_addr, void *p_eth_qzone,
2254 size_t eth_qzone_size, u8 timeset)
2256 struct coalescing_timeset *p_coal_timeset;
2258 if (p_hwfn->cdev->int_coalescing_mode != QED_COAL_MODE_ENABLE) {
2259 DP_NOTICE(p_hwfn, "Coalescing configuration not enabled\n");
2263 p_coal_timeset = p_eth_qzone;
2264 memset(p_coal_timeset, 0, eth_qzone_size);
2265 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_TIMESET, timeset);
2266 SET_FIELD(p_coal_timeset->value, COALESCING_TIMESET_VALID, 1);
2267 qed_memcpy_to(p_hwfn, p_ptt, hw_addr, p_eth_qzone, eth_qzone_size);
2272 int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2273 u16 coalesce, u8 qid, u16 sb_id)
2275 struct ustorm_eth_queue_zone eth_qzone;
2276 u8 timeset, timer_res;
2281 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
2282 if (coalesce <= 0x7F) {
2284 } else if (coalesce <= 0xFF) {
2286 } else if (coalesce <= 0x1FF) {
2289 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
2292 timeset = (u8)(coalesce >> timer_res);
2294 rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
2298 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, false);
2302 address = BAR0_MAP_REG_USDM_RAM + USTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
2304 rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
2305 sizeof(struct ustorm_eth_queue_zone), timeset);
2309 p_hwfn->cdev->rx_coalesce_usecs = coalesce;
2314 int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
2315 u16 coalesce, u8 qid, u16 sb_id)
2317 struct xstorm_eth_queue_zone eth_qzone;
2318 u8 timeset, timer_res;
2323 /* Coalesce = (timeset << timer-resolution), timeset is 7bit wide */
2324 if (coalesce <= 0x7F) {
2326 } else if (coalesce <= 0xFF) {
2328 } else if (coalesce <= 0x1FF) {
2331 DP_ERR(p_hwfn, "Invalid coalesce value - %d\n", coalesce);
2334 timeset = (u8)(coalesce >> timer_res);
2336 rc = qed_fw_l2_queue(p_hwfn, (u16)qid, &fw_qid);
2340 rc = qed_int_set_timer_res(p_hwfn, p_ptt, timer_res, sb_id, true);
2344 address = BAR0_MAP_REG_XSDM_RAM + XSTORM_ETH_QUEUE_ZONE_OFFSET(fw_qid);
2346 rc = qed_set_coalesce(p_hwfn, p_ptt, address, ð_qzone,
2347 sizeof(struct xstorm_eth_queue_zone), timeset);
2351 p_hwfn->cdev->tx_coalesce_usecs = coalesce;
2356 /* Calculate final WFQ values for all vports and configure them.
2357 * After this configuration each vport will have
2358 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
2360 static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
2361 struct qed_ptt *p_ptt,
2364 struct init_qm_vport_params *vport_params;
2367 vport_params = p_hwfn->qm_info.qm_vport_params;
2369 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
2370 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
2372 vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
2374 qed_init_vport_wfq(p_hwfn, p_ptt,
2375 vport_params[i].first_tx_pq_id,
2376 vport_params[i].vport_wfq);
2380 static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
2386 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
2387 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
2390 static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
2391 struct qed_ptt *p_ptt,
2394 struct init_qm_vport_params *vport_params;
2397 vport_params = p_hwfn->qm_info.qm_vport_params;
2399 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
2400 qed_init_wfq_default_param(p_hwfn, min_pf_rate);
2401 qed_init_vport_wfq(p_hwfn, p_ptt,
2402 vport_params[i].first_tx_pq_id,
2403 vport_params[i].vport_wfq);
2407 /* This function performs several validations for WFQ
2408 * configuration and required min rate for a given vport
2409 * 1. req_rate must be greater than one percent of min_pf_rate.
2410 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
2411 * rates to get less than one percent of min_pf_rate.
2412 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
2414 static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
2415 u16 vport_id, u32 req_rate, u32 min_pf_rate)
2417 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
2418 int non_requested_count = 0, req_count = 0, i, num_vports;
2420 num_vports = p_hwfn->qm_info.num_vports;
2422 /* Accounting for the vports which are configured for WFQ explicitly */
2423 for (i = 0; i < num_vports; i++) {
2426 if ((i != vport_id) &&
2427 p_hwfn->qm_info.wfq_data[i].configured) {
2429 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
2430 total_req_min_rate += tmp_speed;
2434 /* Include current vport data as well */
2436 total_req_min_rate += req_rate;
2437 non_requested_count = num_vports - req_count;
2439 if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
2440 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2441 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
2442 vport_id, req_rate, min_pf_rate);
2446 if (num_vports > QED_WFQ_UNIT) {
2447 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2448 "Number of vports is greater than %d\n",
2453 if (total_req_min_rate > min_pf_rate) {
2454 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2455 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
2456 total_req_min_rate, min_pf_rate);
2460 total_left_rate = min_pf_rate - total_req_min_rate;
2462 left_rate_per_vp = total_left_rate / non_requested_count;
2463 if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
2464 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2465 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
2466 left_rate_per_vp, min_pf_rate);
2470 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
2471 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
2473 for (i = 0; i < num_vports; i++) {
2474 if (p_hwfn->qm_info.wfq_data[i].configured)
2477 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
2483 static int __qed_configure_vport_wfq(struct qed_hwfn *p_hwfn,
2484 struct qed_ptt *p_ptt, u16 vp_id, u32 rate)
2486 struct qed_mcp_link_state *p_link;
2489 p_link = &p_hwfn->cdev->hwfns[0].mcp_info->link_output;
2491 if (!p_link->min_pf_rate) {
2492 p_hwfn->qm_info.wfq_data[vp_id].min_speed = rate;
2493 p_hwfn->qm_info.wfq_data[vp_id].configured = true;
2497 rc = qed_init_wfq_param(p_hwfn, vp_id, rate, p_link->min_pf_rate);
2500 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt,
2501 p_link->min_pf_rate);
2504 "Validation failed while configuring min rate\n");
2509 static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
2510 struct qed_ptt *p_ptt,
2513 bool use_wfq = false;
2517 /* Validate all pre configured vports for wfq */
2518 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
2521 if (!p_hwfn->qm_info.wfq_data[i].configured)
2524 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
2527 rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
2530 "WFQ validation failed while configuring min rate\n");
2536 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
2538 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
2543 /* Main API for qed clients to configure vport min rate.
2544 * vp_id - vport id in PF Range[0 - (total_num_vports_per_pf - 1)]
2545 * rate - Speed in Mbps needs to be assigned to a given vport.
2547 int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate)
2549 int i, rc = -EINVAL;
2551 /* Currently not supported; Might change in future */
2552 if (cdev->num_hwfns > 1) {
2554 "WFQ configuration is not supported for this device\n");
2558 for_each_hwfn(cdev, i) {
2559 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2560 struct qed_ptt *p_ptt;
2562 p_ptt = qed_ptt_acquire(p_hwfn);
2566 rc = __qed_configure_vport_wfq(p_hwfn, p_ptt, vp_id, rate);
2569 qed_ptt_release(p_hwfn, p_ptt);
2573 qed_ptt_release(p_hwfn, p_ptt);
2579 /* API to configure WFQ from mcp link change */
2580 void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate)
2584 if (cdev->num_hwfns > 1) {
2587 "WFQ configuration is not supported for this device\n");
2591 for_each_hwfn(cdev, i) {
2592 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2594 __qed_configure_vp_wfq_on_link_change(p_hwfn,
2600 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
2601 struct qed_ptt *p_ptt,
2602 struct qed_mcp_link_state *p_link,
2607 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
2609 if (!p_link->line_speed && (max_bw != 100))
2612 p_link->speed = (p_link->line_speed * max_bw) / 100;
2613 p_hwfn->qm_info.pf_rl = p_link->speed;
2615 /* Since the limiter also affects Tx-switched traffic, we don't want it
2616 * to limit such traffic in case there's no actual limit.
2617 * In that case, set limit to imaginary high boundary.
2620 p_hwfn->qm_info.pf_rl = 100000;
2622 rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
2623 p_hwfn->qm_info.pf_rl);
2625 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2626 "Configured MAX bandwidth to be %08x Mb/sec\n",
2632 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
2633 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
2635 int i, rc = -EINVAL;
2637 if (max_bw < 1 || max_bw > 100) {
2638 DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
2642 for_each_hwfn(cdev, i) {
2643 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2644 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
2645 struct qed_mcp_link_state *p_link;
2646 struct qed_ptt *p_ptt;
2648 p_link = &p_lead->mcp_info->link_output;
2650 p_ptt = qed_ptt_acquire(p_hwfn);
2654 rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
2657 qed_ptt_release(p_hwfn, p_ptt);
2666 int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
2667 struct qed_ptt *p_ptt,
2668 struct qed_mcp_link_state *p_link,
2673 p_hwfn->mcp_info->func_info.bandwidth_min = min_bw;
2674 p_hwfn->qm_info.pf_wfq = min_bw;
2676 if (!p_link->line_speed)
2679 p_link->min_pf_rate = (p_link->line_speed * min_bw) / 100;
2681 rc = qed_init_pf_wfq(p_hwfn, p_ptt, p_hwfn->rel_pf_id, min_bw);
2683 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
2684 "Configured MIN bandwidth to be %d Mb/sec\n",
2685 p_link->min_pf_rate);
2690 /* Main API to configure PF min bandwidth where bw range is [1-100] */
2691 int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw)
2693 int i, rc = -EINVAL;
2695 if (min_bw < 1 || min_bw > 100) {
2696 DP_NOTICE(cdev, "PF min bw valid range is [1-100]\n");
2700 for_each_hwfn(cdev, i) {
2701 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
2702 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
2703 struct qed_mcp_link_state *p_link;
2704 struct qed_ptt *p_ptt;
2706 p_link = &p_lead->mcp_info->link_output;
2708 p_ptt = qed_ptt_acquire(p_hwfn);
2712 rc = __qed_configure_pf_min_bandwidth(p_hwfn, p_ptt,
2715 qed_ptt_release(p_hwfn, p_ptt);
2719 if (p_link->min_pf_rate) {
2720 u32 min_rate = p_link->min_pf_rate;
2722 rc = __qed_configure_vp_wfq_on_link_change(p_hwfn,
2727 qed_ptt_release(p_hwfn, p_ptt);
2733 void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
2735 struct qed_mcp_link_state *p_link;
2737 p_link = &p_hwfn->mcp_info->link_output;
2739 if (p_link->min_pf_rate)
2740 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt,
2741 p_link->min_pf_rate);
2743 memset(p_hwfn->qm_info.wfq_data, 0,
2744 sizeof(*p_hwfn->qm_info.wfq_data) * p_hwfn->qm_info.num_vports);