18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * QLogic Fibre Channel HBA Driver 48c2ecf20Sopenharmony_ci * Copyright (c) 2003-2014 QLogic Corporation 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#include "qla_def.h" 78c2ecf20Sopenharmony_ci#include "qla_tmpl.h" 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define ISPREG(vha) (&(vha)->hw->iobase->isp24) 108c2ecf20Sopenharmony_ci#define IOBAR(reg) offsetof(typeof(*(reg)), iobase_addr) 118c2ecf20Sopenharmony_ci#define IOBASE(vha) IOBAR(ISPREG(vha)) 128c2ecf20Sopenharmony_ci#define INVALID_ENTRY ((struct qla27xx_fwdt_entry *)0xffffffffffffffffUL) 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistatic inline void 158c2ecf20Sopenharmony_ciqla27xx_insert16(uint16_t value, void *buf, ulong *len) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci if (buf) { 188c2ecf20Sopenharmony_ci buf += *len; 198c2ecf20Sopenharmony_ci *(__le16 *)buf = cpu_to_le16(value); 208c2ecf20Sopenharmony_ci } 218c2ecf20Sopenharmony_ci *len += sizeof(value); 228c2ecf20Sopenharmony_ci} 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic inline void 258c2ecf20Sopenharmony_ciqla27xx_insert32(uint32_t value, void *buf, ulong *len) 268c2ecf20Sopenharmony_ci{ 278c2ecf20Sopenharmony_ci if (buf) { 288c2ecf20Sopenharmony_ci buf += *len; 298c2ecf20Sopenharmony_ci *(__le32 *)buf = cpu_to_le32(value); 308c2ecf20Sopenharmony_ci } 318c2ecf20Sopenharmony_ci *len += sizeof(value); 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic inline void 358c2ecf20Sopenharmony_ciqla27xx_insertbuf(void *mem, ulong size, void *buf, ulong *len) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci if (buf && mem && size) { 388c2ecf20Sopenharmony_ci buf += *len; 398c2ecf20Sopenharmony_ci memcpy(buf, mem, size); 408c2ecf20Sopenharmony_ci } 418c2ecf20Sopenharmony_ci *len += size; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic inline void 458c2ecf20Sopenharmony_ciqla27xx_read8(void __iomem *window, void *buf, ulong *len) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci uint8_t value = ~0; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci if (buf) { 508c2ecf20Sopenharmony_ci value = rd_reg_byte(window); 518c2ecf20Sopenharmony_ci } 528c2ecf20Sopenharmony_ci qla27xx_insert32(value, buf, len); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic inline void 568c2ecf20Sopenharmony_ciqla27xx_read16(void __iomem *window, void *buf, ulong *len) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci uint16_t value = ~0; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci if (buf) { 618c2ecf20Sopenharmony_ci value = rd_reg_word(window); 628c2ecf20Sopenharmony_ci } 638c2ecf20Sopenharmony_ci qla27xx_insert32(value, buf, len); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic inline void 678c2ecf20Sopenharmony_ciqla27xx_read32(void __iomem *window, void *buf, ulong *len) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci uint32_t value = ~0; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci if (buf) { 728c2ecf20Sopenharmony_ci value = rd_reg_dword(window); 738c2ecf20Sopenharmony_ci } 748c2ecf20Sopenharmony_ci qla27xx_insert32(value, buf, len); 758c2ecf20Sopenharmony_ci} 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic inline void (*qla27xx_read_vector(uint width))(void __iomem*, void *, ulong *) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci return 808c2ecf20Sopenharmony_ci (width == 1) ? qla27xx_read8 : 818c2ecf20Sopenharmony_ci (width == 2) ? qla27xx_read16 : 828c2ecf20Sopenharmony_ci qla27xx_read32; 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_cistatic inline void 868c2ecf20Sopenharmony_ciqla27xx_read_reg(__iomem struct device_reg_24xx *reg, 878c2ecf20Sopenharmony_ci uint offset, void *buf, ulong *len) 888c2ecf20Sopenharmony_ci{ 898c2ecf20Sopenharmony_ci void __iomem *window = (void __iomem *)reg + offset; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci qla27xx_read32(window, buf, len); 928c2ecf20Sopenharmony_ci} 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_cistatic inline void 958c2ecf20Sopenharmony_ciqla27xx_write_reg(__iomem struct device_reg_24xx *reg, 968c2ecf20Sopenharmony_ci uint offset, uint32_t data, void *buf) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci if (buf) { 998c2ecf20Sopenharmony_ci void __iomem *window = (void __iomem *)reg + offset; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci wrt_reg_dword(window, data); 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistatic inline void 1068c2ecf20Sopenharmony_ciqla27xx_read_window(__iomem struct device_reg_24xx *reg, 1078c2ecf20Sopenharmony_ci uint32_t addr, uint offset, uint count, uint width, void *buf, 1088c2ecf20Sopenharmony_ci ulong *len) 1098c2ecf20Sopenharmony_ci{ 1108c2ecf20Sopenharmony_ci void __iomem *window = (void __iomem *)reg + offset; 1118c2ecf20Sopenharmony_ci void (*readn)(void __iomem*, void *, ulong *) = qla27xx_read_vector(width); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci qla27xx_write_reg(reg, IOBAR(reg), addr, buf); 1148c2ecf20Sopenharmony_ci while (count--) { 1158c2ecf20Sopenharmony_ci qla27xx_insert32(addr, buf, len); 1168c2ecf20Sopenharmony_ci readn(window, buf, len); 1178c2ecf20Sopenharmony_ci window += width; 1188c2ecf20Sopenharmony_ci addr++; 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic inline void 1238c2ecf20Sopenharmony_ciqla27xx_skip_entry(struct qla27xx_fwdt_entry *ent, void *buf) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci if (buf) 1268c2ecf20Sopenharmony_ci ent->hdr.driver_flags |= DRIVER_FLAG_SKIP_ENTRY; 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic inline struct qla27xx_fwdt_entry * 1308c2ecf20Sopenharmony_ciqla27xx_next_entry(struct qla27xx_fwdt_entry *ent) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci return (void *)ent + le32_to_cpu(ent->hdr.size); 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 1368c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t0(struct scsi_qla_host *vha, 1378c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 1388c2ecf20Sopenharmony_ci{ 1398c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd100, 1408c2ecf20Sopenharmony_ci "%s: nop [%lx]\n", __func__, *len); 1418c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 1448c2ecf20Sopenharmony_ci} 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 1478c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t255(struct scsi_qla_host *vha, 1488c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 1498c2ecf20Sopenharmony_ci{ 1508c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd1ff, 1518c2ecf20Sopenharmony_ci "%s: end [%lx]\n", __func__, *len); 1528c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* terminate */ 1558c2ecf20Sopenharmony_ci return NULL; 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 1598c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t256(struct scsi_qla_host *vha, 1608c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 1618c2ecf20Sopenharmony_ci{ 1628c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t256.base_addr); 1638c2ecf20Sopenharmony_ci uint offset = ent->t256.pci_offset; 1648c2ecf20Sopenharmony_ci ulong count = le16_to_cpu(ent->t256.reg_count); 1658c2ecf20Sopenharmony_ci uint width = ent->t256.reg_width; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd200, 1688c2ecf20Sopenharmony_ci "%s: rdio t1 [%lx]\n", __func__, *len); 1698c2ecf20Sopenharmony_ci qla27xx_read_window(ISPREG(vha), addr, offset, count, width, buf, len); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 1728c2ecf20Sopenharmony_ci} 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 1758c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t257(struct scsi_qla_host *vha, 1768c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 1778c2ecf20Sopenharmony_ci{ 1788c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t257.base_addr); 1798c2ecf20Sopenharmony_ci uint offset = ent->t257.pci_offset; 1808c2ecf20Sopenharmony_ci ulong data = le32_to_cpu(ent->t257.write_data); 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd201, 1838c2ecf20Sopenharmony_ci "%s: wrio t1 [%lx]\n", __func__, *len); 1848c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), IOBASE(vha), addr, buf); 1858c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), offset, data, buf); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 1918c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t258(struct scsi_qla_host *vha, 1928c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci uint banksel = ent->t258.banksel_offset; 1958c2ecf20Sopenharmony_ci ulong bank = le32_to_cpu(ent->t258.bank); 1968c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t258.base_addr); 1978c2ecf20Sopenharmony_ci uint offset = ent->t258.pci_offset; 1988c2ecf20Sopenharmony_ci uint count = le16_to_cpu(ent->t258.reg_count); 1998c2ecf20Sopenharmony_ci uint width = ent->t258.reg_width; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd202, 2028c2ecf20Sopenharmony_ci "%s: rdio t2 [%lx]\n", __func__, *len); 2038c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), banksel, bank, buf); 2048c2ecf20Sopenharmony_ci qla27xx_read_window(ISPREG(vha), addr, offset, count, width, buf, len); 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 2108c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t259(struct scsi_qla_host *vha, 2118c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t259.base_addr); 2148c2ecf20Sopenharmony_ci uint banksel = ent->t259.banksel_offset; 2158c2ecf20Sopenharmony_ci ulong bank = le32_to_cpu(ent->t259.bank); 2168c2ecf20Sopenharmony_ci uint offset = ent->t259.pci_offset; 2178c2ecf20Sopenharmony_ci ulong data = le32_to_cpu(ent->t259.write_data); 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd203, 2208c2ecf20Sopenharmony_ci "%s: wrio t2 [%lx]\n", __func__, *len); 2218c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), IOBASE(vha), addr, buf); 2228c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), banksel, bank, buf); 2238c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), offset, data, buf); 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 2298c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t260(struct scsi_qla_host *vha, 2308c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 2318c2ecf20Sopenharmony_ci{ 2328c2ecf20Sopenharmony_ci uint offset = ent->t260.pci_offset; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd204, 2358c2ecf20Sopenharmony_ci "%s: rdpci [%lx]\n", __func__, *len); 2368c2ecf20Sopenharmony_ci qla27xx_insert32(offset, buf, len); 2378c2ecf20Sopenharmony_ci qla27xx_read_reg(ISPREG(vha), offset, buf, len); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 2438c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t261(struct scsi_qla_host *vha, 2448c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 2458c2ecf20Sopenharmony_ci{ 2468c2ecf20Sopenharmony_ci uint offset = ent->t261.pci_offset; 2478c2ecf20Sopenharmony_ci ulong data = le32_to_cpu(ent->t261.write_data); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd205, 2508c2ecf20Sopenharmony_ci "%s: wrpci [%lx]\n", __func__, *len); 2518c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), offset, data, buf); 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 2548c2ecf20Sopenharmony_ci} 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 2578c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t262(struct scsi_qla_host *vha, 2588c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 2598c2ecf20Sopenharmony_ci{ 2608c2ecf20Sopenharmony_ci uint area = ent->t262.ram_area; 2618c2ecf20Sopenharmony_ci ulong start = le32_to_cpu(ent->t262.start_addr); 2628c2ecf20Sopenharmony_ci ulong end = le32_to_cpu(ent->t262.end_addr); 2638c2ecf20Sopenharmony_ci ulong dwords; 2648c2ecf20Sopenharmony_ci int rc; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd206, 2678c2ecf20Sopenharmony_ci "%s: rdram(%x) [%lx]\n", __func__, ent->t262.ram_area, *len); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci if (area == T262_RAM_AREA_CRITICAL_RAM) { 2708c2ecf20Sopenharmony_ci ; 2718c2ecf20Sopenharmony_ci } else if (area == T262_RAM_AREA_EXTERNAL_RAM) { 2728c2ecf20Sopenharmony_ci end = vha->hw->fw_memory_size; 2738c2ecf20Sopenharmony_ci if (buf) 2748c2ecf20Sopenharmony_ci ent->t262.end_addr = cpu_to_le32(end); 2758c2ecf20Sopenharmony_ci } else if (area == T262_RAM_AREA_SHARED_RAM) { 2768c2ecf20Sopenharmony_ci start = vha->hw->fw_shared_ram_start; 2778c2ecf20Sopenharmony_ci end = vha->hw->fw_shared_ram_end; 2788c2ecf20Sopenharmony_ci if (buf) { 2798c2ecf20Sopenharmony_ci ent->t262.start_addr = cpu_to_le32(start); 2808c2ecf20Sopenharmony_ci ent->t262.end_addr = cpu_to_le32(end); 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci } else if (area == T262_RAM_AREA_DDR_RAM) { 2838c2ecf20Sopenharmony_ci start = vha->hw->fw_ddr_ram_start; 2848c2ecf20Sopenharmony_ci end = vha->hw->fw_ddr_ram_end; 2858c2ecf20Sopenharmony_ci if (buf) { 2868c2ecf20Sopenharmony_ci ent->t262.start_addr = cpu_to_le32(start); 2878c2ecf20Sopenharmony_ci ent->t262.end_addr = cpu_to_le32(end); 2888c2ecf20Sopenharmony_ci } 2898c2ecf20Sopenharmony_ci } else if (area == T262_RAM_AREA_MISC) { 2908c2ecf20Sopenharmony_ci if (buf) { 2918c2ecf20Sopenharmony_ci ent->t262.start_addr = cpu_to_le32(start); 2928c2ecf20Sopenharmony_ci ent->t262.end_addr = cpu_to_le32(end); 2938c2ecf20Sopenharmony_ci } 2948c2ecf20Sopenharmony_ci } else { 2958c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd022, 2968c2ecf20Sopenharmony_ci "%s: unknown area %x\n", __func__, area); 2978c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 2988c2ecf20Sopenharmony_ci goto done; 2998c2ecf20Sopenharmony_ci } 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci if (end < start || start == 0 || end == 0) { 3028c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd023, 3038c2ecf20Sopenharmony_ci "%s: unusable range (start=%lx end=%lx)\n", 3048c2ecf20Sopenharmony_ci __func__, start, end); 3058c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 3068c2ecf20Sopenharmony_ci goto done; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci dwords = end - start + 1; 3108c2ecf20Sopenharmony_ci if (buf) { 3118c2ecf20Sopenharmony_ci buf += *len; 3128c2ecf20Sopenharmony_ci rc = qla24xx_dump_ram(vha->hw, start, buf, dwords, &buf); 3138c2ecf20Sopenharmony_ci if (rc != QLA_SUCCESS) { 3148c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_async, vha, 0xffff, 3158c2ecf20Sopenharmony_ci "%s: dump ram MB failed. Area %xh start %lxh end %lxh\n", 3168c2ecf20Sopenharmony_ci __func__, area, start, end); 3178c2ecf20Sopenharmony_ci return INVALID_ENTRY; 3188c2ecf20Sopenharmony_ci } 3198c2ecf20Sopenharmony_ci } 3208c2ecf20Sopenharmony_ci *len += dwords * sizeof(uint32_t); 3218c2ecf20Sopenharmony_cidone: 3228c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 3238c2ecf20Sopenharmony_ci} 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 3268c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t263(struct scsi_qla_host *vha, 3278c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 3288c2ecf20Sopenharmony_ci{ 3298c2ecf20Sopenharmony_ci uint type = ent->t263.queue_type; 3308c2ecf20Sopenharmony_ci uint count = 0; 3318c2ecf20Sopenharmony_ci uint i; 3328c2ecf20Sopenharmony_ci uint length; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd207, 3358c2ecf20Sopenharmony_ci "%s: getq(%x) [%lx]\n", __func__, type, *len); 3368c2ecf20Sopenharmony_ci if (type == T263_QUEUE_TYPE_REQ) { 3378c2ecf20Sopenharmony_ci for (i = 0; i < vha->hw->max_req_queues; i++) { 3388c2ecf20Sopenharmony_ci struct req_que *req = vha->hw->req_q_map[i]; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci if (req || !buf) { 3418c2ecf20Sopenharmony_ci length = req ? 3428c2ecf20Sopenharmony_ci req->length : REQUEST_ENTRY_CNT_24XX; 3438c2ecf20Sopenharmony_ci qla27xx_insert16(i, buf, len); 3448c2ecf20Sopenharmony_ci qla27xx_insert16(length, buf, len); 3458c2ecf20Sopenharmony_ci qla27xx_insertbuf(req ? req->ring : NULL, 3468c2ecf20Sopenharmony_ci length * sizeof(*req->ring), buf, len); 3478c2ecf20Sopenharmony_ci count++; 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci } 3508c2ecf20Sopenharmony_ci } else if (type == T263_QUEUE_TYPE_RSP) { 3518c2ecf20Sopenharmony_ci for (i = 0; i < vha->hw->max_rsp_queues; i++) { 3528c2ecf20Sopenharmony_ci struct rsp_que *rsp = vha->hw->rsp_q_map[i]; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci if (rsp || !buf) { 3558c2ecf20Sopenharmony_ci length = rsp ? 3568c2ecf20Sopenharmony_ci rsp->length : RESPONSE_ENTRY_CNT_MQ; 3578c2ecf20Sopenharmony_ci qla27xx_insert16(i, buf, len); 3588c2ecf20Sopenharmony_ci qla27xx_insert16(length, buf, len); 3598c2ecf20Sopenharmony_ci qla27xx_insertbuf(rsp ? rsp->ring : NULL, 3608c2ecf20Sopenharmony_ci length * sizeof(*rsp->ring), buf, len); 3618c2ecf20Sopenharmony_ci count++; 3628c2ecf20Sopenharmony_ci } 3638c2ecf20Sopenharmony_ci } 3648c2ecf20Sopenharmony_ci } else if (QLA_TGT_MODE_ENABLED() && 3658c2ecf20Sopenharmony_ci ent->t263.queue_type == T263_QUEUE_TYPE_ATIO) { 3668c2ecf20Sopenharmony_ci struct qla_hw_data *ha = vha->hw; 3678c2ecf20Sopenharmony_ci struct atio *atr = ha->tgt.atio_ring; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci if (atr || !buf) { 3708c2ecf20Sopenharmony_ci length = ha->tgt.atio_q_length; 3718c2ecf20Sopenharmony_ci qla27xx_insert16(0, buf, len); 3728c2ecf20Sopenharmony_ci qla27xx_insert16(length, buf, len); 3738c2ecf20Sopenharmony_ci qla27xx_insertbuf(atr, length * sizeof(*atr), buf, len); 3748c2ecf20Sopenharmony_ci count++; 3758c2ecf20Sopenharmony_ci } 3768c2ecf20Sopenharmony_ci } else { 3778c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd026, 3788c2ecf20Sopenharmony_ci "%s: unknown queue %x\n", __func__, type); 3798c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 3808c2ecf20Sopenharmony_ci } 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci if (buf) { 3838c2ecf20Sopenharmony_ci if (count) 3848c2ecf20Sopenharmony_ci ent->t263.num_queues = count; 3858c2ecf20Sopenharmony_ci else 3868c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 3908c2ecf20Sopenharmony_ci} 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 3938c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t264(struct scsi_qla_host *vha, 3948c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 3958c2ecf20Sopenharmony_ci{ 3968c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd208, 3978c2ecf20Sopenharmony_ci "%s: getfce [%lx]\n", __func__, *len); 3988c2ecf20Sopenharmony_ci if (vha->hw->fce) { 3998c2ecf20Sopenharmony_ci if (buf) { 4008c2ecf20Sopenharmony_ci ent->t264.fce_trace_size = FCE_SIZE; 4018c2ecf20Sopenharmony_ci ent->t264.write_pointer = vha->hw->fce_wr; 4028c2ecf20Sopenharmony_ci ent->t264.base_pointer = vha->hw->fce_dma; 4038c2ecf20Sopenharmony_ci ent->t264.fce_enable_mb0 = vha->hw->fce_mb[0]; 4048c2ecf20Sopenharmony_ci ent->t264.fce_enable_mb2 = vha->hw->fce_mb[2]; 4058c2ecf20Sopenharmony_ci ent->t264.fce_enable_mb3 = vha->hw->fce_mb[3]; 4068c2ecf20Sopenharmony_ci ent->t264.fce_enable_mb4 = vha->hw->fce_mb[4]; 4078c2ecf20Sopenharmony_ci ent->t264.fce_enable_mb5 = vha->hw->fce_mb[5]; 4088c2ecf20Sopenharmony_ci ent->t264.fce_enable_mb6 = vha->hw->fce_mb[6]; 4098c2ecf20Sopenharmony_ci } 4108c2ecf20Sopenharmony_ci qla27xx_insertbuf(vha->hw->fce, FCE_SIZE, buf, len); 4118c2ecf20Sopenharmony_ci } else { 4128c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd027, 4138c2ecf20Sopenharmony_ci "%s: missing fce\n", __func__); 4148c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 4158c2ecf20Sopenharmony_ci } 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 4188c2ecf20Sopenharmony_ci} 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 4218c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t265(struct scsi_qla_host *vha, 4228c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 4238c2ecf20Sopenharmony_ci{ 4248c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd209, 4258c2ecf20Sopenharmony_ci "%s: pause risc [%lx]\n", __func__, *len); 4268c2ecf20Sopenharmony_ci if (buf) 4278c2ecf20Sopenharmony_ci qla24xx_pause_risc(ISPREG(vha), vha->hw); 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 4308c2ecf20Sopenharmony_ci} 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 4338c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t266(struct scsi_qla_host *vha, 4348c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd20a, 4378c2ecf20Sopenharmony_ci "%s: reset risc [%lx]\n", __func__, *len); 4388c2ecf20Sopenharmony_ci if (buf) 4398c2ecf20Sopenharmony_ci WARN_ON_ONCE(qla24xx_soft_reset(vha->hw) != QLA_SUCCESS); 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 4428c2ecf20Sopenharmony_ci} 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 4458c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t267(struct scsi_qla_host *vha, 4468c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 4478c2ecf20Sopenharmony_ci{ 4488c2ecf20Sopenharmony_ci uint offset = ent->t267.pci_offset; 4498c2ecf20Sopenharmony_ci ulong data = le32_to_cpu(ent->t267.data); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd20b, 4528c2ecf20Sopenharmony_ci "%s: dis intr [%lx]\n", __func__, *len); 4538c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), offset, data, buf); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 4568c2ecf20Sopenharmony_ci} 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 4598c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t268(struct scsi_qla_host *vha, 4608c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 4618c2ecf20Sopenharmony_ci{ 4628c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd20c, 4638c2ecf20Sopenharmony_ci "%s: gethb(%x) [%lx]\n", __func__, ent->t268.buf_type, *len); 4648c2ecf20Sopenharmony_ci switch (ent->t268.buf_type) { 4658c2ecf20Sopenharmony_ci case T268_BUF_TYPE_EXTD_TRACE: 4668c2ecf20Sopenharmony_ci if (vha->hw->eft) { 4678c2ecf20Sopenharmony_ci if (buf) { 4688c2ecf20Sopenharmony_ci ent->t268.buf_size = EFT_SIZE; 4698c2ecf20Sopenharmony_ci ent->t268.start_addr = vha->hw->eft_dma; 4708c2ecf20Sopenharmony_ci } 4718c2ecf20Sopenharmony_ci qla27xx_insertbuf(vha->hw->eft, EFT_SIZE, buf, len); 4728c2ecf20Sopenharmony_ci } else { 4738c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd028, 4748c2ecf20Sopenharmony_ci "%s: missing eft\n", __func__); 4758c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 4768c2ecf20Sopenharmony_ci } 4778c2ecf20Sopenharmony_ci break; 4788c2ecf20Sopenharmony_ci case T268_BUF_TYPE_EXCH_BUFOFF: 4798c2ecf20Sopenharmony_ci if (vha->hw->exchoffld_buf) { 4808c2ecf20Sopenharmony_ci if (buf) { 4818c2ecf20Sopenharmony_ci ent->t268.buf_size = vha->hw->exchoffld_size; 4828c2ecf20Sopenharmony_ci ent->t268.start_addr = 4838c2ecf20Sopenharmony_ci vha->hw->exchoffld_buf_dma; 4848c2ecf20Sopenharmony_ci } 4858c2ecf20Sopenharmony_ci qla27xx_insertbuf(vha->hw->exchoffld_buf, 4868c2ecf20Sopenharmony_ci vha->hw->exchoffld_size, buf, len); 4878c2ecf20Sopenharmony_ci } else { 4888c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd028, 4898c2ecf20Sopenharmony_ci "%s: missing exch offld\n", __func__); 4908c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 4918c2ecf20Sopenharmony_ci } 4928c2ecf20Sopenharmony_ci break; 4938c2ecf20Sopenharmony_ci case T268_BUF_TYPE_EXTD_LOGIN: 4948c2ecf20Sopenharmony_ci if (vha->hw->exlogin_buf) { 4958c2ecf20Sopenharmony_ci if (buf) { 4968c2ecf20Sopenharmony_ci ent->t268.buf_size = vha->hw->exlogin_size; 4978c2ecf20Sopenharmony_ci ent->t268.start_addr = 4988c2ecf20Sopenharmony_ci vha->hw->exlogin_buf_dma; 4998c2ecf20Sopenharmony_ci } 5008c2ecf20Sopenharmony_ci qla27xx_insertbuf(vha->hw->exlogin_buf, 5018c2ecf20Sopenharmony_ci vha->hw->exlogin_size, buf, len); 5028c2ecf20Sopenharmony_ci } else { 5038c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd028, 5048c2ecf20Sopenharmony_ci "%s: missing ext login\n", __func__); 5058c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 5068c2ecf20Sopenharmony_ci } 5078c2ecf20Sopenharmony_ci break; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci case T268_BUF_TYPE_REQ_MIRROR: 5108c2ecf20Sopenharmony_ci case T268_BUF_TYPE_RSP_MIRROR: 5118c2ecf20Sopenharmony_ci /* 5128c2ecf20Sopenharmony_ci * Mirror pointers are not implemented in the 5138c2ecf20Sopenharmony_ci * driver, instead shadow pointers are used by 5148c2ecf20Sopenharmony_ci * the drier. Skip these entries. 5158c2ecf20Sopenharmony_ci */ 5168c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 5178c2ecf20Sopenharmony_ci break; 5188c2ecf20Sopenharmony_ci default: 5198c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_async, vha, 0xd02b, 5208c2ecf20Sopenharmony_ci "%s: unknown buffer %x\n", __func__, ent->t268.buf_type); 5218c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 5228c2ecf20Sopenharmony_ci break; 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 5268c2ecf20Sopenharmony_ci} 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 5298c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t269(struct scsi_qla_host *vha, 5308c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 5318c2ecf20Sopenharmony_ci{ 5328c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd20d, 5338c2ecf20Sopenharmony_ci "%s: scratch [%lx]\n", __func__, *len); 5348c2ecf20Sopenharmony_ci qla27xx_insert32(0xaaaaaaaa, buf, len); 5358c2ecf20Sopenharmony_ci qla27xx_insert32(0xbbbbbbbb, buf, len); 5368c2ecf20Sopenharmony_ci qla27xx_insert32(0xcccccccc, buf, len); 5378c2ecf20Sopenharmony_ci qla27xx_insert32(0xdddddddd, buf, len); 5388c2ecf20Sopenharmony_ci qla27xx_insert32(*len + sizeof(uint32_t), buf, len); 5398c2ecf20Sopenharmony_ci if (buf) 5408c2ecf20Sopenharmony_ci ent->t269.scratch_size = 5 * sizeof(uint32_t); 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 5438c2ecf20Sopenharmony_ci} 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 5468c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t270(struct scsi_qla_host *vha, 5478c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 5488c2ecf20Sopenharmony_ci{ 5498c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t270.addr); 5508c2ecf20Sopenharmony_ci ulong dwords = le32_to_cpu(ent->t270.count); 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd20e, 5538c2ecf20Sopenharmony_ci "%s: rdremreg [%lx]\n", __func__, *len); 5548c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), IOBASE_ADDR, 0x40, buf); 5558c2ecf20Sopenharmony_ci while (dwords--) { 5568c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), 0xc0, addr|0x80000000, buf); 5578c2ecf20Sopenharmony_ci qla27xx_insert32(addr, buf, len); 5588c2ecf20Sopenharmony_ci qla27xx_read_reg(ISPREG(vha), 0xc4, buf, len); 5598c2ecf20Sopenharmony_ci addr += sizeof(uint32_t); 5608c2ecf20Sopenharmony_ci } 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 5668c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t271(struct scsi_qla_host *vha, 5678c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 5688c2ecf20Sopenharmony_ci{ 5698c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t271.addr); 5708c2ecf20Sopenharmony_ci ulong data = le32_to_cpu(ent->t271.data); 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd20f, 5738c2ecf20Sopenharmony_ci "%s: wrremreg [%lx]\n", __func__, *len); 5748c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), IOBASE(vha), 0x40, buf); 5758c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), 0xc4, data, buf); 5768c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), 0xc0, addr, buf); 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 5828c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t272(struct scsi_qla_host *vha, 5838c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 5848c2ecf20Sopenharmony_ci{ 5858c2ecf20Sopenharmony_ci ulong dwords = le32_to_cpu(ent->t272.count); 5868c2ecf20Sopenharmony_ci ulong start = le32_to_cpu(ent->t272.addr); 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd210, 5898c2ecf20Sopenharmony_ci "%s: rdremram [%lx]\n", __func__, *len); 5908c2ecf20Sopenharmony_ci if (buf) { 5918c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd02c, 5928c2ecf20Sopenharmony_ci "%s: @%lx -> (%lx dwords)\n", __func__, start, dwords); 5938c2ecf20Sopenharmony_ci buf += *len; 5948c2ecf20Sopenharmony_ci qla27xx_dump_mpi_ram(vha->hw, start, buf, dwords, &buf); 5958c2ecf20Sopenharmony_ci } 5968c2ecf20Sopenharmony_ci *len += dwords * sizeof(uint32_t); 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 5998c2ecf20Sopenharmony_ci} 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 6028c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t273(struct scsi_qla_host *vha, 6038c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 6048c2ecf20Sopenharmony_ci{ 6058c2ecf20Sopenharmony_ci ulong dwords = le32_to_cpu(ent->t273.count); 6068c2ecf20Sopenharmony_ci ulong addr = le32_to_cpu(ent->t273.addr); 6078c2ecf20Sopenharmony_ci uint32_t value; 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd211, 6108c2ecf20Sopenharmony_ci "%s: pcicfg [%lx]\n", __func__, *len); 6118c2ecf20Sopenharmony_ci while (dwords--) { 6128c2ecf20Sopenharmony_ci value = ~0; 6138c2ecf20Sopenharmony_ci if (pci_read_config_dword(vha->hw->pdev, addr, &value)) 6148c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd02d, 6158c2ecf20Sopenharmony_ci "%s: failed pcicfg read at %lx\n", __func__, addr); 6168c2ecf20Sopenharmony_ci qla27xx_insert32(addr, buf, len); 6178c2ecf20Sopenharmony_ci qla27xx_insert32(value, buf, len); 6188c2ecf20Sopenharmony_ci addr += sizeof(uint32_t); 6198c2ecf20Sopenharmony_ci } 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 6228c2ecf20Sopenharmony_ci} 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 6258c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t274(struct scsi_qla_host *vha, 6268c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 6278c2ecf20Sopenharmony_ci{ 6288c2ecf20Sopenharmony_ci ulong type = ent->t274.queue_type; 6298c2ecf20Sopenharmony_ci uint count = 0; 6308c2ecf20Sopenharmony_ci uint i; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd212, 6338c2ecf20Sopenharmony_ci "%s: getqsh(%lx) [%lx]\n", __func__, type, *len); 6348c2ecf20Sopenharmony_ci if (type == T274_QUEUE_TYPE_REQ_SHAD) { 6358c2ecf20Sopenharmony_ci for (i = 0; i < vha->hw->max_req_queues; i++) { 6368c2ecf20Sopenharmony_ci struct req_que *req = vha->hw->req_q_map[i]; 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci if (req || !buf) { 6398c2ecf20Sopenharmony_ci qla27xx_insert16(i, buf, len); 6408c2ecf20Sopenharmony_ci qla27xx_insert16(1, buf, len); 6418c2ecf20Sopenharmony_ci qla27xx_insert32(req && req->out_ptr ? 6428c2ecf20Sopenharmony_ci *req->out_ptr : 0, buf, len); 6438c2ecf20Sopenharmony_ci count++; 6448c2ecf20Sopenharmony_ci } 6458c2ecf20Sopenharmony_ci } 6468c2ecf20Sopenharmony_ci } else if (type == T274_QUEUE_TYPE_RSP_SHAD) { 6478c2ecf20Sopenharmony_ci for (i = 0; i < vha->hw->max_rsp_queues; i++) { 6488c2ecf20Sopenharmony_ci struct rsp_que *rsp = vha->hw->rsp_q_map[i]; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci if (rsp || !buf) { 6518c2ecf20Sopenharmony_ci qla27xx_insert16(i, buf, len); 6528c2ecf20Sopenharmony_ci qla27xx_insert16(1, buf, len); 6538c2ecf20Sopenharmony_ci qla27xx_insert32(rsp && rsp->in_ptr ? 6548c2ecf20Sopenharmony_ci *rsp->in_ptr : 0, buf, len); 6558c2ecf20Sopenharmony_ci count++; 6568c2ecf20Sopenharmony_ci } 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci } else if (QLA_TGT_MODE_ENABLED() && 6598c2ecf20Sopenharmony_ci ent->t274.queue_type == T274_QUEUE_TYPE_ATIO_SHAD) { 6608c2ecf20Sopenharmony_ci struct qla_hw_data *ha = vha->hw; 6618c2ecf20Sopenharmony_ci struct atio *atr = ha->tgt.atio_ring_ptr; 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci if (atr || !buf) { 6648c2ecf20Sopenharmony_ci qla27xx_insert16(0, buf, len); 6658c2ecf20Sopenharmony_ci qla27xx_insert16(1, buf, len); 6668c2ecf20Sopenharmony_ci qla27xx_insert32(ha->tgt.atio_q_in ? 6678c2ecf20Sopenharmony_ci readl(ha->tgt.atio_q_in) : 0, buf, len); 6688c2ecf20Sopenharmony_ci count++; 6698c2ecf20Sopenharmony_ci } 6708c2ecf20Sopenharmony_ci } else { 6718c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd02f, 6728c2ecf20Sopenharmony_ci "%s: unknown queue %lx\n", __func__, type); 6738c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 6748c2ecf20Sopenharmony_ci } 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci if (buf) { 6778c2ecf20Sopenharmony_ci if (count) 6788c2ecf20Sopenharmony_ci ent->t274.num_queues = count; 6798c2ecf20Sopenharmony_ci else 6808c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 6818c2ecf20Sopenharmony_ci } 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 6848c2ecf20Sopenharmony_ci} 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 6878c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t275(struct scsi_qla_host *vha, 6888c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 6898c2ecf20Sopenharmony_ci{ 6908c2ecf20Sopenharmony_ci ulong offset = offsetof(typeof(*ent), t275.buffer); 6918c2ecf20Sopenharmony_ci ulong length = le32_to_cpu(ent->t275.length); 6928c2ecf20Sopenharmony_ci ulong size = le32_to_cpu(ent->hdr.size); 6938c2ecf20Sopenharmony_ci void *buffer = ent->t275.buffer; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd213, 6968c2ecf20Sopenharmony_ci "%s: buffer(%lx) [%lx]\n", __func__, length, *len); 6978c2ecf20Sopenharmony_ci if (!length) { 6988c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd020, 6998c2ecf20Sopenharmony_ci "%s: buffer zero length\n", __func__); 7008c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 7018c2ecf20Sopenharmony_ci goto done; 7028c2ecf20Sopenharmony_ci } 7038c2ecf20Sopenharmony_ci if (offset + length > size) { 7048c2ecf20Sopenharmony_ci length = size - offset; 7058c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd030, 7068c2ecf20Sopenharmony_ci "%s: buffer overflow, truncate [%lx]\n", __func__, length); 7078c2ecf20Sopenharmony_ci ent->t275.length = cpu_to_le32(length); 7088c2ecf20Sopenharmony_ci } 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci qla27xx_insertbuf(buffer, length, buf, len); 7118c2ecf20Sopenharmony_cidone: 7128c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 7138c2ecf20Sopenharmony_ci} 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 7168c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t276(struct scsi_qla_host *vha, 7178c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 7188c2ecf20Sopenharmony_ci{ 7198c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd214, 7208c2ecf20Sopenharmony_ci "%s: cond [%lx]\n", __func__, *len); 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci if (buf) { 7238c2ecf20Sopenharmony_ci ulong cond1 = le32_to_cpu(ent->t276.cond1); 7248c2ecf20Sopenharmony_ci ulong cond2 = le32_to_cpu(ent->t276.cond2); 7258c2ecf20Sopenharmony_ci uint type = vha->hw->pdev->device >> 4 & 0xf; 7268c2ecf20Sopenharmony_ci uint func = vha->hw->port_no & 0x3; 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci if (type != cond1 || func != cond2) { 7298c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp = buf; 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci tmp->count--; 7328c2ecf20Sopenharmony_ci ent = qla27xx_next_entry(ent); 7338c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 7348c2ecf20Sopenharmony_ci } 7358c2ecf20Sopenharmony_ci } 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 7388c2ecf20Sopenharmony_ci} 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 7418c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t277(struct scsi_qla_host *vha, 7428c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 7438c2ecf20Sopenharmony_ci{ 7448c2ecf20Sopenharmony_ci ulong cmd_addr = le32_to_cpu(ent->t277.cmd_addr); 7458c2ecf20Sopenharmony_ci ulong wr_cmd_data = le32_to_cpu(ent->t277.wr_cmd_data); 7468c2ecf20Sopenharmony_ci ulong data_addr = le32_to_cpu(ent->t277.data_addr); 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd215, 7498c2ecf20Sopenharmony_ci "%s: rdpep [%lx]\n", __func__, *len); 7508c2ecf20Sopenharmony_ci qla27xx_insert32(wr_cmd_data, buf, len); 7518c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), cmd_addr, wr_cmd_data, buf); 7528c2ecf20Sopenharmony_ci qla27xx_read_reg(ISPREG(vha), data_addr, buf, len); 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 7558c2ecf20Sopenharmony_ci} 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 7588c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_t278(struct scsi_qla_host *vha, 7598c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 7608c2ecf20Sopenharmony_ci{ 7618c2ecf20Sopenharmony_ci ulong cmd_addr = le32_to_cpu(ent->t278.cmd_addr); 7628c2ecf20Sopenharmony_ci ulong wr_cmd_data = le32_to_cpu(ent->t278.wr_cmd_data); 7638c2ecf20Sopenharmony_ci ulong data_addr = le32_to_cpu(ent->t278.data_addr); 7648c2ecf20Sopenharmony_ci ulong wr_data = le32_to_cpu(ent->t278.wr_data); 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc + ql_dbg_verbose, vha, 0xd216, 7678c2ecf20Sopenharmony_ci "%s: wrpep [%lx]\n", __func__, *len); 7688c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), data_addr, wr_data, buf); 7698c2ecf20Sopenharmony_ci qla27xx_write_reg(ISPREG(vha), cmd_addr, wr_cmd_data, buf); 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 7728c2ecf20Sopenharmony_ci} 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_cistatic struct qla27xx_fwdt_entry * 7758c2ecf20Sopenharmony_ciqla27xx_fwdt_entry_other(struct scsi_qla_host *vha, 7768c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent, void *buf, ulong *len) 7778c2ecf20Sopenharmony_ci{ 7788c2ecf20Sopenharmony_ci ulong type = le32_to_cpu(ent->hdr.type); 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd2ff, 7818c2ecf20Sopenharmony_ci "%s: other %lx [%lx]\n", __func__, type, *len); 7828c2ecf20Sopenharmony_ci qla27xx_skip_entry(ent, buf); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci return qla27xx_next_entry(ent); 7858c2ecf20Sopenharmony_ci} 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_cistatic struct { 7888c2ecf20Sopenharmony_ci uint type; 7898c2ecf20Sopenharmony_ci typeof(qla27xx_fwdt_entry_other)(*call); 7908c2ecf20Sopenharmony_ci} qla27xx_fwdt_entry_call[] = { 7918c2ecf20Sopenharmony_ci { ENTRY_TYPE_NOP, qla27xx_fwdt_entry_t0 }, 7928c2ecf20Sopenharmony_ci { ENTRY_TYPE_TMP_END, qla27xx_fwdt_entry_t255 }, 7938c2ecf20Sopenharmony_ci { ENTRY_TYPE_RD_IOB_T1, qla27xx_fwdt_entry_t256 }, 7948c2ecf20Sopenharmony_ci { ENTRY_TYPE_WR_IOB_T1, qla27xx_fwdt_entry_t257 }, 7958c2ecf20Sopenharmony_ci { ENTRY_TYPE_RD_IOB_T2, qla27xx_fwdt_entry_t258 }, 7968c2ecf20Sopenharmony_ci { ENTRY_TYPE_WR_IOB_T2, qla27xx_fwdt_entry_t259 }, 7978c2ecf20Sopenharmony_ci { ENTRY_TYPE_RD_PCI, qla27xx_fwdt_entry_t260 }, 7988c2ecf20Sopenharmony_ci { ENTRY_TYPE_WR_PCI, qla27xx_fwdt_entry_t261 }, 7998c2ecf20Sopenharmony_ci { ENTRY_TYPE_RD_RAM, qla27xx_fwdt_entry_t262 }, 8008c2ecf20Sopenharmony_ci { ENTRY_TYPE_GET_QUEUE, qla27xx_fwdt_entry_t263 }, 8018c2ecf20Sopenharmony_ci { ENTRY_TYPE_GET_FCE, qla27xx_fwdt_entry_t264 }, 8028c2ecf20Sopenharmony_ci { ENTRY_TYPE_PSE_RISC, qla27xx_fwdt_entry_t265 }, 8038c2ecf20Sopenharmony_ci { ENTRY_TYPE_RST_RISC, qla27xx_fwdt_entry_t266 }, 8048c2ecf20Sopenharmony_ci { ENTRY_TYPE_DIS_INTR, qla27xx_fwdt_entry_t267 }, 8058c2ecf20Sopenharmony_ci { ENTRY_TYPE_GET_HBUF, qla27xx_fwdt_entry_t268 }, 8068c2ecf20Sopenharmony_ci { ENTRY_TYPE_SCRATCH, qla27xx_fwdt_entry_t269 }, 8078c2ecf20Sopenharmony_ci { ENTRY_TYPE_RDREMREG, qla27xx_fwdt_entry_t270 }, 8088c2ecf20Sopenharmony_ci { ENTRY_TYPE_WRREMREG, qla27xx_fwdt_entry_t271 }, 8098c2ecf20Sopenharmony_ci { ENTRY_TYPE_RDREMRAM, qla27xx_fwdt_entry_t272 }, 8108c2ecf20Sopenharmony_ci { ENTRY_TYPE_PCICFG, qla27xx_fwdt_entry_t273 }, 8118c2ecf20Sopenharmony_ci { ENTRY_TYPE_GET_SHADOW, qla27xx_fwdt_entry_t274 }, 8128c2ecf20Sopenharmony_ci { ENTRY_TYPE_WRITE_BUF, qla27xx_fwdt_entry_t275 }, 8138c2ecf20Sopenharmony_ci { ENTRY_TYPE_CONDITIONAL, qla27xx_fwdt_entry_t276 }, 8148c2ecf20Sopenharmony_ci { ENTRY_TYPE_RDPEPREG, qla27xx_fwdt_entry_t277 }, 8158c2ecf20Sopenharmony_ci { ENTRY_TYPE_WRPEPREG, qla27xx_fwdt_entry_t278 }, 8168c2ecf20Sopenharmony_ci { -1, qla27xx_fwdt_entry_other } 8178c2ecf20Sopenharmony_ci}; 8188c2ecf20Sopenharmony_ci 8198c2ecf20Sopenharmony_cistatic inline 8208c2ecf20Sopenharmony_citypeof(qla27xx_fwdt_entry_call->call)(qla27xx_find_entry(uint type)) 8218c2ecf20Sopenharmony_ci{ 8228c2ecf20Sopenharmony_ci typeof(*qla27xx_fwdt_entry_call) *list = qla27xx_fwdt_entry_call; 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci while (list->type < type) 8258c2ecf20Sopenharmony_ci list++; 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci if (list->type == type) 8288c2ecf20Sopenharmony_ci return list->call; 8298c2ecf20Sopenharmony_ci return qla27xx_fwdt_entry_other; 8308c2ecf20Sopenharmony_ci} 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_cistatic void 8338c2ecf20Sopenharmony_ciqla27xx_walk_template(struct scsi_qla_host *vha, 8348c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp, void *buf, ulong *len) 8358c2ecf20Sopenharmony_ci{ 8368c2ecf20Sopenharmony_ci struct qla27xx_fwdt_entry *ent = (void *)tmp + 8378c2ecf20Sopenharmony_ci le32_to_cpu(tmp->entry_offset); 8388c2ecf20Sopenharmony_ci ulong type; 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci tmp->count = le32_to_cpu(tmp->entry_count); 8418c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd01a, 8428c2ecf20Sopenharmony_ci "%s: entry count %u\n", __func__, tmp->count); 8438c2ecf20Sopenharmony_ci while (ent && tmp->count--) { 8448c2ecf20Sopenharmony_ci type = le32_to_cpu(ent->hdr.type); 8458c2ecf20Sopenharmony_ci ent = qla27xx_find_entry(type)(vha, ent, buf, len); 8468c2ecf20Sopenharmony_ci if (!ent) 8478c2ecf20Sopenharmony_ci break; 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci if (ent == INVALID_ENTRY) { 8508c2ecf20Sopenharmony_ci *len = 0; 8518c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_async, vha, 0xffff, 8528c2ecf20Sopenharmony_ci "Unable to capture FW dump"); 8538c2ecf20Sopenharmony_ci goto bailout; 8548c2ecf20Sopenharmony_ci } 8558c2ecf20Sopenharmony_ci } 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci if (tmp->count) 8588c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd018, 8598c2ecf20Sopenharmony_ci "%s: entry count residual=+%u\n", __func__, tmp->count); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci if (ent) 8628c2ecf20Sopenharmony_ci ql_dbg(ql_dbg_misc, vha, 0xd019, 8638c2ecf20Sopenharmony_ci "%s: missing end entry\n", __func__); 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_cibailout: 8668c2ecf20Sopenharmony_ci cpu_to_le32s(&tmp->count); /* endianize residual count */ 8678c2ecf20Sopenharmony_ci} 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_cistatic void 8708c2ecf20Sopenharmony_ciqla27xx_time_stamp(struct qla27xx_fwdt_template *tmp) 8718c2ecf20Sopenharmony_ci{ 8728c2ecf20Sopenharmony_ci tmp->capture_timestamp = cpu_to_le32(jiffies); 8738c2ecf20Sopenharmony_ci} 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_cistatic void 8768c2ecf20Sopenharmony_ciqla27xx_driver_info(struct qla27xx_fwdt_template *tmp) 8778c2ecf20Sopenharmony_ci{ 8788c2ecf20Sopenharmony_ci uint8_t v[] = { 0, 0, 0, 0, 0, 0 }; 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci WARN_ON_ONCE(sscanf(qla2x00_version_str, 8818c2ecf20Sopenharmony_ci "%hhu.%hhu.%hhu.%hhu", 8828c2ecf20Sopenharmony_ci v + 0, v + 1, v + 2, v + 3) != 4); 8838c2ecf20Sopenharmony_ci 8848c2ecf20Sopenharmony_ci tmp->driver_info[0] = cpu_to_le32( 8858c2ecf20Sopenharmony_ci v[3] << 24 | v[2] << 16 | v[1] << 8 | v[0]); 8868c2ecf20Sopenharmony_ci tmp->driver_info[1] = cpu_to_le32(v[5] << 8 | v[4]); 8878c2ecf20Sopenharmony_ci tmp->driver_info[2] = __constant_cpu_to_le32(0x12345678); 8888c2ecf20Sopenharmony_ci} 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_cistatic void 8918c2ecf20Sopenharmony_ciqla27xx_firmware_info(struct scsi_qla_host *vha, 8928c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp) 8938c2ecf20Sopenharmony_ci{ 8948c2ecf20Sopenharmony_ci tmp->firmware_version[0] = cpu_to_le32(vha->hw->fw_major_version); 8958c2ecf20Sopenharmony_ci tmp->firmware_version[1] = cpu_to_le32(vha->hw->fw_minor_version); 8968c2ecf20Sopenharmony_ci tmp->firmware_version[2] = cpu_to_le32(vha->hw->fw_subminor_version); 8978c2ecf20Sopenharmony_ci tmp->firmware_version[3] = cpu_to_le32( 8988c2ecf20Sopenharmony_ci vha->hw->fw_attributes_h << 16 | vha->hw->fw_attributes); 8998c2ecf20Sopenharmony_ci tmp->firmware_version[4] = cpu_to_le32( 9008c2ecf20Sopenharmony_ci vha->hw->fw_attributes_ext[1] << 16 | vha->hw->fw_attributes_ext[0]); 9018c2ecf20Sopenharmony_ci} 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_cistatic void 9048c2ecf20Sopenharmony_ciql27xx_edit_template(struct scsi_qla_host *vha, 9058c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp) 9068c2ecf20Sopenharmony_ci{ 9078c2ecf20Sopenharmony_ci qla27xx_time_stamp(tmp); 9088c2ecf20Sopenharmony_ci qla27xx_driver_info(tmp); 9098c2ecf20Sopenharmony_ci qla27xx_firmware_info(vha, tmp); 9108c2ecf20Sopenharmony_ci} 9118c2ecf20Sopenharmony_ci 9128c2ecf20Sopenharmony_cistatic inline uint32_t 9138c2ecf20Sopenharmony_ciqla27xx_template_checksum(void *p, ulong size) 9148c2ecf20Sopenharmony_ci{ 9158c2ecf20Sopenharmony_ci __le32 *buf = p; 9168c2ecf20Sopenharmony_ci uint64_t sum = 0; 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ci size /= sizeof(*buf); 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci for ( ; size--; buf++) 9218c2ecf20Sopenharmony_ci sum += le32_to_cpu(*buf); 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci sum = (sum & 0xffffffff) + (sum >> 32); 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci return ~sum; 9268c2ecf20Sopenharmony_ci} 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_cistatic inline int 9298c2ecf20Sopenharmony_ciqla27xx_verify_template_checksum(struct qla27xx_fwdt_template *tmp) 9308c2ecf20Sopenharmony_ci{ 9318c2ecf20Sopenharmony_ci return qla27xx_template_checksum(tmp, 9328c2ecf20Sopenharmony_ci le32_to_cpu(tmp->template_size)) == 0; 9338c2ecf20Sopenharmony_ci} 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_cistatic inline int 9368c2ecf20Sopenharmony_ciqla27xx_verify_template_header(struct qla27xx_fwdt_template *tmp) 9378c2ecf20Sopenharmony_ci{ 9388c2ecf20Sopenharmony_ci return le32_to_cpu(tmp->template_type) == TEMPLATE_TYPE_FWDUMP; 9398c2ecf20Sopenharmony_ci} 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_cistatic ulong 9428c2ecf20Sopenharmony_ciqla27xx_execute_fwdt_template(struct scsi_qla_host *vha, 9438c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp, void *buf) 9448c2ecf20Sopenharmony_ci{ 9458c2ecf20Sopenharmony_ci ulong len = 0; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci if (qla27xx_fwdt_template_valid(tmp)) { 9488c2ecf20Sopenharmony_ci len = le32_to_cpu(tmp->template_size); 9498c2ecf20Sopenharmony_ci tmp = memcpy(buf, tmp, len); 9508c2ecf20Sopenharmony_ci ql27xx_edit_template(vha, tmp); 9518c2ecf20Sopenharmony_ci qla27xx_walk_template(vha, tmp, buf, &len); 9528c2ecf20Sopenharmony_ci } 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci return len; 9558c2ecf20Sopenharmony_ci} 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_ciulong 9588c2ecf20Sopenharmony_ciqla27xx_fwdt_calculate_dump_size(struct scsi_qla_host *vha, void *p) 9598c2ecf20Sopenharmony_ci{ 9608c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp = p; 9618c2ecf20Sopenharmony_ci ulong len = 0; 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci if (qla27xx_fwdt_template_valid(tmp)) { 9648c2ecf20Sopenharmony_ci len = le32_to_cpu(tmp->template_size); 9658c2ecf20Sopenharmony_ci qla27xx_walk_template(vha, tmp, NULL, &len); 9668c2ecf20Sopenharmony_ci } 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ci return len; 9698c2ecf20Sopenharmony_ci} 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ciulong 9728c2ecf20Sopenharmony_ciqla27xx_fwdt_template_size(void *p) 9738c2ecf20Sopenharmony_ci{ 9748c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp = p; 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci return le32_to_cpu(tmp->template_size); 9778c2ecf20Sopenharmony_ci} 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ciint 9808c2ecf20Sopenharmony_ciqla27xx_fwdt_template_valid(void *p) 9818c2ecf20Sopenharmony_ci{ 9828c2ecf20Sopenharmony_ci struct qla27xx_fwdt_template *tmp = p; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci if (!qla27xx_verify_template_header(tmp)) { 9858c2ecf20Sopenharmony_ci ql_log(ql_log_warn, NULL, 0xd01c, 9868c2ecf20Sopenharmony_ci "%s: template type %x\n", __func__, 9878c2ecf20Sopenharmony_ci le32_to_cpu(tmp->template_type)); 9888c2ecf20Sopenharmony_ci return false; 9898c2ecf20Sopenharmony_ci } 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ci if (!qla27xx_verify_template_checksum(tmp)) { 9928c2ecf20Sopenharmony_ci ql_log(ql_log_warn, NULL, 0xd01d, 9938c2ecf20Sopenharmony_ci "%s: failed template checksum\n", __func__); 9948c2ecf20Sopenharmony_ci return false; 9958c2ecf20Sopenharmony_ci } 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci return true; 9988c2ecf20Sopenharmony_ci} 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_civoid 10018c2ecf20Sopenharmony_ciqla27xx_mpi_fwdump(scsi_qla_host_t *vha, int hardware_locked) 10028c2ecf20Sopenharmony_ci{ 10038c2ecf20Sopenharmony_ci ulong flags = 0; 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci if (!hardware_locked) 10068c2ecf20Sopenharmony_ci spin_lock_irqsave(&vha->hw->hardware_lock, flags); 10078c2ecf20Sopenharmony_ci if (!vha->hw->mpi_fw_dump) { 10088c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0x02f3, "-> mpi_fwdump no buffer\n"); 10098c2ecf20Sopenharmony_ci } else { 10108c2ecf20Sopenharmony_ci struct fwdt *fwdt = &vha->hw->fwdt[1]; 10118c2ecf20Sopenharmony_ci ulong len; 10128c2ecf20Sopenharmony_ci void *buf = vha->hw->mpi_fw_dump; 10138c2ecf20Sopenharmony_ci bool walk_template_only = false; 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci if (vha->hw->mpi_fw_dumped) { 10168c2ecf20Sopenharmony_ci /* Use the spare area for any further dumps. */ 10178c2ecf20Sopenharmony_ci buf += fwdt->dump_size; 10188c2ecf20Sopenharmony_ci walk_template_only = true; 10198c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0x02f4, 10208c2ecf20Sopenharmony_ci "-> MPI firmware already dumped -- dump saving to temporary buffer %p.\n", 10218c2ecf20Sopenharmony_ci buf); 10228c2ecf20Sopenharmony_ci } 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0x02f5, "-> fwdt1 running...\n"); 10258c2ecf20Sopenharmony_ci if (!fwdt->template) { 10268c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0x02f6, 10278c2ecf20Sopenharmony_ci "-> fwdt1 no template\n"); 10288c2ecf20Sopenharmony_ci goto bailout; 10298c2ecf20Sopenharmony_ci } 10308c2ecf20Sopenharmony_ci len = qla27xx_execute_fwdt_template(vha, fwdt->template, buf); 10318c2ecf20Sopenharmony_ci if (len == 0) { 10328c2ecf20Sopenharmony_ci goto bailout; 10338c2ecf20Sopenharmony_ci } else if (len != fwdt->dump_size) { 10348c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0x02f7, 10358c2ecf20Sopenharmony_ci "-> fwdt1 fwdump residual=%+ld\n", 10368c2ecf20Sopenharmony_ci fwdt->dump_size - len); 10378c2ecf20Sopenharmony_ci } 10388c2ecf20Sopenharmony_ci vha->hw->stat.num_mpi_reset++; 10398c2ecf20Sopenharmony_ci if (walk_template_only) 10408c2ecf20Sopenharmony_ci goto bailout; 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci vha->hw->mpi_fw_dump_len = len; 10438c2ecf20Sopenharmony_ci vha->hw->mpi_fw_dumped = 1; 10448c2ecf20Sopenharmony_ci 10458c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0x02f8, 10468c2ecf20Sopenharmony_ci "-> MPI firmware dump saved to buffer (%lu/%p)\n", 10478c2ecf20Sopenharmony_ci vha->host_no, vha->hw->mpi_fw_dump); 10488c2ecf20Sopenharmony_ci qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP); 10498c2ecf20Sopenharmony_ci } 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_cibailout: 10528c2ecf20Sopenharmony_ci if (!hardware_locked) 10538c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); 10548c2ecf20Sopenharmony_ci} 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_civoid 10578c2ecf20Sopenharmony_ciqla27xx_fwdump(scsi_qla_host_t *vha) 10588c2ecf20Sopenharmony_ci{ 10598c2ecf20Sopenharmony_ci lockdep_assert_held(&vha->hw->hardware_lock); 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci if (!vha->hw->fw_dump) { 10628c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0xd01e, "-> fwdump no buffer\n"); 10638c2ecf20Sopenharmony_ci } else if (vha->hw->fw_dumped) { 10648c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0xd01f, 10658c2ecf20Sopenharmony_ci "-> Firmware already dumped (%p) -- ignoring request\n", 10668c2ecf20Sopenharmony_ci vha->hw->fw_dump); 10678c2ecf20Sopenharmony_ci } else { 10688c2ecf20Sopenharmony_ci struct fwdt *fwdt = vha->hw->fwdt; 10698c2ecf20Sopenharmony_ci ulong len; 10708c2ecf20Sopenharmony_ci void *buf = vha->hw->fw_dump; 10718c2ecf20Sopenharmony_ci 10728c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0xd011, "-> fwdt0 running...\n"); 10738c2ecf20Sopenharmony_ci if (!fwdt->template) { 10748c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0xd012, 10758c2ecf20Sopenharmony_ci "-> fwdt0 no template\n"); 10768c2ecf20Sopenharmony_ci return; 10778c2ecf20Sopenharmony_ci } 10788c2ecf20Sopenharmony_ci len = qla27xx_execute_fwdt_template(vha, fwdt->template, buf); 10798c2ecf20Sopenharmony_ci if (len == 0) { 10808c2ecf20Sopenharmony_ci return; 10818c2ecf20Sopenharmony_ci } else if (len != fwdt->dump_size) { 10828c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0xd013, 10838c2ecf20Sopenharmony_ci "-> fwdt0 fwdump residual=%+ld\n", 10848c2ecf20Sopenharmony_ci fwdt->dump_size - len); 10858c2ecf20Sopenharmony_ci } 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_ci vha->hw->fw_dump_len = len; 10888c2ecf20Sopenharmony_ci vha->hw->fw_dumped = true; 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci ql_log(ql_log_warn, vha, 0xd015, 10918c2ecf20Sopenharmony_ci "-> Firmware dump saved to buffer (%lu/%p) <%lx>\n", 10928c2ecf20Sopenharmony_ci vha->host_no, vha->hw->fw_dump, vha->hw->fw_dump_cap_flags); 10938c2ecf20Sopenharmony_ci qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP); 10948c2ecf20Sopenharmony_ci } 10958c2ecf20Sopenharmony_ci} 1096