18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * QLogic iSCSI HBA Driver
48c2ecf20Sopenharmony_ci * Copyright (c)  2003-2012 QLogic Corporation
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "ql4_def.h"
88c2ecf20Sopenharmony_ci#include "ql4_glbl.h"
98c2ecf20Sopenharmony_ci#include "ql4_dbg.h"
108c2ecf20Sopenharmony_ci#include "ql4_inline.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_civoid qla4xxx_dump_buffer(void *b, uint32_t size)
138c2ecf20Sopenharmony_ci{
148c2ecf20Sopenharmony_ci	uint32_t cnt;
158c2ecf20Sopenharmony_ci	uint8_t *c = b;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	printk(" 0   1   2   3   4   5   6   7   8   9  Ah  Bh  Ch  Dh  Eh  "
188c2ecf20Sopenharmony_ci	       "Fh\n");
198c2ecf20Sopenharmony_ci	printk("------------------------------------------------------------"
208c2ecf20Sopenharmony_ci	       "--\n");
218c2ecf20Sopenharmony_ci	for (cnt = 0; cnt < size; c++) {
228c2ecf20Sopenharmony_ci		printk("%02x", *c);
238c2ecf20Sopenharmony_ci		if (!(++cnt % 16))
248c2ecf20Sopenharmony_ci			printk("\n");
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci		else
278c2ecf20Sopenharmony_ci			printk("  ");
288c2ecf20Sopenharmony_ci	}
298c2ecf20Sopenharmony_ci	printk(KERN_INFO "\n");
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_civoid qla4xxx_dump_registers(struct scsi_qla_host *ha)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	uint8_t i;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	if (is_qla8022(ha)) {
378c2ecf20Sopenharmony_ci		for (i = 1; i < MBOX_REG_COUNT; i++)
388c2ecf20Sopenharmony_ci			printk(KERN_INFO "mailbox[%d]     = 0x%08X\n",
398c2ecf20Sopenharmony_ci			    i, readl(&ha->qla4_82xx_reg->mailbox_in[i]));
408c2ecf20Sopenharmony_ci		return;
418c2ecf20Sopenharmony_ci	}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	for (i = 0; i < MBOX_REG_COUNT; i++) {
448c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X mailbox[%d]      = 0x%08X\n",
458c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, mailbox[i]), i,
468c2ecf20Sopenharmony_ci		    readw(&ha->reg->mailbox[i]));
478c2ecf20Sopenharmony_ci	}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	printk(KERN_INFO "0x%02X flash_address            = 0x%08X\n",
508c2ecf20Sopenharmony_ci	    (uint8_t) offsetof(struct isp_reg, flash_address),
518c2ecf20Sopenharmony_ci	    readw(&ha->reg->flash_address));
528c2ecf20Sopenharmony_ci	printk(KERN_INFO "0x%02X flash_data               = 0x%08X\n",
538c2ecf20Sopenharmony_ci	    (uint8_t) offsetof(struct isp_reg, flash_data),
548c2ecf20Sopenharmony_ci	    readw(&ha->reg->flash_data));
558c2ecf20Sopenharmony_ci	printk(KERN_INFO "0x%02X ctrl_status              = 0x%08X\n",
568c2ecf20Sopenharmony_ci	    (uint8_t) offsetof(struct isp_reg, ctrl_status),
578c2ecf20Sopenharmony_ci	    readw(&ha->reg->ctrl_status));
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	if (is_qla4010(ha)) {
608c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X nvram            = 0x%08X\n",
618c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u1.isp4010.nvram),
628c2ecf20Sopenharmony_ci		    readw(&ha->reg->u1.isp4010.nvram));
638c2ecf20Sopenharmony_ci	} else if (is_qla4022(ha) | is_qla4032(ha)) {
648c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X intr_mask        = 0x%08X\n",
658c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u1.isp4022.intr_mask),
668c2ecf20Sopenharmony_ci		    readw(&ha->reg->u1.isp4022.intr_mask));
678c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X nvram            = 0x%08X\n",
688c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u1.isp4022.nvram),
698c2ecf20Sopenharmony_ci		    readw(&ha->reg->u1.isp4022.nvram));
708c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X semaphore	  = 0x%08X\n",
718c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u1.isp4022.semaphore),
728c2ecf20Sopenharmony_ci		    readw(&ha->reg->u1.isp4022.semaphore));
738c2ecf20Sopenharmony_ci	}
748c2ecf20Sopenharmony_ci	printk(KERN_INFO "0x%02X req_q_in                 = 0x%08X\n",
758c2ecf20Sopenharmony_ci	    (uint8_t) offsetof(struct isp_reg, req_q_in),
768c2ecf20Sopenharmony_ci	    readw(&ha->reg->req_q_in));
778c2ecf20Sopenharmony_ci	printk(KERN_INFO "0x%02X rsp_q_out                = 0x%08X\n",
788c2ecf20Sopenharmony_ci	    (uint8_t) offsetof(struct isp_reg, rsp_q_out),
798c2ecf20Sopenharmony_ci	    readw(&ha->reg->rsp_q_out));
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	if (is_qla4010(ha)) {
828c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X ext_hw_conf      = 0x%08X\n",
838c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4010.ext_hw_conf),
848c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.ext_hw_conf));
858c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X port_ctrl        = 0x%08X\n",
868c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4010.port_ctrl),
878c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.port_ctrl));
888c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X port_status      = 0x%08X\n",
898c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4010.port_status),
908c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.port_status));
918c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X req_q_out        = 0x%08X\n",
928c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4010.req_q_out),
938c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.req_q_out));
948c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X gp_out           = 0x%08X\n",
958c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4010.gp_out),
968c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.gp_out));
978c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X gp_in	          = 0x%08X\n",
988c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4010.gp_in),
998c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.gp_in));
1008c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X port_err_status  = 0x%08X\n", (uint8_t)
1018c2ecf20Sopenharmony_ci		    offsetof(struct isp_reg, u2.isp4010.port_err_status),
1028c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4010.port_err_status));
1038c2ecf20Sopenharmony_ci	} else if (is_qla4022(ha) | is_qla4032(ha)) {
1048c2ecf20Sopenharmony_ci		printk(KERN_INFO "Page 0 Registers:\n");
1058c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X ext_hw_conf      = 0x%08X\n", (uint8_t)
1068c2ecf20Sopenharmony_ci		    offsetof(struct isp_reg, u2.isp4022.p0.ext_hw_conf),
1078c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p0.ext_hw_conf));
1088c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X port_ctrl        = 0x%08X\n", (uint8_t)
1098c2ecf20Sopenharmony_ci		    offsetof(struct isp_reg, u2.isp4022.p0.port_ctrl),
1108c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p0.port_ctrl));
1118c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X port_status      = 0x%08X\n", (uint8_t)
1128c2ecf20Sopenharmony_ci		    offsetof(struct isp_reg, u2.isp4022.p0.port_status),
1138c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p0.port_status));
1148c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X gp_out           = 0x%08X\n",
1158c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4022.p0.gp_out),
1168c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p0.gp_out));
1178c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X gp_in            = 0x%08X\n",
1188c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4022.p0.gp_in),
1198c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p0.gp_in));
1208c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X port_err_status  = 0x%08X\n", (uint8_t)
1218c2ecf20Sopenharmony_ci		    offsetof(struct isp_reg, u2.isp4022.p0.port_err_status),
1228c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p0.port_err_status));
1238c2ecf20Sopenharmony_ci		printk(KERN_INFO "Page 1 Registers:\n");
1248c2ecf20Sopenharmony_ci		writel(HOST_MEM_CFG_PAGE & set_rmask(CSR_SCSI_PAGE_SELECT),
1258c2ecf20Sopenharmony_ci		    &ha->reg->ctrl_status);
1268c2ecf20Sopenharmony_ci		printk(KERN_INFO "0x%02X req_q_out        = 0x%08X\n",
1278c2ecf20Sopenharmony_ci		    (uint8_t) offsetof(struct isp_reg, u2.isp4022.p1.req_q_out),
1288c2ecf20Sopenharmony_ci		    readw(&ha->reg->u2.isp4022.p1.req_q_out));
1298c2ecf20Sopenharmony_ci		writel(PORT_CTRL_STAT_PAGE & set_rmask(CSR_SCSI_PAGE_SELECT),
1308c2ecf20Sopenharmony_ci		    &ha->reg->ctrl_status);
1318c2ecf20Sopenharmony_ci	}
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_civoid qla4_8xxx_dump_peg_reg(struct scsi_qla_host *ha)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	uint32_t halt_status1, halt_status2;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci	halt_status1 = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS1);
1398c2ecf20Sopenharmony_ci	halt_status2 = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_HALT_STATUS2);
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	if (is_qla8022(ha)) {
1428c2ecf20Sopenharmony_ci		ql4_printk(KERN_INFO, ha,
1438c2ecf20Sopenharmony_ci			   "scsi(%ld): %s, ISP%04x Dumping hw/fw registers:\n"
1448c2ecf20Sopenharmony_ci			   " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n"
1458c2ecf20Sopenharmony_ci			   " PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,\n"
1468c2ecf20Sopenharmony_ci			   " PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,\n"
1478c2ecf20Sopenharmony_ci			   " PEG_NET_4_PC: 0x%x\n", ha->host_no, __func__,
1488c2ecf20Sopenharmony_ci			   ha->pdev->device, halt_status1, halt_status2,
1498c2ecf20Sopenharmony_ci			   qla4_82xx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x3c),
1508c2ecf20Sopenharmony_ci			   qla4_82xx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 + 0x3c),
1518c2ecf20Sopenharmony_ci			   qla4_82xx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 + 0x3c),
1528c2ecf20Sopenharmony_ci			   qla4_82xx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 + 0x3c),
1538c2ecf20Sopenharmony_ci			   qla4_82xx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 + 0x3c));
1548c2ecf20Sopenharmony_ci	} else if (is_qla8032(ha) || is_qla8042(ha)) {
1558c2ecf20Sopenharmony_ci		ql4_printk(KERN_INFO, ha,
1568c2ecf20Sopenharmony_ci			   "scsi(%ld): %s, ISP%04x Dumping hw/fw registers:\n"
1578c2ecf20Sopenharmony_ci			   " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,\n",
1588c2ecf20Sopenharmony_ci			   ha->host_no, __func__, ha->pdev->device,
1598c2ecf20Sopenharmony_ci			   halt_status1, halt_status2);
1608c2ecf20Sopenharmony_ci	}
1618c2ecf20Sopenharmony_ci}
162