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 */
35 void qed_init_dp(struct qed_dev *cdev,
36 u32 dp_module, u8 dp_level)
40 cdev->dp_level = dp_level;
41 cdev->dp_module = dp_module;
42 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
43 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
45 p_hwfn->dp_level = dp_level;
46 p_hwfn->dp_module = dp_module;
50 void qed_init_struct(struct qed_dev *cdev)
54 for (i = 0; i < MAX_HWFNS_PER_DEVICE; i++) {
55 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
59 p_hwfn->b_active = false;
61 mutex_init(&p_hwfn->dmae_info.mutex);
64 /* hwfn 0 is always active */
65 cdev->hwfns[0].b_active = true;
67 /* set the default cache alignment to 128 */
68 cdev->cache_shift = 7;
71 static void qed_qm_info_free(struct qed_hwfn *p_hwfn)
73 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
75 kfree(qm_info->qm_pq_params);
76 qm_info->qm_pq_params = NULL;
77 kfree(qm_info->qm_vport_params);
78 qm_info->qm_vport_params = NULL;
79 kfree(qm_info->qm_port_params);
80 qm_info->qm_port_params = NULL;
83 void qed_resc_free(struct qed_dev *cdev)
90 kfree(cdev->reset_stats);
92 for_each_hwfn(cdev, i) {
93 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
95 qed_cxt_mngr_free(p_hwfn);
96 qed_qm_info_free(p_hwfn);
98 qed_eq_free(p_hwfn, p_hwfn->p_eq);
99 qed_consq_free(p_hwfn, p_hwfn->p_consq);
100 qed_int_free(p_hwfn);
101 qed_dmae_info_free(p_hwfn);
105 static int qed_init_qm_info(struct qed_hwfn *p_hwfn)
107 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
108 struct init_qm_port_params *p_qm_port;
109 u8 num_vports, i, vport_id, num_ports;
110 u16 num_pqs, multi_cos_tcs = 1;
112 memset(qm_info, 0, sizeof(*qm_info));
114 num_pqs = multi_cos_tcs + 1; /* The '1' is for pure-LB */
115 num_vports = (u8)RESC_NUM(p_hwfn, QED_VPORT);
117 /* Sanity checking that setup requires legal number of resources */
118 if (num_pqs > RESC_NUM(p_hwfn, QED_PQ)) {
120 "Need too many Physical queues - 0x%04x when only %04x are available\n",
121 num_pqs, RESC_NUM(p_hwfn, QED_PQ));
125 /* PQs will be arranged as follows: First per-TC PQ then pure-LB quete.
127 qm_info->qm_pq_params = kzalloc(sizeof(*qm_info->qm_pq_params) *
128 num_pqs, GFP_ATOMIC);
129 if (!qm_info->qm_pq_params)
132 qm_info->qm_vport_params = kzalloc(sizeof(*qm_info->qm_vport_params) *
133 num_vports, GFP_ATOMIC);
134 if (!qm_info->qm_vport_params)
137 qm_info->qm_port_params = kzalloc(sizeof(*qm_info->qm_port_params) *
138 MAX_NUM_PORTS, GFP_ATOMIC);
139 if (!qm_info->qm_port_params)
142 vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
144 /* First init per-TC PQs */
145 for (i = 0; i < multi_cos_tcs; i++) {
146 struct init_qm_pq_params *params = &qm_info->qm_pq_params[i];
148 params->vport_id = vport_id;
149 params->tc_id = p_hwfn->hw_info.non_offload_tc;
150 params->wrr_group = 1;
153 /* Then init pure-LB PQ */
154 qm_info->pure_lb_pq = i;
155 qm_info->qm_pq_params[i].vport_id = (u8)RESC_START(p_hwfn, QED_VPORT);
156 qm_info->qm_pq_params[i].tc_id = PURE_LB_TC;
157 qm_info->qm_pq_params[i].wrr_group = 1;
160 qm_info->offload_pq = 0;
161 qm_info->num_pqs = num_pqs;
162 qm_info->num_vports = num_vports;
164 /* Initialize qm port parameters */
165 num_ports = p_hwfn->cdev->num_ports_in_engines;
166 for (i = 0; i < num_ports; i++) {
167 p_qm_port = &qm_info->qm_port_params[i];
168 p_qm_port->active = 1;
169 p_qm_port->num_active_phys_tcs = 4;
170 p_qm_port->num_pbf_cmd_lines = PBF_MAX_CMD_LINES / num_ports;
171 p_qm_port->num_btb_blocks = BTB_MAX_BLOCKS / num_ports;
174 qm_info->max_phys_tcs_per_port = NUM_OF_PHYS_TCS;
176 qm_info->start_pq = (u16)RESC_START(p_hwfn, QED_PQ);
178 qm_info->start_vport = (u8)RESC_START(p_hwfn, QED_VPORT);
182 qm_info->vport_rl_en = 1;
187 DP_NOTICE(p_hwfn, "Failed to allocate memory for QM params\n");
188 kfree(qm_info->qm_pq_params);
189 kfree(qm_info->qm_vport_params);
190 kfree(qm_info->qm_port_params);
195 int qed_resc_alloc(struct qed_dev *cdev)
197 struct qed_consq *p_consq;
201 cdev->fw_data = kzalloc(sizeof(*cdev->fw_data), GFP_KERNEL);
205 for_each_hwfn(cdev, i) {
206 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
208 /* First allocate the context manager structure */
209 rc = qed_cxt_mngr_alloc(p_hwfn);
213 /* Set the HW cid/tid numbers (in the contest manager)
214 * Must be done prior to any further computations.
216 rc = qed_cxt_set_pf_params(p_hwfn);
220 /* Prepare and process QM requirements */
221 rc = qed_init_qm_info(p_hwfn);
225 /* Compute the ILT client partition */
226 rc = qed_cxt_cfg_ilt_compute(p_hwfn);
230 /* CID map / ILT shadow table / T2
231 * The talbes sizes are determined by the computations above
233 rc = qed_cxt_tables_alloc(p_hwfn);
237 /* SPQ, must follow ILT because initializes SPQ context */
238 rc = qed_spq_alloc(p_hwfn);
242 /* SP status block allocation */
243 p_hwfn->p_dpc_ptt = qed_get_reserved_ptt(p_hwfn,
246 rc = qed_int_alloc(p_hwfn, p_hwfn->p_main_ptt);
251 p_eq = qed_eq_alloc(p_hwfn, 256);
257 p_consq = qed_consq_alloc(p_hwfn);
260 p_hwfn->p_consq = p_consq;
262 /* DMA info initialization */
263 rc = qed_dmae_info_alloc(p_hwfn);
266 "Failed to allocate memory for dmae_info structure\n");
271 cdev->reset_stats = kzalloc(sizeof(*cdev->reset_stats), GFP_KERNEL);
272 if (!cdev->reset_stats) {
273 DP_NOTICE(cdev, "Failed to allocate reset statistics\n");
284 void qed_resc_setup(struct qed_dev *cdev)
288 for_each_hwfn(cdev, i) {
289 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
291 qed_cxt_mngr_setup(p_hwfn);
292 qed_spq_setup(p_hwfn);
293 qed_eq_setup(p_hwfn, p_hwfn->p_eq);
294 qed_consq_setup(p_hwfn, p_hwfn->p_consq);
296 /* Read shadow of current MFW mailbox */
297 qed_mcp_read_mb(p_hwfn, p_hwfn->p_main_ptt);
298 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
299 p_hwfn->mcp_info->mfw_mb_cur,
300 p_hwfn->mcp_info->mfw_mb_length);
302 qed_int_setup(p_hwfn, p_hwfn->p_main_ptt);
306 #define FINAL_CLEANUP_CMD_OFFSET (0)
307 #define FINAL_CLEANUP_CMD (0x1)
308 #define FINAL_CLEANUP_VALID_OFFSET (6)
309 #define FINAL_CLEANUP_VFPF_ID_SHIFT (7)
310 #define FINAL_CLEANUP_COMP (0x2)
311 #define FINAL_CLEANUP_POLL_CNT (100)
312 #define FINAL_CLEANUP_POLL_TIME (10)
313 int qed_final_cleanup(struct qed_hwfn *p_hwfn,
314 struct qed_ptt *p_ptt,
317 u32 command = 0, addr, count = FINAL_CLEANUP_POLL_CNT;
320 addr = GTT_BAR0_MAP_REG_USDM_RAM + USTORM_FLR_FINAL_ACK_OFFSET;
322 command |= FINAL_CLEANUP_CMD << FINAL_CLEANUP_CMD_OFFSET;
323 command |= 1 << FINAL_CLEANUP_VALID_OFFSET;
324 command |= id << FINAL_CLEANUP_VFPF_ID_SHIFT;
325 command |= FINAL_CLEANUP_COMP << SDM_OP_GEN_COMP_TYPE_SHIFT;
327 /* Make sure notification is not set before initiating final cleanup */
328 if (REG_RD(p_hwfn, addr)) {
331 "Unexpected; Found final cleanup notification before initiating final cleanup\n");
332 REG_WR(p_hwfn, addr, 0);
335 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
336 "Sending final cleanup for PFVF[%d] [Command %08x\n]",
339 qed_wr(p_hwfn, p_ptt, XSDM_REG_OPERATION_GEN, command);
341 /* Poll until completion */
342 while (!REG_RD(p_hwfn, addr) && count--)
343 msleep(FINAL_CLEANUP_POLL_TIME);
345 if (REG_RD(p_hwfn, addr))
349 "Failed to receive FW final cleanup notification\n");
351 /* Cleanup afterwards */
352 REG_WR(p_hwfn, addr, 0);
357 static void qed_calc_hw_mode(struct qed_hwfn *p_hwfn)
361 hw_mode = (1 << MODE_BB_A0);
363 switch (p_hwfn->cdev->num_ports_in_engines) {
365 hw_mode |= 1 << MODE_PORTS_PER_ENG_1;
368 hw_mode |= 1 << MODE_PORTS_PER_ENG_2;
371 hw_mode |= 1 << MODE_PORTS_PER_ENG_4;
374 DP_NOTICE(p_hwfn, "num_ports_in_engine = %d not supported\n",
375 p_hwfn->cdev->num_ports_in_engines);
379 switch (p_hwfn->cdev->mf_mode) {
381 hw_mode |= 1 << MODE_SF;
384 hw_mode |= 1 << MODE_MF_SD;
387 hw_mode |= 1 << MODE_MF_SI;
390 DP_NOTICE(p_hwfn, "Unsupported MF mode, init as SF\n");
391 hw_mode |= 1 << MODE_SF;
394 hw_mode |= 1 << MODE_ASIC;
396 p_hwfn->hw_info.hw_mode = hw_mode;
399 /* Init run time data for all PFs on an engine. */
400 static void qed_init_cau_rt_data(struct qed_dev *cdev)
402 u32 offset = CAU_REG_SB_VAR_MEMORY_RT_OFFSET;
405 for_each_hwfn(cdev, i) {
406 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
407 struct qed_igu_info *p_igu_info;
408 struct qed_igu_block *p_block;
409 struct cau_sb_entry sb_entry;
411 p_igu_info = p_hwfn->hw_info.p_igu_info;
413 for (sb_id = 0; sb_id < QED_MAPPING_MEMORY_SIZE(cdev);
415 p_block = &p_igu_info->igu_map.igu_blocks[sb_id];
419 qed_init_cau_sb_entry(p_hwfn, &sb_entry,
420 p_block->function_id,
422 STORE_RT_REG_AGG(p_hwfn, offset + sb_id * 2,
428 static int qed_hw_init_common(struct qed_hwfn *p_hwfn,
429 struct qed_ptt *p_ptt,
432 struct qed_qm_info *qm_info = &p_hwfn->qm_info;
433 struct qed_qm_common_rt_init_params params;
434 struct qed_dev *cdev = p_hwfn->cdev;
437 qed_init_cau_rt_data(cdev);
439 /* Program GTT windows */
440 qed_gtt_init(p_hwfn);
442 if (p_hwfn->mcp_info) {
443 if (p_hwfn->mcp_info->func_info.bandwidth_max)
444 qm_info->pf_rl_en = 1;
445 if (p_hwfn->mcp_info->func_info.bandwidth_min)
446 qm_info->pf_wfq_en = 1;
449 memset(¶ms, 0, sizeof(params));
450 params.max_ports_per_engine = p_hwfn->cdev->num_ports_in_engines;
451 params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
452 params.pf_rl_en = qm_info->pf_rl_en;
453 params.pf_wfq_en = qm_info->pf_wfq_en;
454 params.vport_rl_en = qm_info->vport_rl_en;
455 params.vport_wfq_en = qm_info->vport_wfq_en;
456 params.port_params = qm_info->qm_port_params;
458 qed_qm_common_rt_init(p_hwfn, ¶ms);
460 qed_cxt_hw_init_common(p_hwfn);
462 /* Close gate from NIG to BRB/Storm; By default they are open, but
463 * we close them to prevent NIG from passing data to reset blocks.
464 * Should have been done in the ENGINE phase, but init-tool lacks
465 * proper port-pretend capabilities.
467 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
468 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
469 qed_port_pretend(p_hwfn, p_ptt, p_hwfn->port_id ^ 1);
470 qed_wr(p_hwfn, p_ptt, NIG_REG_RX_BRB_OUT_EN, 0);
471 qed_wr(p_hwfn, p_ptt, NIG_REG_STORM_OUT_EN, 0);
472 qed_port_unpretend(p_hwfn, p_ptt);
474 rc = qed_init_run(p_hwfn, p_ptt, PHASE_ENGINE, ANY_PHASE_ID, hw_mode);
478 qed_wr(p_hwfn, p_ptt, PSWRQ2_REG_L2P_VALIDATE_VFID, 0);
479 qed_wr(p_hwfn, p_ptt, PGLUE_B_REG_USE_CLIENTID_IN_TAG, 1);
481 /* Disable relaxed ordering in the PCI config space */
482 qed_wr(p_hwfn, p_ptt, 0x20b4,
483 qed_rd(p_hwfn, p_ptt, 0x20b4) & ~0x10);
488 static int qed_hw_init_port(struct qed_hwfn *p_hwfn,
489 struct qed_ptt *p_ptt,
494 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PORT, p_hwfn->port_id,
499 static int qed_hw_init_pf(struct qed_hwfn *p_hwfn,
500 struct qed_ptt *p_ptt,
503 enum qed_int_mode int_mode,
504 bool allow_npar_tx_switch)
506 u8 rel_pf_id = p_hwfn->rel_pf_id;
509 if (p_hwfn->mcp_info) {
510 struct qed_mcp_function_info *p_info;
512 p_info = &p_hwfn->mcp_info->func_info;
513 if (p_info->bandwidth_min)
514 p_hwfn->qm_info.pf_wfq = p_info->bandwidth_min;
516 /* Update rate limit once we'll actually have a link */
517 p_hwfn->qm_info.pf_rl = 100;
520 qed_cxt_hw_init_pf(p_hwfn);
522 qed_int_igu_init_rt(p_hwfn);
524 /* Set VLAN in NIG if needed */
525 if (hw_mode & (1 << MODE_MF_SD)) {
526 DP_VERBOSE(p_hwfn, NETIF_MSG_HW, "Configuring LLH_FUNC_TAG\n");
527 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_EN_RT_OFFSET, 1);
528 STORE_RT_REG(p_hwfn, NIG_REG_LLH_FUNC_TAG_VALUE_RT_OFFSET,
529 p_hwfn->hw_info.ovlan);
532 /* Enable classification by MAC if needed */
533 if (hw_mode & MODE_MF_SI) {
534 DP_VERBOSE(p_hwfn, NETIF_MSG_HW,
535 "Configuring TAGMAC_CLS_TYPE\n");
537 NIG_REG_LLH_FUNC_TAGMAC_CLS_TYPE_RT_OFFSET, 1);
540 /* Protocl Configuration */
541 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_TCP_RT_OFFSET, 0);
542 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_FCOE_RT_OFFSET, 0);
543 STORE_RT_REG(p_hwfn, PRS_REG_SEARCH_ROCE_RT_OFFSET, 0);
545 /* Cleanup chip from previous driver if such remains exist */
546 rc = qed_final_cleanup(p_hwfn, p_ptt, rel_pf_id);
550 /* PF Init sequence */
551 rc = qed_init_run(p_hwfn, p_ptt, PHASE_PF, rel_pf_id, hw_mode);
555 /* QM_PF Init sequence (may be invoked separately e.g. for DCB) */
556 rc = qed_init_run(p_hwfn, p_ptt, PHASE_QM_PF, rel_pf_id, hw_mode);
560 /* Pure runtime initializations - directly to the HW */
561 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, true, true);
564 /* enable interrupts */
565 qed_int_igu_enable(p_hwfn, p_ptt, int_mode);
567 /* send function start command */
568 rc = qed_sp_pf_start(p_hwfn, p_hwfn->cdev->mf_mode);
570 DP_NOTICE(p_hwfn, "Function start ramrod failed\n");
575 static int qed_change_pci_hwfn(struct qed_hwfn *p_hwfn,
576 struct qed_ptt *p_ptt,
579 u32 delay_idx = 0, val, set_val = enable ? 1 : 0;
581 /* Change PF in PXP */
582 qed_wr(p_hwfn, p_ptt,
583 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, set_val);
585 /* wait until value is set - try for 1 second every 50us */
586 for (delay_idx = 0; delay_idx < 20000; delay_idx++) {
587 val = qed_rd(p_hwfn, p_ptt,
588 PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
592 usleep_range(50, 60);
595 if (val != set_val) {
597 "PFID_ENABLE_MASTER wasn't changed after a second\n");
604 static void qed_reset_mb_shadow(struct qed_hwfn *p_hwfn,
605 struct qed_ptt *p_main_ptt)
607 /* Read shadow of current MFW mailbox */
608 qed_mcp_read_mb(p_hwfn, p_main_ptt);
609 memcpy(p_hwfn->mcp_info->mfw_mb_shadow,
610 p_hwfn->mcp_info->mfw_mb_cur,
611 p_hwfn->mcp_info->mfw_mb_length);
614 int qed_hw_init(struct qed_dev *cdev,
616 enum qed_int_mode int_mode,
617 bool allow_npar_tx_switch,
618 const u8 *bin_fw_data)
620 u32 load_code, param;
623 rc = qed_init_fw_data(cdev, bin_fw_data);
627 for_each_hwfn(cdev, i) {
628 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
630 /* Enable DMAE in PXP */
631 rc = qed_change_pci_hwfn(p_hwfn, p_hwfn->p_main_ptt, true);
633 qed_calc_hw_mode(p_hwfn);
635 rc = qed_mcp_load_req(p_hwfn, p_hwfn->p_main_ptt,
638 DP_NOTICE(p_hwfn, "Failed sending LOAD_REQ command\n");
642 qed_reset_mb_shadow(p_hwfn, p_hwfn->p_main_ptt);
644 DP_VERBOSE(p_hwfn, QED_MSG_SP,
645 "Load request was sent. Resp:0x%x, Load code: 0x%x\n",
648 p_hwfn->first_on_engine = (load_code ==
649 FW_MSG_CODE_DRV_LOAD_ENGINE);
652 case FW_MSG_CODE_DRV_LOAD_ENGINE:
653 rc = qed_hw_init_common(p_hwfn, p_hwfn->p_main_ptt,
654 p_hwfn->hw_info.hw_mode);
658 case FW_MSG_CODE_DRV_LOAD_PORT:
659 rc = qed_hw_init_port(p_hwfn, p_hwfn->p_main_ptt,
660 p_hwfn->hw_info.hw_mode);
665 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
666 rc = qed_hw_init_pf(p_hwfn, p_hwfn->p_main_ptt,
667 p_hwfn->hw_info.hw_mode,
668 b_hw_start, int_mode,
669 allow_npar_tx_switch);
678 "init phase failed for loadcode 0x%x (rc %d)\n",
681 /* ACK mfw regardless of success or failure of initialization */
682 mfw_rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
683 DRV_MSG_CODE_LOAD_DONE,
684 0, &load_code, ¶m);
688 DP_NOTICE(p_hwfn, "Failed sending LOAD_DONE command\n");
692 p_hwfn->hw_init_done = true;
698 #define QED_HW_STOP_RETRY_LIMIT (10)
699 int qed_hw_stop(struct qed_dev *cdev)
704 for_each_hwfn(cdev, j) {
705 struct qed_hwfn *p_hwfn = &cdev->hwfns[j];
706 struct qed_ptt *p_ptt = p_hwfn->p_main_ptt;
708 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Stopping hw/fw\n");
710 /* mark the hw as uninitialized... */
711 p_hwfn->hw_init_done = false;
713 rc = qed_sp_pf_stop(p_hwfn);
717 qed_wr(p_hwfn, p_ptt,
718 NIG_REG_RX_LLH_BRB_GATE_DNTFWD_PERPF, 0x1);
720 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_TCP, 0x0);
721 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_UDP, 0x0);
722 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_FCOE, 0x0);
723 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_ROCE, 0x0);
724 qed_wr(p_hwfn, p_ptt, PRS_REG_SEARCH_OPENFLOW, 0x0);
726 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_CONN, 0x0);
727 qed_wr(p_hwfn, p_ptt, TM_REG_PF_ENABLE_TASK, 0x0);
728 for (i = 0; i < QED_HW_STOP_RETRY_LIMIT; i++) {
729 if ((!qed_rd(p_hwfn, p_ptt,
730 TM_REG_PF_SCAN_ACTIVE_CONN)) &&
731 (!qed_rd(p_hwfn, p_ptt,
732 TM_REG_PF_SCAN_ACTIVE_TASK)))
735 usleep_range(1000, 2000);
737 if (i == QED_HW_STOP_RETRY_LIMIT)
739 "Timers linear scans are not over [Connection %02x Tasks %02x]\n",
740 (u8)qed_rd(p_hwfn, p_ptt,
741 TM_REG_PF_SCAN_ACTIVE_CONN),
742 (u8)qed_rd(p_hwfn, p_ptt,
743 TM_REG_PF_SCAN_ACTIVE_TASK));
745 /* Disable Attention Generation */
746 qed_int_igu_disable_int(p_hwfn, p_ptt);
748 qed_wr(p_hwfn, p_ptt, IGU_REG_LEADING_EDGE_LATCH, 0);
749 qed_wr(p_hwfn, p_ptt, IGU_REG_TRAILING_EDGE_LATCH, 0);
751 qed_int_igu_init_pure_rt(p_hwfn, p_ptt, false, true);
753 /* Need to wait 1ms to guarantee SBs are cleared */
754 usleep_range(1000, 2000);
757 /* Disable DMAE in PXP - in CMT, this should only be done for
758 * first hw-function, and only after all transactions have
759 * stopped for all active hw-functions.
761 t_rc = qed_change_pci_hwfn(&cdev->hwfns[0],
762 cdev->hwfns[0].p_main_ptt,
770 static int qed_reg_assert(struct qed_hwfn *hwfn,
771 struct qed_ptt *ptt, u32 reg,
774 u32 assert_val = qed_rd(hwfn, ptt, reg);
776 if (assert_val != expected) {
777 DP_NOTICE(hwfn, "Value at address 0x%x != 0x%08x\n",
785 int qed_hw_reset(struct qed_dev *cdev)
788 u32 unload_resp, unload_param;
791 for_each_hwfn(cdev, i) {
792 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
794 DP_VERBOSE(p_hwfn, NETIF_MSG_IFDOWN, "Resetting hw/fw\n");
796 /* Check for incorrect states */
797 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
798 QM_REG_USG_CNT_PF_TX, 0);
799 qed_reg_assert(p_hwfn, p_hwfn->p_main_ptt,
800 QM_REG_USG_CNT_PF_OTHER, 0);
802 /* Disable PF in HW blocks */
803 qed_wr(p_hwfn, p_hwfn->p_main_ptt, DORQ_REG_PF_DB_ENABLE, 0);
804 qed_wr(p_hwfn, p_hwfn->p_main_ptt, QM_REG_PF_EN, 0);
805 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
806 TCFC_REG_STRONG_ENABLE_PF, 0);
807 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
808 CCFC_REG_STRONG_ENABLE_PF, 0);
810 /* Send unload command to MCP */
811 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
812 DRV_MSG_CODE_UNLOAD_REQ,
813 DRV_MB_PARAM_UNLOAD_WOL_MCP,
814 &unload_resp, &unload_param);
816 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_REQ failed\n");
817 unload_resp = FW_MSG_CODE_DRV_UNLOAD_ENGINE;
820 rc = qed_mcp_cmd(p_hwfn, p_hwfn->p_main_ptt,
821 DRV_MSG_CODE_UNLOAD_DONE,
822 0, &unload_resp, &unload_param);
824 DP_NOTICE(p_hwfn, "qed_hw_reset: UNLOAD_DONE failed\n");
832 /* Free hwfn memory and resources acquired in hw_hwfn_prepare */
833 static void qed_hw_hwfn_free(struct qed_hwfn *p_hwfn)
835 qed_ptt_pool_free(p_hwfn);
836 kfree(p_hwfn->hw_info.p_igu_info);
839 /* Setup bar access */
840 static int qed_hw_hwfn_prepare(struct qed_hwfn *p_hwfn)
844 /* Allocate PTT pool */
845 rc = qed_ptt_pool_alloc(p_hwfn);
849 /* Allocate the main PTT */
850 p_hwfn->p_main_ptt = qed_get_reserved_ptt(p_hwfn, RESERVED_PTT_MAIN);
852 /* clear indirect access */
853 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_88_F0, 0);
854 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_8C_F0, 0);
855 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_90_F0, 0);
856 qed_wr(p_hwfn, p_hwfn->p_main_ptt, PGLUE_B_REG_PGL_ADDR_94_F0, 0);
858 /* Clean Previous errors if such exist */
859 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
860 PGLUE_B_REG_WAS_ERROR_PF_31_0_CLR,
861 1 << p_hwfn->abs_pf_id);
863 /* enable internal target-read */
864 qed_wr(p_hwfn, p_hwfn->p_main_ptt,
865 PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
870 static void get_function_id(struct qed_hwfn *p_hwfn)
873 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR);
875 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, PXP_PF_ME_CONCRETE_ADDR);
877 p_hwfn->abs_pf_id = (p_hwfn->hw_info.concrete_fid >> 16) & 0xf;
878 p_hwfn->rel_pf_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
879 PXP_CONCRETE_FID_PFID);
880 p_hwfn->port_id = GET_FIELD(p_hwfn->hw_info.concrete_fid,
881 PXP_CONCRETE_FID_PORT);
884 static void qed_hw_get_resc(struct qed_hwfn *p_hwfn)
886 u32 *resc_start = p_hwfn->hw_info.resc_start;
887 u32 *resc_num = p_hwfn->hw_info.resc_num;
890 num_funcs = IS_MF(p_hwfn) ? MAX_NUM_PFS_BB
891 : p_hwfn->cdev->num_ports_in_engines;
893 resc_num[QED_SB] = min_t(u32,
894 (MAX_SB_PER_PATH_BB / num_funcs),
895 qed_int_get_num_sbs(p_hwfn, NULL));
896 resc_num[QED_VPORT] = MAX_NUM_VPORTS_BB / num_funcs;
897 resc_num[QED_PQ] = MAX_QM_TX_QUEUES_BB / num_funcs;
898 resc_num[QED_RL] = 8;
899 resc_num[QED_ILT] = 950;
901 for (i = 0; i < QED_MAX_RESC; i++)
902 resc_start[i] = resc_num[i] * p_hwfn->rel_pf_id;
904 DP_VERBOSE(p_hwfn, NETIF_MSG_PROBE,
905 "The numbers for each resource are:\n"
906 "SB = %d start = %d\n"
907 "VPORT = %d start = %d\n"
908 "PQ = %d start = %d\n"
909 "RL = %d start = %d\n"
910 "ILT = %d start = %d\n",
911 p_hwfn->hw_info.resc_num[QED_SB],
912 p_hwfn->hw_info.resc_start[QED_SB],
913 p_hwfn->hw_info.resc_num[QED_VPORT],
914 p_hwfn->hw_info.resc_start[QED_VPORT],
915 p_hwfn->hw_info.resc_num[QED_PQ],
916 p_hwfn->hw_info.resc_start[QED_PQ],
917 p_hwfn->hw_info.resc_num[QED_RL],
918 p_hwfn->hw_info.resc_start[QED_RL],
919 p_hwfn->hw_info.resc_num[QED_ILT],
920 p_hwfn->hw_info.resc_start[QED_ILT]);
923 static int qed_hw_get_nvm_info(struct qed_hwfn *p_hwfn,
924 struct qed_ptt *p_ptt)
926 u32 nvm_cfg1_offset, mf_mode, addr, generic_cont0, nvm_cfg_addr;
929 /* Read global nvm_cfg address */
930 nvm_cfg_addr = qed_rd(p_hwfn, p_ptt, MISC_REG_GEN_PURP_CR0);
932 /* Verify MCP has initialized it */
934 DP_NOTICE(p_hwfn, "Shared memory not initialized\n");
938 /* Read nvm_cfg1 (Notice this is just offset, and not offsize (TBD) */
939 nvm_cfg1_offset = qed_rd(p_hwfn, p_ptt, nvm_cfg_addr + 4);
941 /* Read Vendor Id / Device Id */
942 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
943 offsetof(struct nvm_cfg1, glob) +
944 offsetof(struct nvm_cfg1_glob, pci_id);
945 p_hwfn->hw_info.vendor_id = qed_rd(p_hwfn, p_ptt, addr) &
946 NVM_CFG1_GLOB_VENDOR_ID_MASK;
947 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
948 offsetof(struct nvm_cfg1, func[MCP_PF_ID(p_hwfn)]) +
949 offsetof(struct nvm_cfg1_func, device_id);
950 val = qed_rd(p_hwfn, p_ptt, addr);
953 p_hwfn->hw_info.device_id =
954 (val & NVM_CFG1_FUNC_MF_VENDOR_DEVICE_ID_MASK) >>
955 NVM_CFG1_FUNC_MF_VENDOR_DEVICE_ID_OFFSET;
957 p_hwfn->hw_info.device_id =
958 (val & NVM_CFG1_FUNC_VENDOR_DEVICE_ID_MASK) >>
959 NVM_CFG1_FUNC_VENDOR_DEVICE_ID_OFFSET;
962 /* Read Multi-function information from shmem */
963 addr = MCP_REG_SCRATCH + nvm_cfg1_offset +
964 offsetof(struct nvm_cfg1, glob) +
965 offsetof(struct nvm_cfg1_glob, generic_cont0);
967 generic_cont0 = qed_rd(p_hwfn, p_ptt, addr);
969 mf_mode = (generic_cont0 & NVM_CFG1_GLOB_MF_MODE_MASK) >>
970 NVM_CFG1_GLOB_MF_MODE_OFFSET;
973 case NVM_CFG1_GLOB_MF_MODE_MF_ALLOWED:
974 p_hwfn->cdev->mf_mode = MF_OVLAN;
976 case NVM_CFG1_GLOB_MF_MODE_NPAR1_0:
977 p_hwfn->cdev->mf_mode = MF_NPAR;
979 case NVM_CFG1_GLOB_MF_MODE_FORCED_SF:
980 p_hwfn->cdev->mf_mode = SF;
983 DP_INFO(p_hwfn, "Multi function mode is %08x\n",
984 p_hwfn->cdev->mf_mode);
986 return qed_mcp_fill_shmem_func_info(p_hwfn, p_ptt);
990 qed_get_hw_info(struct qed_hwfn *p_hwfn,
991 struct qed_ptt *p_ptt,
992 enum qed_pci_personality personality)
997 /* Read the port mode */
998 port_mode = qed_rd(p_hwfn, p_ptt,
999 CNIG_REG_NW_PORT_MODE_BB_B0);
1001 if (port_mode < 3) {
1002 p_hwfn->cdev->num_ports_in_engines = 1;
1003 } else if (port_mode <= 5) {
1004 p_hwfn->cdev->num_ports_in_engines = 2;
1006 DP_NOTICE(p_hwfn, "PORT MODE: %d not supported\n",
1007 p_hwfn->cdev->num_ports_in_engines);
1009 /* Default num_ports_in_engines to something */
1010 p_hwfn->cdev->num_ports_in_engines = 1;
1013 qed_hw_get_nvm_info(p_hwfn, p_ptt);
1015 rc = qed_int_igu_read_cam(p_hwfn, p_ptt);
1019 if (qed_mcp_is_init(p_hwfn))
1020 ether_addr_copy(p_hwfn->hw_info.hw_mac_addr,
1021 p_hwfn->mcp_info->func_info.mac);
1023 eth_random_addr(p_hwfn->hw_info.hw_mac_addr);
1025 if (qed_mcp_is_init(p_hwfn)) {
1026 if (p_hwfn->mcp_info->func_info.ovlan != QED_MCP_VLAN_UNSET)
1027 p_hwfn->hw_info.ovlan =
1028 p_hwfn->mcp_info->func_info.ovlan;
1030 qed_mcp_cmd_port_init(p_hwfn, p_ptt);
1033 if (qed_mcp_is_init(p_hwfn)) {
1034 enum qed_pci_personality protocol;
1036 protocol = p_hwfn->mcp_info->func_info.protocol;
1037 p_hwfn->hw_info.personality = protocol;
1040 qed_hw_get_resc(p_hwfn);
1045 static void qed_get_dev_info(struct qed_dev *cdev)
1049 cdev->chip_num = (u16)qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
1050 MISCS_REG_CHIP_NUM);
1051 cdev->chip_rev = (u16)qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
1052 MISCS_REG_CHIP_REV);
1053 MASK_FIELD(CHIP_REV, cdev->chip_rev);
1055 /* Learn number of HW-functions */
1056 tmp = qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
1057 MISCS_REG_CMT_ENABLED_FOR_PAIR);
1059 if (tmp & (1 << cdev->hwfns[0].rel_pf_id)) {
1060 DP_NOTICE(cdev->hwfns, "device in CMT mode\n");
1061 cdev->num_hwfns = 2;
1063 cdev->num_hwfns = 1;
1066 cdev->chip_bond_id = qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
1067 MISCS_REG_CHIP_TEST_REG) >> 4;
1068 MASK_FIELD(CHIP_BOND_ID, cdev->chip_bond_id);
1069 cdev->chip_metal = (u16)qed_rd(cdev->hwfns, cdev->hwfns[0].p_main_ptt,
1070 MISCS_REG_CHIP_METAL);
1071 MASK_FIELD(CHIP_METAL, cdev->chip_metal);
1073 DP_INFO(cdev->hwfns,
1074 "Chip details - Num: %04x Rev: %04x Bond id: %04x Metal: %04x\n",
1075 cdev->chip_num, cdev->chip_rev,
1076 cdev->chip_bond_id, cdev->chip_metal);
1079 static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
1080 void __iomem *p_regview,
1081 void __iomem *p_doorbells,
1082 enum qed_pci_personality personality)
1086 /* Split PCI bars evenly between hwfns */
1087 p_hwfn->regview = p_regview;
1088 p_hwfn->doorbells = p_doorbells;
1090 /* Validate that chip access is feasible */
1091 if (REG_RD(p_hwfn, PXP_PF_ME_OPAQUE_ADDR) == 0xffffffff) {
1093 "Reading the ME register returns all Fs; Preventing further chip access\n");
1097 get_function_id(p_hwfn);
1099 rc = qed_hw_hwfn_prepare(p_hwfn);
1101 DP_NOTICE(p_hwfn, "Failed to prepare hwfn's hw\n");
1105 /* First hwfn learns basic information, e.g., number of hwfns */
1107 qed_get_dev_info(p_hwfn->cdev);
1109 /* Initialize MCP structure */
1110 rc = qed_mcp_cmd_init(p_hwfn, p_hwfn->p_main_ptt);
1112 DP_NOTICE(p_hwfn, "Failed initializing mcp command\n");
1116 /* Read the device configuration information from the HW and SHMEM */
1117 rc = qed_get_hw_info(p_hwfn, p_hwfn->p_main_ptt, personality);
1119 DP_NOTICE(p_hwfn, "Failed to get HW information\n");
1123 /* Allocate the init RT array and initialize the init-ops engine */
1124 rc = qed_init_alloc(p_hwfn);
1126 DP_NOTICE(p_hwfn, "Failed to allocate the init array\n");
1132 qed_mcp_free(p_hwfn);
1134 qed_hw_hwfn_free(p_hwfn);
1139 static u32 qed_hw_bar_size(struct qed_dev *cdev,
1142 u32 size = pci_resource_len(cdev->pdev, (bar_id > 0) ? 2 : 0);
1144 return size / cdev->num_hwfns;
1147 int qed_hw_prepare(struct qed_dev *cdev,
1152 /* Store the precompiled init data ptrs */
1153 qed_init_iro_array(cdev);
1155 /* Initialize the first hwfn - will learn number of hwfns */
1156 rc = qed_hw_prepare_single(&cdev->hwfns[0], cdev->regview,
1157 cdev->doorbells, personality);
1161 personality = cdev->hwfns[0].hw_info.personality;
1163 /* Initialize the rest of the hwfns */
1164 for (i = 1; i < cdev->num_hwfns; i++) {
1165 void __iomem *p_regview, *p_doorbell;
1167 p_regview = cdev->regview +
1168 i * qed_hw_bar_size(cdev, 0);
1169 p_doorbell = cdev->doorbells +
1170 i * qed_hw_bar_size(cdev, 1);
1171 rc = qed_hw_prepare_single(&cdev->hwfns[i], p_regview,
1172 p_doorbell, personality);
1174 /* Cleanup previously initialized hwfns */
1176 qed_init_free(&cdev->hwfns[i]);
1177 qed_mcp_free(&cdev->hwfns[i]);
1178 qed_hw_hwfn_free(&cdev->hwfns[i]);
1187 void qed_hw_remove(struct qed_dev *cdev)
1191 for_each_hwfn(cdev, i) {
1192 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
1194 qed_init_free(p_hwfn);
1195 qed_hw_hwfn_free(p_hwfn);
1196 qed_mcp_free(p_hwfn);
1200 int qed_chain_alloc(struct qed_dev *cdev,
1201 enum qed_chain_use_mode intended_use,
1202 enum qed_chain_mode mode,
1205 struct qed_chain *p_chain)
1207 dma_addr_t p_pbl_phys = 0;
1208 void *p_pbl_virt = NULL;
1209 dma_addr_t p_phys = 0;
1210 void *p_virt = NULL;
1214 if (mode == QED_CHAIN_MODE_SINGLE)
1217 page_cnt = QED_CHAIN_PAGE_CNT(num_elems, elem_size, mode);
1219 size = page_cnt * QED_CHAIN_PAGE_SIZE;
1220 p_virt = dma_alloc_coherent(&cdev->pdev->dev,
1221 size, &p_phys, GFP_KERNEL);
1223 DP_NOTICE(cdev, "Failed to allocate chain mem\n");
1227 if (mode == QED_CHAIN_MODE_PBL) {
1228 size = page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1229 p_pbl_virt = dma_alloc_coherent(&cdev->pdev->dev,
1233 DP_NOTICE(cdev, "Failed to allocate chain pbl mem\n");
1237 qed_chain_pbl_init(p_chain, p_virt, p_phys, page_cnt,
1238 (u8)elem_size, intended_use,
1239 p_pbl_phys, p_pbl_virt);
1241 qed_chain_init(p_chain, p_virt, p_phys, page_cnt,
1242 (u8)elem_size, intended_use, mode);
1248 dma_free_coherent(&cdev->pdev->dev,
1249 page_cnt * QED_CHAIN_PAGE_SIZE,
1251 dma_free_coherent(&cdev->pdev->dev,
1252 page_cnt * QED_CHAIN_PBL_ENTRY_SIZE,
1253 p_pbl_virt, p_pbl_phys);
1258 void qed_chain_free(struct qed_dev *cdev,
1259 struct qed_chain *p_chain)
1263 if (!p_chain->p_virt_addr)
1266 if (p_chain->mode == QED_CHAIN_MODE_PBL) {
1267 size = p_chain->page_cnt * QED_CHAIN_PBL_ENTRY_SIZE;
1268 dma_free_coherent(&cdev->pdev->dev, size,
1269 p_chain->pbl.p_virt_table,
1270 p_chain->pbl.p_phys_table);
1273 size = p_chain->page_cnt * QED_CHAIN_PAGE_SIZE;
1274 dma_free_coherent(&cdev->pdev->dev, size,
1275 p_chain->p_virt_addr,
1276 p_chain->p_phys_addr);