blob: 9e714cc5eb2a36a2a48c5c409186163c56e899df [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07007
8/*
9 * Table for showing the current message id in use for particular level
10 * Change this table for addition of log/debug messages.
Arun Easie02587d2011-08-16 11:29:23 -070011 * ----------------------------------------------------------------------
12 * | Level | Last Value Used | Holes |
13 * ----------------------------------------------------------------------
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040014 * | Module Init and Probe | 0x017f | 0x0146 |
Chad Dupuisf73cb692014-02-26 04:15:06 -050015 * | | | 0x015b-0x0160 |
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040016 * | | | 0x016e-0x0170 |
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -050017 * | Mailbox commands | 0x1192 | |
18 * | | | |
Himanshu Madhanidf57cab2014-09-25 05:16:46 -040019 * | Device Discovery | 0x2016 | 0x2020-0x2022, |
Bart Van Assche6593d5b2013-06-25 11:27:24 -040020 * | | | 0x2011-0x2012, |
Himanshu Madhanidf57cab2014-09-25 05:16:46 -040021 * | | | 0x2099-0x20a4 |
Himanshu Madhani6eb54712015-12-17 14:57:00 -050022 * | Queue Command and IO tracing | 0x3074 | 0x300b |
Arun Easi9e522cd2012-08-22 14:21:31 -040023 * | | | 0x3027-0x3028 |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040024 * | | | 0x303d-0x3041 |
25 * | | | 0x302d,0x3033 |
26 * | | | 0x3036,0x3038 |
27 * | | | 0x303a |
Armen Baloyane8f5e952013-10-30 03:38:17 -040028 * | DPC Thread | 0x4023 | 0x4002,0x4013 |
Alexei Potashnikb7bd1042015-12-17 14:57:02 -050029 * | Async Events | 0x5089 | 0x502b-0x502f |
Chad Dupuis0a583e42016-01-27 12:03:28 -050030 * | | | 0x505e |
Saurav Kashyap6ddcfef2013-08-27 01:37:53 -040031 * | | | 0x5084,0x5075 |
Chad Dupuisa78951b2013-08-27 01:37:34 -040032 * | | | 0x503d,0x5044 |
Chad Dupuis8e5a9482014-08-08 07:38:09 -040033 * | | | 0x507b,0x505f |
Armen Baloyan71e56002013-08-27 01:37:38 -040034 * | Timer Routines | 0x6012 | |
Himanshu Madhani6eb54712015-12-17 14:57:00 -050035 * | User Space Interactions | 0x70e65 | 0x7018,0x702e |
Chad Dupuisf73cb692014-02-26 04:15:06 -050036 * | | | 0x7020,0x7024 |
37 * | | | 0x7039,0x7045 |
38 * | | | 0x7073-0x7075 |
39 * | | | 0x70a5-0x70a6 |
40 * | | | 0x70a8,0x70ab |
41 * | | | 0x70ad-0x70ae |
42 * | | | 0x70d7-0x70db |
43 * | | | 0x70de-0x70df |
Chad Dupuis7108b762014-04-11 16:54:45 -040044 * | Task Management | 0x803d | 0x8000,0x800b |
Chad Dupuis63ee7072014-04-11 16:54:46 -040045 * | | | 0x8019 |
Chad Dupuis7108b762014-04-11 16:54:45 -040046 * | | | 0x8025,0x8026 |
47 * | | | 0x8031,0x8032 |
48 * | | | 0x8039,0x803c |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040049 * | AER/EEH | 0x9011 | |
Arun Easie02587d2011-08-16 11:29:23 -070050 * | Virtual Port | 0xa007 | |
Atul Deshmukh27f4b722014-04-11 16:54:26 -040051 * | ISP82XX Specific | 0xb157 | 0xb002,0xb024 |
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -040052 * | | | 0xb09e,0xb0ae |
Hiral Patela018d8f2014-04-11 16:54:34 -040053 * | | | 0xb0c3,0xb0c6 |
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -040054 * | | | 0xb0e0-0xb0ef |
55 * | | | 0xb085,0xb0dc |
56 * | | | 0xb107,0xb108 |
57 * | | | 0xb111,0xb11e |
58 * | | | 0xb12c,0xb12d |
59 * | | | 0xb13a,0xb142 |
60 * | | | 0xb13c-0xb140 |
Saurav Kashyap6ddcfef2013-08-27 01:37:53 -040061 * | | | 0xb149 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080062 * | MultiQ | 0xc00c | |
Himanshu Madhanice1025c2015-12-17 14:56:58 -050063 * | Misc | 0xd301 | 0xd031-0xd0ff |
Chad Dupuisf73cb692014-02-26 04:15:06 -050064 * | | | 0xd101-0xd1fe |
Joe Carnuccio2ac224b2014-09-25 05:16:36 -040065 * | | | 0xd214-0xd2fe |
Alexei Potashnika6ca8872015-07-14 16:00:44 -040066 * | Target Mode | 0xe080 | |
Alexei Potashnikb7bd1042015-12-17 14:57:02 -050067 * | Target Mode Management | 0xf09b | 0xf002 |
Saurav Kashyap6ddcfef2013-08-27 01:37:53 -040068 * | | | 0xf046-0xf049 |
Alexei Potashnika6ca8872015-07-14 16:00:44 -040069 * | Target Mode Task Management | 0x1000d | |
Arun Easie02587d2011-08-16 11:29:23 -070070 * ----------------------------------------------------------------------
Saurav Kashyap3ce88662011-07-14 12:00:12 -070071 */
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include "qla_def.h"
74
75#include <linux/delay.h>
76
Saurav Kashyap3ce88662011-07-14 12:00:12 -070077static uint32_t ql_dbg_offset = 0x800;
78
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070079static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080080qla2xxx_prep_dump(struct qla_hw_data *ha, struct qla2xxx_fw_dump *fw_dump)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070081{
82 fw_dump->fw_major_version = htonl(ha->fw_major_version);
83 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
84 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
85 fw_dump->fw_attributes = htonl(ha->fw_attributes);
86
87 fw_dump->vendor = htonl(ha->pdev->vendor);
88 fw_dump->device = htonl(ha->pdev->device);
89 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
90 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
91}
92
93static inline void *
Anirban Chakraborty73208df2008-12-09 16:45:39 -080094qla2xxx_copy_queues(struct qla_hw_data *ha, void *ptr)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070095{
Anirban Chakraborty73208df2008-12-09 16:45:39 -080096 struct req_que *req = ha->req_q_map[0];
97 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070098 /* Request queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080099 memcpy(ptr, req->ring, req->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700100 sizeof(request_t));
101
102 /* Response queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800103 ptr += req->length * sizeof(request_t);
104 memcpy(ptr, rsp->ring, rsp->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700105 sizeof(response_t));
106
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800107 return ptr + (rsp->length * sizeof(response_t));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700108}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Chad Dupuisf73cb692014-02-26 04:15:06 -0500110int
111qla27xx_dump_mpi_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
112 uint32_t ram_dwords, void **nxt)
113{
114 int rval;
115 uint32_t cnt, stat, timer, dwords, idx;
Bart Van Assche52c82822015-07-09 07:23:26 -0700116 uint16_t mb0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500117 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
118 dma_addr_t dump_dma = ha->gid_list_dma;
119 uint32_t *dump = (uint32_t *)ha->gid_list;
120
121 rval = QLA_SUCCESS;
122 mb0 = 0;
123
124 WRT_REG_WORD(&reg->mailbox0, MBC_LOAD_DUMP_MPI_RAM);
125 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
126
127 dwords = qla2x00_gid_list_size(ha) / 4;
128 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
129 cnt += dwords, addr += dwords) {
130 if (cnt + dwords > ram_dwords)
131 dwords = ram_dwords - cnt;
132
133 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
134 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
135
136 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
137 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
138 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
139 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
140
141 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
142 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
143
144 WRT_REG_WORD(&reg->mailbox9, 0);
145 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
146
147 ha->flags.mbox_int = 0;
148 for (timer = 6000000; timer; timer--) {
149 /* Check for pending interrupts. */
150 stat = RD_REG_DWORD(&reg->host_status);
151 if (stat & HSRX_RISC_INT) {
152 stat &= 0xff;
153
154 if (stat == 0x1 || stat == 0x2 ||
155 stat == 0x10 || stat == 0x11) {
156 set_bit(MBX_INTERRUPT,
157 &ha->mbx_cmd_flags);
158
159 mb0 = RD_REG_WORD(&reg->mailbox0);
Bart Van Assche52c82822015-07-09 07:23:26 -0700160 RD_REG_WORD(&reg->mailbox1);
Chad Dupuisf73cb692014-02-26 04:15:06 -0500161
162 WRT_REG_DWORD(&reg->hccr,
163 HCCRX_CLR_RISC_INT);
164 RD_REG_DWORD(&reg->hccr);
165 break;
166 }
167
168 /* Clear this intr; it wasn't a mailbox intr */
169 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
170 RD_REG_DWORD(&reg->hccr);
171 }
172 udelay(5);
173 }
174 ha->flags.mbox_int = 1;
175
176 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
177 rval = mb0 & MBS_MASK;
178 for (idx = 0; idx < dwords; idx++)
179 ram[cnt + idx] = IS_QLA27XX(ha) ?
180 le32_to_cpu(dump[idx]) : swab32(dump[idx]);
181 } else {
182 rval = QLA_FUNCTION_FAILED;
183 }
184 }
185
186 *nxt = rval == QLA_SUCCESS ? &ram[cnt] : NULL;
187 return rval;
188}
189
190int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800191qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700192 uint32_t ram_dwords, void **nxt)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700193{
194 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700195 uint32_t cnt, stat, timer, dwords, idx;
196 uint16_t mb0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700197 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700198 dma_addr_t dump_dma = ha->gid_list_dma;
199 uint32_t *dump = (uint32_t *)ha->gid_list;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700200
201 rval = QLA_SUCCESS;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700202 mb0 = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700203
Andrew Vasquezc5722702008-04-24 15:21:22 -0700204 WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700205 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
206
Chad Dupuis642ef982012-02-09 11:15:57 -0800207 dwords = qla2x00_gid_list_size(ha) / 4;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700208 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
209 cnt += dwords, addr += dwords) {
210 if (cnt + dwords > ram_dwords)
211 dwords = ram_dwords - cnt;
212
213 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
214 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
215
216 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
217 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
218 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
219 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
220
221 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
222 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700223 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
224
Chad Dupuisf73cb692014-02-26 04:15:06 -0500225 ha->flags.mbox_int = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700226 for (timer = 6000000; timer; timer--) {
227 /* Check for pending interrupts. */
228 stat = RD_REG_DWORD(&reg->host_status);
229 if (stat & HSRX_RISC_INT) {
230 stat &= 0xff;
231
232 if (stat == 0x1 || stat == 0x2 ||
233 stat == 0x10 || stat == 0x11) {
234 set_bit(MBX_INTERRUPT,
235 &ha->mbx_cmd_flags);
236
Andrew Vasquezc5722702008-04-24 15:21:22 -0700237 mb0 = RD_REG_WORD(&reg->mailbox0);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700238
239 WRT_REG_DWORD(&reg->hccr,
240 HCCRX_CLR_RISC_INT);
241 RD_REG_DWORD(&reg->hccr);
242 break;
243 }
244
245 /* Clear this intr; it wasn't a mailbox intr */
246 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
247 RD_REG_DWORD(&reg->hccr);
248 }
249 udelay(5);
250 }
Chad Dupuisf73cb692014-02-26 04:15:06 -0500251 ha->flags.mbox_int = 1;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700252
253 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
Andrew Vasquezc5722702008-04-24 15:21:22 -0700254 rval = mb0 & MBS_MASK;
255 for (idx = 0; idx < dwords; idx++)
Chad Dupuisf73cb692014-02-26 04:15:06 -0500256 ram[cnt + idx] = IS_QLA27XX(ha) ?
257 le32_to_cpu(dump[idx]) : swab32(dump[idx]);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700258 } else {
259 rval = QLA_FUNCTION_FAILED;
260 }
261 }
262
Andrew Vasquezc5722702008-04-24 15:21:22 -0700263 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700264 return rval;
265}
266
Andrew Vasquezc5722702008-04-24 15:21:22 -0700267static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800268qla24xx_dump_memory(struct qla_hw_data *ha, uint32_t *code_ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700269 uint32_t cram_size, void **nxt)
270{
271 int rval;
272
273 /* Code RAM. */
274 rval = qla24xx_dump_ram(ha, 0x20000, code_ram, cram_size / 4, nxt);
275 if (rval != QLA_SUCCESS)
276 return rval;
277
Hiral Patel61f098d2014-04-11 16:54:21 -0400278 set_bit(RISC_SRAM_DUMP_CMPL, &ha->fw_dump_cap_flags);
279
Andrew Vasquezc5722702008-04-24 15:21:22 -0700280 /* External Memory. */
Hiral Patel61f098d2014-04-11 16:54:21 -0400281 rval = qla24xx_dump_ram(ha, 0x100000, *nxt,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700282 ha->fw_memory_size - 0x100000 + 1, nxt);
Hiral Patel61f098d2014-04-11 16:54:21 -0400283 if (rval == QLA_SUCCESS)
284 set_bit(RISC_EXT_MEM_DUMP_CMPL, &ha->fw_dump_cap_flags);
285
286 return rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700287}
288
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700289static uint32_t *
290qla24xx_read_window(struct device_reg_24xx __iomem *reg, uint32_t iobase,
291 uint32_t count, uint32_t *buf)
292{
293 uint32_t __iomem *dmp_reg;
294
295 WRT_REG_DWORD(&reg->iobase_addr, iobase);
296 dmp_reg = &reg->iobase_window;
297 while (count--)
298 *buf++ = htonl(RD_REG_DWORD(dmp_reg++));
299
300 return buf;
301}
302
Hiral Patel2f389fc2014-04-11 16:54:20 -0400303void
Hiral Patel61f098d2014-04-11 16:54:21 -0400304qla24xx_pause_risc(struct device_reg_24xx __iomem *reg, struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700305{
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700306 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700307
Hiral Patel2f389fc2014-04-11 16:54:20 -0400308 /* 100 usec delay is sufficient enough for hardware to pause RISC */
309 udelay(100);
Hiral Patel61f098d2014-04-11 16:54:21 -0400310 if (RD_REG_DWORD(&reg->host_status) & HSRX_RISC_PAUSED)
311 set_bit(RISC_PAUSE_CMPL, &ha->fw_dump_cap_flags);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700312}
313
Chad Dupuisf73cb692014-02-26 04:15:06 -0500314int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800315qla24xx_soft_reset(struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700316{
317 int rval = QLA_SUCCESS;
318 uint32_t cnt;
Hiral Patel2f389fc2014-04-11 16:54:20 -0400319 uint16_t wd;
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700320 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
321
Hiral Patel2f389fc2014-04-11 16:54:20 -0400322 /*
323 * Reset RISC. The delay is dependent on system architecture.
324 * Driver can proceed with the reset sequence after waiting
325 * for a timeout period.
326 */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700327 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
328 for (cnt = 0; cnt < 30000; cnt++) {
329 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
330 break;
331
332 udelay(10);
333 }
Hiral Patel61f098d2014-04-11 16:54:21 -0400334 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
335 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700336
337 WRT_REG_DWORD(&reg->ctrl_status,
338 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
339 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
340
341 udelay(100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700342
343 /* Wait for soft-reset to complete. */
344 for (cnt = 0; cnt < 30000; cnt++) {
345 if ((RD_REG_DWORD(&reg->ctrl_status) &
346 CSRX_ISP_SOFT_RESET) == 0)
347 break;
348
349 udelay(10);
350 }
Hiral Patel61f098d2014-04-11 16:54:21 -0400351 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
352 set_bit(ISP_RESET_CMPL, &ha->fw_dump_cap_flags);
353
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700354 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
355 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
356
Hiral Patel2f389fc2014-04-11 16:54:20 -0400357 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700358 rval == QLA_SUCCESS; cnt--) {
359 if (cnt)
Hiral Patel2f389fc2014-04-11 16:54:20 -0400360 udelay(10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700361 else
362 rval = QLA_FUNCTION_TIMEOUT;
363 }
Hiral Patel61f098d2014-04-11 16:54:21 -0400364 if (rval == QLA_SUCCESS)
365 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700366
367 return rval;
368}
369
Andrew Vasquezc5722702008-04-24 15:21:22 -0700370static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800371qla2xxx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint16_t *ram,
Andrew Vasqueze18e9632009-06-17 10:30:31 -0700372 uint32_t ram_words, void **nxt)
Andrew Vasquezc5722702008-04-24 15:21:22 -0700373{
374 int rval;
375 uint32_t cnt, stat, timer, words, idx;
376 uint16_t mb0;
377 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
378 dma_addr_t dump_dma = ha->gid_list_dma;
379 uint16_t *dump = (uint16_t *)ha->gid_list;
380
381 rval = QLA_SUCCESS;
382 mb0 = 0;
383
384 WRT_MAILBOX_REG(ha, reg, 0, MBC_DUMP_RISC_RAM_EXTENDED);
385 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
386
Chad Dupuis642ef982012-02-09 11:15:57 -0800387 words = qla2x00_gid_list_size(ha) / 2;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700388 for (cnt = 0; cnt < ram_words && rval == QLA_SUCCESS;
389 cnt += words, addr += words) {
390 if (cnt + words > ram_words)
391 words = ram_words - cnt;
392
393 WRT_MAILBOX_REG(ha, reg, 1, LSW(addr));
394 WRT_MAILBOX_REG(ha, reg, 8, MSW(addr));
395
396 WRT_MAILBOX_REG(ha, reg, 2, MSW(dump_dma));
397 WRT_MAILBOX_REG(ha, reg, 3, LSW(dump_dma));
398 WRT_MAILBOX_REG(ha, reg, 6, MSW(MSD(dump_dma)));
399 WRT_MAILBOX_REG(ha, reg, 7, LSW(MSD(dump_dma)));
400
401 WRT_MAILBOX_REG(ha, reg, 4, words);
402 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
403
404 for (timer = 6000000; timer; timer--) {
405 /* Check for pending interrupts. */
406 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
407 if (stat & HSR_RISC_INT) {
408 stat &= 0xff;
409
410 if (stat == 0x1 || stat == 0x2) {
411 set_bit(MBX_INTERRUPT,
412 &ha->mbx_cmd_flags);
413
414 mb0 = RD_MAILBOX_REG(ha, reg, 0);
415
416 /* Release mailbox registers. */
417 WRT_REG_WORD(&reg->semaphore, 0);
418 WRT_REG_WORD(&reg->hccr,
419 HCCR_CLR_RISC_INT);
420 RD_REG_WORD(&reg->hccr);
421 break;
422 } else if (stat == 0x10 || stat == 0x11) {
423 set_bit(MBX_INTERRUPT,
424 &ha->mbx_cmd_flags);
425
426 mb0 = RD_MAILBOX_REG(ha, reg, 0);
427
428 WRT_REG_WORD(&reg->hccr,
429 HCCR_CLR_RISC_INT);
430 RD_REG_WORD(&reg->hccr);
431 break;
432 }
433
434 /* clear this intr; it wasn't a mailbox intr */
435 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
436 RD_REG_WORD(&reg->hccr);
437 }
438 udelay(5);
439 }
440
441 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
442 rval = mb0 & MBS_MASK;
443 for (idx = 0; idx < words; idx++)
444 ram[cnt + idx] = swab16(dump[idx]);
445 } else {
446 rval = QLA_FUNCTION_FAILED;
447 }
448 }
449
450 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
451 return rval;
452}
453
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700454static inline void
455qla2xxx_read_window(struct device_reg_2xxx __iomem *reg, uint32_t count,
456 uint16_t *buf)
457{
458 uint16_t __iomem *dmp_reg = &reg->u.isp2300.fb_cmd;
459
460 while (count--)
461 *buf++ = htons(RD_REG_WORD(dmp_reg++));
462}
463
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800464static inline void *
465qla24xx_copy_eft(struct qla_hw_data *ha, void *ptr)
466{
467 if (!ha->eft)
468 return ptr;
469
470 memcpy(ptr, ha->eft, ntohl(ha->fw_dump->eft_size));
471 return ptr + ntohl(ha->fw_dump->eft_size);
472}
473
474static inline void *
475qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
476{
477 uint32_t cnt;
478 uint32_t *iter_reg;
479 struct qla2xxx_fce_chain *fcec = ptr;
480
481 if (!ha->fce)
482 return ptr;
483
484 *last_chain = &fcec->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700485 fcec->type = htonl(DUMP_CHAIN_FCE);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800486 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
487 fce_calc_size(ha->fce_bufs));
488 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
489 fcec->addr_l = htonl(LSD(ha->fce_dma));
490 fcec->addr_h = htonl(MSD(ha->fce_dma));
491
492 iter_reg = fcec->eregs;
493 for (cnt = 0; cnt < 8; cnt++)
494 *iter_reg++ = htonl(ha->fce_mb[cnt]);
495
496 memcpy(iter_reg, ha->fce, ntohl(fcec->size));
497
Giridhar Malavali3cb0a672011-11-18 09:03:11 -0800498 return (char *)iter_reg + ntohl(fcec->size);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800499}
500
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800501static inline void *
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400502qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr,
503 uint32_t **last_chain)
504{
505 struct qla2xxx_mqueue_chain *q;
506 struct qla2xxx_mqueue_header *qh;
507 uint32_t num_queues;
508 int que;
509 struct {
510 int length;
511 void *ring;
512 } aq, *aqp;
513
Arun Easi00876ae2013-03-25 02:21:37 -0400514 if (!ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400515 return ptr;
516
517 num_queues = 1;
518 aqp = &aq;
519 aqp->length = ha->tgt.atio_q_length;
520 aqp->ring = ha->tgt.atio_ring;
521
522 for (que = 0; que < num_queues; que++) {
523 /* aqp = ha->atio_q_map[que]; */
524 q = ptr;
525 *last_chain = &q->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700526 q->type = htonl(DUMP_CHAIN_QUEUE);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400527 q->chain_size = htonl(
528 sizeof(struct qla2xxx_mqueue_chain) +
529 sizeof(struct qla2xxx_mqueue_header) +
530 (aqp->length * sizeof(request_t)));
531 ptr += sizeof(struct qla2xxx_mqueue_chain);
532
533 /* Add header. */
534 qh = ptr;
Bart Van Asschead950362015-07-09 07:24:08 -0700535 qh->queue = htonl(TYPE_ATIO_QUEUE);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400536 qh->number = htonl(que);
537 qh->size = htonl(aqp->length * sizeof(request_t));
538 ptr += sizeof(struct qla2xxx_mqueue_header);
539
540 /* Add data. */
541 memcpy(ptr, aqp->ring, aqp->length * sizeof(request_t));
542
543 ptr += aqp->length * sizeof(request_t);
544 }
545
546 return ptr;
547}
548
549static inline void *
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800550qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
551{
552 struct qla2xxx_mqueue_chain *q;
553 struct qla2xxx_mqueue_header *qh;
554 struct req_que *req;
555 struct rsp_que *rsp;
556 int que;
557
558 if (!ha->mqenable)
559 return ptr;
560
561 /* Request queues */
562 for (que = 1; que < ha->max_req_queues; que++) {
563 req = ha->req_q_map[que];
564 if (!req)
565 break;
566
567 /* Add chain. */
568 q = ptr;
569 *last_chain = &q->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700570 q->type = htonl(DUMP_CHAIN_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800571 q->chain_size = htonl(
572 sizeof(struct qla2xxx_mqueue_chain) +
573 sizeof(struct qla2xxx_mqueue_header) +
574 (req->length * sizeof(request_t)));
575 ptr += sizeof(struct qla2xxx_mqueue_chain);
576
577 /* Add header. */
578 qh = ptr;
Bart Van Asschead950362015-07-09 07:24:08 -0700579 qh->queue = htonl(TYPE_REQUEST_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800580 qh->number = htonl(que);
581 qh->size = htonl(req->length * sizeof(request_t));
582 ptr += sizeof(struct qla2xxx_mqueue_header);
583
584 /* Add data. */
585 memcpy(ptr, req->ring, req->length * sizeof(request_t));
586 ptr += req->length * sizeof(request_t);
587 }
588
589 /* Response queues */
590 for (que = 1; que < ha->max_rsp_queues; que++) {
591 rsp = ha->rsp_q_map[que];
592 if (!rsp)
593 break;
594
595 /* Add chain. */
596 q = ptr;
597 *last_chain = &q->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700598 q->type = htonl(DUMP_CHAIN_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800599 q->chain_size = htonl(
600 sizeof(struct qla2xxx_mqueue_chain) +
601 sizeof(struct qla2xxx_mqueue_header) +
602 (rsp->length * sizeof(response_t)));
603 ptr += sizeof(struct qla2xxx_mqueue_chain);
604
605 /* Add header. */
606 qh = ptr;
Bart Van Asschead950362015-07-09 07:24:08 -0700607 qh->queue = htonl(TYPE_RESPONSE_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800608 qh->number = htonl(que);
609 qh->size = htonl(rsp->length * sizeof(response_t));
610 ptr += sizeof(struct qla2xxx_mqueue_header);
611
612 /* Add data. */
613 memcpy(ptr, rsp->ring, rsp->length * sizeof(response_t));
614 ptr += rsp->length * sizeof(response_t);
615 }
616
617 return ptr;
618}
619
620static inline void *
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800621qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
622{
623 uint32_t cnt, que_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700624 uint8_t que_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800625 struct qla2xxx_mq_chain *mq = ptr;
Bart Van Assche118e2ef2015-07-09 07:24:27 -0700626 device_reg_t *reg;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800627
Chad Dupuisf73cb692014-02-26 04:15:06 -0500628 if (!ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800629 return ptr;
630
631 mq = ptr;
632 *last_chain = &mq->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700633 mq->type = htonl(DUMP_CHAIN_MQ);
634 mq->chain_size = htonl(sizeof(struct qla2xxx_mq_chain));
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800635
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700636 que_cnt = ha->max_req_queues > ha->max_rsp_queues ?
637 ha->max_req_queues : ha->max_rsp_queues;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800638 mq->count = htonl(que_cnt);
639 for (cnt = 0; cnt < que_cnt; cnt++) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -0400640 reg = ISP_QUE_REG(ha, cnt);
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800641 que_idx = cnt * 4;
Andrew Vasquezda9b1d52013-08-27 01:37:30 -0400642 mq->qregs[que_idx] =
643 htonl(RD_REG_DWORD(&reg->isp25mq.req_q_in));
644 mq->qregs[que_idx+1] =
645 htonl(RD_REG_DWORD(&reg->isp25mq.req_q_out));
646 mq->qregs[que_idx+2] =
647 htonl(RD_REG_DWORD(&reg->isp25mq.rsp_q_in));
648 mq->qregs[que_idx+3] =
649 htonl(RD_REG_DWORD(&reg->isp25mq.rsp_q_out));
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800650 }
651
652 return ptr + sizeof(struct qla2xxx_mq_chain);
653}
654
Giridhar Malavali08de2842011-08-16 11:31:44 -0700655void
Andrew Vasquez3420d362009-10-13 15:16:45 -0700656qla2xxx_dump_post_process(scsi_qla_host_t *vha, int rval)
657{
658 struct qla_hw_data *ha = vha->hw;
659
660 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700661 ql_log(ql_log_warn, vha, 0xd000,
Hiral Patel61f098d2014-04-11 16:54:21 -0400662 "Failed to dump firmware (%x), dump status flags (0x%lx).\n",
663 rval, ha->fw_dump_cap_flags);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700664 ha->fw_dumped = 0;
665 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700666 ql_log(ql_log_info, vha, 0xd001,
Hiral Patel61f098d2014-04-11 16:54:21 -0400667 "Firmware dump saved to temp buffer (%ld/%p), dump status flags (0x%lx).\n",
668 vha->host_no, ha->fw_dump, ha->fw_dump_cap_flags);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700669 ha->fw_dumped = 1;
670 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
671 }
672}
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674/**
675 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
676 * @ha: HA context
677 * @hardware_locked: Called with the hardware_lock
678 */
679void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800680qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
682 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700683 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800684 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700685 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 uint16_t __iomem *dmp_reg;
687 unsigned long flags;
688 struct qla2300_fw_dump *fw;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700689 void *nxt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800690 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 flags = 0;
693
Bart Van Assche8d163662015-07-09 07:25:46 -0700694#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (!hardware_locked)
696 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -0700697#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700699 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700700 ql_log(ql_log_warn, vha, 0xd002,
701 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 goto qla2300_fw_dump_failed;
703 }
704
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700705 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700706 ql_log(ql_log_warn, vha, 0xd003,
707 "Firmware has been previously dumped (%p) "
708 "-- ignoring request.\n",
709 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 goto qla2300_fw_dump_failed;
711 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700712 fw = &ha->fw_dump->isp.isp23;
713 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700716 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700719 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (IS_QLA2300(ha)) {
721 for (cnt = 30000;
722 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
723 rval == QLA_SUCCESS; cnt--) {
724 if (cnt)
725 udelay(100);
726 else
727 rval = QLA_FUNCTION_TIMEOUT;
728 }
729 } else {
730 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
731 udelay(10);
732 }
733
734 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700735 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700736 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700737 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700739 dmp_reg = &reg->u.isp2300.req_q_in;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700740 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700741 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700743 dmp_reg = &reg->u.isp2300.mailbox0;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700744 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700745 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 WRT_REG_WORD(&reg->ctrl_status, 0x40);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700748 qla2xxx_read_window(reg, 32, fw->resp_dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 WRT_REG_WORD(&reg->ctrl_status, 0x50);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700751 qla2xxx_read_window(reg, 48, fw->dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700754 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700755 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700756 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700758 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700759 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700761 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700762 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700764 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700765 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700767 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700768 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700770 WRT_REG_WORD(&reg->pcr, 0x2800);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700771 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700773 WRT_REG_WORD(&reg->pcr, 0x2A00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700774 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700776 WRT_REG_WORD(&reg->pcr, 0x2C00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700777 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700779 WRT_REG_WORD(&reg->pcr, 0x2E00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700780 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700782 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700783 qla2xxx_read_window(reg, 64, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700785 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700786 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700788 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700789 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 /* Reset RISC. */
792 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
793 for (cnt = 0; cnt < 30000; cnt++) {
794 if ((RD_REG_WORD(&reg->ctrl_status) &
795 CSR_ISP_SOFT_RESET) == 0)
796 break;
797
798 udelay(10);
799 }
800 }
801
802 if (!IS_QLA2300(ha)) {
803 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
804 rval == QLA_SUCCESS; cnt--) {
805 if (cnt)
806 udelay(100);
807 else
808 rval = QLA_FUNCTION_TIMEOUT;
809 }
810 }
811
Andrew Vasquezc5722702008-04-24 15:21:22 -0700812 /* Get RISC SRAM. */
813 if (rval == QLA_SUCCESS)
814 rval = qla2xxx_dump_ram(ha, 0x800, fw->risc_ram,
815 sizeof(fw->risc_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Andrew Vasquezc5722702008-04-24 15:21:22 -0700817 /* Get stack SRAM. */
818 if (rval == QLA_SUCCESS)
819 rval = qla2xxx_dump_ram(ha, 0x10000, fw->stack_ram,
820 sizeof(fw->stack_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Andrew Vasquezc5722702008-04-24 15:21:22 -0700822 /* Get data SRAM. */
823 if (rval == QLA_SUCCESS)
824 rval = qla2xxx_dump_ram(ha, 0x11000, fw->data_ram,
825 ha->fw_memory_size - 0x11000 + 1, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700827 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800828 qla2xxx_copy_queues(ha, nxt);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700829
Andrew Vasquez3420d362009-10-13 15:16:45 -0700830 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832qla2300_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -0700833#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 if (!hardware_locked)
835 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -0700836#else
837 ;
838#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839}
840
841/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
843 * @ha: HA context
844 * @hardware_locked: Called with the hardware_lock
845 */
846void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800847qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 int rval;
850 uint32_t cnt, timer;
851 uint16_t risc_address;
852 uint16_t mb0, mb2;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800853 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700854 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 uint16_t __iomem *dmp_reg;
856 unsigned long flags;
857 struct qla2100_fw_dump *fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800858 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 risc_address = 0;
861 mb0 = mb2 = 0;
862 flags = 0;
863
Bart Van Assche8d163662015-07-09 07:25:46 -0700864#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (!hardware_locked)
866 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -0700867#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700869 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700870 ql_log(ql_log_warn, vha, 0xd004,
871 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 goto qla2100_fw_dump_failed;
873 }
874
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700875 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700876 ql_log(ql_log_warn, vha, 0xd005,
877 "Firmware has been previously dumped (%p) "
878 "-- ignoring request.\n",
879 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 goto qla2100_fw_dump_failed;
881 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700882 fw = &ha->fw_dump->isp.isp21;
883 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
885 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700886 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700889 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
891 rval == QLA_SUCCESS; cnt--) {
892 if (cnt)
893 udelay(100);
894 else
895 rval = QLA_FUNCTION_TIMEOUT;
896 }
897 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700898 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700899 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700900 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700902 dmp_reg = &reg->u.isp2100.mailbox0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700904 if (cnt == 8)
905 dmp_reg = &reg->u_end.isp2200.mailbox8;
906
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700907 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 }
909
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700910 dmp_reg = &reg->u.isp2100.unused_2[0];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700911 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700912 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700915 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700916 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700917 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700919 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700920 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700922 WRT_REG_WORD(&reg->pcr, 0x2100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700923 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700925 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700926 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700928 WRT_REG_WORD(&reg->pcr, 0x2300);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700929 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700931 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700932 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700934 WRT_REG_WORD(&reg->pcr, 0x2500);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700935 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700937 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700938 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700940 WRT_REG_WORD(&reg->pcr, 0x2700);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700941 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700943 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700944 qla2xxx_read_window(reg, 16, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700946 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700947 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700949 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700950 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /* Reset the ISP. */
953 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
954 }
955
956 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
957 rval == QLA_SUCCESS; cnt--) {
958 if (cnt)
959 udelay(100);
960 else
961 rval = QLA_FUNCTION_TIMEOUT;
962 }
963
964 /* Pause RISC. */
965 if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
966 (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {
967
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700968 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 for (cnt = 30000;
970 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
971 rval == QLA_SUCCESS; cnt--) {
972 if (cnt)
973 udelay(100);
974 else
975 rval = QLA_FUNCTION_TIMEOUT;
976 }
977 if (rval == QLA_SUCCESS) {
978 /* Set memory configuration and timing. */
979 if (IS_QLA2100(ha))
980 WRT_REG_WORD(&reg->mctr, 0xf1);
981 else
982 WRT_REG_WORD(&reg->mctr, 0xf2);
983 RD_REG_WORD(&reg->mctr); /* PCI Posting. */
984
985 /* Release RISC. */
986 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
987 }
988 }
989
990 if (rval == QLA_SUCCESS) {
991 /* Get RISC SRAM. */
992 risc_address = 0x1000;
993 WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
994 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
995 }
996 for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
997 cnt++, risc_address++) {
998 WRT_MAILBOX_REG(ha, reg, 1, risc_address);
999 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
1000
1001 for (timer = 6000000; timer != 0; timer--) {
1002 /* Check for pending interrupts. */
1003 if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
1004 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
1005 set_bit(MBX_INTERRUPT,
1006 &ha->mbx_cmd_flags);
1007
1008 mb0 = RD_MAILBOX_REG(ha, reg, 0);
1009 mb2 = RD_MAILBOX_REG(ha, reg, 2);
1010
1011 WRT_REG_WORD(&reg->semaphore, 0);
1012 WRT_REG_WORD(&reg->hccr,
1013 HCCR_CLR_RISC_INT);
1014 RD_REG_WORD(&reg->hccr);
1015 break;
1016 }
1017 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1018 RD_REG_WORD(&reg->hccr);
1019 }
1020 udelay(5);
1021 }
1022
1023 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
1024 rval = mb0 & MBS_MASK;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001025 fw->risc_ram[cnt] = htons(mb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 } else {
1027 rval = QLA_FUNCTION_FAILED;
1028 }
1029 }
1030
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001031 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001032 qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001033
Andrew Vasquez3420d362009-10-13 15:16:45 -07001034 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036qla2100_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001037#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (!hardware_locked)
1039 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001040#else
1041 ;
1042#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001045void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001046qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001047{
1048 int rval;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001049 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001050 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001051 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1052 uint32_t __iomem *dmp_reg;
1053 uint32_t *iter_reg;
1054 uint16_t __iomem *mbx_reg;
1055 unsigned long flags;
1056 struct qla24xx_fw_dump *fw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001057 void *nxt;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001058 void *nxt_chain;
1059 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001060 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001061
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001062 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001063 return;
1064
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001065 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001066 ha->fw_dump_cap_flags = 0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001067
Bart Van Assche8d163662015-07-09 07:25:46 -07001068#ifndef __CHECKER__
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001069 if (!hardware_locked)
1070 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001071#endif
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001072
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001073 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001074 ql_log(ql_log_warn, vha, 0xd006,
1075 "No buffer available for dump.\n");
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001076 goto qla24xx_fw_dump_failed;
1077 }
1078
1079 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 ql_log(ql_log_warn, vha, 0xd007,
1081 "Firmware has been previously dumped (%p) "
1082 "-- ignoring request.\n",
1083 ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001084 goto qla24xx_fw_dump_failed;
1085 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001086 fw = &ha->fw_dump->isp.isp24;
1087 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001088
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001089 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001090
Hiral Patel2f389fc2014-04-11 16:54:20 -04001091 /*
1092 * Pause RISC. No need to track timeout, as resetting the chip
1093 * is the right approach incase of pause timeout
1094 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001095 qla24xx_pause_risc(reg, ha);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001096
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001097 /* Host interface registers. */
1098 dmp_reg = &reg->flash_addr;
1099 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1100 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001101
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001102 /* Disable interrupts. */
1103 WRT_REG_DWORD(&reg->ictrl, 0);
1104 RD_REG_DWORD(&reg->ictrl);
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001105
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001106 /* Shadow registers. */
1107 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1108 RD_REG_DWORD(&reg->iobase_addr);
1109 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1110 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001111
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001112 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1113 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001114
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001115 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1116 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001117
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001118 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1119 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001120
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001121 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1122 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001123
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001124 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1125 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001126
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001127 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1128 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001129
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001130 /* Mailbox registers. */
1131 mbx_reg = &reg->mailbox0;
1132 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1133 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001134
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001135 /* Transfer sequence registers. */
1136 iter_reg = fw->xseq_gp_reg;
1137 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1138 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1139 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1140 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1141 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1142 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1143 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1144 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001145
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001146 qla24xx_read_window(reg, 0xBFE0, 16, fw->xseq_0_reg);
1147 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001148
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001149 /* Receive sequence registers. */
1150 iter_reg = fw->rseq_gp_reg;
1151 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1152 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1153 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1154 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1155 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1156 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1157 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1158 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001159
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001160 qla24xx_read_window(reg, 0xFFD0, 16, fw->rseq_0_reg);
1161 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1162 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001163
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001164 /* Command DMA registers. */
1165 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001166
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001167 /* Queues. */
1168 iter_reg = fw->req0_dma_reg;
1169 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1170 dmp_reg = &reg->iobase_q;
1171 for (cnt = 0; cnt < 7; cnt++)
1172 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001173
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001174 iter_reg = fw->resp0_dma_reg;
1175 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1176 dmp_reg = &reg->iobase_q;
1177 for (cnt = 0; cnt < 7; cnt++)
1178 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001179
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001180 iter_reg = fw->req1_dma_reg;
1181 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1182 dmp_reg = &reg->iobase_q;
1183 for (cnt = 0; cnt < 7; cnt++)
1184 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001185
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001186 /* Transmit DMA registers. */
1187 iter_reg = fw->xmt0_dma_reg;
1188 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1189 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001190
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001191 iter_reg = fw->xmt1_dma_reg;
1192 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1193 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001194
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001195 iter_reg = fw->xmt2_dma_reg;
1196 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1197 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001198
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001199 iter_reg = fw->xmt3_dma_reg;
1200 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1201 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001202
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001203 iter_reg = fw->xmt4_dma_reg;
1204 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1205 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001206
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001207 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001208
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001209 /* Receive DMA registers. */
1210 iter_reg = fw->rcvt0_data_dma_reg;
1211 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1212 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001213
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001214 iter_reg = fw->rcvt1_data_dma_reg;
1215 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1216 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001217
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001218 /* RISC registers. */
1219 iter_reg = fw->risc_gp_reg;
1220 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1221 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1222 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1223 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1224 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1225 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1226 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1227 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001228
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001229 /* Local memory controller registers. */
1230 iter_reg = fw->lmc_reg;
1231 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1232 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1233 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1234 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1235 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1236 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1237 qla24xx_read_window(reg, 0x3060, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001238
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001239 /* Fibre Protocol Module registers. */
1240 iter_reg = fw->fpm_hdw_reg;
1241 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1242 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1243 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1244 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1245 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1246 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1247 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1248 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1249 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1250 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1251 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1252 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001253
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001254 /* Frame Buffer registers. */
1255 iter_reg = fw->fb_hdw_reg;
1256 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1257 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1258 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1259 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1260 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1261 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1262 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1263 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1264 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1265 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1266 qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001267
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001268 rval = qla24xx_soft_reset(ha);
1269 if (rval != QLA_SUCCESS)
1270 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001271
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001272 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001273 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001274 if (rval != QLA_SUCCESS)
1275 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001276
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001277 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001278
1279 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001280
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001281 nxt_chain = (void *)ha->fw_dump + ha->chain_offset;
1282 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
1283 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07001284 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1285 *last_chain |= htonl(DUMP_CHAIN_LAST);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001286 }
1287
1288 /* Adjust valid length. */
1289 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1290
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001291qla24xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001292 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001293
1294qla24xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001295#ifndef __CHECKER__
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001296 if (!hardware_locked)
1297 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001298#else
1299 ;
1300#endif
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001301}
1302
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001303void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001304qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001305{
1306 int rval;
1307 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001308 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001309 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1310 uint32_t __iomem *dmp_reg;
1311 uint32_t *iter_reg;
1312 uint16_t __iomem *mbx_reg;
1313 unsigned long flags;
1314 struct qla25xx_fw_dump *fw;
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001315 void *nxt, *nxt_chain;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001316 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001317 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001318
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001319 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001320 ha->fw_dump_cap_flags = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001321
Bart Van Assche8d163662015-07-09 07:25:46 -07001322#ifndef __CHECKER__
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001323 if (!hardware_locked)
1324 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001325#endif
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001326
1327 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001328 ql_log(ql_log_warn, vha, 0xd008,
1329 "No buffer available for dump.\n");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001330 goto qla25xx_fw_dump_failed;
1331 }
1332
1333 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001334 ql_log(ql_log_warn, vha, 0xd009,
1335 "Firmware has been previously dumped (%p) "
1336 "-- ignoring request.\n",
1337 ha->fw_dump);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001338 goto qla25xx_fw_dump_failed;
1339 }
1340 fw = &ha->fw_dump->isp.isp25;
1341 qla2xxx_prep_dump(ha, ha->fw_dump);
Bart Van Asschead950362015-07-09 07:24:08 -07001342 ha->fw_dump->version = htonl(2);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001343
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001344 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1345
Hiral Patel2f389fc2014-04-11 16:54:20 -04001346 /*
1347 * Pause RISC. No need to track timeout, as resetting the chip
1348 * is the right approach incase of pause timeout
1349 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001350 qla24xx_pause_risc(reg, ha);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001351
Andrew Vasquezb5836922007-09-20 14:07:39 -07001352 /* Host/Risc registers. */
1353 iter_reg = fw->host_risc_reg;
1354 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1355 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1356
1357 /* PCIe registers. */
1358 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1359 RD_REG_DWORD(&reg->iobase_addr);
1360 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1361 dmp_reg = &reg->iobase_c4;
1362 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1363 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1364 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1365 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001366
Andrew Vasquezb5836922007-09-20 14:07:39 -07001367 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1368 RD_REG_DWORD(&reg->iobase_window);
1369
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001370 /* Host interface registers. */
1371 dmp_reg = &reg->flash_addr;
1372 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1373 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001374
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001375 /* Disable interrupts. */
1376 WRT_REG_DWORD(&reg->ictrl, 0);
1377 RD_REG_DWORD(&reg->ictrl);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001378
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001379 /* Shadow registers. */
1380 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1381 RD_REG_DWORD(&reg->iobase_addr);
1382 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1383 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001384
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001385 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1386 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001387
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001388 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1389 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001390
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001391 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1392 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001393
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001394 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1395 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001396
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001397 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1398 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001399
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001400 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1401 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001402
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001403 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1404 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001405
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001406 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1407 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001408
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001409 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1410 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001411
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001412 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1413 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001414
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001415 /* RISC I/O register. */
1416 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1417 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001418
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001419 /* Mailbox registers. */
1420 mbx_reg = &reg->mailbox0;
1421 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1422 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001423
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001424 /* Transfer sequence registers. */
1425 iter_reg = fw->xseq_gp_reg;
1426 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1427 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1428 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1429 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1430 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1431 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1432 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1433 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001434
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001435 iter_reg = fw->xseq_0_reg;
1436 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1437 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1438 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001439
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001440 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001441
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001442 /* Receive sequence registers. */
1443 iter_reg = fw->rseq_gp_reg;
1444 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1445 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1446 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1447 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1448 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1449 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1450 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1451 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001452
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001453 iter_reg = fw->rseq_0_reg;
1454 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1455 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001456
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001457 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1458 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001459
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001460 /* Auxiliary sequence registers. */
1461 iter_reg = fw->aseq_gp_reg;
1462 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1463 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1464 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1465 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1466 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1467 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1468 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1469 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001470
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001471 iter_reg = fw->aseq_0_reg;
1472 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1473 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001474
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001475 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1476 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001477
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001478 /* Command DMA registers. */
1479 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001480
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001481 /* Queues. */
1482 iter_reg = fw->req0_dma_reg;
1483 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1484 dmp_reg = &reg->iobase_q;
1485 for (cnt = 0; cnt < 7; cnt++)
1486 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001487
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001488 iter_reg = fw->resp0_dma_reg;
1489 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1490 dmp_reg = &reg->iobase_q;
1491 for (cnt = 0; cnt < 7; cnt++)
1492 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001493
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001494 iter_reg = fw->req1_dma_reg;
1495 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1496 dmp_reg = &reg->iobase_q;
1497 for (cnt = 0; cnt < 7; cnt++)
1498 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001499
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001500 /* Transmit DMA registers. */
1501 iter_reg = fw->xmt0_dma_reg;
1502 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1503 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001504
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001505 iter_reg = fw->xmt1_dma_reg;
1506 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1507 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001508
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001509 iter_reg = fw->xmt2_dma_reg;
1510 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1511 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001512
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001513 iter_reg = fw->xmt3_dma_reg;
1514 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1515 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001516
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001517 iter_reg = fw->xmt4_dma_reg;
1518 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1519 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001520
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001521 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001522
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001523 /* Receive DMA registers. */
1524 iter_reg = fw->rcvt0_data_dma_reg;
1525 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1526 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001527
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001528 iter_reg = fw->rcvt1_data_dma_reg;
1529 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1530 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001531
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001532 /* RISC registers. */
1533 iter_reg = fw->risc_gp_reg;
1534 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1535 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1536 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1537 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1538 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1539 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1540 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1541 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001542
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001543 /* Local memory controller registers. */
1544 iter_reg = fw->lmc_reg;
1545 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1546 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1547 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1548 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1549 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1550 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1551 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1552 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001553
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001554 /* Fibre Protocol Module registers. */
1555 iter_reg = fw->fpm_hdw_reg;
1556 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1557 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1558 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1559 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1560 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1561 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1562 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1563 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1564 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1565 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1566 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1567 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001568
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001569 /* Frame Buffer registers. */
1570 iter_reg = fw->fb_hdw_reg;
1571 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1572 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1573 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1574 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1575 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1576 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1577 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1578 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1579 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1580 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1581 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1582 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001583
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001584 /* Multi queue registers */
1585 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1586 &last_chain);
1587
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001588 rval = qla24xx_soft_reset(ha);
1589 if (rval != QLA_SUCCESS)
1590 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001591
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001592 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001593 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001594 if (rval != QLA_SUCCESS)
1595 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001596
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001597 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001598
Bart Van Assche7f544d02013-06-25 11:27:27 -04001599 qla24xx_copy_eft(ha, nxt);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001600
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001601 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001602 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1603 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001604 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001605 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07001606 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1607 *last_chain |= htonl(DUMP_CHAIN_LAST);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001608 }
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001609
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001610 /* Adjust valid length. */
1611 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1612
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001613qla25xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001614 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001615
1616qla25xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001617#ifndef __CHECKER__
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001618 if (!hardware_locked)
1619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001620#else
1621 ;
1622#endif
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001623}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001624
1625void
1626qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1627{
1628 int rval;
1629 uint32_t cnt;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001630 struct qla_hw_data *ha = vha->hw;
1631 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1632 uint32_t __iomem *dmp_reg;
1633 uint32_t *iter_reg;
1634 uint16_t __iomem *mbx_reg;
1635 unsigned long flags;
1636 struct qla81xx_fw_dump *fw;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001637 void *nxt, *nxt_chain;
1638 uint32_t *last_chain = NULL;
1639 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1640
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001641 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001642 ha->fw_dump_cap_flags = 0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001643
Bart Van Assche8d163662015-07-09 07:25:46 -07001644#ifndef __CHECKER__
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001645 if (!hardware_locked)
1646 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001647#endif
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001648
1649 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001650 ql_log(ql_log_warn, vha, 0xd00a,
1651 "No buffer available for dump.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001652 goto qla81xx_fw_dump_failed;
1653 }
1654
1655 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001656 ql_log(ql_log_warn, vha, 0xd00b,
1657 "Firmware has been previously dumped (%p) "
1658 "-- ignoring request.\n",
1659 ha->fw_dump);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001660 goto qla81xx_fw_dump_failed;
1661 }
1662 fw = &ha->fw_dump->isp.isp81;
1663 qla2xxx_prep_dump(ha, ha->fw_dump);
1664
1665 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1666
Hiral Patel2f389fc2014-04-11 16:54:20 -04001667 /*
1668 * Pause RISC. No need to track timeout, as resetting the chip
1669 * is the right approach incase of pause timeout
1670 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001671 qla24xx_pause_risc(reg, ha);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001672
1673 /* Host/Risc registers. */
1674 iter_reg = fw->host_risc_reg;
1675 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1676 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1677
1678 /* PCIe registers. */
1679 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1680 RD_REG_DWORD(&reg->iobase_addr);
1681 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1682 dmp_reg = &reg->iobase_c4;
1683 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1684 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1685 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1686 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1687
1688 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1689 RD_REG_DWORD(&reg->iobase_window);
1690
1691 /* Host interface registers. */
1692 dmp_reg = &reg->flash_addr;
1693 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1694 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1695
1696 /* Disable interrupts. */
1697 WRT_REG_DWORD(&reg->ictrl, 0);
1698 RD_REG_DWORD(&reg->ictrl);
1699
1700 /* Shadow registers. */
1701 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1702 RD_REG_DWORD(&reg->iobase_addr);
1703 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1704 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1705
1706 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1707 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1708
1709 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1710 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1711
1712 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1713 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1714
1715 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1716 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1717
1718 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1719 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1720
1721 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1722 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1723
1724 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1725 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1726
1727 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1728 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1729
1730 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1731 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1732
1733 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1734 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1735
1736 /* RISC I/O register. */
1737 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1738 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1739
1740 /* Mailbox registers. */
1741 mbx_reg = &reg->mailbox0;
1742 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1743 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1744
1745 /* Transfer sequence registers. */
1746 iter_reg = fw->xseq_gp_reg;
1747 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1748 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1749 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1750 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1751 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1752 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1753 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1754 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1755
1756 iter_reg = fw->xseq_0_reg;
1757 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1758 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1759 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1760
1761 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1762
1763 /* Receive sequence registers. */
1764 iter_reg = fw->rseq_gp_reg;
1765 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1766 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1767 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1768 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1769 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1770 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1771 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1772 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1773
1774 iter_reg = fw->rseq_0_reg;
1775 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1776 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1777
1778 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1779 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1780
1781 /* Auxiliary sequence registers. */
1782 iter_reg = fw->aseq_gp_reg;
1783 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1784 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1785 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1786 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1787 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1788 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1789 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1790 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
1791
1792 iter_reg = fw->aseq_0_reg;
1793 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1794 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
1795
1796 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1797 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
1798
1799 /* Command DMA registers. */
1800 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
1801
1802 /* Queues. */
1803 iter_reg = fw->req0_dma_reg;
1804 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1805 dmp_reg = &reg->iobase_q;
1806 for (cnt = 0; cnt < 7; cnt++)
1807 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1808
1809 iter_reg = fw->resp0_dma_reg;
1810 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1811 dmp_reg = &reg->iobase_q;
1812 for (cnt = 0; cnt < 7; cnt++)
1813 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1814
1815 iter_reg = fw->req1_dma_reg;
1816 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1817 dmp_reg = &reg->iobase_q;
1818 for (cnt = 0; cnt < 7; cnt++)
1819 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1820
1821 /* Transmit DMA registers. */
1822 iter_reg = fw->xmt0_dma_reg;
1823 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1824 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
1825
1826 iter_reg = fw->xmt1_dma_reg;
1827 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1828 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
1829
1830 iter_reg = fw->xmt2_dma_reg;
1831 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1832 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
1833
1834 iter_reg = fw->xmt3_dma_reg;
1835 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1836 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
1837
1838 iter_reg = fw->xmt4_dma_reg;
1839 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1840 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
1841
1842 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
1843
1844 /* Receive DMA registers. */
1845 iter_reg = fw->rcvt0_data_dma_reg;
1846 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1847 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
1848
1849 iter_reg = fw->rcvt1_data_dma_reg;
1850 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1851 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
1852
1853 /* RISC registers. */
1854 iter_reg = fw->risc_gp_reg;
1855 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1856 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1857 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1858 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1859 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1860 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1861 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1862 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
1863
1864 /* Local memory controller registers. */
1865 iter_reg = fw->lmc_reg;
1866 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1867 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1868 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1869 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1870 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1871 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1872 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1873 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
1874
1875 /* Fibre Protocol Module registers. */
1876 iter_reg = fw->fpm_hdw_reg;
1877 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1878 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1879 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1880 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1881 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1882 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1883 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1884 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1885 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1886 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1887 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1888 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
1889 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
1890 qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
1891
1892 /* Frame Buffer registers. */
1893 iter_reg = fw->fb_hdw_reg;
1894 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1895 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1896 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1897 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1898 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1899 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1900 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1901 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1902 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1903 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1904 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1905 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
1906 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
1907
1908 /* Multi queue registers */
1909 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1910 &last_chain);
1911
1912 rval = qla24xx_soft_reset(ha);
1913 if (rval != QLA_SUCCESS)
1914 goto qla81xx_fw_dump_failed_0;
1915
1916 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
1917 &nxt);
1918 if (rval != QLA_SUCCESS)
1919 goto qla81xx_fw_dump_failed_0;
1920
1921 nxt = qla2xxx_copy_queues(ha, nxt);
1922
Bart Van Assche7f544d02013-06-25 11:27:27 -04001923 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001924
1925 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001926 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1927 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001928 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001929 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07001930 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1931 *last_chain |= htonl(DUMP_CHAIN_LAST);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001932 }
1933
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001934 /* Adjust valid length. */
1935 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1936
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001937qla81xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001938 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001939
1940qla81xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001941#ifndef __CHECKER__
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001942 if (!hardware_locked)
1943 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001944#else
1945 ;
1946#endif
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001947}
1948
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001949void
1950qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1951{
1952 int rval;
Bart Van Assche52c82822015-07-09 07:23:26 -07001953 uint32_t cnt;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001954 struct qla_hw_data *ha = vha->hw;
1955 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1956 uint32_t __iomem *dmp_reg;
1957 uint32_t *iter_reg;
1958 uint16_t __iomem *mbx_reg;
1959 unsigned long flags;
1960 struct qla83xx_fw_dump *fw;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001961 void *nxt, *nxt_chain;
1962 uint32_t *last_chain = NULL;
1963 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1964
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001965 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001966 ha->fw_dump_cap_flags = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001967
Bart Van Assche8d163662015-07-09 07:25:46 -07001968#ifndef __CHECKER__
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001969 if (!hardware_locked)
1970 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001971#endif
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001972
1973 if (!ha->fw_dump) {
1974 ql_log(ql_log_warn, vha, 0xd00c,
1975 "No buffer available for dump!!!\n");
1976 goto qla83xx_fw_dump_failed;
1977 }
1978
1979 if (ha->fw_dumped) {
1980 ql_log(ql_log_warn, vha, 0xd00d,
1981 "Firmware has been previously dumped (%p) -- ignoring "
1982 "request...\n", ha->fw_dump);
1983 goto qla83xx_fw_dump_failed;
1984 }
1985 fw = &ha->fw_dump->isp.isp83;
1986 qla2xxx_prep_dump(ha, ha->fw_dump);
1987
1988 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1989
Hiral Patel2f389fc2014-04-11 16:54:20 -04001990 /*
1991 * Pause RISC. No need to track timeout, as resetting the chip
1992 * is the right approach incase of pause timeout
1993 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001994 qla24xx_pause_risc(reg, ha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001995
1996 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
1997 dmp_reg = &reg->iobase_window;
Bart Van Assche52c82822015-07-09 07:23:26 -07001998 RD_REG_DWORD(dmp_reg);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001999 WRT_REG_DWORD(dmp_reg, 0);
2000
2001 dmp_reg = &reg->unused_4_1[0];
Bart Van Assche52c82822015-07-09 07:23:26 -07002002 RD_REG_DWORD(dmp_reg);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002003 WRT_REG_DWORD(dmp_reg, 0);
2004
2005 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
2006 dmp_reg = &reg->unused_4_1[2];
Bart Van Assche52c82822015-07-09 07:23:26 -07002007 RD_REG_DWORD(dmp_reg);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002008 WRT_REG_DWORD(dmp_reg, 0);
2009
2010 /* select PCR and disable ecc checking and correction */
2011 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
2012 RD_REG_DWORD(&reg->iobase_addr);
2013 WRT_REG_DWORD(&reg->iobase_select, 0x60000000); /* write to F0h = PCR */
2014
2015 /* Host/Risc registers. */
2016 iter_reg = fw->host_risc_reg;
2017 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
2018 iter_reg = qla24xx_read_window(reg, 0x7010, 16, iter_reg);
2019 qla24xx_read_window(reg, 0x7040, 16, iter_reg);
2020
2021 /* PCIe registers. */
2022 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2023 RD_REG_DWORD(&reg->iobase_addr);
2024 WRT_REG_DWORD(&reg->iobase_window, 0x01);
2025 dmp_reg = &reg->iobase_c4;
2026 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
2027 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
2028 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
2029 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
2030
2031 WRT_REG_DWORD(&reg->iobase_window, 0x00);
2032 RD_REG_DWORD(&reg->iobase_window);
2033
2034 /* Host interface registers. */
2035 dmp_reg = &reg->flash_addr;
2036 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
2037 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
2038
2039 /* Disable interrupts. */
2040 WRT_REG_DWORD(&reg->ictrl, 0);
2041 RD_REG_DWORD(&reg->ictrl);
2042
2043 /* Shadow registers. */
2044 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
2045 RD_REG_DWORD(&reg->iobase_addr);
2046 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
2047 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2048
2049 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
2050 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2051
2052 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
2053 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2054
2055 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
2056 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2057
2058 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
2059 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2060
2061 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
2062 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2063
2064 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
2065 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2066
2067 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
2068 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2069
2070 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
2071 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2072
2073 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
2074 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2075
2076 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
2077 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2078
2079 /* RISC I/O register. */
2080 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
2081 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
2082
2083 /* Mailbox registers. */
2084 mbx_reg = &reg->mailbox0;
2085 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
2086 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
2087
2088 /* Transfer sequence registers. */
2089 iter_reg = fw->xseq_gp_reg;
2090 iter_reg = qla24xx_read_window(reg, 0xBE00, 16, iter_reg);
2091 iter_reg = qla24xx_read_window(reg, 0xBE10, 16, iter_reg);
2092 iter_reg = qla24xx_read_window(reg, 0xBE20, 16, iter_reg);
2093 iter_reg = qla24xx_read_window(reg, 0xBE30, 16, iter_reg);
2094 iter_reg = qla24xx_read_window(reg, 0xBE40, 16, iter_reg);
2095 iter_reg = qla24xx_read_window(reg, 0xBE50, 16, iter_reg);
2096 iter_reg = qla24xx_read_window(reg, 0xBE60, 16, iter_reg);
2097 iter_reg = qla24xx_read_window(reg, 0xBE70, 16, iter_reg);
2098 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
2099 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
2100 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
2101 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
2102 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
2103 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
2104 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
2105 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
2106
2107 iter_reg = fw->xseq_0_reg;
2108 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
2109 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
2110 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
2111
2112 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
2113
2114 qla24xx_read_window(reg, 0xBEF0, 16, fw->xseq_2_reg);
2115
2116 /* Receive sequence registers. */
2117 iter_reg = fw->rseq_gp_reg;
2118 iter_reg = qla24xx_read_window(reg, 0xFE00, 16, iter_reg);
2119 iter_reg = qla24xx_read_window(reg, 0xFE10, 16, iter_reg);
2120 iter_reg = qla24xx_read_window(reg, 0xFE20, 16, iter_reg);
2121 iter_reg = qla24xx_read_window(reg, 0xFE30, 16, iter_reg);
2122 iter_reg = qla24xx_read_window(reg, 0xFE40, 16, iter_reg);
2123 iter_reg = qla24xx_read_window(reg, 0xFE50, 16, iter_reg);
2124 iter_reg = qla24xx_read_window(reg, 0xFE60, 16, iter_reg);
2125 iter_reg = qla24xx_read_window(reg, 0xFE70, 16, iter_reg);
2126 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
2127 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
2128 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
2129 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
2130 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
2131 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
2132 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
2133 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
2134
2135 iter_reg = fw->rseq_0_reg;
2136 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
2137 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
2138
2139 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
2140 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
2141 qla24xx_read_window(reg, 0xFEF0, 16, fw->rseq_3_reg);
2142
2143 /* Auxiliary sequence registers. */
2144 iter_reg = fw->aseq_gp_reg;
2145 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
2146 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
2147 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
2148 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
2149 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
2150 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
2151 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
2152 iter_reg = qla24xx_read_window(reg, 0xB070, 16, iter_reg);
2153 iter_reg = qla24xx_read_window(reg, 0xB100, 16, iter_reg);
2154 iter_reg = qla24xx_read_window(reg, 0xB110, 16, iter_reg);
2155 iter_reg = qla24xx_read_window(reg, 0xB120, 16, iter_reg);
2156 iter_reg = qla24xx_read_window(reg, 0xB130, 16, iter_reg);
2157 iter_reg = qla24xx_read_window(reg, 0xB140, 16, iter_reg);
2158 iter_reg = qla24xx_read_window(reg, 0xB150, 16, iter_reg);
2159 iter_reg = qla24xx_read_window(reg, 0xB160, 16, iter_reg);
2160 qla24xx_read_window(reg, 0xB170, 16, iter_reg);
2161
2162 iter_reg = fw->aseq_0_reg;
2163 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
2164 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
2165
2166 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
2167 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
2168 qla24xx_read_window(reg, 0xB1F0, 16, fw->aseq_3_reg);
2169
2170 /* Command DMA registers. */
2171 iter_reg = fw->cmd_dma_reg;
2172 iter_reg = qla24xx_read_window(reg, 0x7100, 16, iter_reg);
2173 iter_reg = qla24xx_read_window(reg, 0x7120, 16, iter_reg);
2174 iter_reg = qla24xx_read_window(reg, 0x7130, 16, iter_reg);
2175 qla24xx_read_window(reg, 0x71F0, 16, iter_reg);
2176
2177 /* Queues. */
2178 iter_reg = fw->req0_dma_reg;
2179 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
2180 dmp_reg = &reg->iobase_q;
2181 for (cnt = 0; cnt < 7; cnt++)
2182 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2183
2184 iter_reg = fw->resp0_dma_reg;
2185 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
2186 dmp_reg = &reg->iobase_q;
2187 for (cnt = 0; cnt < 7; cnt++)
2188 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2189
2190 iter_reg = fw->req1_dma_reg;
2191 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
2192 dmp_reg = &reg->iobase_q;
2193 for (cnt = 0; cnt < 7; cnt++)
2194 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2195
2196 /* Transmit DMA registers. */
2197 iter_reg = fw->xmt0_dma_reg;
2198 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
2199 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
2200
2201 iter_reg = fw->xmt1_dma_reg;
2202 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
2203 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
2204
2205 iter_reg = fw->xmt2_dma_reg;
2206 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
2207 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
2208
2209 iter_reg = fw->xmt3_dma_reg;
2210 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
2211 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
2212
2213 iter_reg = fw->xmt4_dma_reg;
2214 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
2215 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
2216
2217 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
2218
2219 /* Receive DMA registers. */
2220 iter_reg = fw->rcvt0_data_dma_reg;
2221 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
2222 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
2223
2224 iter_reg = fw->rcvt1_data_dma_reg;
2225 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
2226 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
2227
2228 /* RISC registers. */
2229 iter_reg = fw->risc_gp_reg;
2230 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
2231 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
2232 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
2233 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
2234 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
2235 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
2236 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
2237 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
2238
2239 /* Local memory controller registers. */
2240 iter_reg = fw->lmc_reg;
2241 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
2242 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
2243 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
2244 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
2245 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
2246 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
2247 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
2248 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
2249
2250 /* Fibre Protocol Module registers. */
2251 iter_reg = fw->fpm_hdw_reg;
2252 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
2253 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
2254 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
2255 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
2256 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
2257 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
2258 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
2259 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
2260 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
2261 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
2262 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
2263 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
2264 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
2265 iter_reg = qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
2266 iter_reg = qla24xx_read_window(reg, 0x40E0, 16, iter_reg);
2267 qla24xx_read_window(reg, 0x40F0, 16, iter_reg);
2268
2269 /* RQ0 Array registers. */
2270 iter_reg = fw->rq0_array_reg;
2271 iter_reg = qla24xx_read_window(reg, 0x5C00, 16, iter_reg);
2272 iter_reg = qla24xx_read_window(reg, 0x5C10, 16, iter_reg);
2273 iter_reg = qla24xx_read_window(reg, 0x5C20, 16, iter_reg);
2274 iter_reg = qla24xx_read_window(reg, 0x5C30, 16, iter_reg);
2275 iter_reg = qla24xx_read_window(reg, 0x5C40, 16, iter_reg);
2276 iter_reg = qla24xx_read_window(reg, 0x5C50, 16, iter_reg);
2277 iter_reg = qla24xx_read_window(reg, 0x5C60, 16, iter_reg);
2278 iter_reg = qla24xx_read_window(reg, 0x5C70, 16, iter_reg);
2279 iter_reg = qla24xx_read_window(reg, 0x5C80, 16, iter_reg);
2280 iter_reg = qla24xx_read_window(reg, 0x5C90, 16, iter_reg);
2281 iter_reg = qla24xx_read_window(reg, 0x5CA0, 16, iter_reg);
2282 iter_reg = qla24xx_read_window(reg, 0x5CB0, 16, iter_reg);
2283 iter_reg = qla24xx_read_window(reg, 0x5CC0, 16, iter_reg);
2284 iter_reg = qla24xx_read_window(reg, 0x5CD0, 16, iter_reg);
2285 iter_reg = qla24xx_read_window(reg, 0x5CE0, 16, iter_reg);
2286 qla24xx_read_window(reg, 0x5CF0, 16, iter_reg);
2287
2288 /* RQ1 Array registers. */
2289 iter_reg = fw->rq1_array_reg;
2290 iter_reg = qla24xx_read_window(reg, 0x5D00, 16, iter_reg);
2291 iter_reg = qla24xx_read_window(reg, 0x5D10, 16, iter_reg);
2292 iter_reg = qla24xx_read_window(reg, 0x5D20, 16, iter_reg);
2293 iter_reg = qla24xx_read_window(reg, 0x5D30, 16, iter_reg);
2294 iter_reg = qla24xx_read_window(reg, 0x5D40, 16, iter_reg);
2295 iter_reg = qla24xx_read_window(reg, 0x5D50, 16, iter_reg);
2296 iter_reg = qla24xx_read_window(reg, 0x5D60, 16, iter_reg);
2297 iter_reg = qla24xx_read_window(reg, 0x5D70, 16, iter_reg);
2298 iter_reg = qla24xx_read_window(reg, 0x5D80, 16, iter_reg);
2299 iter_reg = qla24xx_read_window(reg, 0x5D90, 16, iter_reg);
2300 iter_reg = qla24xx_read_window(reg, 0x5DA0, 16, iter_reg);
2301 iter_reg = qla24xx_read_window(reg, 0x5DB0, 16, iter_reg);
2302 iter_reg = qla24xx_read_window(reg, 0x5DC0, 16, iter_reg);
2303 iter_reg = qla24xx_read_window(reg, 0x5DD0, 16, iter_reg);
2304 iter_reg = qla24xx_read_window(reg, 0x5DE0, 16, iter_reg);
2305 qla24xx_read_window(reg, 0x5DF0, 16, iter_reg);
2306
2307 /* RP0 Array registers. */
2308 iter_reg = fw->rp0_array_reg;
2309 iter_reg = qla24xx_read_window(reg, 0x5E00, 16, iter_reg);
2310 iter_reg = qla24xx_read_window(reg, 0x5E10, 16, iter_reg);
2311 iter_reg = qla24xx_read_window(reg, 0x5E20, 16, iter_reg);
2312 iter_reg = qla24xx_read_window(reg, 0x5E30, 16, iter_reg);
2313 iter_reg = qla24xx_read_window(reg, 0x5E40, 16, iter_reg);
2314 iter_reg = qla24xx_read_window(reg, 0x5E50, 16, iter_reg);
2315 iter_reg = qla24xx_read_window(reg, 0x5E60, 16, iter_reg);
2316 iter_reg = qla24xx_read_window(reg, 0x5E70, 16, iter_reg);
2317 iter_reg = qla24xx_read_window(reg, 0x5E80, 16, iter_reg);
2318 iter_reg = qla24xx_read_window(reg, 0x5E90, 16, iter_reg);
2319 iter_reg = qla24xx_read_window(reg, 0x5EA0, 16, iter_reg);
2320 iter_reg = qla24xx_read_window(reg, 0x5EB0, 16, iter_reg);
2321 iter_reg = qla24xx_read_window(reg, 0x5EC0, 16, iter_reg);
2322 iter_reg = qla24xx_read_window(reg, 0x5ED0, 16, iter_reg);
2323 iter_reg = qla24xx_read_window(reg, 0x5EE0, 16, iter_reg);
2324 qla24xx_read_window(reg, 0x5EF0, 16, iter_reg);
2325
2326 /* RP1 Array registers. */
2327 iter_reg = fw->rp1_array_reg;
2328 iter_reg = qla24xx_read_window(reg, 0x5F00, 16, iter_reg);
2329 iter_reg = qla24xx_read_window(reg, 0x5F10, 16, iter_reg);
2330 iter_reg = qla24xx_read_window(reg, 0x5F20, 16, iter_reg);
2331 iter_reg = qla24xx_read_window(reg, 0x5F30, 16, iter_reg);
2332 iter_reg = qla24xx_read_window(reg, 0x5F40, 16, iter_reg);
2333 iter_reg = qla24xx_read_window(reg, 0x5F50, 16, iter_reg);
2334 iter_reg = qla24xx_read_window(reg, 0x5F60, 16, iter_reg);
2335 iter_reg = qla24xx_read_window(reg, 0x5F70, 16, iter_reg);
2336 iter_reg = qla24xx_read_window(reg, 0x5F80, 16, iter_reg);
2337 iter_reg = qla24xx_read_window(reg, 0x5F90, 16, iter_reg);
2338 iter_reg = qla24xx_read_window(reg, 0x5FA0, 16, iter_reg);
2339 iter_reg = qla24xx_read_window(reg, 0x5FB0, 16, iter_reg);
2340 iter_reg = qla24xx_read_window(reg, 0x5FC0, 16, iter_reg);
2341 iter_reg = qla24xx_read_window(reg, 0x5FD0, 16, iter_reg);
2342 iter_reg = qla24xx_read_window(reg, 0x5FE0, 16, iter_reg);
2343 qla24xx_read_window(reg, 0x5FF0, 16, iter_reg);
2344
2345 iter_reg = fw->at0_array_reg;
2346 iter_reg = qla24xx_read_window(reg, 0x7080, 16, iter_reg);
2347 iter_reg = qla24xx_read_window(reg, 0x7090, 16, iter_reg);
2348 iter_reg = qla24xx_read_window(reg, 0x70A0, 16, iter_reg);
2349 iter_reg = qla24xx_read_window(reg, 0x70B0, 16, iter_reg);
2350 iter_reg = qla24xx_read_window(reg, 0x70C0, 16, iter_reg);
2351 iter_reg = qla24xx_read_window(reg, 0x70D0, 16, iter_reg);
2352 iter_reg = qla24xx_read_window(reg, 0x70E0, 16, iter_reg);
2353 qla24xx_read_window(reg, 0x70F0, 16, iter_reg);
2354
2355 /* I/O Queue Control registers. */
2356 qla24xx_read_window(reg, 0x7800, 16, fw->queue_control_reg);
2357
2358 /* Frame Buffer registers. */
2359 iter_reg = fw->fb_hdw_reg;
2360 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
2361 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
2362 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
2363 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
2364 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
2365 iter_reg = qla24xx_read_window(reg, 0x6060, 16, iter_reg);
2366 iter_reg = qla24xx_read_window(reg, 0x6070, 16, iter_reg);
2367 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
2368 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
2369 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
2370 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
2371 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
2372 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
2373 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
2374 iter_reg = qla24xx_read_window(reg, 0x6530, 16, iter_reg);
2375 iter_reg = qla24xx_read_window(reg, 0x6540, 16, iter_reg);
2376 iter_reg = qla24xx_read_window(reg, 0x6550, 16, iter_reg);
2377 iter_reg = qla24xx_read_window(reg, 0x6560, 16, iter_reg);
2378 iter_reg = qla24xx_read_window(reg, 0x6570, 16, iter_reg);
2379 iter_reg = qla24xx_read_window(reg, 0x6580, 16, iter_reg);
2380 iter_reg = qla24xx_read_window(reg, 0x6590, 16, iter_reg);
2381 iter_reg = qla24xx_read_window(reg, 0x65A0, 16, iter_reg);
2382 iter_reg = qla24xx_read_window(reg, 0x65B0, 16, iter_reg);
2383 iter_reg = qla24xx_read_window(reg, 0x65C0, 16, iter_reg);
2384 iter_reg = qla24xx_read_window(reg, 0x65D0, 16, iter_reg);
2385 iter_reg = qla24xx_read_window(reg, 0x65E0, 16, iter_reg);
2386 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
2387
2388 /* Multi queue registers */
2389 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
2390 &last_chain);
2391
2392 rval = qla24xx_soft_reset(ha);
2393 if (rval != QLA_SUCCESS) {
2394 ql_log(ql_log_warn, vha, 0xd00e,
2395 "SOFT RESET FAILED, forcing continuation of dump!!!\n");
2396 rval = QLA_SUCCESS;
2397
2398 ql_log(ql_log_warn, vha, 0xd00f, "try a bigger hammer!!!\n");
2399
2400 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2401 RD_REG_DWORD(&reg->hccr);
2402
2403 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2404 RD_REG_DWORD(&reg->hccr);
2405
2406 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2407 RD_REG_DWORD(&reg->hccr);
2408
2409 for (cnt = 30000; cnt && (RD_REG_WORD(&reg->mailbox0)); cnt--)
2410 udelay(5);
2411
2412 if (!cnt) {
2413 nxt = fw->code_ram;
Saurav Kashyap8c0bc702012-11-21 02:40:35 -05002414 nxt += sizeof(fw->code_ram);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002415 nxt += (ha->fw_memory_size - 0x100000 + 1);
2416 goto copy_queue;
Hiral Patel61f098d2014-04-11 16:54:21 -04002417 } else {
2418 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002419 ql_log(ql_log_warn, vha, 0xd010,
2420 "bigger hammer success?\n");
Hiral Patel61f098d2014-04-11 16:54:21 -04002421 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002422 }
2423
2424 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
2425 &nxt);
2426 if (rval != QLA_SUCCESS)
2427 goto qla83xx_fw_dump_failed_0;
2428
2429copy_queue:
2430 nxt = qla2xxx_copy_queues(ha, nxt);
2431
Bart Van Assche7f544d02013-06-25 11:27:27 -04002432 qla24xx_copy_eft(ha, nxt);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002433
2434 /* Chain entries -- started with MQ. */
2435 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
2436 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002437 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002438 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07002439 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
2440 *last_chain |= htonl(DUMP_CHAIN_LAST);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002441 }
2442
2443 /* Adjust valid length. */
2444 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
2445
2446qla83xx_fw_dump_failed_0:
2447 qla2xxx_dump_post_process(base_vha, rval);
2448
2449qla83xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07002450#ifndef __CHECKER__
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002451 if (!hardware_locked)
2452 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07002453#else
2454 ;
2455#endif
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002456}
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458/****************************************************************************/
2459/* Driver Debug Functions. */
2460/****************************************************************************/
Chad Dupuiscfb09192011-11-18 09:03:07 -08002461
2462static inline int
2463ql_mask_match(uint32_t level)
2464{
2465 if (ql2xextended_error_logging == 1)
2466 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2467 return (level & ql2xextended_error_logging) == level;
2468}
2469
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002470/*
2471 * This function is for formatting and logging debug information.
2472 * It is to be used when vha is available. It formats the message
2473 * and logs it to the messages file.
2474 * parameters:
2475 * level: The level of the debug messages to be printed.
2476 * If ql2xextended_error_logging value is correctly set,
2477 * this message will appear in the messages file.
2478 * vha: Pointer to the scsi_qla_host_t.
2479 * id: This is a unique identifier for the level. It identifies the
2480 * part of the code from where the message originated.
2481 * msg: The message to be displayed.
2482 */
2483void
Joe Perches086b3e82011-11-18 09:03:05 -08002484ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2485{
2486 va_list va;
2487 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002488
Chad Dupuiscfb09192011-11-18 09:03:07 -08002489 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002490 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002491
Joe Perches086b3e82011-11-18 09:03:05 -08002492 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002493
Joe Perches086b3e82011-11-18 09:03:05 -08002494 vaf.fmt = fmt;
2495 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002496
Joe Perches086b3e82011-11-18 09:03:05 -08002497 if (vha != NULL) {
2498 const struct pci_dev *pdev = vha->hw->pdev;
2499 /* <module-name> <pci-name> <msg-id>:<host> Message */
2500 pr_warn("%s [%s]-%04x:%ld: %pV",
2501 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset,
2502 vha->host_no, &vaf);
2503 } else {
2504 pr_warn("%s [%s]-%04x: : %pV",
2505 QL_MSGHDR, "0000:00:00.0", id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002506 }
2507
Joe Perches086b3e82011-11-18 09:03:05 -08002508 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002509
2510}
2511
2512/*
2513 * This function is for formatting and logging debug information.
Masanari Iidad6a03582012-08-22 14:20:58 -04002514 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002515 * i.e., before host allocation. It formats the message and logs it
2516 * to the messages file.
2517 * parameters:
2518 * level: The level of the debug messages to be printed.
2519 * If ql2xextended_error_logging value is correctly set,
2520 * this message will appear in the messages file.
2521 * pdev: Pointer to the struct pci_dev.
2522 * id: This is a unique id for the level. It identifies the part
2523 * of the code from where the message originated.
2524 * msg: The message to be displayed.
2525 */
2526void
Joe Perches086b3e82011-11-18 09:03:05 -08002527ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2528 const char *fmt, ...)
2529{
2530 va_list va;
2531 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002532
2533 if (pdev == NULL)
2534 return;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002535 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002536 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002537
Joe Perches086b3e82011-11-18 09:03:05 -08002538 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002539
Joe Perches086b3e82011-11-18 09:03:05 -08002540 vaf.fmt = fmt;
2541 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002542
Joe Perches086b3e82011-11-18 09:03:05 -08002543 /* <module-name> <dev-name>:<msg-id> Message */
2544 pr_warn("%s [%s]-%04x: : %pV",
2545 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002546
Joe Perches086b3e82011-11-18 09:03:05 -08002547 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002548}
2549
2550/*
2551 * This function is for formatting and logging log messages.
2552 * It is to be used when vha is available. It formats the message
2553 * and logs it to the messages file. All the messages will be logged
2554 * irrespective of value of ql2xextended_error_logging.
2555 * parameters:
2556 * level: The level of the log messages to be printed in the
2557 * messages file.
2558 * vha: Pointer to the scsi_qla_host_t
2559 * id: This is a unique id for the level. It identifies the
2560 * part of the code from where the message originated.
2561 * msg: The message to be displayed.
2562 */
2563void
Joe Perches086b3e82011-11-18 09:03:05 -08002564ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2565{
2566 va_list va;
2567 struct va_format vaf;
2568 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002569
Joe Perches086b3e82011-11-18 09:03:05 -08002570 if (level > ql_errlev)
2571 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002572
Joe Perches086b3e82011-11-18 09:03:05 -08002573 if (vha != NULL) {
2574 const struct pci_dev *pdev = vha->hw->pdev;
2575 /* <module-name> <msg-id>:<host> Message */
2576 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x:%ld: ",
2577 QL_MSGHDR, dev_name(&(pdev->dev)), id, vha->host_no);
2578 } else {
2579 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2580 QL_MSGHDR, "0000:00:00.0", id);
2581 }
2582 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002583
Joe Perches086b3e82011-11-18 09:03:05 -08002584 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002585
Joe Perches086b3e82011-11-18 09:03:05 -08002586 vaf.fmt = fmt;
2587 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002588
Joe Perches086b3e82011-11-18 09:03:05 -08002589 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002590 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002591 pr_crit("%s%pV", pbuf, &vaf);
2592 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002593 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002594 pr_err("%s%pV", pbuf, &vaf);
2595 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002596 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002597 pr_warn("%s%pV", pbuf, &vaf);
2598 break;
2599 default:
2600 pr_info("%s%pV", pbuf, &vaf);
2601 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002602 }
2603
Joe Perches086b3e82011-11-18 09:03:05 -08002604 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002605}
2606
2607/*
2608 * This function is for formatting and logging log messages.
Masanari Iidad6a03582012-08-22 14:20:58 -04002609 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002610 * i.e., before host allocation. It formats the message and logs
2611 * it to the messages file. All the messages are logged irrespective
2612 * of the value of ql2xextended_error_logging.
2613 * parameters:
2614 * level: The level of the log messages to be printed in the
2615 * messages file.
2616 * pdev: Pointer to the struct pci_dev.
2617 * id: This is a unique id for the level. It identifies the
2618 * part of the code from where the message originated.
2619 * msg: The message to be displayed.
2620 */
2621void
Joe Perches086b3e82011-11-18 09:03:05 -08002622ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2623 const char *fmt, ...)
2624{
2625 va_list va;
2626 struct va_format vaf;
2627 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002628
2629 if (pdev == NULL)
2630 return;
Joe Perches086b3e82011-11-18 09:03:05 -08002631 if (level > ql_errlev)
2632 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002633
Joe Perches086b3e82011-11-18 09:03:05 -08002634 /* <module-name> <dev-name>:<msg-id> Message */
2635 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2636 QL_MSGHDR, dev_name(&(pdev->dev)), id);
2637 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002638
Joe Perches086b3e82011-11-18 09:03:05 -08002639 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002640
Joe Perches086b3e82011-11-18 09:03:05 -08002641 vaf.fmt = fmt;
2642 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002643
Joe Perches086b3e82011-11-18 09:03:05 -08002644 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002645 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002646 pr_crit("%s%pV", pbuf, &vaf);
2647 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002648 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002649 pr_err("%s%pV", pbuf, &vaf);
2650 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002651 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002652 pr_warn("%s%pV", pbuf, &vaf);
2653 break;
2654 default:
2655 pr_info("%s%pV", pbuf, &vaf);
2656 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002657 }
2658
Joe Perches086b3e82011-11-18 09:03:05 -08002659 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002660}
2661
2662void
2663ql_dump_regs(uint32_t level, scsi_qla_host_t *vha, int32_t id)
2664{
2665 int i;
2666 struct qla_hw_data *ha = vha->hw;
2667 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2668 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2669 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
2670 uint16_t __iomem *mbx_reg;
2671
Chad Dupuiscfb09192011-11-18 09:03:07 -08002672 if (!ql_mask_match(level))
2673 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002674
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002675 if (IS_P3P_TYPE(ha))
Chad Dupuiscfb09192011-11-18 09:03:07 -08002676 mbx_reg = &reg82->mailbox_in[0];
2677 else if (IS_FWI2_CAPABLE(ha))
2678 mbx_reg = &reg24->mailbox0;
2679 else
2680 mbx_reg = MAILBOX_REG(ha, reg, 0);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002681
Chad Dupuiscfb09192011-11-18 09:03:07 -08002682 ql_dbg(level, vha, id, "Mailbox registers:\n");
2683 for (i = 0; i < 6; i++)
2684 ql_dbg(level, vha, id,
2685 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002686}
2687
2688
2689void
2690ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, int32_t id,
2691 uint8_t *b, uint32_t size)
2692{
2693 uint32_t cnt;
2694 uint8_t c;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002695
Chad Dupuiscfb09192011-11-18 09:03:07 -08002696 if (!ql_mask_match(level))
2697 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002698
Chad Dupuiscfb09192011-11-18 09:03:07 -08002699 ql_dbg(level, vha, id, " 0 1 2 3 4 5 6 7 8 "
2700 "9 Ah Bh Ch Dh Eh Fh\n");
2701 ql_dbg(level, vha, id, "----------------------------------"
2702 "----------------------------\n");
2703
2704 ql_dbg(level, vha, id, " ");
2705 for (cnt = 0; cnt < size;) {
2706 c = *b++;
2707 printk("%02x", (uint32_t) c);
2708 cnt++;
2709 if (!(cnt % 16))
2710 printk("\n");
2711 else
2712 printk(" ");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002713 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002714 if (cnt % 16)
2715 ql_dbg(level, vha, id, "\n");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002716}