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"
34 /* API common to all protocols */
36 BAR_ID_0, /* used for GRC */
37 BAR_ID_1 /* Used for doorbells */
40 static u32 qed_hw_bar_size(struct qed_hwfn *p_hwfn,
43 u32 bar_reg = (bar_id == BAR_ID_0 ?
44 PGLUE_B_REG_PF_BAR0_SIZE : PGLUE_B_REG_PF_BAR1_SIZE);
45 u32 val = qed_rd(p_hwfn, p_hwfn->p_main_ptt, bar_reg);
48 return 1 << (val + 15);
50 /* Old MFW initialized above registered only conditionally */
51 if (p_hwfn->cdev->num_hwfns > 1) {
53 "BAR size not configured. Assuming BAR size of 256kB for GRC and 512kB for DB\n");
54 return BAR_ID_0 ? 256 * 1024 : 512 * 1024;
57 "BAR size not configured. Assuming BAR size of 512kB for GRC and 512kB for DB\n");
62 void qed_init_dp(struct qed_dev *cdev,
63 u32 dp_module, u8 dp_level)
67 cdev->dp_level = dp_level;
68 cdev->dp_module = dp_module;
69 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
70 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
72 p_hwfn->dp_level = dp_level;
73 p_hwfn->dp_module = dp_module;
77 void qed_init_struct(struct qed_dev *cdev)
81 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
82 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
86 p_hwfn->b_active = false;
88 mutex_init(&p_hwfn->dmae_info.mutex);
91 /* hwfn 0 is always active */
92 cdev->hwfns[0].b_active = true;
94 /* set the default cache alignment to 128 */
95 cdev->cache_shift = 7;
98 static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
100 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
102 kfree(qm_info->qm_pq_params);
103 qm_info->qm_pq_params = NULL;
104 kfree(qm_info->qm_vport_params);
105 qm_info->qm_vport_params = NULL;
106 kfree(qm_info->qm_port_params);
107 qm_info->qm_port_params = NULL;
108 kfree(qm_info->wfq_data);
109 qm_info->wfq_data = NULL;
112 void qed_resc_free(struct qed_dev *cdev)
116 kfree(cdev->fw_data);
117 cdev->fw_data = NULL;
119 kfree(cdev->reset_stats);
121 for_each_hwfn(cdev, i) {
122 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
124 kfree(p_hwfn->p_tx_cids);
125 p_hwfn->p_tx_cids = NULL;
126 kfree(p_hwfn->p_rx_cids);
127 p_hwfn->p_rx_cids = NULL;
130 for_each_hwfn(cdev, i) {
131 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
133 qed_cxt_mngr_free(p_hwfn);
134 qed_qm_info_free(p_hwfn);
135 qed_spq_free(p_hwfn);
136 qed_eq_free(p_hwfn, p_hwfn->p_eq);
137 qed_consq_free(p_hwfn, p_hwfn->p_consq);
138 qed_int_free(p_hwfn);
139 qed_dmae_info_free(p_hwfn);
143 static int qed_init_qm_info(struct qed_hwfn *p_hwfn)
145 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
146 struct init_qm_port_params *p_qm_port;
147 u8 num_vports, i, vport_id, num_ports;
148 u16 num_pqs, multi_cos_tcs = 1;
150 memset(qm_info, 0, sizeof(*qm_info));
152 num_pqs = multi_cos_tcs + 1; /* The '1' is for pure-LB */
153 num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
155 /* Sanity checking that setup requires legal number of resources */
156 if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
158 "Need too many Physical queues - 0x%04x when only %04x are available\n",
159 num_pqs, RESC_NUM(p_hwfn, QED_PQ));
163 /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
165 qm_info->qm_pq_params = kzalloc(sizeof(*qm_info->qm_pq_params) *
166 num_pqs, GFP_KERNEL);
167 if (!qm_info->qm_pq_params)
170 qm_info->qm_vport_params = kzalloc(sizeof(*qm_info->qm_vport_params) *
171 num_vports, GFP_KERNEL);
172 if (!qm_info->qm_vport_params)
175 qm_info->qm_port_params = kzalloc(sizeof(*qm_info->qm_port_params) *
176 MAX_NUM_PORTS, GFP_KERNEL);
177 if (!qm_info->qm_port_params)
180 qm_info->wfq_data = kcalloc(num_vports, sizeof(*qm_info->wfq_data),
182 if (!qm_info->wfq_data)
185 vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
187 /* First init per-TC PQs */
188 for (i = 0; i < multi_cos_tcs; i++) {
189 struct init_qm_pq_params *params = &qm_info->qm_pq_params[i];
191 params->vport_id = vport_id;
192 params->tc_id = p_hwfn->hw_info.non_offload_tc;
193 params->wrr_group = 1;
196 /* Then init pure-LB PQ */
197 qm_info->pure_lb_pq = i;
198 qm_info->qm_pq_params[i].vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
199 qm_info->qm_pq_params[i].tc_id = PURE_LB_TC;
200 qm_info->qm_pq_params[i].wrr_group = 1;
203 qm_info->offload_pq = 0;
204 qm_info->num_pqs = num_pqs;
205 qm_info->num_vports = num_vports;
207 /* Initialize qm port parameters */
208 num_ports = p_hwfn->cdev->num_ports_in_engines;
209 for (i = 0; i < num_ports; i++) {
210 p_qm_port = &qm_info->qm_port_params[i];
211 p_qm_port->active = 1;
212 p_qm_port->num_active_phys_tcs = 4;
213 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
214 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
217 qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
219 qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
221 qm_info->start_vport = (u8)RESC_START(p_hwfn, QED_VPORT);
225 qm_info->vport_rl_en = 1;
230 DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
231 qed_qm_info_free(p_hwfn);
235 int qed_resc_alloc(struct qed_dev *cdev)
237 struct qed_consq *p_consq;
241 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
245 /* Allocate Memory for the Queue->CID mapping */
246 for_each_hwfn(cdev, i) {
247 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
248 int tx_size = sizeof(struct qed_hw_cid_data) *
249 RESC_NUM(p_hwfn, QED_L2_QUEUE);
250 int rx_size = sizeof(struct qed_hw_cid_data) *
251 RESC_NUM(p_hwfn, QED_L2_QUEUE);
253 p_hwfn->p_tx_cids = kzalloc(tx_size, GFP_KERNEL);
254 if (!p_hwfn->p_tx_cids) {
256 "Failed to allocate memory for Tx Cids\n");
261 p_hwfn->p_rx_cids = kzalloc(rx_size, GFP_KERNEL);
262 if (!p_hwfn->p_rx_cids) {
264 "Failed to allocate memory for Rx Cids\n");
270 for_each_hwfn(cdev, i) {
271 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
273 /* First allocate the context manager structure */
274 rc = qed_cxt_mngr_alloc(p_hwfn);
278 /* Set the HW cid/tid numbers (in the contest manager)
279 * Must be done prior to any further computations.
281 rc = qed_cxt_set_pf_params(p_hwfn);
285 /* Prepare and process QM requirements */
286 rc = qed_init_qm_info(p_hwfn);
290 /* Compute the ILT client partition */
291 rc = qed_cxt_cfg_ilt_compute(p_hwfn);
295 /* CID map / ILT shadow table / T2
296 * The talbes sizes are determined by the computations above
298 rc = qed_cxt_tables_alloc(p_hwfn);
302 /* SPQ, must follow ILT because initializes SPQ context */
303 rc = qed_spq_alloc(p_hwfn);
307 /* SP status block allocation */
308 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
311 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
316 p_eq = qed_eq_alloc(p_hwfn, 256);
323 p_consq = qed_consq_alloc(p_hwfn);
328 p_hwfn->p_consq = p_consq;
330 /* DMA info initialization */
331 rc = qed_dmae_info_alloc(p_hwfn);
334 "Failed to allocate memory for dmae_info structure\n");
339 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
340 if (!cdev->reset_stats) {
341 DP_NOTICE(cdev, "Failed to allocate reset statistics\n");
353 void qed_resc_setup(struct qed_dev *cdev)
357 for_each_hwfn(cdev, i) {
358 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
360 qed_cxt_mngr_setup(p_hwfn);
361 qed_spq_setup(p_hwfn);
362 qed_eq_setup(p_hwfn, p_hwfn->p_eq);
363 qed_consq_setup(p_hwfn, p_hwfn->p_consq);
365 /* Read shadow of current MFW mailbox */
366 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
367 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
368 p_hwfn->mcp_info->mfw_mb_cur,
369 p_hwfn->mcp_info->mfw_mb_length);
371 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
375 #define FINAL_CLEANUP_POLL_CNT (100)
376 #define FINAL_CLEANUP_POLL_TIME (10)
377 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
378 struct qed_ptt *p_ptt,
381 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
384 addr = GTT_BAR0_MAP_REG_USDM_RAM +
385 USTORM_FLR_FINAL_ACK_OFFSET(p_hwfn->rel_pf_id);
387 command |= X_FINAL_CLEANUP_AGG_INT <<
388 SDM_AGG_INT_COMP_PARAMS_AGG_INT_INDEX_SHIFT;
389 command |= 1 << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_ENABLE_SHIFT;
390 command |= id << SDM_AGG_INT_COMP_PARAMS_AGG_VECTOR_BIT_SHIFT;
391 command |= SDM_COMP_TYPE_AGG_INT << SDM_OP_GEN_COMP_TYPE_SHIFT;
393 /* Make sure notification is not set before initiating final cleanup */
394 if (REG_RD(p_hwfn, addr)) {
397 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
398 REG_WR(p_hwfn, addr, 0);
401 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
402 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
405 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
407 /* Poll until completion */
408 while (!REG_RD(p_hwfn, addr) && count--)
409 msleep(FINAL_CLEANUP_POLL_TIME);
411 if (REG_RD(p_hwfn, addr))
415 "Failed to receive FW final cleanup notification\n");
417 /* Cleanup afterwards */
418 REG_WR(p_hwfn, addr, 0);
423 static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
427 hw_mode = (1 << MODE_BB_B0);
429 switch (p_hwfn->cdev->num_ports_in_engines) {
431 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
434 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
437 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
440 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
441 p_hwfn->cdev->num_ports_in_engines);
445 switch (p_hwfn->cdev->mf_mode) {
448 hw_mode |= 1 << MODE_MF_SI;
451 hw_mode |= 1 << MODE_MF_SD;
454 DP_NOTICE(p_hwfn, "Unsupported MF mode, init as DEFAULT\n");
455 hw_mode |= 1 << MODE_MF_SI;
458 hw_mode |= 1 << MODE_ASIC;
460 p_hwfn->hw_info.hw_mode = hw_mode;
463 /* Init run time data for all PFs on an engine. */
464 static void qed_init_cau_rt_data(struct qed_dev *cdev)
466 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
469 for_each_hwfn(cdev, i) {
470 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
471 struct qed_igu_info *p_igu_info;
472 struct qed_igu_block *p_block;
473 struct cau_sb_entry sb_entry;
475 p_igu_info = p_hwfn->hw_info.p_igu_info;
477 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
479 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
483 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
484 p_block->function_id,
486 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2,
492 static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
493 struct qed_ptt *p_ptt,
496 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
497 struct qed_qm_common_rt_init_params params;
498 struct qed_dev *cdev = p_hwfn->cdev;
501 qed_init_cau_rt_data(cdev);
503 /* Program GTT windows */
504 qed_gtt_init(p_hwfn);
506 if (p_hwfn->mcp_info) {
507 if (p_hwfn->mcp_info->func_info.bandwidth_max)
508 qm_info->pf_rl_en = 1;
509 if (p_hwfn->mcp_info->func_info.bandwidth_min)
510 qm_info->pf_wfq_en = 1;
513 memset(¶ms, 0, sizeof(params));
514 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
515 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
516 params.pf_rl_en = qm_info->pf_rl_en;
517 params.pf_wfq_en = qm_info->pf_wfq_en;
518 params.vport_rl_en = qm_info->vport_rl_en;
519 params.vport_wfq_en = qm_info->vport_wfq_en;
520 params.port_params = qm_info->qm_port_params;
522 qed_qm_common_rt_init(p_hwfn, ¶ms);
524 qed_cxt_hw_init_common(p_hwfn);
526 /* Close gate from NIG to BRB/Storm; By default they are open, but
527 * we close them to prevent NIG from passing data to reset blocks.
528 * Should have been done in the ENGINE phase, but init-tool lacks
529 * proper port-pretend capabilities.
531 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
532 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
533 qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
534 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
535 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
536 qed_port_unpretend(p_hwfn, p_ptt);
538 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
542 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
543 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
545 /* Disable relaxed ordering in the PCI config space */
546 qed_wr(p_hwfn, p_ptt, 0x20b4,
547 qed_rd(p_hwfn, p_ptt, 0x20b4) & ~0x10);
552 static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
553 struct qed_ptt *p_ptt,
558 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
563 static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
564 struct qed_ptt *p_ptt,
565 struct qed_tunn_start_params *p_tunn,
568 enum qed_int_mode int_mode,
569 bool allow_npar_tx_switch)
571 u8 rel_pf_id = p_hwfn->rel_pf_id;
574 if (p_hwfn->mcp_info) {
575 struct qed_mcp_function_info *p_info;
577 p_info = &p_hwfn->mcp_info->func_info;
578 if (p_info->bandwidth_min)
579 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
581 /* Update rate limit once we'll actually have a link */
582 p_hwfn->qm_info.pf_rl = 100000;
585 qed_cxt_hw_init_pf(p_hwfn);
587 qed_int_igu_init_rt(p_hwfn);
589 /* Set VLAN in NIG if needed */
590 if (hw_mode & (1 << MODE_MF_SD)) {
591 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
592 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
593 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
594 p_hwfn->hw_info.ovlan);
597 /* Enable classification by MAC if needed */
598 if (hw_mode & (1 << MODE_MF_SI)) {
599 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
600 "Configuring TAGMAC_CLS_TYPE\n");
602 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
605 /* Protocl Configuration */
606 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET, 0);
607 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
608 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
610 /* Cleanup chip from previous driver if such remains exist */
611 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id);
615 /* PF Init sequence */
616 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
620 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
621 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
625 /* Pure runtime initializations - directly to the HW */
626 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
629 /* enable interrupts */
630 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
632 /* send function start command */
633 rc = qed_sp_pf_start(p_hwfn, p_tunn, p_hwfn->cdev->mf_mode);
635 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
640 static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
641 struct qed_ptt *p_ptt,
644 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
646 /* Change PF in PXP */
647 qed_wr(p_hwfn, p_ptt,
648 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
650 /* wait until value is set - try for 1 second every 50us */
651 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
652 val = qed_rd(p_hwfn, p_ptt,
653 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
657 usleep_range(50, 60);
660 if (val != set_val) {
662 "PFID_ENABLE_MASTER wasn't changed after a second\n");
669 static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
670 struct qed_ptt *p_main_ptt)
672 /* Read shadow of current MFW mailbox */
673 qed_mcp_read_mb(p_hwfn, p_main_ptt);
674 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
675 p_hwfn->mcp_info->mfw_mb_cur,
676 p_hwfn->mcp_info->mfw_mb_length);
679 int qed_hw_init(struct qed_dev *cdev,
680 struct qed_tunn_start_params *p_tunn,
682 enum qed_int_mode int_mode,
683 bool allow_npar_tx_switch,
684 const u8 *bin_fw_data)
686 u32 load_code, param;
689 rc = qed_init_fw_data(cdev, bin_fw_data);
693 for_each_hwfn(cdev, i) {
694 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
696 /* Enable DMAE in PXP */
697 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
699 qed_calc_hw_mode(p_hwfn);
701 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
704 DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
708 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
710 DP_VERBOSE(p_hwfn, QED_MSG_SP,
711 "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
714 p_hwfn->first_on_engine = (load_code ==
715 FW_MSG_CODE_DRV_LOAD_ENGINE);
718 case FW_MSG_CODE_DRV_LOAD_ENGINE:
719 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
720 p_hwfn->hw_info.hw_mode);
724 case FW_MSG_CODE_DRV_LOAD_PORT:
725 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
726 p_hwfn->hw_info.hw_mode);
731 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
732 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
733 p_tunn, p_hwfn->hw_info.hw_mode,
734 b_hw_start, int_mode,
735 allow_npar_tx_switch);
744 "init phase failed for loadcode 0x%x (rc %d)\n",
747 /* ACK mfw regardless of success or failure of initialization */
748 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
749 DRV_MSG_CODE_LOAD_DONE,
750 0, &load_code, ¶m);
754 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
758 p_hwfn->hw_init_done = true;
764 #define QED_HW_STOP_RETRY_LIMIT (10)
765 static inline void qed_hw_timers_stop(struct qed_dev *cdev,
766 struct qed_hwfn *p_hwfn,
767 struct qed_ptt *p_ptt)
772 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
773 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
775 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
776 if ((!qed_rd(p_hwfn, p_ptt,
777 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
778 (!qed_rd(p_hwfn, p_ptt,
779 TM_REG_PF_SCAN_ACTIVE_TASK)))
782 /* Dependent on number of connection/tasks, possibly
783 * 1ms sleep is required between polls
785 usleep_range(1000, 2000);
788 if (i < QED_HW_STOP_RETRY_LIMIT)
792 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
793 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_CONN),
794 (u8)qed_rd(p_hwfn, p_ptt, TM_REG_PF_SCAN_ACTIVE_TASK));
797 void qed_hw_timers_stop_all(struct qed_dev *cdev)
801 for_each_hwfn(cdev, j) {
802 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
803 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
805 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
809 int qed_hw_stop(struct qed_dev *cdev)
814 for_each_hwfn(cdev, j) {
815 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
816 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
818 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
820 /* mark the hw as uninitialized... */
821 p_hwfn->hw_init_done = false;
823 rc = qed_sp_pf_stop(p_hwfn);
826 "Failed to close PF against FW. Continue to stop HW to prevent illegal host access by the device\n");
828 qed_wr(p_hwfn, p_ptt,
829 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
831 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
832 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
833 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
834 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
835 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
837 qed_hw_timers_stop(cdev, p_hwfn, p_ptt);
839 /* Disable Attention Generation */
840 qed_int_igu_disable_int(p_hwfn, p_ptt);
842 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
843 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
845 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
847 /* Need to wait 1ms to guarantee SBs are cleared */
848 usleep_range(1000, 2000);
851 /* Disable DMAE in PXP - in CMT, this should only be done for
852 * first hw-function, and only after all transactions have
853 * stopped for all active hw-functions.
855 t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
856 cdev->hwfns[0].p_main_ptt,
864 void qed_hw_stop_fastpath(struct qed_dev *cdev)
868 for_each_hwfn(cdev, j) {
869 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
870 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
874 "Shutting down the fastpath\n");
876 qed_wr(p_hwfn, p_ptt,
877 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
879 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
880 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
881 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
882 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
883 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
885 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, false);
887 /* Need to wait 1ms to guarantee SBs are cleared */
888 usleep_range(1000, 2000);
892 void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn)
894 /* Re-open incoming traffic */
895 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
896 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x0);
899 static int qed_reg_assert(struct qed_hwfn *hwfn,
900 struct qed_ptt *ptt, u32 reg,
903 u32 assert_val = qed_rd(hwfn, ptt, reg);
905 if (assert_val != expected) {
906 DP_NOTICE(hwfn, "Value at address 0x%x != 0x%08x\n",
914 int qed_hw_reset(struct qed_dev *cdev)
917 u32 unload_resp, unload_param;
920 for_each_hwfn(cdev, i) {
921 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
923 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
925 /* Check for incorrect states */
926 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
927 QM_REG_USG_CNT_PF_TX, 0);
928 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
929 QM_REG_USG_CNT_PF_OTHER, 0);
931 /* Disable PF in HW blocks */
932 qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
933 qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
934 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
935 TCFC_REG_STRONG_ENABLE_PF, 0);
936 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
937 CCFC_REG_STRONG_ENABLE_PF, 0);
939 /* Send unload command to MCP */
940 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
941 DRV_MSG_CODE_UNLOAD_REQ,
942 DRV_MB_PARAM_UNLOAD_WOL_MCP,
943 &unload_resp, &unload_param);
945 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
946 unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
949 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
950 DRV_MSG_CODE_UNLOAD_DONE,
951 0, &unload_resp, &unload_param);
953 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
961 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
962 static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
964 qed_ptt_pool_free(p_hwfn);
965 kfree(p_hwfn->hw_info.p_igu_info);
968 /* Setup bar access */
969 static void qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
971 /* clear indirect access */
972 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
973 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
974 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
975 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
977 /* Clean Previous errors if such exist */
978 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
979 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
980 1 << p_hwfn->abs_pf_id);
982 /* enable internal target-read */
983 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
984 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
987 static void get_function_id(struct qed_hwfn *p_hwfn)
990 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR);
992 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
994 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
995 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
996 PXP_CONCRETE_FID_PFID);
997 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
998 PXP_CONCRETE_FID_PORT);
1001 static void qed_hw_set_feat(struct qed_hwfn *p_hwfn)
1003 u32 *feat_num = p_hwfn->hw_info.feat_num;
1004 int num_features = 1;
1006 feat_num[QED_PF_L2_QUE] = min_t(u32, RESC_NUM(p_hwfn, QED_SB) /
1008 RESC_NUM(p_hwfn, QED_L2_QUEUE));
1009 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1010 "#PF_L2_QUEUES=%d #SBS=%d num_features=%d\n",
1011 feat_num[QED_PF_L2_QUE], RESC_NUM(p_hwfn, QED_SB),
1015 static void qed_hw_get_resc(struct qed_hwfn *p_hwfn)
1017 u32 *resc_start = p_hwfn->hw_info.resc_start;
1018 u32 *resc_num = p_hwfn->hw_info.resc_num;
1019 struct qed_sb_cnt_info sb_cnt_info;
1022 num_funcs = MAX_NUM_PFS_BB;
1024 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
1025 qed_int_get_num_sbs(p_hwfn, &sb_cnt_info);
1027 resc_num[QED_SB] = min_t(u32,
1028 (MAX_SB_PER_PATH_BB / num_funcs),
1029 sb_cnt_info.sb_cnt);
1030 resc_num[QED_L2_QUEUE] = MAX_NUM_L2_QUEUES_BB / num_funcs;
1031 resc_num[QED_VPORT] = MAX_NUM_VPORTS_BB / num_funcs;
1032 resc_num[QED_RSS_ENG] = ETH_RSS_ENGINE_NUM_BB / num_funcs;
1033 resc_num[QED_PQ] = MAX_QM_TX_QUEUES_BB / num_funcs;
1034 resc_num[QED_RL] = 8;
1035 resc_num[QED_MAC] = ETH_NUM_MAC_FILTERS / num_funcs;
1036 resc_num[QED_VLAN] = (ETH_NUM_VLAN_FILTERS - 1 /*For vlan0*/) /
1038 resc_num[QED_ILT] = 950;
1040 for (i = 0; i < QED_MAX_RESC; i++)
1041 resc_start[i] = resc_num[i] * p_hwfn->rel_pf_id;
1043 qed_hw_set_feat(p_hwfn);
1045 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
1046 "The numbers for each resource are:\n"
1047 "SB = %d start = %d\n"
1048 "L2_QUEUE = %d start = %d\n"
1049 "VPORT = %d start = %d\n"
1050 "PQ = %d start = %d\n"
1051 "RL = %d start = %d\n"
1052 "MAC = %d start = %d\n"
1053 "VLAN = %d start = %d\n"
1054 "ILT = %d start = %d\n",
1055 p_hwfn->hw_info.resc_num[QED_SB],
1056 p_hwfn->hw_info.resc_start[QED_SB],
1057 p_hwfn->hw_info.resc_num[QED_L2_QUEUE],
1058 p_hwfn->hw_info.resc_start[QED_L2_QUEUE],
1059 p_hwfn->hw_info.resc_num[QED_VPORT],
1060 p_hwfn->hw_info.resc_start[QED_VPORT],
1061 p_hwfn->hw_info.resc_num[QED_PQ],
1062 p_hwfn->hw_info.resc_start[QED_PQ],
1063 p_hwfn->hw_info.resc_num[QED_RL],
1064 p_hwfn->hw_info.resc_start[QED_RL],
1065 p_hwfn->hw_info.resc_num[QED_MAC],
1066 p_hwfn->hw_info.resc_start[QED_MAC],
1067 p_hwfn->hw_info.resc_num[QED_VLAN],
1068 p_hwfn->hw_info.resc_start[QED_VLAN],
1069 p_hwfn->hw_info.resc_num[QED_ILT],
1070 p_hwfn->hw_info.resc_start[QED_ILT]);
1073 static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn,
1074 struct qed_ptt *p_ptt)
1076 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, core_cfg;
1077 u32 port_cfg_addr, link_temp, nvm_cfg_addr, device_capabilities;
1078 struct qed_mcp_link_params *link;
1080 /* Read global nvm_cfg address */
1081 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
1083 /* Verify MCP has initialized it */
1084 if (!nvm_cfg_addr) {
1085 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
1089 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
1090 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
1092 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1093 offsetof(struct nvm_cfg1, glob) +
1094 offsetof(struct nvm_cfg1_glob, core_cfg);
1096 core_cfg = qed_rd(p_hwfn, p_ptt, addr);
1098 switch ((core_cfg & NVM_CFG1_GLOB_NETWORK_PORT_MODE_MASK) >>
1099 NVM_CFG1_GLOB_NETWORK_PORT_MODE_OFFSET) {
1100 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X40G:
1101 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X40G;
1103 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X50G:
1104 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X50G;
1106 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X100G:
1107 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X100G;
1109 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_F:
1110 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_F;
1112 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X10G_E:
1113 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X10G_E;
1115 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_4X20G:
1116 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_4X20G;
1118 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X40G:
1119 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X40G;
1121 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_2X25G:
1122 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_2X25G;
1124 case NVM_CFG1_GLOB_NETWORK_PORT_MODE_DE_1X25G:
1125 p_hwfn->hw_info.port_mode = QED_PORT_MODE_DE_1X25G;
1128 DP_NOTICE(p_hwfn, "Unknown port mode in 0x%08x\n",
1133 /* Read default link configuration */
1134 link = &p_hwfn->mcp_info->link_input;
1135 port_cfg_addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1136 offsetof(struct nvm_cfg1, port[MFW_PORT(p_hwfn)]);
1137 link_temp = qed_rd(p_hwfn, p_ptt,
1139 offsetof(struct nvm_cfg1_port, speed_cap_mask));
1140 link->speed.advertised_speeds =
1141 link_temp & NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_MASK;
1143 p_hwfn->mcp_info->link_capabilities.speed_capabilities =
1144 link->speed.advertised_speeds;
1146 link_temp = qed_rd(p_hwfn, p_ptt,
1148 offsetof(struct nvm_cfg1_port, link_settings));
1149 switch ((link_temp & NVM_CFG1_PORT_DRV_LINK_SPEED_MASK) >>
1150 NVM_CFG1_PORT_DRV_LINK_SPEED_OFFSET) {
1151 case NVM_CFG1_PORT_DRV_LINK_SPEED_AUTONEG:
1152 link->speed.autoneg = true;
1154 case NVM_CFG1_PORT_DRV_LINK_SPEED_1G:
1155 link->speed.forced_speed = 1000;
1157 case NVM_CFG1_PORT_DRV_LINK_SPEED_10G:
1158 link->speed.forced_speed = 10000;
1160 case NVM_CFG1_PORT_DRV_LINK_SPEED_25G:
1161 link->speed.forced_speed = 25000;
1163 case NVM_CFG1_PORT_DRV_LINK_SPEED_40G:
1164 link->speed.forced_speed = 40000;
1166 case NVM_CFG1_PORT_DRV_LINK_SPEED_50G:
1167 link->speed.forced_speed = 50000;
1169 case NVM_CFG1_PORT_DRV_LINK_SPEED_100G:
1170 link->speed.forced_speed = 100000;
1173 DP_NOTICE(p_hwfn, "Unknown Speed in 0x%08x\n",
1177 link_temp &= NVM_CFG1_PORT_DRV_FLOW_CONTROL_MASK;
1178 link_temp >>= NVM_CFG1_PORT_DRV_FLOW_CONTROL_OFFSET;
1179 link->pause.autoneg = !!(link_temp &
1180 NVM_CFG1_PORT_DRV_FLOW_CONTROL_AUTONEG);
1181 link->pause.forced_rx = !!(link_temp &
1182 NVM_CFG1_PORT_DRV_FLOW_CONTROL_RX);
1183 link->pause.forced_tx = !!(link_temp &
1184 NVM_CFG1_PORT_DRV_FLOW_CONTROL_TX);
1185 link->loopback_mode = 0;
1187 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1188 "Read default link: Speed 0x%08x, Adv. Speed 0x%08x, AN: 0x%02x, PAUSE AN: 0x%02x\n",
1189 link->speed.forced_speed, link->speed.advertised_speeds,
1190 link->speed.autoneg, link->pause.autoneg);
1192 /* Read Multi-function information from shmem */
1193 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1194 offsetof(struct nvm_cfg1, glob) +
1195 offsetof(struct nvm_cfg1_glob, generic_cont0);
1197 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
1199 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
1200 NVM_CFG1_GLOB_MF_MODE_OFFSET;
1203 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
1204 p_hwfn->cdev->mf_mode = QED_MF_OVLAN;
1206 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
1207 p_hwfn->cdev->mf_mode = QED_MF_NPAR;
1209 case NVM_CFG1_GLOB_MF_MODE_DEFAULT:
1210 p_hwfn->cdev->mf_mode = QED_MF_DEFAULT;
1213 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
1214 p_hwfn->cdev->mf_mode);
1216 /* Read Multi-function information from shmem */
1217 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
1218 offsetof(struct nvm_cfg1, glob) +
1219 offsetof(struct nvm_cfg1_glob, device_capabilities);
1221 device_capabilities = qed_rd(p_hwfn, p_ptt, addr);
1222 if (device_capabilities & NVM_CFG1_GLOB_DEVICE_CAPABILITIES_ETHERNET)
1223 __set_bit(QED_DEV_CAP_ETH,
1224 &p_hwfn->hw_info.device_capabilities);
1226 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
1230 qed_get_hw_info(struct qed_hwfn *p_hwfn,
1231 struct qed_ptt *p_ptt,
1232 enum qed_pci_personality personality)
1237 /* Read the port mode */
1238 port_mode = qed_rd(p_hwfn, p_ptt,
1239 CNIG_REG_NW_PORT_MODE_BB_B0);
1241 if (port_mode < 3) {
1242 p_hwfn->cdev->num_ports_in_engines = 1;
1243 } else if (port_mode <= 5) {
1244 p_hwfn->cdev->num_ports_in_engines = 2;
1246 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
1247 p_hwfn->cdev->num_ports_in_engines);
1249 /* Default num_ports_in_engines to something */
1250 p_hwfn->cdev->num_ports_in_engines = 1;
1253 qed_hw_get_nvm_info(p_hwfn, p_ptt);
1255 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
1259 if (qed_mcp_is_init(p_hwfn))
1260 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
1261 p_hwfn->mcp_info->func_info.mac);
1263 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
1265 if (qed_mcp_is_init(p_hwfn)) {
1266 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
1267 p_hwfn->hw_info.ovlan =
1268 p_hwfn->mcp_info->func_info.ovlan;
1270 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
1273 if (qed_mcp_is_init(p_hwfn)) {
1274 enum qed_pci_personality protocol;
1276 protocol = p_hwfn->mcp_info->func_info.protocol;
1277 p_hwfn->hw_info.personality = protocol;
1280 qed_hw_get_resc(p_hwfn);
1285 static int qed_get_dev_info(struct qed_dev *cdev)
1287 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
1290 /* Read Vendor Id / Device Id */
1291 pci_read_config_word(cdev->pdev, PCI_VENDOR_ID,
1293 pci_read_config_word(cdev->pdev, PCI_DEVICE_ID,
1295 cdev->chip_num = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1296 MISCS_REG_CHIP_NUM);
1297 cdev->chip_rev = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1298 MISCS_REG_CHIP_REV);
1299 MASK_FIELD(CHIP_REV, cdev->chip_rev);
1301 cdev->type = QED_DEV_TYPE_BB;
1302 /* Learn number of HW-functions */
1303 tmp = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1304 MISCS_REG_CMT_ENABLED_FOR_PAIR);
1306 if (tmp & (1 << p_hwfn->rel_pf_id)) {
1307 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
1308 cdev->num_hwfns = 2;
1310 cdev->num_hwfns = 1;
1313 cdev->chip_bond_id = qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1314 MISCS_REG_CHIP_TEST_REG) >> 4;
1315 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
1316 cdev->chip_metal = (u16)qed_rd(p_hwfn, p_hwfn->p_main_ptt,
1317 MISCS_REG_CHIP_METAL);
1318 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
1320 DP_INFO(cdev->hwfns,
1321 "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
1322 cdev->chip_num, cdev->chip_rev,
1323 cdev->chip_bond_id, cdev->chip_metal);
1325 if (QED_IS_BB(cdev) && CHIP_REV_IS_A0(cdev)) {
1326 DP_NOTICE(cdev->hwfns,
1327 "The chip type/rev (BB A0) is not supported!\n");
1334 static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
1335 void __iomem *p_regview,
1336 void __iomem *p_doorbells,
1337 enum qed_pci_personality personality)
1341 /* Split PCI bars evenly between hwfns */
1342 p_hwfn->regview = p_regview;
1343 p_hwfn->doorbells = p_doorbells;
1345 /* Validate that chip access is feasible */
1346 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
1348 "Reading the ME register returns all Fs; Preventing further chip access\n");
1352 get_function_id(p_hwfn);
1354 /* Allocate PTT pool */
1355 rc = qed_ptt_pool_alloc(p_hwfn);
1357 DP_NOTICE(p_hwfn, "Failed to prepare hwfn's hw\n");
1361 /* Allocate the main PTT */
1362 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
1364 /* First hwfn learns basic information, e.g., number of hwfns */
1365 if (!p_hwfn->my_id) {
1366 rc = qed_get_dev_info(p_hwfn->cdev);
1371 qed_hw_hwfn_prepare(p_hwfn);
1373 /* Initialize MCP structure */
1374 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
1376 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
1380 /* Read the device configuration information from the HW and SHMEM */
1381 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
1383 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
1387 /* Allocate the init RT array and initialize the init-ops engine */
1388 rc = qed_init_alloc(p_hwfn);
1390 DP_NOTICE(p_hwfn, "Failed to allocate the init array\n");
1396 qed_mcp_free(p_hwfn);
1398 qed_hw_hwfn_free(p_hwfn);
1403 int qed_hw_prepare(struct qed_dev *cdev,
1406 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
1409 /* Store the precompiled init data ptrs */
1410 qed_init_iro_array(cdev);
1412 /* Initialize the first hwfn - will learn number of hwfns */
1413 rc = qed_hw_prepare_single(p_hwfn,
1415 cdev->doorbells, personality);
1419 personality = p_hwfn->hw_info.personality;
1421 /* Initialize the rest of the hwfns */
1422 if (cdev->num_hwfns > 1) {
1423 void __iomem *p_regview, *p_doorbell;
1426 /* adjust bar offset for second engine */
1427 addr = cdev->regview + qed_hw_bar_size(p_hwfn, BAR_ID_0) / 2;
1430 /* adjust doorbell bar offset for second engine */
1431 addr = cdev->doorbells + qed_hw_bar_size(p_hwfn, BAR_ID_1) / 2;
1434 /* prepare second hw function */
1435 rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
1436 p_doorbell, personality);
1438 /* in case of error, need to free the previously
1439 * initiliazed hwfn 0.
1442 qed_init_free(p_hwfn);
1443 qed_mcp_free(p_hwfn);
1444 qed_hw_hwfn_free(p_hwfn);
1451 void qed_hw_remove(struct qed_dev *cdev)
1455 for_each_hwfn(cdev, i) {
1456 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1458 qed_init_free(p_hwfn);
1459 qed_hw_hwfn_free(p_hwfn);
1460 qed_mcp_free(p_hwfn);
1464 int qed_chain_alloc(struct qed_dev *cdev,
1465 enum qed_chain_use_mode intended_use,
1466 enum qed_chain_mode mode,
1469 struct qed_chain *p_chain)
1471 dma_addr_t p_pbl_phys = 0;
1472 void *p_pbl_virt = NULL;
1473 dma_addr_t p_phys = 0;
1474 void *p_virt = NULL;
1478 if (mode == QED_CHAIN_MODE_SINGLE)
1481 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
1483 size = page_cnt * QED_CHAIN_PAGE_SIZE;
1484 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
1485 size, &p_phys, GFP_KERNEL);
1487 DP_NOTICE(cdev, "Failed to allocate chain mem\n");
1491 if (mode == QED_CHAIN_MODE_PBL) {
1492 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1493 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
1497 DP_NOTICE(cdev, "Failed to allocate chain pbl mem\n");
1501 qed_chain_pbl_init(p_chain, p_virt, p_phys, page_cnt,
1502 (u8)elem_size, intended_use,
1503 p_pbl_phys, p_pbl_virt);
1505 qed_chain_init(p_chain, p_virt, p_phys, page_cnt,
1506 (u8)elem_size, intended_use, mode);
1512 dma_free_coherent(&cdev->pdev->dev,
1513 page_cnt * QED_CHAIN_PAGE_SIZE,
1515 dma_free_coherent(&cdev->pdev->dev,
1516 page_cnt * QED_CHAIN_PBL_ENTRY_SIZE,
1517 p_pbl_virt, p_pbl_phys);
1522 void qed_chain_free(struct qed_dev *cdev,
1523 struct qed_chain *p_chain)
1527 if (!p_chain->p_virt_addr)
1530 if (p_chain->mode == QED_CHAIN_MODE_PBL) {
1531 size = p_chain->page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1532 dma_free_coherent(&cdev->pdev->dev, size,
1533 p_chain->pbl.p_virt_table,
1534 p_chain->pbl.p_phys_table);
1537 size = p_chain->page_cnt * QED_CHAIN_PAGE_SIZE;
1538 dma_free_coherent(&cdev->pdev->dev, size,
1539 p_chain->p_virt_addr,
1540 p_chain->p_phys_addr);
1543 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn,
1544 u16 src_id, u16 *dst_id)
1546 if (src_id >= RESC_NUM(p_hwfn, QED_L2_QUEUE)) {
1549 min = (u16)RESC_START(p_hwfn, QED_L2_QUEUE);
1550 max = min + RESC_NUM(p_hwfn, QED_L2_QUEUE);
1552 "l2_queue id [%d] is not valid, available indices [%d - %d]\n",
1558 *dst_id = RESC_START(p_hwfn, QED_L2_QUEUE) + src_id;
1563 int qed_fw_vport(struct qed_hwfn *p_hwfn,
1564 u8 src_id, u8 *dst_id)
1566 if (src_id >= RESC_NUM(p_hwfn, QED_VPORT)) {
1569 min = (u8)RESC_START(p_hwfn, QED_VPORT);
1570 max = min + RESC_NUM(p_hwfn, QED_VPORT);
1572 "vport id [%d] is not valid, available indices [%d - %d]\n",
1578 *dst_id = RESC_START(p_hwfn, QED_VPORT) + src_id;
1583 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn,
1584 u8 src_id, u8 *dst_id)
1586 if (src_id >= RESC_NUM(p_hwfn, QED_RSS_ENG)) {
1589 min = (u8)RESC_START(p_hwfn, QED_RSS_ENG);
1590 max = min + RESC_NUM(p_hwfn, QED_RSS_ENG);
1592 "rss_eng id [%d] is not valid, available indices [%d - %d]\n",
1598 *dst_id = RESC_START(p_hwfn, QED_RSS_ENG) + src_id;
1603 /* Calculate final WFQ values for all vports and configure them.
1604 * After this configuration each vport will have
1605 * approx min rate = min_pf_rate * (vport_wfq / QED_WFQ_UNIT)
1607 static void qed_configure_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
1608 struct qed_ptt *p_ptt,
1611 struct init_qm_vport_params *vport_params;
1614 vport_params = p_hwfn->qm_info.qm_vport_params;
1616 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
1617 u32 wfq_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
1619 vport_params[i].vport_wfq = (wfq_speed * QED_WFQ_UNIT) /
1621 qed_init_vport_wfq(p_hwfn, p_ptt,
1622 vport_params[i].first_tx_pq_id,
1623 vport_params[i].vport_wfq);
1627 static void qed_init_wfq_default_param(struct qed_hwfn *p_hwfn,
1633 for (i = 0; i < p_hwfn->qm_info.num_vports; i++)
1634 p_hwfn->qm_info.qm_vport_params[i].vport_wfq = 1;
1637 static void qed_disable_wfq_for_all_vports(struct qed_hwfn *p_hwfn,
1638 struct qed_ptt *p_ptt,
1641 struct init_qm_vport_params *vport_params;
1644 vport_params = p_hwfn->qm_info.qm_vport_params;
1646 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
1647 qed_init_wfq_default_param(p_hwfn, min_pf_rate);
1648 qed_init_vport_wfq(p_hwfn, p_ptt,
1649 vport_params[i].first_tx_pq_id,
1650 vport_params[i].vport_wfq);
1654 /* This function performs several validations for WFQ
1655 * configuration and required min rate for a given vport
1656 * 1. req_rate must be greater than one percent of min_pf_rate.
1657 * 2. req_rate should not cause other vports [not configured for WFQ explicitly]
1658 * rates to get less than one percent of min_pf_rate.
1659 * 3. total_req_min_rate [all vports min rate sum] shouldn't exceed min_pf_rate.
1661 static int qed_init_wfq_param(struct qed_hwfn *p_hwfn,
1662 u16 vport_id, u32 req_rate,
1665 u32 total_req_min_rate = 0, total_left_rate = 0, left_rate_per_vp = 0;
1666 int non_requested_count = 0, req_count = 0, i, num_vports;
1668 num_vports = p_hwfn->qm_info.num_vports;
1670 /* Accounting for the vports which are configured for WFQ explicitly */
1671 for (i = 0; i < num_vports; i++) {
1674 if ((i != vport_id) &&
1675 p_hwfn->qm_info.wfq_data[i].configured) {
1677 tmp_speed = p_hwfn->qm_info.wfq_data[i].min_speed;
1678 total_req_min_rate += tmp_speed;
1682 /* Include current vport data as well */
1684 total_req_min_rate += req_rate;
1685 non_requested_count = num_vports - req_count;
1687 if (req_rate < min_pf_rate / QED_WFQ_UNIT) {
1688 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1689 "Vport [%d] - Requested rate[%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
1690 vport_id, req_rate, min_pf_rate);
1694 if (num_vports > QED_WFQ_UNIT) {
1695 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1696 "Number of vports is greater than %d\n",
1701 if (total_req_min_rate > min_pf_rate) {
1702 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1703 "Total requested min rate for all vports[%d Mbps] is greater than configured PF min rate[%d Mbps]\n",
1704 total_req_min_rate, min_pf_rate);
1708 total_left_rate = min_pf_rate - total_req_min_rate;
1710 left_rate_per_vp = total_left_rate / non_requested_count;
1711 if (left_rate_per_vp < min_pf_rate / QED_WFQ_UNIT) {
1712 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1713 "Non WFQ configured vports rate [%d Mbps] is less than one percent of configured PF min rate[%d Mbps]\n",
1714 left_rate_per_vp, min_pf_rate);
1718 p_hwfn->qm_info.wfq_data[vport_id].min_speed = req_rate;
1719 p_hwfn->qm_info.wfq_data[vport_id].configured = true;
1721 for (i = 0; i < num_vports; i++) {
1722 if (p_hwfn->qm_info.wfq_data[i].configured)
1725 p_hwfn->qm_info.wfq_data[i].min_speed = left_rate_per_vp;
1731 static int __qed_configure_vp_wfq_on_link_change(struct qed_hwfn *p_hwfn,
1732 struct qed_ptt *p_ptt,
1735 bool use_wfq = false;
1739 /* Validate all pre configured vports for wfq */
1740 for (i = 0; i < p_hwfn->qm_info.num_vports; i++) {
1743 if (!p_hwfn->qm_info.wfq_data[i].configured)
1746 rate = p_hwfn->qm_info.wfq_data[i].min_speed;
1749 rc = qed_init_wfq_param(p_hwfn, i, rate, min_pf_rate);
1752 "WFQ validation failed while configuring min rate\n");
1758 qed_configure_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
1760 qed_disable_wfq_for_all_vports(p_hwfn, p_ptt, min_pf_rate);
1765 /* API to configure WFQ from mcp link change */
1766 void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate)
1770 for_each_hwfn(cdev, i) {
1771 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1773 __qed_configure_vp_wfq_on_link_change(p_hwfn,
1779 int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
1780 struct qed_ptt *p_ptt,
1781 struct qed_mcp_link_state *p_link,
1786 p_hwfn->mcp_info->func_info.bandwidth_max = max_bw;
1788 if (!p_link->line_speed && (max_bw != 100))
1791 p_link->speed = (p_link->line_speed * max_bw) / 100;
1792 p_hwfn->qm_info.pf_rl = p_link->speed;
1794 /* Since the limiter also affects Tx-switched traffic, we don't want it
1795 * to limit such traffic in case there's no actual limit.
1796 * In that case, set limit to imaginary high boundary.
1799 p_hwfn->qm_info.pf_rl = 100000;
1801 rc = qed_init_pf_rl(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
1802 p_hwfn->qm_info.pf_rl);
1804 DP_VERBOSE(p_hwfn, NETIF_MSG_LINK,
1805 "Configured MAX bandwidth to be %08x Mb/sec\n",
1811 /* Main API to configure PF max bandwidth where bw range is [1 - 100] */
1812 int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw)
1814 int i, rc = -EINVAL;
1816 if (max_bw < 1 || max_bw > 100) {
1817 DP_NOTICE(cdev, "PF max bw valid range is [1-100]\n");
1821 for_each_hwfn(cdev, i) {
1822 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1823 struct qed_hwfn *p_lead = QED_LEADING_HWFN(cdev);
1824 struct qed_mcp_link_state *p_link;
1825 struct qed_ptt *p_ptt;
1827 p_link = &p_lead->mcp_info->link_output;
1829 p_ptt = qed_ptt_acquire(p_hwfn);
1833 rc = __qed_configure_pf_max_bandwidth(p_hwfn, p_ptt,
1836 qed_ptt_release(p_hwfn, p_ptt);