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/etherdevice.h>
21 #include <linux/qed/qed_chain.h>
22 #include <linux/qed/qed_if.h>
25 #include "qed_dev_api.h"
28 #include "qed_init_ops.h"
31 #include "qed_reg_addr.h"
33 #include "qed_sriov.h"
36 /* API common to all protocols */
38 BAR_ID_0
, /* used for GRC */
39 BAR_ID_1
/* Used for doorbells */
42 static u32
qed_hw_bar_size(struct qed_hwfn
*p_hwfn
,
45 u32 bar_reg
= (bar_id
== BAR_ID_0
?
46 PGLUE_B_REG_PF_BAR0_SIZE
: PGLUE_B_REG_PF_BAR1_SIZE
);
49 if (IS_VF(p_hwfn
->cdev
))
52 val
= qed_rd(p_hwfn
, p_hwfn
->p_main_ptt
, bar_reg
);
54 return 1 << (val
+ 15);
56 /* Old MFW initialized above registered only conditionally */
57 if (p_hwfn
->cdev
->num_hwfns
> 1) {
59 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
60 return BAR_ID_0
? 256 * 1024 : 512 * 1024;
63 "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
68 void qed_init_dp(struct qed_dev
*cdev
,
69 u32 dp_module
, u8 dp_level
)
73 cdev
->dp_level
= dp_level
;
74 cdev
->dp_module
= dp_module
;
75 for (i
= 0; i
< MAX_HWFNS_PER_DEVICE
; i
++) {
76 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
78 p_hwfn
->dp_level
= dp_level
;
79 p_hwfn
->dp_module
= dp_module
;
83 void qed_init_struct(struct qed_dev
*cdev
)
87 for (i
= 0; i
< MAX_HWFNS_PER_DEVICE
; i
++) {
88 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
92 p_hwfn
->b_active
= false;
94 mutex_init(&p_hwfn
->dmae_info
.mutex
);
97 /* hwfn 0 is always active */
98 cdev
->hwfns
[0].b_active
= true;
100 /* set the default cache alignment to 128 */
101 cdev
->cache_shift
= 7;
104 static void qed_qm_info_free(struct qed_hwfn
*p_hwfn
)
106 struct qed_qm_info
*qm_info
= &p_hwfn
->qm_info
;
108 kfree(qm_info
->qm_pq_params
);
109 qm_info
->qm_pq_params
= NULL
;
110 kfree(qm_info
->qm_vport_params
);
111 qm_info
->qm_vport_params
= NULL
;
112 kfree(qm_info
->qm_port_params
);
113 qm_info
->qm_port_params
= NULL
;
114 kfree(qm_info
->wfq_data
);
115 qm_info
->wfq_data
= NULL
;
118 void qed_resc_free(struct qed_dev
*cdev
)
125 kfree(cdev
->fw_data
);
126 cdev
->fw_data
= NULL
;
128 kfree(cdev
->reset_stats
);
130 for_each_hwfn(cdev
, i
) {
131 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
133 kfree(p_hwfn
->p_tx_cids
);
134 p_hwfn
->p_tx_cids
= NULL
;
135 kfree(p_hwfn
->p_rx_cids
);
136 p_hwfn
->p_rx_cids
= NULL
;
139 for_each_hwfn(cdev
, i
) {
140 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
142 qed_cxt_mngr_free(p_hwfn
);
143 qed_qm_info_free(p_hwfn
);
144 qed_spq_free(p_hwfn
);
145 qed_eq_free(p_hwfn
, p_hwfn
->p_eq
);
146 qed_consq_free(p_hwfn
, p_hwfn
->p_consq
);
147 qed_int_free(p_hwfn
);
148 qed_iov_free(p_hwfn
);
149 qed_dmae_info_free(p_hwfn
);
153 static int qed_init_qm_info(struct qed_hwfn
*p_hwfn
)
155 u8 num_vports
, vf_offset
= 0, i
, vport_id
, num_ports
, curr_queue
= 0;
156 struct qed_qm_info
*qm_info
= &p_hwfn
->qm_info
;
157 struct init_qm_port_params
*p_qm_port
;
158 u16 num_pqs
, multi_cos_tcs
= 1;
161 #ifdef CONFIG_QED_SRIOV
162 if (p_hwfn
->cdev
->p_iov_info
)
163 num_vfs
= p_hwfn
->cdev
->p_iov_info
->total_vfs
;
165 memset(qm_info
, 0, sizeof(*qm_info
));
167 num_pqs
= multi_cos_tcs
+ num_vfs
+ 1; /* The '1' is for pure-LB */
168 num_vports
= (u8
)RESC_NUM(p_hwfn
, QED_VPORT
);
170 /* Sanity checking that setup requires legal number of resources */
171 if (num_pqs
> RESC_NUM(p_hwfn
, QED_PQ
)) {
173 "Need too many Physical queues - 0x%04x when only %04x are available\n",
174 num_pqs
, RESC_NUM(p_hwfn
, QED_PQ
));
178 /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
180 qm_info
->qm_pq_params
= kzalloc(sizeof(*qm_info
->qm_pq_params
) *
181 num_pqs
, GFP_KERNEL
);
182 if (!qm_info
->qm_pq_params
)
185 qm_info
->qm_vport_params
= kzalloc(sizeof(*qm_info
->qm_vport_params
) *
186 num_vports
, GFP_KERNEL
);
187 if (!qm_info
->qm_vport_params
)
190 qm_info
->qm_port_params
= kzalloc(sizeof(*qm_info
->qm_port_params
) *
191 MAX_NUM_PORTS
, GFP_KERNEL
);
192 if (!qm_info
->qm_port_params
)
195 qm_info
->wfq_data
= kcalloc(num_vports
, sizeof(*qm_info
->wfq_data
),
197 if (!qm_info
->wfq_data
)
200 vport_id
= (u8
)RESC_START(p_hwfn
, QED_VPORT
);
202 /* First init per-TC PQs */
203 for (i
= 0; i
< multi_cos_tcs
; i
++, curr_queue
++) {
204 struct init_qm_pq_params
*params
=
205 &qm_info
->qm_pq_params
[curr_queue
];
207 params
->vport_id
= vport_id
;
208 params
->tc_id
= p_hwfn
->hw_info
.non_offload_tc
;
209 params
->wrr_group
= 1;
212 /* Then init pure-LB PQ */
213 qm_info
->pure_lb_pq
= curr_queue
;
214 qm_info
->qm_pq_params
[curr_queue
].vport_id
=
215 (u8
) RESC_START(p_hwfn
, QED_VPORT
);
216 qm_info
->qm_pq_params
[curr_queue
].tc_id
= PURE_LB_TC
;
217 qm_info
->qm_pq_params
[curr_queue
].wrr_group
= 1;
220 qm_info
->offload_pq
= 0;
221 /* Then init per-VF PQs */
222 vf_offset
= curr_queue
;
223 for (i
= 0; i
< num_vfs
; i
++) {
224 /* First vport is used by the PF */
225 qm_info
->qm_pq_params
[curr_queue
].vport_id
= vport_id
+ i
+ 1;
226 qm_info
->qm_pq_params
[curr_queue
].tc_id
=
227 p_hwfn
->hw_info
.non_offload_tc
;
228 qm_info
->qm_pq_params
[curr_queue
].wrr_group
= 1;
232 qm_info
->vf_queues_offset
= vf_offset
;
233 qm_info
->num_pqs
= num_pqs
;
234 qm_info
->num_vports
= num_vports
;
236 /* Initialize qm port parameters */
237 num_ports
= p_hwfn
->cdev
->num_ports_in_engines
;
238 for (i
= 0; i
< num_ports
; i
++) {
239 p_qm_port
= &qm_info
->qm_port_params
[i
];
240 p_qm_port
->active
= 1;
241 p_qm_port
->num_active_phys_tcs
= 4;
242 p_qm_port
->num_pbf_cmd_lines
= PBF_MAX_CMD_LINES
/ num_ports
;
243 p_qm_port
->num_btb_blocks
= BTB_MAX_BLOCKS
/ num_ports
;
246 qm_info
->max_phys_tcs_per_port
= NUM_OF_PHYS_TCS
;
248 qm_info
->start_pq
= (u16
)RESC_START(p_hwfn
, QED_PQ
);
250 qm_info
->num_vf_pqs
= num_vfs
;
251 qm_info
->start_vport
= (u8
) RESC_START(p_hwfn
, QED_VPORT
);
253 for (i
= 0; i
< qm_info
->num_vports
; i
++)
254 qm_info
->qm_vport_params
[i
].vport_wfq
= 1;
258 qm_info
->vport_rl_en
= 1;
259 qm_info
->vport_wfq_en
= 1;
264 DP_NOTICE(p_hwfn
, "Failed to allocate memory for QM params\n");
265 qed_qm_info_free(p_hwfn
);
269 int qed_resc_alloc(struct qed_dev
*cdev
)
271 struct qed_consq
*p_consq
;
278 cdev
->fw_data
= kzalloc(sizeof(*cdev
->fw_data
), GFP_KERNEL
);
282 /* Allocate Memory for the Queue->CID mapping */
283 for_each_hwfn(cdev
, i
) {
284 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
285 int tx_size
= sizeof(struct qed_hw_cid_data
) *
286 RESC_NUM(p_hwfn
, QED_L2_QUEUE
);
287 int rx_size
= sizeof(struct qed_hw_cid_data
) *
288 RESC_NUM(p_hwfn
, QED_L2_QUEUE
);
290 p_hwfn
->p_tx_cids
= kzalloc(tx_size
, GFP_KERNEL
);
291 if (!p_hwfn
->p_tx_cids
) {
293 "Failed to allocate memory for Tx Cids\n");
298 p_hwfn
->p_rx_cids
= kzalloc(rx_size
, GFP_KERNEL
);
299 if (!p_hwfn
->p_rx_cids
) {
301 "Failed to allocate memory for Rx Cids\n");
307 for_each_hwfn(cdev
, i
) {
308 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
310 /* First allocate the context manager structure */
311 rc
= qed_cxt_mngr_alloc(p_hwfn
);
315 /* Set the HW cid/tid numbers (in the contest manager)
316 * Must be done prior to any further computations.
318 rc
= qed_cxt_set_pf_params(p_hwfn
);
322 /* Prepare and process QM requirements */
323 rc
= qed_init_qm_info(p_hwfn
);
327 /* Compute the ILT client partition */
328 rc
= qed_cxt_cfg_ilt_compute(p_hwfn
);
332 /* CID map / ILT shadow table / T2
333 * The talbes sizes are determined by the computations above
335 rc
= qed_cxt_tables_alloc(p_hwfn
);
339 /* SPQ, must follow ILT because initializes SPQ context */
340 rc
= qed_spq_alloc(p_hwfn
);
344 /* SP status block allocation */
345 p_hwfn
->p_dpc_ptt
= qed_get_reserved_ptt(p_hwfn
,
348 rc
= qed_int_alloc(p_hwfn
, p_hwfn
->p_main_ptt
);
352 rc
= qed_iov_alloc(p_hwfn
);
357 p_eq
= qed_eq_alloc(p_hwfn
, 256);
364 p_consq
= qed_consq_alloc(p_hwfn
);
369 p_hwfn
->p_consq
= p_consq
;
371 /* DMA info initialization */
372 rc
= qed_dmae_info_alloc(p_hwfn
);
375 "Failed to allocate memory for dmae_info structure\n");
380 cdev
->reset_stats
= kzalloc(sizeof(*cdev
->reset_stats
), GFP_KERNEL
);
381 if (!cdev
->reset_stats
) {
382 DP_NOTICE(cdev
, "Failed to allocate reset statistics\n");
394 void qed_resc_setup(struct qed_dev
*cdev
)
401 for_each_hwfn(cdev
, i
) {
402 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
404 qed_cxt_mngr_setup(p_hwfn
);
405 qed_spq_setup(p_hwfn
);
406 qed_eq_setup(p_hwfn
, p_hwfn
->p_eq
);
407 qed_consq_setup(p_hwfn
, p_hwfn
->p_consq
);
409 /* Read shadow of current MFW mailbox */
410 qed_mcp_read_mb(p_hwfn
, p_hwfn
->p_main_ptt
);
411 memcpy(p_hwfn
->mcp_info
->mfw_mb_shadow
,
412 p_hwfn
->mcp_info
->mfw_mb_cur
,
413 p_hwfn
->mcp_info
->mfw_mb_length
);
415 qed_int_setup(p_hwfn
, p_hwfn
->p_main_ptt
);
417 qed_iov_setup(p_hwfn
, p_hwfn
->p_main_ptt
);
421 #define FINAL_CLEANUP_POLL_CNT (100)
422 #define FINAL_CLEANUP_POLL_TIME (10)
423 int qed_final_cleanup(struct qed_hwfn
*p_hwfn
,
424 struct qed_ptt
*p_ptt
, u16 id
, bool is_vf
)
426 u32 command
= 0, addr
, count
= FINAL_CLEANUP_POLL_CNT
;
429 addr
= GTT_BAR0_MAP_REG_USDM_RAM
+
430 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn
->rel_pf_id
);
435 command
|= X_FINAL_CLEANUP_AGG_INT
<<
436 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT
;
437 command
|= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT
;
438 command
|= id
<< SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT
;
439 command
|= SDM_COMP_TYPE_AGG_INT
<< SDM_OP_GEN_COMP_TYPE_SHIFT
;
441 /* Make sure notification is not set before initiating final cleanup */
442 if (REG_RD(p_hwfn
, addr
)) {
445 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
446 REG_WR(p_hwfn
, addr
, 0);
449 DP_VERBOSE(p_hwfn
, QED_MSG_IOV
,
450 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
453 qed_wr(p_hwfn
, p_ptt
, XSDM_REG_OPERATION_GEN
, command
);
455 /* Poll until completion */
456 while (!REG_RD(p_hwfn
, addr
) && count
--)
457 msleep(FINAL_CLEANUP_POLL_TIME
);
459 if (REG_RD(p_hwfn
, addr
))
463 "Failed to receive FW final cleanup notification\n");
465 /* Cleanup afterwards */
466 REG_WR(p_hwfn
, addr
, 0);
471 static void qed_calc_hw_mode(struct qed_hwfn
*p_hwfn
)
475 hw_mode
= (1 << MODE_BB_B0
);
477 switch (p_hwfn
->cdev
->num_ports_in_engines
) {
479 hw_mode
|= 1 << MODE_PORTS_PER_ENG_1
;
482 hw_mode
|= 1 << MODE_PORTS_PER_ENG_2
;
485 hw_mode
|= 1 << MODE_PORTS_PER_ENG_4
;
488 DP_NOTICE(p_hwfn
, "num_ports_in_engine = %d not supported\n",
489 p_hwfn
->cdev
->num_ports_in_engines
);
493 switch (p_hwfn
->cdev
->mf_mode
) {
496 hw_mode
|= 1 << MODE_MF_SI
;
499 hw_mode
|= 1 << MODE_MF_SD
;
502 DP_NOTICE(p_hwfn
, "Unsupported MF mode, init as DEFAULT\n");
503 hw_mode
|= 1 << MODE_MF_SI
;
506 hw_mode
|= 1 << MODE_ASIC
;
508 p_hwfn
->hw_info
.hw_mode
= hw_mode
;
511 /* Init run time data for all PFs on an engine. */
512 static void qed_init_cau_rt_data(struct qed_dev
*cdev
)
514 u32 offset
= CAU_REG_SB_VAR_MEMORY_RT_OFFSET
;
517 for_each_hwfn(cdev
, i
) {
518 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
519 struct qed_igu_info
*p_igu_info
;
520 struct qed_igu_block
*p_block
;
521 struct cau_sb_entry sb_entry
;
523 p_igu_info
= p_hwfn
->hw_info
.p_igu_info
;
525 for (sb_id
= 0; sb_id
< QED_MAPPING_MEMORY_SIZE(cdev
);
527 p_block
= &p_igu_info
->igu_map
.igu_blocks
[sb_id
];
531 qed_init_cau_sb_entry(p_hwfn
, &sb_entry
,
532 p_block
->function_id
,
534 STORE_RT_REG_AGG(p_hwfn
, offset
+ sb_id
* 2,
540 static int qed_hw_init_common(struct qed_hwfn
*p_hwfn
,
541 struct qed_ptt
*p_ptt
,
544 struct qed_qm_info
*qm_info
= &p_hwfn
->qm_info
;
545 struct qed_qm_common_rt_init_params params
;
546 struct qed_dev
*cdev
= p_hwfn
->cdev
;
551 qed_init_cau_rt_data(cdev
);
553 /* Program GTT windows */
554 qed_gtt_init(p_hwfn
);
556 if (p_hwfn
->mcp_info
) {
557 if (p_hwfn
->mcp_info
->func_info
.bandwidth_max
)
558 qm_info
->pf_rl_en
= 1;
559 if (p_hwfn
->mcp_info
->func_info
.bandwidth_min
)
560 qm_info
->pf_wfq_en
= 1;
563 memset(¶ms
, 0, sizeof(params
));
564 params
.max_ports_per_engine
= p_hwfn
->cdev
->num_ports_in_engines
;
565 params
.max_phys_tcs_per_port
= qm_info
->max_phys_tcs_per_port
;
566 params
.pf_rl_en
= qm_info
->pf_rl_en
;
567 params
.pf_wfq_en
= qm_info
->pf_wfq_en
;
568 params
.vport_rl_en
= qm_info
->vport_rl_en
;
569 params
.vport_wfq_en
= qm_info
->vport_wfq_en
;
570 params
.port_params
= qm_info
->qm_port_params
;
572 qed_qm_common_rt_init(p_hwfn
, ¶ms
);
574 qed_cxt_hw_init_common(p_hwfn
);
576 /* Close gate from NIG to BRB/Storm; By default they are open, but
577 * we close them to prevent NIG from passing data to reset blocks.
578 * Should have been done in the ENGINE phase, but init-tool lacks
579 * proper port-pretend capabilities.
581 qed_wr(p_hwfn
, p_ptt
, NIG_REG_RX_BRB_OUT_EN
, 0);
582 qed_wr(p_hwfn
, p_ptt
, NIG_REG_STORM_OUT_EN
, 0);
583 qed_port_pretend(p_hwfn
, p_ptt
, p_hwfn
->port_id
^ 1);
584 qed_wr(p_hwfn
, p_ptt
, NIG_REG_RX_BRB_OUT_EN
, 0);
585 qed_wr(p_hwfn
, p_ptt
, NIG_REG_STORM_OUT_EN
, 0);
586 qed_port_unpretend(p_hwfn
, p_ptt
);
588 rc
= qed_init_run(p_hwfn
, p_ptt
, PHASE_ENGINE
, ANY_PHASE_ID
, hw_mode
);
592 qed_wr(p_hwfn
, p_ptt
, PSWRQ2_REG_L2P_VALIDATE_VFID
, 0);
593 qed_wr(p_hwfn
, p_ptt
, PGLUE_B_REG_USE_CLIENTID_IN_TAG
, 1);
595 /* Disable relaxed ordering in the PCI config space */
596 qed_wr(p_hwfn
, p_ptt
, 0x20b4,
597 qed_rd(p_hwfn
, p_ptt
, 0x20b4) & ~0x10);
599 for (vf_id
= 0; vf_id
< MAX_NUM_VFS_BB
; vf_id
++) {
600 concrete_fid
= qed_vfid_to_concrete(p_hwfn
, vf_id
);
601 qed_fid_pretend(p_hwfn
, p_ptt
, (u16
) concrete_fid
);
602 qed_wr(p_hwfn
, p_ptt
, CCFC_REG_STRONG_ENABLE_VF
, 0x1);
604 /* pretend to original PF */
605 qed_fid_pretend(p_hwfn
, p_ptt
, p_hwfn
->rel_pf_id
);
610 static int qed_hw_init_port(struct qed_hwfn
*p_hwfn
,
611 struct qed_ptt
*p_ptt
,
616 rc
= qed_init_run(p_hwfn
, p_ptt
, PHASE_PORT
, p_hwfn
->port_id
,
621 static int qed_hw_init_pf(struct qed_hwfn
*p_hwfn
,
622 struct qed_ptt
*p_ptt
,
623 struct qed_tunn_start_params
*p_tunn
,
626 enum qed_int_mode int_mode
,
627 bool allow_npar_tx_switch
)
629 u8 rel_pf_id
= p_hwfn
->rel_pf_id
;
632 if (p_hwfn
->mcp_info
) {
633 struct qed_mcp_function_info
*p_info
;
635 p_info
= &p_hwfn
->mcp_info
->func_info
;
636 if (p_info
->bandwidth_min
)
637 p_hwfn
->qm_info
.pf_wfq
= p_info
->bandwidth_min
;
639 /* Update rate limit once we'll actually have a link */
640 p_hwfn
->qm_info
.pf_rl
= 100000;
643 qed_cxt_hw_init_pf(p_hwfn
);
645 qed_int_igu_init_rt(p_hwfn
);
647 /* Set VLAN in NIG if needed */
648 if (hw_mode
& (1 << MODE_MF_SD
)) {
649 DP_VERBOSE(p_hwfn
, NETIF_MSG_HW
, "Configuring LLH_FUNC_TAG\n");
650 STORE_RT_REG(p_hwfn
, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET
, 1);
651 STORE_RT_REG(p_hwfn
, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET
,
652 p_hwfn
->hw_info
.ovlan
);
655 /* Enable classification by MAC if needed */
656 if (hw_mode
& (1 << MODE_MF_SI
)) {
657 DP_VERBOSE(p_hwfn
, NETIF_MSG_HW
,
658 "Configuring TAGMAC_CLS_TYPE\n");
660 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET
, 1);
663 /* Protocl Configuration */
664 STORE_RT_REG(p_hwfn
, PRS_REG_SEARCH_TCP_RT_OFFSET
, 0);
665 STORE_RT_REG(p_hwfn
, PRS_REG_SEARCH_FCOE_RT_OFFSET
, 0);
666 STORE_RT_REG(p_hwfn
, PRS_REG_SEARCH_ROCE_RT_OFFSET
, 0);
668 /* Cleanup chip from previous driver if such remains exist */
669 rc
= qed_final_cleanup(p_hwfn
, p_ptt
, rel_pf_id
, false);
673 /* PF Init sequence */
674 rc
= qed_init_run(p_hwfn
, p_ptt
, PHASE_PF
, rel_pf_id
, hw_mode
);
678 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
679 rc
= qed_init_run(p_hwfn
, p_ptt
, PHASE_QM_PF
, rel_pf_id
, hw_mode
);
683 /* Pure runtime initializations - directly to the HW */
684 qed_int_igu_init_pure_rt(p_hwfn
, p_ptt
, true, true);
687 /* enable interrupts */
688 qed_int_igu_enable(p_hwfn
, p_ptt
, int_mode
);
690 /* send function start command */
691 rc
= qed_sp_pf_start(p_hwfn
, p_tunn
, p_hwfn
->cdev
->mf_mode
);
693 DP_NOTICE(p_hwfn
, "Function start ramrod failed\n");
698 static int qed_change_pci_hwfn(struct qed_hwfn
*p_hwfn
,
699 struct qed_ptt
*p_ptt
,
702 u32 delay_idx
= 0, val
, set_val
= enable
? 1 : 0;
704 /* Change PF in PXP */
705 qed_wr(p_hwfn
, p_ptt
,
706 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
, set_val
);
708 /* wait until value is set - try for 1 second every 50us */
709 for (delay_idx
= 0; delay_idx
< 20000; delay_idx
++) {
710 val
= qed_rd(p_hwfn
, p_ptt
,
711 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER
);
715 usleep_range(50, 60);
718 if (val
!= set_val
) {
720 "PFID_ENABLE_MASTER wasn't changed after a second\n");
727 static void qed_reset_mb_shadow(struct qed_hwfn
*p_hwfn
,
728 struct qed_ptt
*p_main_ptt
)
730 /* Read shadow of current MFW mailbox */
731 qed_mcp_read_mb(p_hwfn
, p_main_ptt
);
732 memcpy(p_hwfn
->mcp_info
->mfw_mb_shadow
,
733 p_hwfn
->mcp_info
->mfw_mb_cur
,
734 p_hwfn
->mcp_info
->mfw_mb_length
);
737 int qed_hw_init(struct qed_dev
*cdev
,
738 struct qed_tunn_start_params
*p_tunn
,
740 enum qed_int_mode int_mode
,
741 bool allow_npar_tx_switch
,
742 const u8
*bin_fw_data
)
744 u32 load_code
, param
;
748 rc
= qed_init_fw_data(cdev
, bin_fw_data
);
753 for_each_hwfn(cdev
, i
) {
754 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
757 p_hwfn
->b_int_enabled
= 1;
761 /* Enable DMAE in PXP */
762 rc
= qed_change_pci_hwfn(p_hwfn
, p_hwfn
->p_main_ptt
, true);
764 qed_calc_hw_mode(p_hwfn
);
766 rc
= qed_mcp_load_req(p_hwfn
, p_hwfn
->p_main_ptt
,
769 DP_NOTICE(p_hwfn
, "Failed sending LOAD_REQ command\n");
773 qed_reset_mb_shadow(p_hwfn
, p_hwfn
->p_main_ptt
);
775 DP_VERBOSE(p_hwfn
, QED_MSG_SP
,
776 "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
779 p_hwfn
->first_on_engine
= (load_code
==
780 FW_MSG_CODE_DRV_LOAD_ENGINE
);
783 case FW_MSG_CODE_DRV_LOAD_ENGINE
:
784 rc
= qed_hw_init_common(p_hwfn
, p_hwfn
->p_main_ptt
,
785 p_hwfn
->hw_info
.hw_mode
);
789 case FW_MSG_CODE_DRV_LOAD_PORT
:
790 rc
= qed_hw_init_port(p_hwfn
, p_hwfn
->p_main_ptt
,
791 p_hwfn
->hw_info
.hw_mode
);
796 case FW_MSG_CODE_DRV_LOAD_FUNCTION
:
797 rc
= qed_hw_init_pf(p_hwfn
, p_hwfn
->p_main_ptt
,
798 p_tunn
, p_hwfn
->hw_info
.hw_mode
,
799 b_hw_start
, int_mode
,
800 allow_npar_tx_switch
);
809 "init phase failed for loadcode 0x%x (rc %d)\n",
812 /* ACK mfw regardless of success or failure of initialization */
813 mfw_rc
= qed_mcp_cmd(p_hwfn
, p_hwfn
->p_main_ptt
,
814 DRV_MSG_CODE_LOAD_DONE
,
815 0, &load_code
, ¶m
);
819 DP_NOTICE(p_hwfn
, "Failed sending LOAD_DONE command\n");
823 p_hwfn
->hw_init_done
= true;
829 #define QED_HW_STOP_RETRY_LIMIT (10)
830 static inline void qed_hw_timers_stop(struct qed_dev
*cdev
,
831 struct qed_hwfn
*p_hwfn
,
832 struct qed_ptt
*p_ptt
)
837 qed_wr(p_hwfn
, p_ptt
, TM_REG_PF_ENABLE_CONN
, 0x0);
838 qed_wr(p_hwfn
, p_ptt
, TM_REG_PF_ENABLE_TASK
, 0x0);
840 for (i
= 0; i
< QED_HW_STOP_RETRY_LIMIT
; i
++) {
841 if ((!qed_rd(p_hwfn
, p_ptt
,
842 TM_REG_PF_SCAN_ACTIVE_CONN
)) &&
843 (!qed_rd(p_hwfn
, p_ptt
,
844 TM_REG_PF_SCAN_ACTIVE_TASK
)))
847 /* Dependent on number of connection/tasks, possibly
848 * 1ms sleep is required between polls
850 usleep_range(1000, 2000);
853 if (i
< QED_HW_STOP_RETRY_LIMIT
)
857 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
858 (u8
)qed_rd(p_hwfn
, p_ptt
, TM_REG_PF_SCAN_ACTIVE_CONN
),
859 (u8
)qed_rd(p_hwfn
, p_ptt
, TM_REG_PF_SCAN_ACTIVE_TASK
));
862 void qed_hw_timers_stop_all(struct qed_dev
*cdev
)
866 for_each_hwfn(cdev
, j
) {
867 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[j
];
868 struct qed_ptt
*p_ptt
= p_hwfn
->p_main_ptt
;
870 qed_hw_timers_stop(cdev
, p_hwfn
, p_ptt
);
874 int qed_hw_stop(struct qed_dev
*cdev
)
879 for_each_hwfn(cdev
, j
) {
880 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[j
];
881 struct qed_ptt
*p_ptt
= p_hwfn
->p_main_ptt
;
883 DP_VERBOSE(p_hwfn
, NETIF_MSG_IFDOWN
, "Stopping hw/fw\n");
886 qed_vf_pf_int_cleanup(p_hwfn
);
890 /* mark the hw as uninitialized... */
891 p_hwfn
->hw_init_done
= false;
893 rc
= qed_sp_pf_stop(p_hwfn
);
896 "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
898 qed_wr(p_hwfn
, p_ptt
,
899 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF
, 0x1);
901 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_TCP
, 0x0);
902 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_UDP
, 0x0);
903 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_FCOE
, 0x0);
904 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_ROCE
, 0x0);
905 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_OPENFLOW
, 0x0);
907 qed_hw_timers_stop(cdev
, p_hwfn
, p_ptt
);
909 /* Disable Attention Generation */
910 qed_int_igu_disable_int(p_hwfn
, p_ptt
);
912 qed_wr(p_hwfn
, p_ptt
, IGU_REG_LEADING_EDGE_LATCH
, 0);
913 qed_wr(p_hwfn
, p_ptt
, IGU_REG_TRAILING_EDGE_LATCH
, 0);
915 qed_int_igu_init_pure_rt(p_hwfn
, p_ptt
, false, true);
917 /* Need to wait 1ms to guarantee SBs are cleared */
918 usleep_range(1000, 2000);
922 /* Disable DMAE in PXP - in CMT, this should only be done for
923 * first hw-function, and only after all transactions have
924 * stopped for all active hw-functions.
926 t_rc
= qed_change_pci_hwfn(&cdev
->hwfns
[0],
927 cdev
->hwfns
[0].p_main_ptt
, false);
935 void qed_hw_stop_fastpath(struct qed_dev
*cdev
)
939 for_each_hwfn(cdev
, j
) {
940 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[j
];
941 struct qed_ptt
*p_ptt
= p_hwfn
->p_main_ptt
;
945 "Shutting down the fastpath\n");
947 qed_wr(p_hwfn
, p_ptt
,
948 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF
, 0x1);
950 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_TCP
, 0x0);
951 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_UDP
, 0x0);
952 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_FCOE
, 0x0);
953 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_ROCE
, 0x0);
954 qed_wr(p_hwfn
, p_ptt
, PRS_REG_SEARCH_OPENFLOW
, 0x0);
956 qed_int_igu_init_pure_rt(p_hwfn
, p_ptt
, false, false);
958 /* Need to wait 1ms to guarantee SBs are cleared */
959 usleep_range(1000, 2000);
963 void qed_hw_start_fastpath(struct qed_hwfn
*p_hwfn
)
965 /* Re-open incoming traffic */
966 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
,
967 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF
, 0x0);
970 static int qed_reg_assert(struct qed_hwfn
*hwfn
,
971 struct qed_ptt
*ptt
, u32 reg
,
974 u32 assert_val
= qed_rd(hwfn
, ptt
, reg
);
976 if (assert_val
!= expected
) {
977 DP_NOTICE(hwfn
, "Value at address 0x%x != 0x%08x\n",
985 int qed_hw_reset(struct qed_dev
*cdev
)
988 u32 unload_resp
, unload_param
;
991 for_each_hwfn(cdev
, i
) {
992 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
995 rc
= qed_vf_pf_reset(p_hwfn
);
1001 DP_VERBOSE(p_hwfn
, NETIF_MSG_IFDOWN
, "Resetting hw/fw\n");
1003 /* Check for incorrect states */
1004 qed_reg_assert(p_hwfn
, p_hwfn
->p_main_ptt
,
1005 QM_REG_USG_CNT_PF_TX
, 0);
1006 qed_reg_assert(p_hwfn
, p_hwfn
->p_main_ptt
,
1007 QM_REG_USG_CNT_PF_OTHER
, 0);
1009 /* Disable PF in HW blocks */
1010 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
, DORQ_REG_PF_DB_ENABLE
, 0);
1011 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
, QM_REG_PF_EN
, 0);
1012 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
,
1013 TCFC_REG_STRONG_ENABLE_PF
, 0);
1014 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
,
1015 CCFC_REG_STRONG_ENABLE_PF
, 0);
1017 /* Send unload command to MCP */
1018 rc
= qed_mcp_cmd(p_hwfn
, p_hwfn
->p_main_ptt
,
1019 DRV_MSG_CODE_UNLOAD_REQ
,
1020 DRV_MB_PARAM_UNLOAD_WOL_MCP
,
1021 &unload_resp
, &unload_param
);
1023 DP_NOTICE(p_hwfn
, "qed_hw_reset: UNLOAD_REQ failed\n");
1024 unload_resp
= FW_MSG_CODE_DRV_UNLOAD_ENGINE
;
1027 rc
= qed_mcp_cmd(p_hwfn
, p_hwfn
->p_main_ptt
,
1028 DRV_MSG_CODE_UNLOAD_DONE
,
1029 0, &unload_resp
, &unload_param
);
1031 DP_NOTICE(p_hwfn
, "qed_hw_reset: UNLOAD_DONE failed\n");
1039 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
1040 static void qed_hw_hwfn_free(struct qed_hwfn
*p_hwfn
)
1042 qed_ptt_pool_free(p_hwfn
);
1043 kfree(p_hwfn
->hw_info
.p_igu_info
);
1046 /* Setup bar access */
1047 static void qed_hw_hwfn_prepare(struct qed_hwfn
*p_hwfn
)
1049 /* clear indirect access */
1050 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
, PGLUE_B_REG_PGL_ADDR_88_F0
, 0);
1051 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
, PGLUE_B_REG_PGL_ADDR_8C_F0
, 0);
1052 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
, PGLUE_B_REG_PGL_ADDR_90_F0
, 0);
1053 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
, PGLUE_B_REG_PGL_ADDR_94_F0
, 0);
1055 /* Clean Previous errors if such exist */
1056 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
,
1057 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR
,
1058 1 << p_hwfn
->abs_pf_id
);
1060 /* enable internal target-read */
1061 qed_wr(p_hwfn
, p_hwfn
->p_main_ptt
,
1062 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ
, 1);
1065 static void get_function_id(struct qed_hwfn
*p_hwfn
)
1068 p_hwfn
->hw_info
.opaque_fid
= (u16
)REG_RD(p_hwfn
, PXP_PF_ME_OPAQUE_ADDR
);
1070 p_hwfn
->hw_info
.concrete_fid
= REG_RD(p_hwfn
, PXP_PF_ME_CONCRETE_ADDR
);
1072 p_hwfn
->abs_pf_id
= (p_hwfn
->hw_info
.concrete_fid
>> 16) & 0xf;
1073 p_hwfn
->rel_pf_id
= GET_FIELD(p_hwfn
->hw_info
.concrete_fid
,
1074 PXP_CONCRETE_FID_PFID
);
1075 p_hwfn
->port_id
= GET_FIELD(p_hwfn
->hw_info
.concrete_fid
,
1076 PXP_CONCRETE_FID_PORT
);
1079 static void qed_hw_set_feat(struct qed_hwfn
*p_hwfn
)
1081 u32
*feat_num
= p_hwfn
->hw_info
.feat_num
;
1082 int num_features
= 1;
1084 feat_num
[QED_PF_L2_QUE
] = min_t(u32
, RESC_NUM(p_hwfn
, QED_SB
) /
1086 RESC_NUM(p_hwfn
, QED_L2_QUEUE
));
1087 DP_VERBOSE(p_hwfn
, NETIF_MSG_PROBE
,
1088 "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
1089 feat_num
[QED_PF_L2_QUE
], RESC_NUM(p_hwfn
, QED_SB
),
1093 static void qed_hw_get_resc(struct qed_hwfn
*p_hwfn
)
1095 u32
*resc_start
= p_hwfn
->hw_info
.resc_start
;
1096 u8 num_funcs
= p_hwfn
->num_funcs_on_engine
;
1097 u32
*resc_num
= p_hwfn
->hw_info
.resc_num
;
1098 struct qed_sb_cnt_info sb_cnt_info
;
1101 memset(&sb_cnt_info
, 0, sizeof(sb_cnt_info
));
1102 qed_int_get_num_sbs(p_hwfn
, &sb_cnt_info
);
1104 resc_num
[QED_SB
] = min_t(u32
,
1105 (MAX_SB_PER_PATH_BB
/ num_funcs
),
1106 sb_cnt_info
.sb_cnt
);
1107 resc_num
[QED_L2_QUEUE
] = MAX_NUM_L2_QUEUES_BB
/ num_funcs
;
1108 resc_num
[QED_VPORT
] = MAX_NUM_VPORTS_BB
/ num_funcs
;
1109 resc_num
[QED_RSS_ENG
] = ETH_RSS_ENGINE_NUM_BB
/ num_funcs
;
1110 resc_num
[QED_PQ
] = MAX_QM_TX_QUEUES_BB
/ num_funcs
;
1111 resc_num
[QED_RL
] = 8;
1112 resc_num
[QED_MAC
] = ETH_NUM_MAC_FILTERS
/ num_funcs
;
1113 resc_num
[QED_VLAN
] = (ETH_NUM_VLAN_FILTERS
- 1 /*For vlan0*/) /
1115 resc_num
[QED_ILT
] = 950;
1117 for (i
= 0; i
< QED_MAX_RESC
; i
++)
1118 resc_start
[i
] = resc_num
[i
] * p_hwfn
->rel_pf_id
;
1120 qed_hw_set_feat(p_hwfn
);
1122 DP_VERBOSE(p_hwfn
, NETIF_MSG_PROBE
,
1123 "The numbers for each resource are:\n"
1124 "SB = %d start = %d\n"
1125 "L2_QUEUE = %d start = %d\n"
1126 "VPORT = %d start = %d\n"
1127 "PQ = %d start = %d\n"
1128 "RL = %d start = %d\n"
1129 "MAC = %d start = %d\n"
1130 "VLAN = %d start = %d\n"
1131 "ILT = %d start = %d\n",
1132 p_hwfn
->hw_info
.resc_num
[QED_SB
],
1133 p_hwfn
->hw_info
.resc_start
[QED_SB
],
1134 p_hwfn
->hw_info
.resc_num
[QED_L2_QUEUE
],
1135 p_hwfn
->hw_info
.resc_start
[QED_L2_QUEUE
],
1136 p_hwfn
->hw_info
.resc_num
[QED_VPORT
],
1137 p_hwfn
->hw_info
.resc_start
[QED_VPORT
],
1138 p_hwfn
->hw_info
.resc_num
[QED_PQ
],
1139 p_hwfn
->hw_info
.resc_start
[QED_PQ
],
1140 p_hwfn
->hw_info
.resc_num
[QED_RL
],
1141 p_hwfn
->hw_info
.resc_start
[QED_RL
],
1142 p_hwfn
->hw_info
.resc_num
[QED_MAC
],
1143 p_hwfn
->hw_info
.resc_start
[QED_MAC
],
1144 p_hwfn
->hw_info
.resc_num
[QED_VLAN
],
1145 p_hwfn
->hw_info
.resc_start
[QED_VLAN
],
1146 p_hwfn
->hw_info
.resc_num
[QED_ILT
],
1147 p_hwfn
->hw_info
.resc_start
[QED_ILT
]);
1150 static int qed_hw_get_nvm_info(struct qed_hwfn
*p_hwfn
,
1151 struct qed_ptt
*p_ptt
)
1153 u32 nvm_cfg1_offset
, mf_mode
, addr
, generic_cont0
, core_cfg
;
1154 u32 port_cfg_addr
, link_temp
, nvm_cfg_addr
, device_capabilities
;
1155 struct qed_mcp_link_params
*link
;
1157 /* Read global nvm_cfg address */
1158 nvm_cfg_addr
= qed_rd(p_hwfn
, p_ptt
, MISC_REG_GEN_PURP_CR0
);
1160 /* Verify MCP has initialized it */
1161 if (!nvm_cfg_addr
) {
1162 DP_NOTICE(p_hwfn
, "Shared memory not initialized\n");
1166 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
1167 nvm_cfg1_offset
= qed_rd(p_hwfn
, p_ptt
, nvm_cfg_addr
+ 4);
1169 addr
= MCP_REG_SCRATCH
+ nvm_cfg1_offset
+
1170 offsetof(struct nvm_cfg1
, glob
) +
1171 offsetof(struct nvm_cfg1_glob
, core_cfg
);
1173 core_cfg
= qed_rd(p_hwfn
, p_ptt
, addr
);
1175 switch ((core_cfg
& NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK
) >>
1176 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET
) {
1177 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X40G
:
1178 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_2X40G
;
1180 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X50G
:
1181 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_2X50G
;
1183 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X100G
:
1184 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_1X100G
;
1186 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_F
:
1187 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_4X10G_F
;
1189 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_E
:
1190 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_4X10G_E
;
1192 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X20G
:
1193 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_4X20G
;
1195 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X40G
:
1196 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_1X40G
;
1198 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X25G
:
1199 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_2X25G
;
1201 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X25G
:
1202 p_hwfn
->hw_info
.port_mode
= QED_PORT_MODE_DE_1X25G
;
1205 DP_NOTICE(p_hwfn
, "Unknown port mode in 0x%08x\n",
1210 /* Read default link configuration */
1211 link
= &p_hwfn
->mcp_info
->link_input
;
1212 port_cfg_addr
= MCP_REG_SCRATCH
+ nvm_cfg1_offset
+
1213 offsetof(struct nvm_cfg1
, port
[MFW_PORT(p_hwfn
)]);
1214 link_temp
= qed_rd(p_hwfn
, p_ptt
,
1216 offsetof(struct nvm_cfg1_port
, speed_cap_mask
));
1217 link
->speed
.advertised_speeds
=
1218 link_temp
& NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK
;
1220 p_hwfn
->mcp_info
->link_capabilities
.speed_capabilities
=
1221 link
->speed
.advertised_speeds
;
1223 link_temp
= qed_rd(p_hwfn
, p_ptt
,
1225 offsetof(struct nvm_cfg1_port
, link_settings
));
1226 switch ((link_temp
& NVM_CFG1_PORT_DRV_LINK_SPEED_MASK
) >>
1227 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET
) {
1228 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG
:
1229 link
->speed
.autoneg
= true;
1231 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G
:
1232 link
->speed
.forced_speed
= 1000;
1234 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G
:
1235 link
->speed
.forced_speed
= 10000;
1237 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G
:
1238 link
->speed
.forced_speed
= 25000;
1240 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G
:
1241 link
->speed
.forced_speed
= 40000;
1243 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G
:
1244 link
->speed
.forced_speed
= 50000;
1246 case NVM_CFG1_PORT_DRV_LINK_SPEED_100G
:
1247 link
->speed
.forced_speed
= 100000;
1250 DP_NOTICE(p_hwfn
, "Unknown Speed in 0x%08x\n",
1254 link_temp
&= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK
;
1255 link_temp
>>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET
;
1256 link
->pause
.autoneg
= !!(link_temp
&
1257 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG
);
1258 link
->pause
.forced_rx
= !!(link_temp
&
1259 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX
);
1260 link
->pause
.forced_tx
= !!(link_temp
&
1261 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX
);
1262 link
->loopback_mode
= 0;
1264 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
1265 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
1266 link
->speed
.forced_speed
, link
->speed
.advertised_speeds
,
1267 link
->speed
.autoneg
, link
->pause
.autoneg
);
1269 /* Read Multi-function information from shmem */
1270 addr
= MCP_REG_SCRATCH
+ nvm_cfg1_offset
+
1271 offsetof(struct nvm_cfg1
, glob
) +
1272 offsetof(struct nvm_cfg1_glob
, generic_cont0
);
1274 generic_cont0
= qed_rd(p_hwfn
, p_ptt
, addr
);
1276 mf_mode
= (generic_cont0
& NVM_CFG1_GLOB_MF_MODE_MASK
) >>
1277 NVM_CFG1_GLOB_MF_MODE_OFFSET
;
1280 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED
:
1281 p_hwfn
->cdev
->mf_mode
= QED_MF_OVLAN
;
1283 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0
:
1284 p_hwfn
->cdev
->mf_mode
= QED_MF_NPAR
;
1286 case NVM_CFG1_GLOB_MF_MODE_DEFAULT
:
1287 p_hwfn
->cdev
->mf_mode
= QED_MF_DEFAULT
;
1290 DP_INFO(p_hwfn
, "Multi function mode is %08x\n",
1291 p_hwfn
->cdev
->mf_mode
);
1293 /* Read Multi-function information from shmem */
1294 addr
= MCP_REG_SCRATCH
+ nvm_cfg1_offset
+
1295 offsetof(struct nvm_cfg1
, glob
) +
1296 offsetof(struct nvm_cfg1_glob
, device_capabilities
);
1298 device_capabilities
= qed_rd(p_hwfn
, p_ptt
, addr
);
1299 if (device_capabilities
& NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET
)
1300 __set_bit(QED_DEV_CAP_ETH
,
1301 &p_hwfn
->hw_info
.device_capabilities
);
1303 return qed_mcp_fill_shmem_func_info(p_hwfn
, p_ptt
);
1306 static void qed_get_num_funcs(struct qed_hwfn
*p_hwfn
, struct qed_ptt
*p_ptt
)
1308 u32 reg_function_hide
, tmp
, eng_mask
;
1311 num_funcs
= MAX_NUM_PFS_BB
;
1313 /* Bit 0 of MISCS_REG_FUNCTION_HIDE indicates whether the bypass values
1314 * in the other bits are selected.
1315 * Bits 1-15 are for functions 1-15, respectively, and their value is
1316 * '0' only for enabled functions (function 0 always exists and
1318 * In case of CMT, only the "even" functions are enabled, and thus the
1319 * number of functions for both hwfns is learnt from the same bits.
1321 reg_function_hide
= qed_rd(p_hwfn
, p_ptt
, MISCS_REG_FUNCTION_HIDE
);
1323 if (reg_function_hide
& 0x1) {
1324 if (QED_PATH_ID(p_hwfn
) && p_hwfn
->cdev
->num_hwfns
== 1) {
1332 /* Get the number of the enabled functions on the engine */
1333 tmp
= (reg_function_hide
^ 0xffffffff) & eng_mask
;
1341 p_hwfn
->num_funcs_on_engine
= num_funcs
;
1345 "PF [rel_id %d, abs_id %d] within the %d enabled functions on the engine\n",
1348 p_hwfn
->num_funcs_on_engine
);
1352 qed_get_hw_info(struct qed_hwfn
*p_hwfn
,
1353 struct qed_ptt
*p_ptt
,
1354 enum qed_pci_personality personality
)
1359 /* Since all information is common, only first hwfns should do this */
1360 if (IS_LEAD_HWFN(p_hwfn
)) {
1361 rc
= qed_iov_hw_info(p_hwfn
);
1366 /* Read the port mode */
1367 port_mode
= qed_rd(p_hwfn
, p_ptt
,
1368 CNIG_REG_NW_PORT_MODE_BB_B0
);
1370 if (port_mode
< 3) {
1371 p_hwfn
->cdev
->num_ports_in_engines
= 1;
1372 } else if (port_mode
<= 5) {
1373 p_hwfn
->cdev
->num_ports_in_engines
= 2;
1375 DP_NOTICE(p_hwfn
, "PORT MODE: %d not supported\n",
1376 p_hwfn
->cdev
->num_ports_in_engines
);
1378 /* Default num_ports_in_engines to something */
1379 p_hwfn
->cdev
->num_ports_in_engines
= 1;
1382 qed_hw_get_nvm_info(p_hwfn
, p_ptt
);
1384 rc
= qed_int_igu_read_cam(p_hwfn
, p_ptt
);
1388 if (qed_mcp_is_init(p_hwfn
))
1389 ether_addr_copy(p_hwfn
->hw_info
.hw_mac_addr
,
1390 p_hwfn
->mcp_info
->func_info
.mac
);
1392 eth_random_addr(p_hwfn
->hw_info
.hw_mac_addr
);
1394 if (qed_mcp_is_init(p_hwfn
)) {
1395 if (p_hwfn
->mcp_info
->func_info
.ovlan
!= QED_MCP_VLAN_UNSET
)
1396 p_hwfn
->hw_info
.ovlan
=
1397 p_hwfn
->mcp_info
->func_info
.ovlan
;
1399 qed_mcp_cmd_port_init(p_hwfn
, p_ptt
);
1402 if (qed_mcp_is_init(p_hwfn
)) {
1403 enum qed_pci_personality protocol
;
1405 protocol
= p_hwfn
->mcp_info
->func_info
.protocol
;
1406 p_hwfn
->hw_info
.personality
= protocol
;
1409 qed_get_num_funcs(p_hwfn
, p_ptt
);
1411 qed_hw_get_resc(p_hwfn
);
1416 static int qed_get_dev_info(struct qed_dev
*cdev
)
1418 struct qed_hwfn
*p_hwfn
= QED_LEADING_HWFN(cdev
);
1421 /* Read Vendor Id / Device Id */
1422 pci_read_config_word(cdev
->pdev
, PCI_VENDOR_ID
,
1424 pci_read_config_word(cdev
->pdev
, PCI_DEVICE_ID
,
1426 cdev
->chip_num
= (u16
)qed_rd(p_hwfn
, p_hwfn
->p_main_ptt
,
1427 MISCS_REG_CHIP_NUM
);
1428 cdev
->chip_rev
= (u16
)qed_rd(p_hwfn
, p_hwfn
->p_main_ptt
,
1429 MISCS_REG_CHIP_REV
);
1430 MASK_FIELD(CHIP_REV
, cdev
->chip_rev
);
1432 cdev
->type
= QED_DEV_TYPE_BB
;
1433 /* Learn number of HW-functions */
1434 tmp
= qed_rd(p_hwfn
, p_hwfn
->p_main_ptt
,
1435 MISCS_REG_CMT_ENABLED_FOR_PAIR
);
1437 if (tmp
& (1 << p_hwfn
->rel_pf_id
)) {
1438 DP_NOTICE(cdev
->hwfns
, "device in CMT mode\n");
1439 cdev
->num_hwfns
= 2;
1441 cdev
->num_hwfns
= 1;
1444 cdev
->chip_bond_id
= qed_rd(p_hwfn
, p_hwfn
->p_main_ptt
,
1445 MISCS_REG_CHIP_TEST_REG
) >> 4;
1446 MASK_FIELD(CHIP_BOND_ID
, cdev
->chip_bond_id
);
1447 cdev
->chip_metal
= (u16
)qed_rd(p_hwfn
, p_hwfn
->p_main_ptt
,
1448 MISCS_REG_CHIP_METAL
);
1449 MASK_FIELD(CHIP_METAL
, cdev
->chip_metal
);
1451 DP_INFO(cdev
->hwfns
,
1452 "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
1453 cdev
->chip_num
, cdev
->chip_rev
,
1454 cdev
->chip_bond_id
, cdev
->chip_metal
);
1456 if (QED_IS_BB(cdev
) && CHIP_REV_IS_A0(cdev
)) {
1457 DP_NOTICE(cdev
->hwfns
,
1458 "The chip type/rev (BB A0) is not supported!\n");
1465 static int qed_hw_prepare_single(struct qed_hwfn
*p_hwfn
,
1466 void __iomem
*p_regview
,
1467 void __iomem
*p_doorbells
,
1468 enum qed_pci_personality personality
)
1472 /* Split PCI bars evenly between hwfns */
1473 p_hwfn
->regview
= p_regview
;
1474 p_hwfn
->doorbells
= p_doorbells
;
1476 if (IS_VF(p_hwfn
->cdev
))
1477 return qed_vf_hw_prepare(p_hwfn
);
1479 /* Validate that chip access is feasible */
1480 if (REG_RD(p_hwfn
, PXP_PF_ME_OPAQUE_ADDR
) == 0xffffffff) {
1482 "Reading the ME register returns all Fs; Preventing further chip access\n");
1486 get_function_id(p_hwfn
);
1488 /* Allocate PTT pool */
1489 rc
= qed_ptt_pool_alloc(p_hwfn
);
1491 DP_NOTICE(p_hwfn
, "Failed to prepare hwfn's hw\n");
1495 /* Allocate the main PTT */
1496 p_hwfn
->p_main_ptt
= qed_get_reserved_ptt(p_hwfn
, RESERVED_PTT_MAIN
);
1498 /* First hwfn learns basic information, e.g., number of hwfns */
1499 if (!p_hwfn
->my_id
) {
1500 rc
= qed_get_dev_info(p_hwfn
->cdev
);
1505 qed_hw_hwfn_prepare(p_hwfn
);
1507 /* Initialize MCP structure */
1508 rc
= qed_mcp_cmd_init(p_hwfn
, p_hwfn
->p_main_ptt
);
1510 DP_NOTICE(p_hwfn
, "Failed initializing mcp command\n");
1514 /* Read the device configuration information from the HW and SHMEM */
1515 rc
= qed_get_hw_info(p_hwfn
, p_hwfn
->p_main_ptt
, personality
);
1517 DP_NOTICE(p_hwfn
, "Failed to get HW information\n");
1521 /* Allocate the init RT array and initialize the init-ops engine */
1522 rc
= qed_init_alloc(p_hwfn
);
1524 DP_NOTICE(p_hwfn
, "Failed to allocate the init array\n");
1530 if (IS_LEAD_HWFN(p_hwfn
))
1531 qed_iov_free_hw_info(p_hwfn
->cdev
);
1532 qed_mcp_free(p_hwfn
);
1534 qed_hw_hwfn_free(p_hwfn
);
1539 int qed_hw_prepare(struct qed_dev
*cdev
,
1542 struct qed_hwfn
*p_hwfn
= QED_LEADING_HWFN(cdev
);
1545 /* Store the precompiled init data ptrs */
1547 qed_init_iro_array(cdev
);
1549 /* Initialize the first hwfn - will learn number of hwfns */
1550 rc
= qed_hw_prepare_single(p_hwfn
,
1552 cdev
->doorbells
, personality
);
1556 personality
= p_hwfn
->hw_info
.personality
;
1558 /* Initialize the rest of the hwfns */
1559 if (cdev
->num_hwfns
> 1) {
1560 void __iomem
*p_regview
, *p_doorbell
;
1563 /* adjust bar offset for second engine */
1564 addr
= cdev
->regview
+ qed_hw_bar_size(p_hwfn
, BAR_ID_0
) / 2;
1567 /* adjust doorbell bar offset for second engine */
1568 addr
= cdev
->doorbells
+ qed_hw_bar_size(p_hwfn
, BAR_ID_1
) / 2;
1571 /* prepare second hw function */
1572 rc
= qed_hw_prepare_single(&cdev
->hwfns
[1], p_regview
,
1573 p_doorbell
, personality
);
1575 /* in case of error, need to free the previously
1576 * initiliazed hwfn 0.
1580 qed_init_free(p_hwfn
);
1581 qed_mcp_free(p_hwfn
);
1582 qed_hw_hwfn_free(p_hwfn
);
1590 void qed_hw_remove(struct qed_dev
*cdev
)
1594 for_each_hwfn(cdev
, i
) {
1595 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1598 qed_vf_pf_release(p_hwfn
);
1602 qed_init_free(p_hwfn
);
1603 qed_hw_hwfn_free(p_hwfn
);
1604 qed_mcp_free(p_hwfn
);
1607 qed_iov_free_hw_info(cdev
);
1610 int qed_chain_alloc(struct qed_dev
*cdev
,
1611 enum qed_chain_use_mode intended_use
,
1612 enum qed_chain_mode mode
,
1615 struct qed_chain
*p_chain
)
1617 dma_addr_t p_pbl_phys
= 0;
1618 void *p_pbl_virt
= NULL
;
1619 dma_addr_t p_phys
= 0;
1620 void *p_virt
= NULL
;
1624 if (mode
== QED_CHAIN_MODE_SINGLE
)
1627 page_cnt
= QED_CHAIN_PAGE_CNT(num_elems
, elem_size
, mode
);
1629 size
= page_cnt
* QED_CHAIN_PAGE_SIZE
;
1630 p_virt
= dma_alloc_coherent(&cdev
->pdev
->dev
,
1631 size
, &p_phys
, GFP_KERNEL
);
1633 DP_NOTICE(cdev
, "Failed to allocate chain mem\n");
1637 if (mode
== QED_CHAIN_MODE_PBL
) {
1638 size
= page_cnt
* QED_CHAIN_PBL_ENTRY_SIZE
;
1639 p_pbl_virt
= dma_alloc_coherent(&cdev
->pdev
->dev
,
1643 DP_NOTICE(cdev
, "Failed to allocate chain pbl mem\n");
1647 qed_chain_pbl_init(p_chain
, p_virt
, p_phys
, page_cnt
,
1648 (u8
)elem_size
, intended_use
,
1649 p_pbl_phys
, p_pbl_virt
);
1651 qed_chain_init(p_chain
, p_virt
, p_phys
, page_cnt
,
1652 (u8
)elem_size
, intended_use
, mode
);
1658 dma_free_coherent(&cdev
->pdev
->dev
,
1659 page_cnt
* QED_CHAIN_PAGE_SIZE
,
1661 dma_free_coherent(&cdev
->pdev
->dev
,
1662 page_cnt
* QED_CHAIN_PBL_ENTRY_SIZE
,
1663 p_pbl_virt
, p_pbl_phys
);
1668 void qed_chain_free(struct qed_dev
*cdev
,
1669 struct qed_chain
*p_chain
)
1673 if (!p_chain
->p_virt_addr
)
1676 if (p_chain
->mode
== QED_CHAIN_MODE_PBL
) {
1677 size
= p_chain
->page_cnt
* QED_CHAIN_PBL_ENTRY_SIZE
;
1678 dma_free_coherent(&cdev
->pdev
->dev
, size
,
1679 p_chain
->pbl
.p_virt_table
,
1680 p_chain
->pbl
.p_phys_table
);
1683 size
= p_chain
->page_cnt
* QED_CHAIN_PAGE_SIZE
;
1684 dma_free_coherent(&cdev
->pdev
->dev
, size
,
1685 p_chain
->p_virt_addr
,
1686 p_chain
->p_phys_addr
);
1689 int qed_fw_l2_queue(struct qed_hwfn
*p_hwfn
,
1690 u16 src_id
, u16
*dst_id
)
1692 if (src_id
>= RESC_NUM(p_hwfn
, QED_L2_QUEUE
)) {
1695 min
= (u16
)RESC_START(p_hwfn
, QED_L2_QUEUE
);
1696 max
= min
+ RESC_NUM(p_hwfn
, QED_L2_QUEUE
);
1698 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
1704 *dst_id
= RESC_START(p_hwfn
, QED_L2_QUEUE
) + src_id
;
1709 int qed_fw_vport(struct qed_hwfn
*p_hwfn
,
1710 u8 src_id
, u8
*dst_id
)
1712 if (src_id
>= RESC_NUM(p_hwfn
, QED_VPORT
)) {
1715 min
= (u8
)RESC_START(p_hwfn
, QED_VPORT
);
1716 max
= min
+ RESC_NUM(p_hwfn
, QED_VPORT
);
1718 "vport id [%d] is not valid, available indices [%d - %d]\n",
1724 *dst_id
= RESC_START(p_hwfn
, QED_VPORT
) + src_id
;
1729 int qed_fw_rss_eng(struct qed_hwfn
*p_hwfn
,
1730 u8 src_id
, u8
*dst_id
)
1732 if (src_id
>= RESC_NUM(p_hwfn
, QED_RSS_ENG
)) {
1735 min
= (u8
)RESC_START(p_hwfn
, QED_RSS_ENG
);
1736 max
= min
+ RESC_NUM(p_hwfn
, QED_RSS_ENG
);
1738 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
1744 *dst_id
= RESC_START(p_hwfn
, QED_RSS_ENG
) + src_id
;
1749 /* Calculate final WFQ values for all vports and configure them.
1750 * After this configuration each vport will have
1751 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
1753 static void qed_configure_wfq_for_all_vports(struct qed_hwfn
*p_hwfn
,
1754 struct qed_ptt
*p_ptt
,
1757 struct init_qm_vport_params
*vport_params
;
1760 vport_params
= p_hwfn
->qm_info
.qm_vport_params
;
1762 for (i
= 0; i
< p_hwfn
->qm_info
.num_vports
; i
++) {
1763 u32 wfq_speed
= p_hwfn
->qm_info
.wfq_data
[i
].min_speed
;
1765 vport_params
[i
].vport_wfq
= (wfq_speed
* QED_WFQ_UNIT
) /
1767 qed_init_vport_wfq(p_hwfn
, p_ptt
,
1768 vport_params
[i
].first_tx_pq_id
,
1769 vport_params
[i
].vport_wfq
);
1773 static void qed_init_wfq_default_param(struct qed_hwfn
*p_hwfn
,
1779 for (i
= 0; i
< p_hwfn
->qm_info
.num_vports
; i
++)
1780 p_hwfn
->qm_info
.qm_vport_params
[i
].vport_wfq
= 1;
1783 static void qed_disable_wfq_for_all_vports(struct qed_hwfn
*p_hwfn
,
1784 struct qed_ptt
*p_ptt
,
1787 struct init_qm_vport_params
*vport_params
;
1790 vport_params
= p_hwfn
->qm_info
.qm_vport_params
;
1792 for (i
= 0; i
< p_hwfn
->qm_info
.num_vports
; i
++) {
1793 qed_init_wfq_default_param(p_hwfn
, min_pf_rate
);
1794 qed_init_vport_wfq(p_hwfn
, p_ptt
,
1795 vport_params
[i
].first_tx_pq_id
,
1796 vport_params
[i
].vport_wfq
);
1800 /* This function performs several validations for WFQ
1801 * configuration and required min rate for a given vport
1802 * 1. req_rate must be greater than one percent of min_pf_rate.
1803 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
1804 * rates to get less than one percent of min_pf_rate.
1805 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
1807 static int qed_init_wfq_param(struct qed_hwfn
*p_hwfn
,
1808 u16 vport_id
, u32 req_rate
,
1811 u32 total_req_min_rate
= 0, total_left_rate
= 0, left_rate_per_vp
= 0;
1812 int non_requested_count
= 0, req_count
= 0, i
, num_vports
;
1814 num_vports
= p_hwfn
->qm_info
.num_vports
;
1816 /* Accounting for the vports which are configured for WFQ explicitly */
1817 for (i
= 0; i
< num_vports
; i
++) {
1820 if ((i
!= vport_id
) &&
1821 p_hwfn
->qm_info
.wfq_data
[i
].configured
) {
1823 tmp_speed
= p_hwfn
->qm_info
.wfq_data
[i
].min_speed
;
1824 total_req_min_rate
+= tmp_speed
;
1828 /* Include current vport data as well */
1830 total_req_min_rate
+= req_rate
;
1831 non_requested_count
= num_vports
- req_count
;
1833 if (req_rate
< min_pf_rate
/ QED_WFQ_UNIT
) {
1834 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
1835 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
1836 vport_id
, req_rate
, min_pf_rate
);
1840 if (num_vports
> QED_WFQ_UNIT
) {
1841 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
1842 "Number of vports is greater than %d\n",
1847 if (total_req_min_rate
> min_pf_rate
) {
1848 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
1849 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
1850 total_req_min_rate
, min_pf_rate
);
1854 total_left_rate
= min_pf_rate
- total_req_min_rate
;
1856 left_rate_per_vp
= total_left_rate
/ non_requested_count
;
1857 if (left_rate_per_vp
< min_pf_rate
/ QED_WFQ_UNIT
) {
1858 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
1859 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
1860 left_rate_per_vp
, min_pf_rate
);
1864 p_hwfn
->qm_info
.wfq_data
[vport_id
].min_speed
= req_rate
;
1865 p_hwfn
->qm_info
.wfq_data
[vport_id
].configured
= true;
1867 for (i
= 0; i
< num_vports
; i
++) {
1868 if (p_hwfn
->qm_info
.wfq_data
[i
].configured
)
1871 p_hwfn
->qm_info
.wfq_data
[i
].min_speed
= left_rate_per_vp
;
1877 static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn
*p_hwfn
,
1878 struct qed_ptt
*p_ptt
,
1881 bool use_wfq
= false;
1885 /* Validate all pre configured vports for wfq */
1886 for (i
= 0; i
< p_hwfn
->qm_info
.num_vports
; i
++) {
1889 if (!p_hwfn
->qm_info
.wfq_data
[i
].configured
)
1892 rate
= p_hwfn
->qm_info
.wfq_data
[i
].min_speed
;
1895 rc
= qed_init_wfq_param(p_hwfn
, i
, rate
, min_pf_rate
);
1898 "WFQ validation failed while configuring min rate\n");
1904 qed_configure_wfq_for_all_vports(p_hwfn
, p_ptt
, min_pf_rate
);
1906 qed_disable_wfq_for_all_vports(p_hwfn
, p_ptt
, min_pf_rate
);
1911 /* API to configure WFQ from mcp link change */
1912 void qed_configure_vp_wfq_on_link_change(struct qed_dev
*cdev
, u32 min_pf_rate
)
1916 for_each_hwfn(cdev
, i
) {
1917 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1919 __qed_configure_vp_wfq_on_link_change(p_hwfn
,
1925 int __qed_configure_pf_max_bandwidth(struct qed_hwfn
*p_hwfn
,
1926 struct qed_ptt
*p_ptt
,
1927 struct qed_mcp_link_state
*p_link
,
1932 p_hwfn
->mcp_info
->func_info
.bandwidth_max
= max_bw
;
1934 if (!p_link
->line_speed
&& (max_bw
!= 100))
1937 p_link
->speed
= (p_link
->line_speed
* max_bw
) / 100;
1938 p_hwfn
->qm_info
.pf_rl
= p_link
->speed
;
1940 /* Since the limiter also affects Tx-switched traffic, we don't want it
1941 * to limit such traffic in case there's no actual limit.
1942 * In that case, set limit to imaginary high boundary.
1945 p_hwfn
->qm_info
.pf_rl
= 100000;
1947 rc
= qed_init_pf_rl(p_hwfn
, p_ptt
, p_hwfn
->rel_pf_id
,
1948 p_hwfn
->qm_info
.pf_rl
);
1950 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
1951 "Configured MAX bandwidth to be %08x Mb/sec\n",
1957 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
1958 int qed_configure_pf_max_bandwidth(struct qed_dev
*cdev
, u8 max_bw
)
1960 int i
, rc
= -EINVAL
;
1962 if (max_bw
< 1 || max_bw
> 100) {
1963 DP_NOTICE(cdev
, "PF max bw valid range is [1-100]\n");
1967 for_each_hwfn(cdev
, i
) {
1968 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
1969 struct qed_hwfn
*p_lead
= QED_LEADING_HWFN(cdev
);
1970 struct qed_mcp_link_state
*p_link
;
1971 struct qed_ptt
*p_ptt
;
1973 p_link
= &p_lead
->mcp_info
->link_output
;
1975 p_ptt
= qed_ptt_acquire(p_hwfn
);
1979 rc
= __qed_configure_pf_max_bandwidth(p_hwfn
, p_ptt
,
1982 qed_ptt_release(p_hwfn
, p_ptt
);
1991 int __qed_configure_pf_min_bandwidth(struct qed_hwfn
*p_hwfn
,
1992 struct qed_ptt
*p_ptt
,
1993 struct qed_mcp_link_state
*p_link
,
1998 p_hwfn
->mcp_info
->func_info
.bandwidth_min
= min_bw
;
1999 p_hwfn
->qm_info
.pf_wfq
= min_bw
;
2001 if (!p_link
->line_speed
)
2004 p_link
->min_pf_rate
= (p_link
->line_speed
* min_bw
) / 100;
2006 rc
= qed_init_pf_wfq(p_hwfn
, p_ptt
, p_hwfn
->rel_pf_id
, min_bw
);
2008 DP_VERBOSE(p_hwfn
, NETIF_MSG_LINK
,
2009 "Configured MIN bandwidth to be %d Mb/sec\n",
2010 p_link
->min_pf_rate
);
2015 /* Main API to configure PF min bandwidth where bw range is [1-100] */
2016 int qed_configure_pf_min_bandwidth(struct qed_dev
*cdev
, u8 min_bw
)
2018 int i
, rc
= -EINVAL
;
2020 if (min_bw
< 1 || min_bw
> 100) {
2021 DP_NOTICE(cdev
, "PF min bw valid range is [1-100]\n");
2025 for_each_hwfn(cdev
, i
) {
2026 struct qed_hwfn
*p_hwfn
= &cdev
->hwfns
[i
];
2027 struct qed_hwfn
*p_lead
= QED_LEADING_HWFN(cdev
);
2028 struct qed_mcp_link_state
*p_link
;
2029 struct qed_ptt
*p_ptt
;
2031 p_link
= &p_lead
->mcp_info
->link_output
;
2033 p_ptt
= qed_ptt_acquire(p_hwfn
);
2037 rc
= __qed_configure_pf_min_bandwidth(p_hwfn
, p_ptt
,
2040 qed_ptt_release(p_hwfn
, p_ptt
);
2044 if (p_link
->min_pf_rate
) {
2045 u32 min_rate
= p_link
->min_pf_rate
;
2047 rc
= __qed_configure_vp_wfq_on_link_change(p_hwfn
,
2052 qed_ptt_release(p_hwfn
, p_ptt
);