blob: f15f903aec5524302365235402efdb8abd9e07b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 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 */
7#include "qla_def.h"
8
9#include <linux/delay.h>
10
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070011static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080012qla2xxx_prep_dump(struct qla_hw_data *ha, struct qla2xxx_fw_dump *fw_dump)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070013{
14 fw_dump->fw_major_version = htonl(ha->fw_major_version);
15 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
16 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
17 fw_dump->fw_attributes = htonl(ha->fw_attributes);
18
19 fw_dump->vendor = htonl(ha->pdev->vendor);
20 fw_dump->device = htonl(ha->pdev->device);
21 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
22 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
23}
24
25static inline void *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080026qla2xxx_copy_queues(scsi_qla_host_t *vha, void *ptr)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070027{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080028 struct req_que *req = vha->hw->req;
29 struct rsp_que *rsp = vha->hw->rsp;
30
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070031 /* Request queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080032 memcpy(ptr, req->ring, req->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070033 sizeof(request_t));
34
35 /* Response queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080036 ptr += req->length * sizeof(request_t);
37 memcpy(ptr, rsp->ring, rsp->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070038 sizeof(response_t));
39
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080040 return ptr + (rsp->length * sizeof(response_t));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070041}
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070043static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080044qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -070045 uint32_t ram_dwords, void **nxt)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070046{
47 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -070048 uint32_t cnt, stat, timer, dwords, idx;
49 uint16_t mb0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070050 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquezc5722702008-04-24 15:21:22 -070051 dma_addr_t dump_dma = ha->gid_list_dma;
52 uint32_t *dump = (uint32_t *)ha->gid_list;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070053
54 rval = QLA_SUCCESS;
Andrew Vasquezc5722702008-04-24 15:21:22 -070055 mb0 = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070056
Andrew Vasquezc5722702008-04-24 15:21:22 -070057 WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070058 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
59
Andrew Vasquezc5722702008-04-24 15:21:22 -070060 dwords = GID_LIST_SIZE / 4;
61 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
62 cnt += dwords, addr += dwords) {
63 if (cnt + dwords > ram_dwords)
64 dwords = ram_dwords - cnt;
65
66 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
67 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
68
69 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
70 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
71 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
72 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
73
74 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
75 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070076 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
77
78 for (timer = 6000000; timer; timer--) {
79 /* Check for pending interrupts. */
80 stat = RD_REG_DWORD(&reg->host_status);
81 if (stat & HSRX_RISC_INT) {
82 stat &= 0xff;
83
84 if (stat == 0x1 || stat == 0x2 ||
85 stat == 0x10 || stat == 0x11) {
86 set_bit(MBX_INTERRUPT,
87 &ha->mbx_cmd_flags);
88
Andrew Vasquezc5722702008-04-24 15:21:22 -070089 mb0 = RD_REG_WORD(&reg->mailbox0);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070090
91 WRT_REG_DWORD(&reg->hccr,
92 HCCRX_CLR_RISC_INT);
93 RD_REG_DWORD(&reg->hccr);
94 break;
95 }
96
97 /* Clear this intr; it wasn't a mailbox intr */
98 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
99 RD_REG_DWORD(&reg->hccr);
100 }
101 udelay(5);
102 }
103
104 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
Andrew Vasquezc5722702008-04-24 15:21:22 -0700105 rval = mb0 & MBS_MASK;
106 for (idx = 0; idx < dwords; idx++)
107 ram[cnt + idx] = swab32(dump[idx]);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700108 } else {
109 rval = QLA_FUNCTION_FAILED;
110 }
111 }
112
Andrew Vasquezc5722702008-04-24 15:21:22 -0700113 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700114 return rval;
115}
116
Andrew Vasquezc5722702008-04-24 15:21:22 -0700117static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800118qla24xx_dump_memory(struct qla_hw_data *ha, uint32_t *code_ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700119 uint32_t cram_size, void **nxt)
120{
121 int rval;
122
123 /* Code RAM. */
124 rval = qla24xx_dump_ram(ha, 0x20000, code_ram, cram_size / 4, nxt);
125 if (rval != QLA_SUCCESS)
126 return rval;
127
128 /* External Memory. */
129 return qla24xx_dump_ram(ha, 0x100000, *nxt,
130 ha->fw_memory_size - 0x100000 + 1, nxt);
131}
132
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700133static uint32_t *
134qla24xx_read_window(struct device_reg_24xx __iomem *reg, uint32_t iobase,
135 uint32_t count, uint32_t *buf)
136{
137 uint32_t __iomem *dmp_reg;
138
139 WRT_REG_DWORD(&reg->iobase_addr, iobase);
140 dmp_reg = &reg->iobase_window;
141 while (count--)
142 *buf++ = htonl(RD_REG_DWORD(dmp_reg++));
143
144 return buf;
145}
146
147static inline int
148qla24xx_pause_risc(struct device_reg_24xx __iomem *reg)
149{
150 int rval = QLA_SUCCESS;
151 uint32_t cnt;
152
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700153 if (RD_REG_DWORD(&reg->hccr) & HCCRX_RISC_PAUSE)
154 return rval;
155
156 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
157 for (cnt = 30000; (RD_REG_DWORD(&reg->hccr) & HCCRX_RISC_PAUSE) == 0 &&
158 rval == QLA_SUCCESS; cnt--) {
159 if (cnt)
160 udelay(100);
161 else
162 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700163 }
164
165 return rval;
166}
167
168static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800169qla24xx_soft_reset(struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700170{
171 int rval = QLA_SUCCESS;
172 uint32_t cnt;
173 uint16_t mb0, wd;
174 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
175
176 /* Reset RISC. */
177 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
178 for (cnt = 0; cnt < 30000; cnt++) {
179 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
180 break;
181
182 udelay(10);
183 }
184
185 WRT_REG_DWORD(&reg->ctrl_status,
186 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
187 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
188
189 udelay(100);
190 /* Wait for firmware to complete NVRAM accesses. */
191 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
192 for (cnt = 10000 ; cnt && mb0; cnt--) {
193 udelay(5);
194 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
195 barrier();
196 }
197
198 /* Wait for soft-reset to complete. */
199 for (cnt = 0; cnt < 30000; cnt++) {
200 if ((RD_REG_DWORD(&reg->ctrl_status) &
201 CSRX_ISP_SOFT_RESET) == 0)
202 break;
203
204 udelay(10);
205 }
206 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
207 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
208
209 for (cnt = 30000; RD_REG_WORD(&reg->mailbox0) != 0 &&
210 rval == QLA_SUCCESS; cnt--) {
211 if (cnt)
212 udelay(100);
213 else
214 rval = QLA_FUNCTION_TIMEOUT;
215 }
216
217 return rval;
218}
219
Andrew Vasquezc5722702008-04-24 15:21:22 -0700220static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800221qla2xxx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint16_t *ram,
222 uint16_t ram_words, void **nxt)
Andrew Vasquezc5722702008-04-24 15:21:22 -0700223{
224 int rval;
225 uint32_t cnt, stat, timer, words, idx;
226 uint16_t mb0;
227 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
228 dma_addr_t dump_dma = ha->gid_list_dma;
229 uint16_t *dump = (uint16_t *)ha->gid_list;
230
231 rval = QLA_SUCCESS;
232 mb0 = 0;
233
234 WRT_MAILBOX_REG(ha, reg, 0, MBC_DUMP_RISC_RAM_EXTENDED);
235 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
236
237 words = GID_LIST_SIZE / 2;
238 for (cnt = 0; cnt < ram_words && rval == QLA_SUCCESS;
239 cnt += words, addr += words) {
240 if (cnt + words > ram_words)
241 words = ram_words - cnt;
242
243 WRT_MAILBOX_REG(ha, reg, 1, LSW(addr));
244 WRT_MAILBOX_REG(ha, reg, 8, MSW(addr));
245
246 WRT_MAILBOX_REG(ha, reg, 2, MSW(dump_dma));
247 WRT_MAILBOX_REG(ha, reg, 3, LSW(dump_dma));
248 WRT_MAILBOX_REG(ha, reg, 6, MSW(MSD(dump_dma)));
249 WRT_MAILBOX_REG(ha, reg, 7, LSW(MSD(dump_dma)));
250
251 WRT_MAILBOX_REG(ha, reg, 4, words);
252 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
253
254 for (timer = 6000000; timer; timer--) {
255 /* Check for pending interrupts. */
256 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
257 if (stat & HSR_RISC_INT) {
258 stat &= 0xff;
259
260 if (stat == 0x1 || stat == 0x2) {
261 set_bit(MBX_INTERRUPT,
262 &ha->mbx_cmd_flags);
263
264 mb0 = RD_MAILBOX_REG(ha, reg, 0);
265
266 /* Release mailbox registers. */
267 WRT_REG_WORD(&reg->semaphore, 0);
268 WRT_REG_WORD(&reg->hccr,
269 HCCR_CLR_RISC_INT);
270 RD_REG_WORD(&reg->hccr);
271 break;
272 } else if (stat == 0x10 || stat == 0x11) {
273 set_bit(MBX_INTERRUPT,
274 &ha->mbx_cmd_flags);
275
276 mb0 = RD_MAILBOX_REG(ha, reg, 0);
277
278 WRT_REG_WORD(&reg->hccr,
279 HCCR_CLR_RISC_INT);
280 RD_REG_WORD(&reg->hccr);
281 break;
282 }
283
284 /* clear this intr; it wasn't a mailbox intr */
285 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
286 RD_REG_WORD(&reg->hccr);
287 }
288 udelay(5);
289 }
290
291 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
292 rval = mb0 & MBS_MASK;
293 for (idx = 0; idx < words; idx++)
294 ram[cnt + idx] = swab16(dump[idx]);
295 } else {
296 rval = QLA_FUNCTION_FAILED;
297 }
298 }
299
300 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
301 return rval;
302}
303
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700304static inline void
305qla2xxx_read_window(struct device_reg_2xxx __iomem *reg, uint32_t count,
306 uint16_t *buf)
307{
308 uint16_t __iomem *dmp_reg = &reg->u.isp2300.fb_cmd;
309
310 while (count--)
311 *buf++ = htons(RD_REG_WORD(dmp_reg++));
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/**
315 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
316 * @ha: HA context
317 * @hardware_locked: Called with the hardware_lock
318 */
319void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800320qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700323 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800324 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700325 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 uint16_t __iomem *dmp_reg;
327 unsigned long flags;
328 struct qla2300_fw_dump *fw;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700329 void *nxt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 flags = 0;
332
333 if (!hardware_locked)
334 spin_lock_irqsave(&ha->hardware_lock, flags);
335
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700336 if (!ha->fw_dump) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 qla_printk(KERN_WARNING, ha,
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700338 "No buffer available for dump!!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 goto qla2300_fw_dump_failed;
340 }
341
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700342 if (ha->fw_dumped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 qla_printk(KERN_WARNING, ha,
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700344 "Firmware has been previously dumped (%p) -- ignoring "
345 "request...\n", ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 goto qla2300_fw_dump_failed;
347 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700348 fw = &ha->fw_dump->isp.isp23;
349 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700352 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700355 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (IS_QLA2300(ha)) {
357 for (cnt = 30000;
358 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
359 rval == QLA_SUCCESS; cnt--) {
360 if (cnt)
361 udelay(100);
362 else
363 rval = QLA_FUNCTION_TIMEOUT;
364 }
365 } else {
366 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
367 udelay(10);
368 }
369
370 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700371 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700372 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700373 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700375 dmp_reg = &reg->u.isp2300.req_q_in;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700376 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700377 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700379 dmp_reg = &reg->u.isp2300.mailbox0;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700380 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700381 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 WRT_REG_WORD(&reg->ctrl_status, 0x40);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700384 qla2xxx_read_window(reg, 32, fw->resp_dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 WRT_REG_WORD(&reg->ctrl_status, 0x50);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700387 qla2xxx_read_window(reg, 48, fw->dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700390 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700391 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700392 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700394 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700395 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700397 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700398 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700400 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700401 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700403 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700404 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700406 WRT_REG_WORD(&reg->pcr, 0x2800);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700407 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700409 WRT_REG_WORD(&reg->pcr, 0x2A00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700410 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700412 WRT_REG_WORD(&reg->pcr, 0x2C00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700413 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700415 WRT_REG_WORD(&reg->pcr, 0x2E00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700416 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700418 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700419 qla2xxx_read_window(reg, 64, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700421 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700422 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700424 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700425 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 /* Reset RISC. */
428 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
429 for (cnt = 0; cnt < 30000; cnt++) {
430 if ((RD_REG_WORD(&reg->ctrl_status) &
431 CSR_ISP_SOFT_RESET) == 0)
432 break;
433
434 udelay(10);
435 }
436 }
437
438 if (!IS_QLA2300(ha)) {
439 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
440 rval == QLA_SUCCESS; cnt--) {
441 if (cnt)
442 udelay(100);
443 else
444 rval = QLA_FUNCTION_TIMEOUT;
445 }
446 }
447
Andrew Vasquezc5722702008-04-24 15:21:22 -0700448 /* Get RISC SRAM. */
449 if (rval == QLA_SUCCESS)
450 rval = qla2xxx_dump_ram(ha, 0x800, fw->risc_ram,
451 sizeof(fw->risc_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Andrew Vasquezc5722702008-04-24 15:21:22 -0700453 /* Get stack SRAM. */
454 if (rval == QLA_SUCCESS)
455 rval = qla2xxx_dump_ram(ha, 0x10000, fw->stack_ram,
456 sizeof(fw->stack_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Andrew Vasquezc5722702008-04-24 15:21:22 -0700458 /* Get data SRAM. */
459 if (rval == QLA_SUCCESS)
460 rval = qla2xxx_dump_ram(ha, 0x11000, fw->data_ram,
461 ha->fw_memory_size - 0x11000 + 1, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700463 if (rval == QLA_SUCCESS)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800464 qla2xxx_copy_queues(vha, nxt);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (rval != QLA_SUCCESS) {
467 qla_printk(KERN_WARNING, ha,
468 "Failed to dump firmware (%x)!!!\n", rval);
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700469 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 } else {
472 qla_printk(KERN_INFO, ha,
473 "Firmware dump saved to temp buffer (%ld/%p).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800474 vha->host_no, ha->fw_dump);
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700475 ha->fw_dumped = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477
478qla2300_fw_dump_failed:
479 if (!hardware_locked)
480 spin_unlock_irqrestore(&ha->hardware_lock, flags);
481}
482
483/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
485 * @ha: HA context
486 * @hardware_locked: Called with the hardware_lock
487 */
488void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800489qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
491 int rval;
492 uint32_t cnt, timer;
493 uint16_t risc_address;
494 uint16_t mb0, mb2;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800495 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700496 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 uint16_t __iomem *dmp_reg;
498 unsigned long flags;
499 struct qla2100_fw_dump *fw;
500
501 risc_address = 0;
502 mb0 = mb2 = 0;
503 flags = 0;
504
505 if (!hardware_locked)
506 spin_lock_irqsave(&ha->hardware_lock, flags);
507
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700508 if (!ha->fw_dump) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 qla_printk(KERN_WARNING, ha,
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700510 "No buffer available for dump!!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 goto qla2100_fw_dump_failed;
512 }
513
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700514 if (ha->fw_dumped) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 qla_printk(KERN_WARNING, ha,
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700516 "Firmware has been previously dumped (%p) -- ignoring "
517 "request...\n", ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 goto qla2100_fw_dump_failed;
519 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700520 fw = &ha->fw_dump->isp.isp21;
521 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700524 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700527 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
529 rval == QLA_SUCCESS; cnt--) {
530 if (cnt)
531 udelay(100);
532 else
533 rval = QLA_FUNCTION_TIMEOUT;
534 }
535 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700536 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700537 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700538 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700540 dmp_reg = &reg->u.isp2100.mailbox0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700542 if (cnt == 8)
543 dmp_reg = &reg->u_end.isp2200.mailbox8;
544
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700545 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700548 dmp_reg = &reg->u.isp2100.unused_2[0];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700549 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700550 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700553 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700554 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700555 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700557 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700558 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700560 WRT_REG_WORD(&reg->pcr, 0x2100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700561 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700563 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700564 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700566 WRT_REG_WORD(&reg->pcr, 0x2300);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700567 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700569 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700570 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700572 WRT_REG_WORD(&reg->pcr, 0x2500);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700573 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700575 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700576 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700578 WRT_REG_WORD(&reg->pcr, 0x2700);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700579 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700581 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700582 qla2xxx_read_window(reg, 16, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700584 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700585 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700587 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700588 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 /* Reset the ISP. */
591 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
592 }
593
594 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
595 rval == QLA_SUCCESS; cnt--) {
596 if (cnt)
597 udelay(100);
598 else
599 rval = QLA_FUNCTION_TIMEOUT;
600 }
601
602 /* Pause RISC. */
603 if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
604 (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {
605
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700606 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 for (cnt = 30000;
608 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
609 rval == QLA_SUCCESS; cnt--) {
610 if (cnt)
611 udelay(100);
612 else
613 rval = QLA_FUNCTION_TIMEOUT;
614 }
615 if (rval == QLA_SUCCESS) {
616 /* Set memory configuration and timing. */
617 if (IS_QLA2100(ha))
618 WRT_REG_WORD(&reg->mctr, 0xf1);
619 else
620 WRT_REG_WORD(&reg->mctr, 0xf2);
621 RD_REG_WORD(&reg->mctr); /* PCI Posting. */
622
623 /* Release RISC. */
624 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
625 }
626 }
627
628 if (rval == QLA_SUCCESS) {
629 /* Get RISC SRAM. */
630 risc_address = 0x1000;
631 WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
632 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
633 }
634 for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
635 cnt++, risc_address++) {
636 WRT_MAILBOX_REG(ha, reg, 1, risc_address);
637 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
638
639 for (timer = 6000000; timer != 0; timer--) {
640 /* Check for pending interrupts. */
641 if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
642 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
643 set_bit(MBX_INTERRUPT,
644 &ha->mbx_cmd_flags);
645
646 mb0 = RD_MAILBOX_REG(ha, reg, 0);
647 mb2 = RD_MAILBOX_REG(ha, reg, 2);
648
649 WRT_REG_WORD(&reg->semaphore, 0);
650 WRT_REG_WORD(&reg->hccr,
651 HCCR_CLR_RISC_INT);
652 RD_REG_WORD(&reg->hccr);
653 break;
654 }
655 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
656 RD_REG_WORD(&reg->hccr);
657 }
658 udelay(5);
659 }
660
661 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
662 rval = mb0 & MBS_MASK;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700663 fw->risc_ram[cnt] = htons(mb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 } else {
665 rval = QLA_FUNCTION_FAILED;
666 }
667 }
668
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700669 if (rval == QLA_SUCCESS)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800670 qla2xxx_copy_queues(vha, &fw->risc_ram[cnt]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 if (rval != QLA_SUCCESS) {
673 qla_printk(KERN_WARNING, ha,
674 "Failed to dump firmware (%x)!!!\n", rval);
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700675 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 } else {
678 qla_printk(KERN_INFO, ha,
679 "Firmware dump saved to temp buffer (%ld/%p).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800680 vha->host_no, ha->fw_dump);
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700681 ha->fw_dumped = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683
684qla2100_fw_dump_failed:
685 if (!hardware_locked)
686 spin_unlock_irqrestore(&ha->hardware_lock, flags);
687}
688
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700689void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800690qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700691{
692 int rval;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700693 uint32_t cnt;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700694 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800695 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700696 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
697 uint32_t __iomem *dmp_reg;
698 uint32_t *iter_reg;
699 uint16_t __iomem *mbx_reg;
700 unsigned long flags;
701 struct qla24xx_fw_dump *fw;
702 uint32_t ext_mem_cnt;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700703 void *nxt;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700704
705 risc_address = ext_mem_cnt = 0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700706 flags = 0;
707
708 if (!hardware_locked)
709 spin_lock_irqsave(&ha->hardware_lock, flags);
710
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700711 if (!ha->fw_dump) {
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700712 qla_printk(KERN_WARNING, ha,
713 "No buffer available for dump!!!\n");
714 goto qla24xx_fw_dump_failed;
715 }
716
717 if (ha->fw_dumped) {
718 qla_printk(KERN_WARNING, ha,
719 "Firmware has been previously dumped (%p) -- ignoring "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700720 "request...\n", ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700721 goto qla24xx_fw_dump_failed;
722 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700723 fw = &ha->fw_dump->isp.isp24;
724 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700725
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700726 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700727
728 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700729 rval = qla24xx_pause_risc(reg);
730 if (rval != QLA_SUCCESS)
731 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700732
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700733 /* Host interface registers. */
734 dmp_reg = &reg->flash_addr;
735 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
736 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700737
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700738 /* Disable interrupts. */
739 WRT_REG_DWORD(&reg->ictrl, 0);
740 RD_REG_DWORD(&reg->ictrl);
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800741
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700742 /* Shadow registers. */
743 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
744 RD_REG_DWORD(&reg->iobase_addr);
745 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
746 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800747
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700748 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
749 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800750
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700751 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
752 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800753
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700754 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
755 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800756
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700757 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
758 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800759
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700760 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
761 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800762
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700763 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
764 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800765
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700766 /* Mailbox registers. */
767 mbx_reg = &reg->mailbox0;
768 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
769 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700770
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700771 /* Transfer sequence registers. */
772 iter_reg = fw->xseq_gp_reg;
773 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
774 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
775 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
776 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
777 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
778 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
779 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
780 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700781
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700782 qla24xx_read_window(reg, 0xBFE0, 16, fw->xseq_0_reg);
783 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700784
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700785 /* Receive sequence registers. */
786 iter_reg = fw->rseq_gp_reg;
787 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
788 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
789 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
790 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
791 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
792 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
793 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
794 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700795
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700796 qla24xx_read_window(reg, 0xFFD0, 16, fw->rseq_0_reg);
797 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
798 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700799
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700800 /* Command DMA registers. */
801 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700802
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700803 /* Queues. */
804 iter_reg = fw->req0_dma_reg;
805 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
806 dmp_reg = &reg->iobase_q;
807 for (cnt = 0; cnt < 7; cnt++)
808 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700809
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700810 iter_reg = fw->resp0_dma_reg;
811 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
812 dmp_reg = &reg->iobase_q;
813 for (cnt = 0; cnt < 7; cnt++)
814 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700815
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700816 iter_reg = fw->req1_dma_reg;
817 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
818 dmp_reg = &reg->iobase_q;
819 for (cnt = 0; cnt < 7; cnt++)
820 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700821
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700822 /* Transmit DMA registers. */
823 iter_reg = fw->xmt0_dma_reg;
824 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
825 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700826
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700827 iter_reg = fw->xmt1_dma_reg;
828 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
829 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700830
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700831 iter_reg = fw->xmt2_dma_reg;
832 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
833 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700834
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700835 iter_reg = fw->xmt3_dma_reg;
836 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
837 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700838
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700839 iter_reg = fw->xmt4_dma_reg;
840 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
841 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700842
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700843 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700844
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700845 /* Receive DMA registers. */
846 iter_reg = fw->rcvt0_data_dma_reg;
847 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
848 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700849
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700850 iter_reg = fw->rcvt1_data_dma_reg;
851 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
852 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700853
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700854 /* RISC registers. */
855 iter_reg = fw->risc_gp_reg;
856 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
857 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
858 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
859 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
860 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
861 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
862 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
863 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700864
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700865 /* Local memory controller registers. */
866 iter_reg = fw->lmc_reg;
867 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
868 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
869 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
870 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
871 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
872 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
873 qla24xx_read_window(reg, 0x3060, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700874
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700875 /* Fibre Protocol Module registers. */
876 iter_reg = fw->fpm_hdw_reg;
877 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
878 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
879 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
880 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
881 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
882 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
883 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
884 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
885 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
886 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
887 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
888 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700889
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700890 /* Frame Buffer registers. */
891 iter_reg = fw->fb_hdw_reg;
892 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
893 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
894 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
895 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
896 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
897 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
898 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
899 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
900 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
901 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
902 qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700903
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700904 rval = qla24xx_soft_reset(ha);
905 if (rval != QLA_SUCCESS)
906 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700907
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700908 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -0700909 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700910 if (rval != QLA_SUCCESS)
911 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700912
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800913 nxt = qla2xxx_copy_queues(vha, nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700914 if (ha->eft)
915 memcpy(nxt, ha->eft, ntohl(ha->fw_dump->eft_size));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700916
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700917qla24xx_fw_dump_failed_0:
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700918 if (rval != QLA_SUCCESS) {
919 qla_printk(KERN_WARNING, ha,
920 "Failed to dump firmware (%x)!!!\n", rval);
921 ha->fw_dumped = 0;
922
923 } else {
924 qla_printk(KERN_INFO, ha,
925 "Firmware dump saved to temp buffer (%ld/%p).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800926 vha->host_no, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700927 ha->fw_dumped = 1;
928 }
929
930qla24xx_fw_dump_failed:
931 if (!hardware_locked)
932 spin_unlock_irqrestore(&ha->hardware_lock, flags);
933}
934
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700935void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800936qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700937{
938 int rval;
939 uint32_t cnt;
940 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800941 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700942 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
943 uint32_t __iomem *dmp_reg;
944 uint32_t *iter_reg;
945 uint16_t __iomem *mbx_reg;
946 unsigned long flags;
947 struct qla25xx_fw_dump *fw;
948 uint32_t ext_mem_cnt;
949 void *nxt;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800950 struct qla2xxx_fce_chain *fcec;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700951
952 risc_address = ext_mem_cnt = 0;
953 flags = 0;
954
955 if (!hardware_locked)
956 spin_lock_irqsave(&ha->hardware_lock, flags);
957
958 if (!ha->fw_dump) {
959 qla_printk(KERN_WARNING, ha,
960 "No buffer available for dump!!!\n");
961 goto qla25xx_fw_dump_failed;
962 }
963
964 if (ha->fw_dumped) {
965 qla_printk(KERN_WARNING, ha,
966 "Firmware has been previously dumped (%p) -- ignoring "
967 "request...\n", ha->fw_dump);
968 goto qla25xx_fw_dump_failed;
969 }
970 fw = &ha->fw_dump->isp.isp25;
971 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquezb5836922007-09-20 14:07:39 -0700972 ha->fw_dump->version = __constant_htonl(2);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700973
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700974 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
975
976 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700977 rval = qla24xx_pause_risc(reg);
978 if (rval != QLA_SUCCESS)
979 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700980
Andrew Vasquezb5836922007-09-20 14:07:39 -0700981 /* Host/Risc registers. */
982 iter_reg = fw->host_risc_reg;
983 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
984 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
985
986 /* PCIe registers. */
987 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
988 RD_REG_DWORD(&reg->iobase_addr);
989 WRT_REG_DWORD(&reg->iobase_window, 0x01);
990 dmp_reg = &reg->iobase_c4;
991 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
992 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
993 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
994 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
995 WRT_REG_DWORD(&reg->iobase_window, 0x00);
996 RD_REG_DWORD(&reg->iobase_window);
997
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700998 /* Host interface registers. */
999 dmp_reg = &reg->flash_addr;
1000 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1001 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001002
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001003 /* Disable interrupts. */
1004 WRT_REG_DWORD(&reg->ictrl, 0);
1005 RD_REG_DWORD(&reg->ictrl);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001006
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001007 /* Shadow registers. */
1008 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1009 RD_REG_DWORD(&reg->iobase_addr);
1010 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1011 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001012
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001013 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1014 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001015
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001016 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1017 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001018
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001019 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1020 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001021
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001022 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1023 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001024
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001025 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1026 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001027
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001028 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1029 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001030
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001031 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1032 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001033
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001034 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1035 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001036
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001037 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1038 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001039
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001040 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1041 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001042
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001043 /* RISC I/O register. */
1044 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1045 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001046
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001047 /* Mailbox registers. */
1048 mbx_reg = &reg->mailbox0;
1049 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1050 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001051
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001052 /* Transfer sequence registers. */
1053 iter_reg = fw->xseq_gp_reg;
1054 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1055 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1056 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1057 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1058 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1059 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1060 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1061 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001062
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001063 iter_reg = fw->xseq_0_reg;
1064 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1065 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1066 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001067
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001068 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001069
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001070 /* Receive sequence registers. */
1071 iter_reg = fw->rseq_gp_reg;
1072 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1073 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1074 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1075 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1076 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1077 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1078 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1079 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001080
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001081 iter_reg = fw->rseq_0_reg;
1082 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1083 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001084
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001085 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1086 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001087
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001088 /* Auxiliary sequence registers. */
1089 iter_reg = fw->aseq_gp_reg;
1090 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1091 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1092 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1093 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1094 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1095 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1096 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1097 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001098
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001099 iter_reg = fw->aseq_0_reg;
1100 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1101 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001102
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001103 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1104 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001105
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001106 /* Command DMA registers. */
1107 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001108
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001109 /* Queues. */
1110 iter_reg = fw->req0_dma_reg;
1111 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1112 dmp_reg = &reg->iobase_q;
1113 for (cnt = 0; cnt < 7; cnt++)
1114 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001115
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001116 iter_reg = fw->resp0_dma_reg;
1117 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1118 dmp_reg = &reg->iobase_q;
1119 for (cnt = 0; cnt < 7; cnt++)
1120 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001121
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001122 iter_reg = fw->req1_dma_reg;
1123 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1124 dmp_reg = &reg->iobase_q;
1125 for (cnt = 0; cnt < 7; cnt++)
1126 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001127
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001128 /* Transmit DMA registers. */
1129 iter_reg = fw->xmt0_dma_reg;
1130 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1131 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001132
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001133 iter_reg = fw->xmt1_dma_reg;
1134 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1135 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001136
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001137 iter_reg = fw->xmt2_dma_reg;
1138 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1139 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001140
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001141 iter_reg = fw->xmt3_dma_reg;
1142 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1143 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001144
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001145 iter_reg = fw->xmt4_dma_reg;
1146 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1147 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001148
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001149 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001150
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001151 /* Receive DMA registers. */
1152 iter_reg = fw->rcvt0_data_dma_reg;
1153 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1154 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001155
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001156 iter_reg = fw->rcvt1_data_dma_reg;
1157 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1158 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001159
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001160 /* RISC registers. */
1161 iter_reg = fw->risc_gp_reg;
1162 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1163 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1164 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1165 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1166 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1167 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1168 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1169 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001170
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001171 /* Local memory controller registers. */
1172 iter_reg = fw->lmc_reg;
1173 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1174 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1175 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1176 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1177 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1178 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1179 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1180 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001181
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001182 /* Fibre Protocol Module registers. */
1183 iter_reg = fw->fpm_hdw_reg;
1184 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1185 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1186 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1187 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1188 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1189 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1190 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1191 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1192 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1193 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1194 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1195 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001196
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001197 /* Frame Buffer registers. */
1198 iter_reg = fw->fb_hdw_reg;
1199 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1200 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1201 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1202 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1203 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1204 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1205 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1206 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1207 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1208 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1209 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1210 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001211
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001212 rval = qla24xx_soft_reset(ha);
1213 if (rval != QLA_SUCCESS)
1214 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001215
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001216 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001217 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001218 if (rval != QLA_SUCCESS)
1219 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001220
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001221 /* Fibre Channel Trace Buffer. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001222 nxt = qla2xxx_copy_queues(vha, nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001223 if (ha->eft)
1224 memcpy(nxt, ha->eft, ntohl(ha->fw_dump->eft_size));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001225
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001226 /* Fibre Channel Event Buffer. */
1227 if (!ha->fce)
1228 goto qla25xx_fw_dump_failed_0;
1229
1230 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1231
1232 fcec = nxt + ntohl(ha->fw_dump->eft_size);
1233 fcec->type = __constant_htonl(DUMP_CHAIN_FCE | DUMP_CHAIN_LAST);
1234 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
1235 fce_calc_size(ha->fce_bufs));
1236 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
1237 fcec->addr_l = htonl(LSD(ha->fce_dma));
1238 fcec->addr_h = htonl(MSD(ha->fce_dma));
1239
1240 iter_reg = fcec->eregs;
1241 for (cnt = 0; cnt < 8; cnt++)
1242 *iter_reg++ = htonl(ha->fce_mb[cnt]);
1243
1244 memcpy(iter_reg, ha->fce, ntohl(fcec->size));
1245
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001246qla25xx_fw_dump_failed_0:
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001247 if (rval != QLA_SUCCESS) {
1248 qla_printk(KERN_WARNING, ha,
1249 "Failed to dump firmware (%x)!!!\n", rval);
1250 ha->fw_dumped = 0;
1251
1252 } else {
1253 qla_printk(KERN_INFO, ha,
1254 "Firmware dump saved to temp buffer (%ld/%p).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001255 vha->host_no, ha->fw_dump);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001256 ha->fw_dumped = 1;
1257 }
1258
1259qla25xx_fw_dump_failed:
1260 if (!hardware_locked)
1261 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1262}
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264/****************************************************************************/
1265/* Driver Debug Functions. */
1266/****************************************************************************/
1267
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001268void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001269qla2x00_dump_regs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Andrew Vasquez6afd9762007-08-12 18:22:56 -07001271 int i;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001272 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001273 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquez6afd9762007-08-12 18:22:56 -07001274 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
1275 uint16_t __iomem *mbx_reg;
1276
1277 mbx_reg = IS_FWI2_CAPABLE(ha) ? &reg24->mailbox0:
1278 MAILBOX_REG(ha, reg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 printk("Mailbox registers:\n");
Andrew Vasquez6afd9762007-08-12 18:22:56 -07001281 for (i = 0; i < 6; i++)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001282 printk("scsi(%ld): mbox %d 0x%04x \n", vha->host_no, i,
Andrew Vasquez6afd9762007-08-12 18:22:56 -07001283 RD_REG_WORD(mbx_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284}
1285
1286
1287void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001288qla2x00_dump_buffer(uint8_t * b, uint32_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 uint32_t cnt;
1291 uint8_t c;
1292
1293 printk(" 0 1 2 3 4 5 6 7 8 9 "
1294 "Ah Bh Ch Dh Eh Fh\n");
1295 printk("----------------------------------------"
1296 "----------------------\n");
1297
1298 for (cnt = 0; cnt < size;) {
1299 c = *b++;
1300 printk("%02x",(uint32_t) c);
1301 cnt++;
1302 if (!(cnt % 16))
1303 printk("\n");
1304 else
1305 printk(" ");
1306 }
1307 if (cnt % 16)
1308 printk("\n");
1309}