blob: 1457186a0f2cee5aaee0a71fe75966fc550deef5 [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 Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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 * ----------------------------------------------------------------------
Chad Dupuis0b91d112012-02-09 11:15:42 -080014 * | Module Init and Probe | 0x0120 | 0x4b,0xba,0xfa |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040015 * | Mailbox commands | 0x113e | 0x111a-0x111b |
16 * | | | 0x112c-0x112e |
Andrew Vasquezaf11f642012-02-09 11:15:43 -080017 * | | | 0x113a |
Arun Easi557cf782012-02-09 11:15:50 -080018 * | Device Discovery | 0x2086 | 0x2020-0x2022 |
Giridhar Malavali4aee5762012-04-25 07:26:15 -070019 * | Queue Command and IO tracing | 0x3030 | 0x3006,0x3008 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080020 * | | | 0x302d-0x302e |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040021 * | DPC Thread | 0x401c | 0x4002,0x4013 |
Chad Dupuisdaae62a2012-05-15 14:34:23 -040022 * | Async Events | 0x505f | 0x502b-0x502f |
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080023 * | | | 0x5047,0x5052 |
Giridhar Malavali5988aeb2012-05-15 14:34:12 -040024 * | Timer Routines | 0x6011 | |
Joe Carnuccio733a95b2012-02-09 11:15:55 -080025 * | User Space Interactions | 0x709f | 0x7018,0x702e, |
26 * | | | 0x7039,0x7045, |
27 * | | | 0x7073-0x7075, |
28 * | | | 0x708c |
Chad Dupuiscfb09192011-11-18 09:03:07 -080029 * | Task Management | 0x803c | 0x8025-0x8026 |
30 * | | | 0x800b,0x8039 |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040031 * | AER/EEH | 0x9011 | |
Arun Easie02587d2011-08-16 11:29:23 -070032 * | Virtual Port | 0xa007 | |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040033 * | ISP82XX Specific | 0xb054 | 0xb024 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080034 * | MultiQ | 0xc00c | |
35 * | Misc | 0xd010 | |
Arun Easie02587d2011-08-16 11:29:23 -070036 * ----------------------------------------------------------------------
Saurav Kashyap3ce88662011-07-14 12:00:12 -070037 */
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "qla_def.h"
40
41#include <linux/delay.h>
42
Saurav Kashyap3ce88662011-07-14 12:00:12 -070043static uint32_t ql_dbg_offset = 0x800;
44
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070045static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080046qla2xxx_prep_dump(struct qla_hw_data *ha, struct qla2xxx_fw_dump *fw_dump)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070047{
48 fw_dump->fw_major_version = htonl(ha->fw_major_version);
49 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
50 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
51 fw_dump->fw_attributes = htonl(ha->fw_attributes);
52
53 fw_dump->vendor = htonl(ha->pdev->vendor);
54 fw_dump->device = htonl(ha->pdev->device);
55 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
56 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
57}
58
59static inline void *
Anirban Chakraborty73208df2008-12-09 16:45:39 -080060qla2xxx_copy_queues(struct qla_hw_data *ha, void *ptr)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070061{
Anirban Chakraborty73208df2008-12-09 16:45:39 -080062 struct req_que *req = ha->req_q_map[0];
63 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070064 /* Request queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080065 memcpy(ptr, req->ring, req->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070066 sizeof(request_t));
67
68 /* Response queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080069 ptr += req->length * sizeof(request_t);
70 memcpy(ptr, rsp->ring, rsp->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070071 sizeof(response_t));
72
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080073 return ptr + (rsp->length * sizeof(response_t));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070074}
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070076static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080077qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -070078 uint32_t ram_dwords, void **nxt)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070079{
80 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -070081 uint32_t cnt, stat, timer, dwords, idx;
82 uint16_t mb0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070083 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquezc5722702008-04-24 15:21:22 -070084 dma_addr_t dump_dma = ha->gid_list_dma;
85 uint32_t *dump = (uint32_t *)ha->gid_list;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070086
87 rval = QLA_SUCCESS;
Andrew Vasquezc5722702008-04-24 15:21:22 -070088 mb0 = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070089
Andrew Vasquezc5722702008-04-24 15:21:22 -070090 WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070091 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
92
Chad Dupuis642ef982012-02-09 11:15:57 -080093 dwords = qla2x00_gid_list_size(ha) / 4;
Andrew Vasquezc5722702008-04-24 15:21:22 -070094 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
95 cnt += dwords, addr += dwords) {
96 if (cnt + dwords > ram_dwords)
97 dwords = ram_dwords - cnt;
98
99 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
100 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
101
102 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
103 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
104 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
105 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
106
107 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
108 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700109 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
110
111 for (timer = 6000000; timer; timer--) {
112 /* Check for pending interrupts. */
113 stat = RD_REG_DWORD(&reg->host_status);
114 if (stat & HSRX_RISC_INT) {
115 stat &= 0xff;
116
117 if (stat == 0x1 || stat == 0x2 ||
118 stat == 0x10 || stat == 0x11) {
119 set_bit(MBX_INTERRUPT,
120 &ha->mbx_cmd_flags);
121
Andrew Vasquezc5722702008-04-24 15:21:22 -0700122 mb0 = RD_REG_WORD(&reg->mailbox0);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700123
124 WRT_REG_DWORD(&reg->hccr,
125 HCCRX_CLR_RISC_INT);
126 RD_REG_DWORD(&reg->hccr);
127 break;
128 }
129
130 /* Clear this intr; it wasn't a mailbox intr */
131 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
132 RD_REG_DWORD(&reg->hccr);
133 }
134 udelay(5);
135 }
136
137 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
Andrew Vasquezc5722702008-04-24 15:21:22 -0700138 rval = mb0 & MBS_MASK;
139 for (idx = 0; idx < dwords; idx++)
140 ram[cnt + idx] = swab32(dump[idx]);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700141 } else {
142 rval = QLA_FUNCTION_FAILED;
143 }
144 }
145
Andrew Vasquezc5722702008-04-24 15:21:22 -0700146 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700147 return rval;
148}
149
Andrew Vasquezc5722702008-04-24 15:21:22 -0700150static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800151qla24xx_dump_memory(struct qla_hw_data *ha, uint32_t *code_ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700152 uint32_t cram_size, void **nxt)
153{
154 int rval;
155
156 /* Code RAM. */
157 rval = qla24xx_dump_ram(ha, 0x20000, code_ram, cram_size / 4, nxt);
158 if (rval != QLA_SUCCESS)
159 return rval;
160
161 /* External Memory. */
162 return qla24xx_dump_ram(ha, 0x100000, *nxt,
163 ha->fw_memory_size - 0x100000 + 1, nxt);
164}
165
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700166static uint32_t *
167qla24xx_read_window(struct device_reg_24xx __iomem *reg, uint32_t iobase,
168 uint32_t count, uint32_t *buf)
169{
170 uint32_t __iomem *dmp_reg;
171
172 WRT_REG_DWORD(&reg->iobase_addr, iobase);
173 dmp_reg = &reg->iobase_window;
174 while (count--)
175 *buf++ = htonl(RD_REG_DWORD(dmp_reg++));
176
177 return buf;
178}
179
180static inline int
181qla24xx_pause_risc(struct device_reg_24xx __iomem *reg)
182{
183 int rval = QLA_SUCCESS;
184 uint32_t cnt;
185
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700186 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
Andrew Vasquezaed10882009-06-03 09:55:26 -0700187 for (cnt = 30000;
188 ((RD_REG_DWORD(&reg->host_status) & HSRX_RISC_PAUSED) == 0) &&
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700189 rval == QLA_SUCCESS; cnt--) {
190 if (cnt)
191 udelay(100);
192 else
193 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700194 }
195
196 return rval;
197}
198
199static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800200qla24xx_soft_reset(struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700201{
202 int rval = QLA_SUCCESS;
203 uint32_t cnt;
204 uint16_t mb0, wd;
205 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
206
207 /* Reset RISC. */
208 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
209 for (cnt = 0; cnt < 30000; cnt++) {
210 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
211 break;
212
213 udelay(10);
214 }
215
216 WRT_REG_DWORD(&reg->ctrl_status,
217 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
218 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
219
220 udelay(100);
221 /* Wait for firmware to complete NVRAM accesses. */
222 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
223 for (cnt = 10000 ; cnt && mb0; cnt--) {
224 udelay(5);
225 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
226 barrier();
227 }
228
229 /* Wait for soft-reset to complete. */
230 for (cnt = 0; cnt < 30000; cnt++) {
231 if ((RD_REG_DWORD(&reg->ctrl_status) &
232 CSRX_ISP_SOFT_RESET) == 0)
233 break;
234
235 udelay(10);
236 }
237 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
238 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
239
240 for (cnt = 30000; RD_REG_WORD(&reg->mailbox0) != 0 &&
241 rval == QLA_SUCCESS; cnt--) {
242 if (cnt)
243 udelay(100);
244 else
245 rval = QLA_FUNCTION_TIMEOUT;
246 }
247
248 return rval;
249}
250
Andrew Vasquezc5722702008-04-24 15:21:22 -0700251static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800252qla2xxx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint16_t *ram,
Andrew Vasqueze18e9632009-06-17 10:30:31 -0700253 uint32_t ram_words, void **nxt)
Andrew Vasquezc5722702008-04-24 15:21:22 -0700254{
255 int rval;
256 uint32_t cnt, stat, timer, words, idx;
257 uint16_t mb0;
258 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
259 dma_addr_t dump_dma = ha->gid_list_dma;
260 uint16_t *dump = (uint16_t *)ha->gid_list;
261
262 rval = QLA_SUCCESS;
263 mb0 = 0;
264
265 WRT_MAILBOX_REG(ha, reg, 0, MBC_DUMP_RISC_RAM_EXTENDED);
266 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
267
Chad Dupuis642ef982012-02-09 11:15:57 -0800268 words = qla2x00_gid_list_size(ha) / 2;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700269 for (cnt = 0; cnt < ram_words && rval == QLA_SUCCESS;
270 cnt += words, addr += words) {
271 if (cnt + words > ram_words)
272 words = ram_words - cnt;
273
274 WRT_MAILBOX_REG(ha, reg, 1, LSW(addr));
275 WRT_MAILBOX_REG(ha, reg, 8, MSW(addr));
276
277 WRT_MAILBOX_REG(ha, reg, 2, MSW(dump_dma));
278 WRT_MAILBOX_REG(ha, reg, 3, LSW(dump_dma));
279 WRT_MAILBOX_REG(ha, reg, 6, MSW(MSD(dump_dma)));
280 WRT_MAILBOX_REG(ha, reg, 7, LSW(MSD(dump_dma)));
281
282 WRT_MAILBOX_REG(ha, reg, 4, words);
283 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
284
285 for (timer = 6000000; timer; timer--) {
286 /* Check for pending interrupts. */
287 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
288 if (stat & HSR_RISC_INT) {
289 stat &= 0xff;
290
291 if (stat == 0x1 || stat == 0x2) {
292 set_bit(MBX_INTERRUPT,
293 &ha->mbx_cmd_flags);
294
295 mb0 = RD_MAILBOX_REG(ha, reg, 0);
296
297 /* Release mailbox registers. */
298 WRT_REG_WORD(&reg->semaphore, 0);
299 WRT_REG_WORD(&reg->hccr,
300 HCCR_CLR_RISC_INT);
301 RD_REG_WORD(&reg->hccr);
302 break;
303 } else if (stat == 0x10 || stat == 0x11) {
304 set_bit(MBX_INTERRUPT,
305 &ha->mbx_cmd_flags);
306
307 mb0 = RD_MAILBOX_REG(ha, reg, 0);
308
309 WRT_REG_WORD(&reg->hccr,
310 HCCR_CLR_RISC_INT);
311 RD_REG_WORD(&reg->hccr);
312 break;
313 }
314
315 /* clear this intr; it wasn't a mailbox intr */
316 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
317 RD_REG_WORD(&reg->hccr);
318 }
319 udelay(5);
320 }
321
322 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
323 rval = mb0 & MBS_MASK;
324 for (idx = 0; idx < words; idx++)
325 ram[cnt + idx] = swab16(dump[idx]);
326 } else {
327 rval = QLA_FUNCTION_FAILED;
328 }
329 }
330
331 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
332 return rval;
333}
334
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700335static inline void
336qla2xxx_read_window(struct device_reg_2xxx __iomem *reg, uint32_t count,
337 uint16_t *buf)
338{
339 uint16_t __iomem *dmp_reg = &reg->u.isp2300.fb_cmd;
340
341 while (count--)
342 *buf++ = htons(RD_REG_WORD(dmp_reg++));
343}
344
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800345static inline void *
346qla24xx_copy_eft(struct qla_hw_data *ha, void *ptr)
347{
348 if (!ha->eft)
349 return ptr;
350
351 memcpy(ptr, ha->eft, ntohl(ha->fw_dump->eft_size));
352 return ptr + ntohl(ha->fw_dump->eft_size);
353}
354
355static inline void *
356qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
357{
358 uint32_t cnt;
359 uint32_t *iter_reg;
360 struct qla2xxx_fce_chain *fcec = ptr;
361
362 if (!ha->fce)
363 return ptr;
364
365 *last_chain = &fcec->type;
366 fcec->type = __constant_htonl(DUMP_CHAIN_FCE);
367 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
368 fce_calc_size(ha->fce_bufs));
369 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
370 fcec->addr_l = htonl(LSD(ha->fce_dma));
371 fcec->addr_h = htonl(MSD(ha->fce_dma));
372
373 iter_reg = fcec->eregs;
374 for (cnt = 0; cnt < 8; cnt++)
375 *iter_reg++ = htonl(ha->fce_mb[cnt]);
376
377 memcpy(iter_reg, ha->fce, ntohl(fcec->size));
378
Giridhar Malavali3cb0a672011-11-18 09:03:11 -0800379 return (char *)iter_reg + ntohl(fcec->size);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800380}
381
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800382static inline void *
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800383qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
384{
385 struct qla2xxx_mqueue_chain *q;
386 struct qla2xxx_mqueue_header *qh;
387 struct req_que *req;
388 struct rsp_que *rsp;
389 int que;
390
391 if (!ha->mqenable)
392 return ptr;
393
394 /* Request queues */
395 for (que = 1; que < ha->max_req_queues; que++) {
396 req = ha->req_q_map[que];
397 if (!req)
398 break;
399
400 /* Add chain. */
401 q = ptr;
402 *last_chain = &q->type;
403 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
404 q->chain_size = htonl(
405 sizeof(struct qla2xxx_mqueue_chain) +
406 sizeof(struct qla2xxx_mqueue_header) +
407 (req->length * sizeof(request_t)));
408 ptr += sizeof(struct qla2xxx_mqueue_chain);
409
410 /* Add header. */
411 qh = ptr;
412 qh->queue = __constant_htonl(TYPE_REQUEST_QUEUE);
413 qh->number = htonl(que);
414 qh->size = htonl(req->length * sizeof(request_t));
415 ptr += sizeof(struct qla2xxx_mqueue_header);
416
417 /* Add data. */
418 memcpy(ptr, req->ring, req->length * sizeof(request_t));
419 ptr += req->length * sizeof(request_t);
420 }
421
422 /* Response queues */
423 for (que = 1; que < ha->max_rsp_queues; que++) {
424 rsp = ha->rsp_q_map[que];
425 if (!rsp)
426 break;
427
428 /* Add chain. */
429 q = ptr;
430 *last_chain = &q->type;
431 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
432 q->chain_size = htonl(
433 sizeof(struct qla2xxx_mqueue_chain) +
434 sizeof(struct qla2xxx_mqueue_header) +
435 (rsp->length * sizeof(response_t)));
436 ptr += sizeof(struct qla2xxx_mqueue_chain);
437
438 /* Add header. */
439 qh = ptr;
440 qh->queue = __constant_htonl(TYPE_RESPONSE_QUEUE);
441 qh->number = htonl(que);
442 qh->size = htonl(rsp->length * sizeof(response_t));
443 ptr += sizeof(struct qla2xxx_mqueue_header);
444
445 /* Add data. */
446 memcpy(ptr, rsp->ring, rsp->length * sizeof(response_t));
447 ptr += rsp->length * sizeof(response_t);
448 }
449
450 return ptr;
451}
452
453static inline void *
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800454qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
455{
456 uint32_t cnt, que_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700457 uint8_t que_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800458 struct qla2xxx_mq_chain *mq = ptr;
459 struct device_reg_25xxmq __iomem *reg;
460
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800461 if (!ha->mqenable || IS_QLA83XX(ha))
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800462 return ptr;
463
464 mq = ptr;
465 *last_chain = &mq->type;
466 mq->type = __constant_htonl(DUMP_CHAIN_MQ);
467 mq->chain_size = __constant_htonl(sizeof(struct qla2xxx_mq_chain));
468
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700469 que_cnt = ha->max_req_queues > ha->max_rsp_queues ?
470 ha->max_req_queues : ha->max_rsp_queues;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800471 mq->count = htonl(que_cnt);
472 for (cnt = 0; cnt < que_cnt; cnt++) {
473 reg = (struct device_reg_25xxmq *) ((void *)
474 ha->mqiobase + cnt * QLA_QUE_PAGE);
475 que_idx = cnt * 4;
476 mq->qregs[que_idx] = htonl(RD_REG_DWORD(&reg->req_q_in));
477 mq->qregs[que_idx+1] = htonl(RD_REG_DWORD(&reg->req_q_out));
478 mq->qregs[que_idx+2] = htonl(RD_REG_DWORD(&reg->rsp_q_in));
479 mq->qregs[que_idx+3] = htonl(RD_REG_DWORD(&reg->rsp_q_out));
480 }
481
482 return ptr + sizeof(struct qla2xxx_mq_chain);
483}
484
Giridhar Malavali08de2842011-08-16 11:31:44 -0700485void
Andrew Vasquez3420d362009-10-13 15:16:45 -0700486qla2xxx_dump_post_process(scsi_qla_host_t *vha, int rval)
487{
488 struct qla_hw_data *ha = vha->hw;
489
490 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700491 ql_log(ql_log_warn, vha, 0xd000,
492 "Failed to dump firmware (%x).\n", rval);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700493 ha->fw_dumped = 0;
494 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700495 ql_log(ql_log_info, vha, 0xd001,
Andrew Vasquez3420d362009-10-13 15:16:45 -0700496 "Firmware dump saved to temp buffer (%ld/%p).\n",
497 vha->host_no, ha->fw_dump);
498 ha->fw_dumped = 1;
499 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
500 }
501}
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503/**
504 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
505 * @ha: HA context
506 * @hardware_locked: Called with the hardware_lock
507 */
508void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800509qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
511 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700512 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800513 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700514 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 uint16_t __iomem *dmp_reg;
516 unsigned long flags;
517 struct qla2300_fw_dump *fw;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700518 void *nxt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800519 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 flags = 0;
522
523 if (!hardware_locked)
524 spin_lock_irqsave(&ha->hardware_lock, flags);
525
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700526 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700527 ql_log(ql_log_warn, vha, 0xd002,
528 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 goto qla2300_fw_dump_failed;
530 }
531
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700532 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700533 ql_log(ql_log_warn, vha, 0xd003,
534 "Firmware has been previously dumped (%p) "
535 "-- ignoring request.\n",
536 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 goto qla2300_fw_dump_failed;
538 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700539 fw = &ha->fw_dump->isp.isp23;
540 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700543 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700546 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (IS_QLA2300(ha)) {
548 for (cnt = 30000;
549 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
550 rval == QLA_SUCCESS; cnt--) {
551 if (cnt)
552 udelay(100);
553 else
554 rval = QLA_FUNCTION_TIMEOUT;
555 }
556 } else {
557 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
558 udelay(10);
559 }
560
561 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700562 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700563 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700564 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700566 dmp_reg = &reg->u.isp2300.req_q_in;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700567 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700568 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700570 dmp_reg = &reg->u.isp2300.mailbox0;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700571 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700572 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 WRT_REG_WORD(&reg->ctrl_status, 0x40);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700575 qla2xxx_read_window(reg, 32, fw->resp_dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 WRT_REG_WORD(&reg->ctrl_status, 0x50);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700578 qla2xxx_read_window(reg, 48, fw->dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700581 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700582 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700583 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700585 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700586 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700588 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700589 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700591 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700592 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700594 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700595 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700597 WRT_REG_WORD(&reg->pcr, 0x2800);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700598 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700600 WRT_REG_WORD(&reg->pcr, 0x2A00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700601 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700603 WRT_REG_WORD(&reg->pcr, 0x2C00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700604 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700606 WRT_REG_WORD(&reg->pcr, 0x2E00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700607 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700609 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700610 qla2xxx_read_window(reg, 64, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700612 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700613 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700615 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700616 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 /* Reset RISC. */
619 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
620 for (cnt = 0; cnt < 30000; cnt++) {
621 if ((RD_REG_WORD(&reg->ctrl_status) &
622 CSR_ISP_SOFT_RESET) == 0)
623 break;
624
625 udelay(10);
626 }
627 }
628
629 if (!IS_QLA2300(ha)) {
630 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
631 rval == QLA_SUCCESS; cnt--) {
632 if (cnt)
633 udelay(100);
634 else
635 rval = QLA_FUNCTION_TIMEOUT;
636 }
637 }
638
Andrew Vasquezc5722702008-04-24 15:21:22 -0700639 /* Get RISC SRAM. */
640 if (rval == QLA_SUCCESS)
641 rval = qla2xxx_dump_ram(ha, 0x800, fw->risc_ram,
642 sizeof(fw->risc_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Andrew Vasquezc5722702008-04-24 15:21:22 -0700644 /* Get stack SRAM. */
645 if (rval == QLA_SUCCESS)
646 rval = qla2xxx_dump_ram(ha, 0x10000, fw->stack_ram,
647 sizeof(fw->stack_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Andrew Vasquezc5722702008-04-24 15:21:22 -0700649 /* Get data SRAM. */
650 if (rval == QLA_SUCCESS)
651 rval = qla2xxx_dump_ram(ha, 0x11000, fw->data_ram,
652 ha->fw_memory_size - 0x11000 + 1, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700654 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800655 qla2xxx_copy_queues(ha, nxt);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700656
Andrew Vasquez3420d362009-10-13 15:16:45 -0700657 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659qla2300_fw_dump_failed:
660 if (!hardware_locked)
661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
662}
663
664/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
666 * @ha: HA context
667 * @hardware_locked: Called with the hardware_lock
668 */
669void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800670qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
672 int rval;
673 uint32_t cnt, timer;
674 uint16_t risc_address;
675 uint16_t mb0, mb2;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800676 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700677 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 uint16_t __iomem *dmp_reg;
679 unsigned long flags;
680 struct qla2100_fw_dump *fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800681 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 risc_address = 0;
684 mb0 = mb2 = 0;
685 flags = 0;
686
687 if (!hardware_locked)
688 spin_lock_irqsave(&ha->hardware_lock, flags);
689
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700690 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 ql_log(ql_log_warn, vha, 0xd004,
692 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 goto qla2100_fw_dump_failed;
694 }
695
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700696 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700697 ql_log(ql_log_warn, vha, 0xd005,
698 "Firmware has been previously dumped (%p) "
699 "-- ignoring request.\n",
700 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 goto qla2100_fw_dump_failed;
702 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700703 fw = &ha->fw_dump->isp.isp21;
704 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700707 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700710 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
712 rval == QLA_SUCCESS; cnt--) {
713 if (cnt)
714 udelay(100);
715 else
716 rval = QLA_FUNCTION_TIMEOUT;
717 }
718 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700719 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700720 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700721 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700723 dmp_reg = &reg->u.isp2100.mailbox0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700725 if (cnt == 8)
726 dmp_reg = &reg->u_end.isp2200.mailbox8;
727
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700728 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700731 dmp_reg = &reg->u.isp2100.unused_2[0];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700732 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700733 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700736 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700737 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700738 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700740 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700741 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700743 WRT_REG_WORD(&reg->pcr, 0x2100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700744 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700746 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700747 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700749 WRT_REG_WORD(&reg->pcr, 0x2300);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700750 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700752 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700753 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700755 WRT_REG_WORD(&reg->pcr, 0x2500);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700756 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700758 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700759 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700761 WRT_REG_WORD(&reg->pcr, 0x2700);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700762 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700764 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700765 qla2xxx_read_window(reg, 16, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700767 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700768 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700770 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700771 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 /* Reset the ISP. */
774 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
775 }
776
777 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
778 rval == QLA_SUCCESS; cnt--) {
779 if (cnt)
780 udelay(100);
781 else
782 rval = QLA_FUNCTION_TIMEOUT;
783 }
784
785 /* Pause RISC. */
786 if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
787 (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {
788
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700789 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 for (cnt = 30000;
791 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
792 rval == QLA_SUCCESS; cnt--) {
793 if (cnt)
794 udelay(100);
795 else
796 rval = QLA_FUNCTION_TIMEOUT;
797 }
798 if (rval == QLA_SUCCESS) {
799 /* Set memory configuration and timing. */
800 if (IS_QLA2100(ha))
801 WRT_REG_WORD(&reg->mctr, 0xf1);
802 else
803 WRT_REG_WORD(&reg->mctr, 0xf2);
804 RD_REG_WORD(&reg->mctr); /* PCI Posting. */
805
806 /* Release RISC. */
807 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
808 }
809 }
810
811 if (rval == QLA_SUCCESS) {
812 /* Get RISC SRAM. */
813 risc_address = 0x1000;
814 WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
815 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
816 }
817 for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
818 cnt++, risc_address++) {
819 WRT_MAILBOX_REG(ha, reg, 1, risc_address);
820 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
821
822 for (timer = 6000000; timer != 0; timer--) {
823 /* Check for pending interrupts. */
824 if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
825 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
826 set_bit(MBX_INTERRUPT,
827 &ha->mbx_cmd_flags);
828
829 mb0 = RD_MAILBOX_REG(ha, reg, 0);
830 mb2 = RD_MAILBOX_REG(ha, reg, 2);
831
832 WRT_REG_WORD(&reg->semaphore, 0);
833 WRT_REG_WORD(&reg->hccr,
834 HCCR_CLR_RISC_INT);
835 RD_REG_WORD(&reg->hccr);
836 break;
837 }
838 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
839 RD_REG_WORD(&reg->hccr);
840 }
841 udelay(5);
842 }
843
844 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
845 rval = mb0 & MBS_MASK;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700846 fw->risc_ram[cnt] = htons(mb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 } else {
848 rval = QLA_FUNCTION_FAILED;
849 }
850 }
851
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700852 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800853 qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700854
Andrew Vasquez3420d362009-10-13 15:16:45 -0700855 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
857qla2100_fw_dump_failed:
858 if (!hardware_locked)
859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
860}
861
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700862void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800863qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700864{
865 int rval;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700866 uint32_t cnt;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700867 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800868 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700869 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
870 uint32_t __iomem *dmp_reg;
871 uint32_t *iter_reg;
872 uint16_t __iomem *mbx_reg;
873 unsigned long flags;
874 struct qla24xx_fw_dump *fw;
875 uint32_t ext_mem_cnt;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700876 void *nxt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800877 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700878
Giridhar Malavalia9083012010-04-12 17:59:55 -0700879 if (IS_QLA82XX(ha))
880 return;
881
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700882 risc_address = ext_mem_cnt = 0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700883 flags = 0;
884
885 if (!hardware_locked)
886 spin_lock_irqsave(&ha->hardware_lock, flags);
887
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700888 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700889 ql_log(ql_log_warn, vha, 0xd006,
890 "No buffer available for dump.\n");
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700891 goto qla24xx_fw_dump_failed;
892 }
893
894 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700895 ql_log(ql_log_warn, vha, 0xd007,
896 "Firmware has been previously dumped (%p) "
897 "-- ignoring request.\n",
898 ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700899 goto qla24xx_fw_dump_failed;
900 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700901 fw = &ha->fw_dump->isp.isp24;
902 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700903
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700904 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700905
906 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700907 rval = qla24xx_pause_risc(reg);
908 if (rval != QLA_SUCCESS)
909 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700910
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700911 /* Host interface registers. */
912 dmp_reg = &reg->flash_addr;
913 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
914 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700915
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700916 /* Disable interrupts. */
917 WRT_REG_DWORD(&reg->ictrl, 0);
918 RD_REG_DWORD(&reg->ictrl);
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800919
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700920 /* Shadow registers. */
921 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
922 RD_REG_DWORD(&reg->iobase_addr);
923 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
924 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800925
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700926 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
927 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800928
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700929 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
930 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800931
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700932 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
933 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800934
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700935 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
936 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800937
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700938 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
939 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800940
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700941 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
942 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800943
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700944 /* Mailbox registers. */
945 mbx_reg = &reg->mailbox0;
946 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
947 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700948
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700949 /* Transfer sequence registers. */
950 iter_reg = fw->xseq_gp_reg;
951 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
952 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
953 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
954 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
955 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
956 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
957 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
958 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700959
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700960 qla24xx_read_window(reg, 0xBFE0, 16, fw->xseq_0_reg);
961 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700962
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700963 /* Receive sequence registers. */
964 iter_reg = fw->rseq_gp_reg;
965 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
966 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
967 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
968 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
969 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
970 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
971 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
972 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700973
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700974 qla24xx_read_window(reg, 0xFFD0, 16, fw->rseq_0_reg);
975 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
976 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700977
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700978 /* Command DMA registers. */
979 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700980
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700981 /* Queues. */
982 iter_reg = fw->req0_dma_reg;
983 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
984 dmp_reg = &reg->iobase_q;
985 for (cnt = 0; cnt < 7; cnt++)
986 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700987
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700988 iter_reg = fw->resp0_dma_reg;
989 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
990 dmp_reg = &reg->iobase_q;
991 for (cnt = 0; cnt < 7; cnt++)
992 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700993
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700994 iter_reg = fw->req1_dma_reg;
995 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
996 dmp_reg = &reg->iobase_q;
997 for (cnt = 0; cnt < 7; cnt++)
998 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700999
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001000 /* Transmit DMA registers. */
1001 iter_reg = fw->xmt0_dma_reg;
1002 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1003 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001004
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001005 iter_reg = fw->xmt1_dma_reg;
1006 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1007 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001008
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001009 iter_reg = fw->xmt2_dma_reg;
1010 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1011 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001012
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001013 iter_reg = fw->xmt3_dma_reg;
1014 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1015 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001016
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001017 iter_reg = fw->xmt4_dma_reg;
1018 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1019 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001020
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001021 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001022
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001023 /* Receive DMA registers. */
1024 iter_reg = fw->rcvt0_data_dma_reg;
1025 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1026 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001027
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001028 iter_reg = fw->rcvt1_data_dma_reg;
1029 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1030 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001031
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001032 /* RISC registers. */
1033 iter_reg = fw->risc_gp_reg;
1034 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1035 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1036 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1037 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1038 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1039 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1040 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1041 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001042
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001043 /* Local memory controller registers. */
1044 iter_reg = fw->lmc_reg;
1045 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1046 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1047 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1048 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1049 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1050 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1051 qla24xx_read_window(reg, 0x3060, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001052
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001053 /* Fibre Protocol Module registers. */
1054 iter_reg = fw->fpm_hdw_reg;
1055 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1056 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1057 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1058 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1059 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1060 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1061 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1062 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1063 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1064 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1065 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1066 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001067
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001068 /* Frame Buffer registers. */
1069 iter_reg = fw->fb_hdw_reg;
1070 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1071 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1072 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1073 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1074 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1075 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1076 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1077 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1078 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1079 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1080 qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001081
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001082 rval = qla24xx_soft_reset(ha);
1083 if (rval != QLA_SUCCESS)
1084 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001085
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001086 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001087 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001088 if (rval != QLA_SUCCESS)
1089 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001090
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001091 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001092
1093 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001094
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001095qla24xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001096 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001097
1098qla24xx_fw_dump_failed:
1099 if (!hardware_locked)
1100 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1101}
1102
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001103void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001104qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001105{
1106 int rval;
1107 uint32_t cnt;
1108 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001109 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001110 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1111 uint32_t __iomem *dmp_reg;
1112 uint32_t *iter_reg;
1113 uint16_t __iomem *mbx_reg;
1114 unsigned long flags;
1115 struct qla25xx_fw_dump *fw;
1116 uint32_t ext_mem_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001117 void *nxt, *nxt_chain;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001118 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001119 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001120
1121 risc_address = ext_mem_cnt = 0;
1122 flags = 0;
1123
1124 if (!hardware_locked)
1125 spin_lock_irqsave(&ha->hardware_lock, flags);
1126
1127 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001128 ql_log(ql_log_warn, vha, 0xd008,
1129 "No buffer available for dump.\n");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001130 goto qla25xx_fw_dump_failed;
1131 }
1132
1133 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001134 ql_log(ql_log_warn, vha, 0xd009,
1135 "Firmware has been previously dumped (%p) "
1136 "-- ignoring request.\n",
1137 ha->fw_dump);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001138 goto qla25xx_fw_dump_failed;
1139 }
1140 fw = &ha->fw_dump->isp.isp25;
1141 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquezb5836922007-09-20 14:07:39 -07001142 ha->fw_dump->version = __constant_htonl(2);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001143
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001144 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1145
1146 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001147 rval = qla24xx_pause_risc(reg);
1148 if (rval != QLA_SUCCESS)
1149 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001150
Andrew Vasquezb5836922007-09-20 14:07:39 -07001151 /* Host/Risc registers. */
1152 iter_reg = fw->host_risc_reg;
1153 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1154 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1155
1156 /* PCIe registers. */
1157 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1158 RD_REG_DWORD(&reg->iobase_addr);
1159 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1160 dmp_reg = &reg->iobase_c4;
1161 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1162 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1163 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1164 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001165
Andrew Vasquezb5836922007-09-20 14:07:39 -07001166 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1167 RD_REG_DWORD(&reg->iobase_window);
1168
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001169 /* Host interface registers. */
1170 dmp_reg = &reg->flash_addr;
1171 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1172 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001173
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001174 /* Disable interrupts. */
1175 WRT_REG_DWORD(&reg->ictrl, 0);
1176 RD_REG_DWORD(&reg->ictrl);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001177
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001178 /* Shadow registers. */
1179 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1180 RD_REG_DWORD(&reg->iobase_addr);
1181 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1182 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001183
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001184 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1185 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001186
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001187 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1188 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001189
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001190 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1191 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001192
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001193 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1194 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001195
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001196 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1197 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001198
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001199 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1200 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001201
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001202 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1203 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001204
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001205 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1206 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001207
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001208 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1209 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001210
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001211 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1212 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001213
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001214 /* RISC I/O register. */
1215 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1216 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001217
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001218 /* Mailbox registers. */
1219 mbx_reg = &reg->mailbox0;
1220 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1221 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001222
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001223 /* Transfer sequence registers. */
1224 iter_reg = fw->xseq_gp_reg;
1225 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1226 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1227 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1228 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1229 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1230 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1231 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1232 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001233
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001234 iter_reg = fw->xseq_0_reg;
1235 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1236 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1237 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001238
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001239 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001240
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001241 /* Receive sequence registers. */
1242 iter_reg = fw->rseq_gp_reg;
1243 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1244 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1245 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1246 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1247 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1248 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1249 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1250 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001251
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001252 iter_reg = fw->rseq_0_reg;
1253 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1254 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001255
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001256 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1257 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001258
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001259 /* Auxiliary sequence registers. */
1260 iter_reg = fw->aseq_gp_reg;
1261 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1262 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1263 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1264 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1265 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1266 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1267 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1268 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001269
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001270 iter_reg = fw->aseq_0_reg;
1271 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1272 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001273
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001274 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1275 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001276
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001277 /* Command DMA registers. */
1278 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001279
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001280 /* Queues. */
1281 iter_reg = fw->req0_dma_reg;
1282 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1283 dmp_reg = &reg->iobase_q;
1284 for (cnt = 0; cnt < 7; cnt++)
1285 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001286
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001287 iter_reg = fw->resp0_dma_reg;
1288 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1289 dmp_reg = &reg->iobase_q;
1290 for (cnt = 0; cnt < 7; cnt++)
1291 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001292
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001293 iter_reg = fw->req1_dma_reg;
1294 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1295 dmp_reg = &reg->iobase_q;
1296 for (cnt = 0; cnt < 7; cnt++)
1297 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001298
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001299 /* Transmit DMA registers. */
1300 iter_reg = fw->xmt0_dma_reg;
1301 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1302 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001303
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001304 iter_reg = fw->xmt1_dma_reg;
1305 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1306 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001307
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001308 iter_reg = fw->xmt2_dma_reg;
1309 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1310 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001311
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001312 iter_reg = fw->xmt3_dma_reg;
1313 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1314 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001315
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001316 iter_reg = fw->xmt4_dma_reg;
1317 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1318 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001319
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001320 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001321
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001322 /* Receive DMA registers. */
1323 iter_reg = fw->rcvt0_data_dma_reg;
1324 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1325 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001326
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001327 iter_reg = fw->rcvt1_data_dma_reg;
1328 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1329 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001330
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001331 /* RISC registers. */
1332 iter_reg = fw->risc_gp_reg;
1333 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1334 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1335 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1336 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1337 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1338 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1339 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1340 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001341
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001342 /* Local memory controller registers. */
1343 iter_reg = fw->lmc_reg;
1344 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1345 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1346 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1347 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1348 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1349 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1350 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1351 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001352
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001353 /* Fibre Protocol Module registers. */
1354 iter_reg = fw->fpm_hdw_reg;
1355 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1356 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1357 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1358 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1359 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1360 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1361 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1362 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1363 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1364 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1365 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1366 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001367
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001368 /* Frame Buffer registers. */
1369 iter_reg = fw->fb_hdw_reg;
1370 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1371 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1372 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1373 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1374 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1375 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1376 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1377 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1378 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1379 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1380 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1381 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001382
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001383 /* Multi queue registers */
1384 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1385 &last_chain);
1386
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001387 rval = qla24xx_soft_reset(ha);
1388 if (rval != QLA_SUCCESS)
1389 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001390
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001391 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001392 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001393 if (rval != QLA_SUCCESS)
1394 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001395
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001396 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001397
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001398 nxt = qla24xx_copy_eft(ha, nxt);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001399
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001400 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001401 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1402 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001403 if (last_chain) {
1404 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1405 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1406 }
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001407
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001408 /* Adjust valid length. */
1409 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1410
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001411qla25xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001412 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001413
1414qla25xx_fw_dump_failed:
1415 if (!hardware_locked)
1416 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1417}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001418
1419void
1420qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1421{
1422 int rval;
1423 uint32_t cnt;
1424 uint32_t risc_address;
1425 struct qla_hw_data *ha = vha->hw;
1426 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1427 uint32_t __iomem *dmp_reg;
1428 uint32_t *iter_reg;
1429 uint16_t __iomem *mbx_reg;
1430 unsigned long flags;
1431 struct qla81xx_fw_dump *fw;
1432 uint32_t ext_mem_cnt;
1433 void *nxt, *nxt_chain;
1434 uint32_t *last_chain = NULL;
1435 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1436
1437 risc_address = ext_mem_cnt = 0;
1438 flags = 0;
1439
1440 if (!hardware_locked)
1441 spin_lock_irqsave(&ha->hardware_lock, flags);
1442
1443 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001444 ql_log(ql_log_warn, vha, 0xd00a,
1445 "No buffer available for dump.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001446 goto qla81xx_fw_dump_failed;
1447 }
1448
1449 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001450 ql_log(ql_log_warn, vha, 0xd00b,
1451 "Firmware has been previously dumped (%p) "
1452 "-- ignoring request.\n",
1453 ha->fw_dump);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001454 goto qla81xx_fw_dump_failed;
1455 }
1456 fw = &ha->fw_dump->isp.isp81;
1457 qla2xxx_prep_dump(ha, ha->fw_dump);
1458
1459 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1460
1461 /* Pause RISC. */
1462 rval = qla24xx_pause_risc(reg);
1463 if (rval != QLA_SUCCESS)
1464 goto qla81xx_fw_dump_failed_0;
1465
1466 /* Host/Risc registers. */
1467 iter_reg = fw->host_risc_reg;
1468 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1469 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1470
1471 /* PCIe registers. */
1472 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1473 RD_REG_DWORD(&reg->iobase_addr);
1474 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1475 dmp_reg = &reg->iobase_c4;
1476 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1477 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1478 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1479 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1480
1481 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1482 RD_REG_DWORD(&reg->iobase_window);
1483
1484 /* Host interface registers. */
1485 dmp_reg = &reg->flash_addr;
1486 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1487 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1488
1489 /* Disable interrupts. */
1490 WRT_REG_DWORD(&reg->ictrl, 0);
1491 RD_REG_DWORD(&reg->ictrl);
1492
1493 /* Shadow registers. */
1494 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1495 RD_REG_DWORD(&reg->iobase_addr);
1496 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1497 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1498
1499 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1500 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1501
1502 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1503 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1504
1505 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1506 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1507
1508 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1509 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1510
1511 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1512 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1513
1514 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1515 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1516
1517 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1518 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1519
1520 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1521 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1522
1523 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1524 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1525
1526 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1527 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1528
1529 /* RISC I/O register. */
1530 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1531 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1532
1533 /* Mailbox registers. */
1534 mbx_reg = &reg->mailbox0;
1535 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1536 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1537
1538 /* Transfer sequence registers. */
1539 iter_reg = fw->xseq_gp_reg;
1540 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1541 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1542 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1543 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1544 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1545 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1546 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1547 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1548
1549 iter_reg = fw->xseq_0_reg;
1550 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1551 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1552 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1553
1554 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1555
1556 /* Receive sequence registers. */
1557 iter_reg = fw->rseq_gp_reg;
1558 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1559 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1560 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1561 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1562 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1563 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1564 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1565 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1566
1567 iter_reg = fw->rseq_0_reg;
1568 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1569 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1570
1571 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1572 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1573
1574 /* Auxiliary sequence registers. */
1575 iter_reg = fw->aseq_gp_reg;
1576 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1577 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1578 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1579 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1580 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1581 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1582 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1583 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
1584
1585 iter_reg = fw->aseq_0_reg;
1586 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1587 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
1588
1589 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1590 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
1591
1592 /* Command DMA registers. */
1593 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
1594
1595 /* Queues. */
1596 iter_reg = fw->req0_dma_reg;
1597 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1598 dmp_reg = &reg->iobase_q;
1599 for (cnt = 0; cnt < 7; cnt++)
1600 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1601
1602 iter_reg = fw->resp0_dma_reg;
1603 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1604 dmp_reg = &reg->iobase_q;
1605 for (cnt = 0; cnt < 7; cnt++)
1606 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1607
1608 iter_reg = fw->req1_dma_reg;
1609 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1610 dmp_reg = &reg->iobase_q;
1611 for (cnt = 0; cnt < 7; cnt++)
1612 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1613
1614 /* Transmit DMA registers. */
1615 iter_reg = fw->xmt0_dma_reg;
1616 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1617 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
1618
1619 iter_reg = fw->xmt1_dma_reg;
1620 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1621 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
1622
1623 iter_reg = fw->xmt2_dma_reg;
1624 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1625 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
1626
1627 iter_reg = fw->xmt3_dma_reg;
1628 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1629 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
1630
1631 iter_reg = fw->xmt4_dma_reg;
1632 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1633 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
1634
1635 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
1636
1637 /* Receive DMA registers. */
1638 iter_reg = fw->rcvt0_data_dma_reg;
1639 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1640 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
1641
1642 iter_reg = fw->rcvt1_data_dma_reg;
1643 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1644 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
1645
1646 /* RISC registers. */
1647 iter_reg = fw->risc_gp_reg;
1648 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1649 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1650 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1651 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1652 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1653 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1654 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1655 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
1656
1657 /* Local memory controller registers. */
1658 iter_reg = fw->lmc_reg;
1659 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1660 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1661 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1662 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1663 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1664 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1665 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1666 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
1667
1668 /* Fibre Protocol Module registers. */
1669 iter_reg = fw->fpm_hdw_reg;
1670 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1671 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1672 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1673 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1674 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1675 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1676 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1677 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1678 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1679 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1680 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1681 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
1682 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
1683 qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
1684
1685 /* Frame Buffer registers. */
1686 iter_reg = fw->fb_hdw_reg;
1687 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1688 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1689 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1690 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1691 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1692 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1693 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1694 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1695 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1696 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1697 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1698 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
1699 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
1700
1701 /* Multi queue registers */
1702 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1703 &last_chain);
1704
1705 rval = qla24xx_soft_reset(ha);
1706 if (rval != QLA_SUCCESS)
1707 goto qla81xx_fw_dump_failed_0;
1708
1709 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
1710 &nxt);
1711 if (rval != QLA_SUCCESS)
1712 goto qla81xx_fw_dump_failed_0;
1713
1714 nxt = qla2xxx_copy_queues(ha, nxt);
1715
1716 nxt = qla24xx_copy_eft(ha, nxt);
1717
1718 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001719 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1720 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001721 if (last_chain) {
1722 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1723 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1724 }
1725
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001726 /* Adjust valid length. */
1727 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1728
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001729qla81xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001730 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001731
1732qla81xx_fw_dump_failed:
1733 if (!hardware_locked)
1734 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1735}
1736
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001737void
1738qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1739{
1740 int rval;
1741 uint32_t cnt, reg_data;
1742 uint32_t risc_address;
1743 struct qla_hw_data *ha = vha->hw;
1744 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1745 uint32_t __iomem *dmp_reg;
1746 uint32_t *iter_reg;
1747 uint16_t __iomem *mbx_reg;
1748 unsigned long flags;
1749 struct qla83xx_fw_dump *fw;
1750 uint32_t ext_mem_cnt;
1751 void *nxt, *nxt_chain;
1752 uint32_t *last_chain = NULL;
1753 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1754
1755 risc_address = ext_mem_cnt = 0;
1756 flags = 0;
1757
1758 if (!hardware_locked)
1759 spin_lock_irqsave(&ha->hardware_lock, flags);
1760
1761 if (!ha->fw_dump) {
1762 ql_log(ql_log_warn, vha, 0xd00c,
1763 "No buffer available for dump!!!\n");
1764 goto qla83xx_fw_dump_failed;
1765 }
1766
1767 if (ha->fw_dumped) {
1768 ql_log(ql_log_warn, vha, 0xd00d,
1769 "Firmware has been previously dumped (%p) -- ignoring "
1770 "request...\n", ha->fw_dump);
1771 goto qla83xx_fw_dump_failed;
1772 }
1773 fw = &ha->fw_dump->isp.isp83;
1774 qla2xxx_prep_dump(ha, ha->fw_dump);
1775
1776 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1777
1778 /* Pause RISC. */
1779 rval = qla24xx_pause_risc(reg);
1780 if (rval != QLA_SUCCESS)
1781 goto qla83xx_fw_dump_failed_0;
1782
1783 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
1784 dmp_reg = &reg->iobase_window;
1785 reg_data = RD_REG_DWORD(dmp_reg);
1786 WRT_REG_DWORD(dmp_reg, 0);
1787
1788 dmp_reg = &reg->unused_4_1[0];
1789 reg_data = RD_REG_DWORD(dmp_reg);
1790 WRT_REG_DWORD(dmp_reg, 0);
1791
1792 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
1793 dmp_reg = &reg->unused_4_1[2];
1794 reg_data = RD_REG_DWORD(dmp_reg);
1795 WRT_REG_DWORD(dmp_reg, 0);
1796
1797 /* select PCR and disable ecc checking and correction */
1798 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1799 RD_REG_DWORD(&reg->iobase_addr);
1800 WRT_REG_DWORD(&reg->iobase_select, 0x60000000); /* write to F0h = PCR */
1801
1802 /* Host/Risc registers. */
1803 iter_reg = fw->host_risc_reg;
1804 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1805 iter_reg = qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1806 qla24xx_read_window(reg, 0x7040, 16, iter_reg);
1807
1808 /* PCIe registers. */
1809 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1810 RD_REG_DWORD(&reg->iobase_addr);
1811 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1812 dmp_reg = &reg->iobase_c4;
1813 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1814 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1815 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1816 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1817
1818 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1819 RD_REG_DWORD(&reg->iobase_window);
1820
1821 /* Host interface registers. */
1822 dmp_reg = &reg->flash_addr;
1823 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1824 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1825
1826 /* Disable interrupts. */
1827 WRT_REG_DWORD(&reg->ictrl, 0);
1828 RD_REG_DWORD(&reg->ictrl);
1829
1830 /* Shadow registers. */
1831 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1832 RD_REG_DWORD(&reg->iobase_addr);
1833 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1834 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1835
1836 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1837 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1838
1839 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1840 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1841
1842 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1843 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1844
1845 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1846 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1847
1848 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1849 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1850
1851 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1852 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1853
1854 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1855 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1856
1857 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1858 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1859
1860 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1861 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1862
1863 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1864 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1865
1866 /* RISC I/O register. */
1867 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1868 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1869
1870 /* Mailbox registers. */
1871 mbx_reg = &reg->mailbox0;
1872 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1873 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1874
1875 /* Transfer sequence registers. */
1876 iter_reg = fw->xseq_gp_reg;
1877 iter_reg = qla24xx_read_window(reg, 0xBE00, 16, iter_reg);
1878 iter_reg = qla24xx_read_window(reg, 0xBE10, 16, iter_reg);
1879 iter_reg = qla24xx_read_window(reg, 0xBE20, 16, iter_reg);
1880 iter_reg = qla24xx_read_window(reg, 0xBE30, 16, iter_reg);
1881 iter_reg = qla24xx_read_window(reg, 0xBE40, 16, iter_reg);
1882 iter_reg = qla24xx_read_window(reg, 0xBE50, 16, iter_reg);
1883 iter_reg = qla24xx_read_window(reg, 0xBE60, 16, iter_reg);
1884 iter_reg = qla24xx_read_window(reg, 0xBE70, 16, iter_reg);
1885 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1886 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1887 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1888 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1889 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1890 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1891 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1892 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1893
1894 iter_reg = fw->xseq_0_reg;
1895 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1896 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1897 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1898
1899 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1900
1901 qla24xx_read_window(reg, 0xBEF0, 16, fw->xseq_2_reg);
1902
1903 /* Receive sequence registers. */
1904 iter_reg = fw->rseq_gp_reg;
1905 iter_reg = qla24xx_read_window(reg, 0xFE00, 16, iter_reg);
1906 iter_reg = qla24xx_read_window(reg, 0xFE10, 16, iter_reg);
1907 iter_reg = qla24xx_read_window(reg, 0xFE20, 16, iter_reg);
1908 iter_reg = qla24xx_read_window(reg, 0xFE30, 16, iter_reg);
1909 iter_reg = qla24xx_read_window(reg, 0xFE40, 16, iter_reg);
1910 iter_reg = qla24xx_read_window(reg, 0xFE50, 16, iter_reg);
1911 iter_reg = qla24xx_read_window(reg, 0xFE60, 16, iter_reg);
1912 iter_reg = qla24xx_read_window(reg, 0xFE70, 16, iter_reg);
1913 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1914 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1915 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1916 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1917 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1918 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1919 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1920 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1921
1922 iter_reg = fw->rseq_0_reg;
1923 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1924 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1925
1926 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1927 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1928 qla24xx_read_window(reg, 0xFEF0, 16, fw->rseq_3_reg);
1929
1930 /* Auxiliary sequence registers. */
1931 iter_reg = fw->aseq_gp_reg;
1932 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1933 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1934 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1935 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1936 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1937 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1938 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1939 iter_reg = qla24xx_read_window(reg, 0xB070, 16, iter_reg);
1940 iter_reg = qla24xx_read_window(reg, 0xB100, 16, iter_reg);
1941 iter_reg = qla24xx_read_window(reg, 0xB110, 16, iter_reg);
1942 iter_reg = qla24xx_read_window(reg, 0xB120, 16, iter_reg);
1943 iter_reg = qla24xx_read_window(reg, 0xB130, 16, iter_reg);
1944 iter_reg = qla24xx_read_window(reg, 0xB140, 16, iter_reg);
1945 iter_reg = qla24xx_read_window(reg, 0xB150, 16, iter_reg);
1946 iter_reg = qla24xx_read_window(reg, 0xB160, 16, iter_reg);
1947 qla24xx_read_window(reg, 0xB170, 16, iter_reg);
1948
1949 iter_reg = fw->aseq_0_reg;
1950 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1951 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
1952
1953 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1954 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
1955 qla24xx_read_window(reg, 0xB1F0, 16, fw->aseq_3_reg);
1956
1957 /* Command DMA registers. */
1958 iter_reg = fw->cmd_dma_reg;
1959 iter_reg = qla24xx_read_window(reg, 0x7100, 16, iter_reg);
1960 iter_reg = qla24xx_read_window(reg, 0x7120, 16, iter_reg);
1961 iter_reg = qla24xx_read_window(reg, 0x7130, 16, iter_reg);
1962 qla24xx_read_window(reg, 0x71F0, 16, iter_reg);
1963
1964 /* Queues. */
1965 iter_reg = fw->req0_dma_reg;
1966 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1967 dmp_reg = &reg->iobase_q;
1968 for (cnt = 0; cnt < 7; cnt++)
1969 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1970
1971 iter_reg = fw->resp0_dma_reg;
1972 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1973 dmp_reg = &reg->iobase_q;
1974 for (cnt = 0; cnt < 7; cnt++)
1975 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1976
1977 iter_reg = fw->req1_dma_reg;
1978 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1979 dmp_reg = &reg->iobase_q;
1980 for (cnt = 0; cnt < 7; cnt++)
1981 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1982
1983 /* Transmit DMA registers. */
1984 iter_reg = fw->xmt0_dma_reg;
1985 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1986 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
1987
1988 iter_reg = fw->xmt1_dma_reg;
1989 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1990 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
1991
1992 iter_reg = fw->xmt2_dma_reg;
1993 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1994 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
1995
1996 iter_reg = fw->xmt3_dma_reg;
1997 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1998 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
1999
2000 iter_reg = fw->xmt4_dma_reg;
2001 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
2002 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
2003
2004 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
2005
2006 /* Receive DMA registers. */
2007 iter_reg = fw->rcvt0_data_dma_reg;
2008 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
2009 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
2010
2011 iter_reg = fw->rcvt1_data_dma_reg;
2012 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
2013 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
2014
2015 /* RISC registers. */
2016 iter_reg = fw->risc_gp_reg;
2017 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
2018 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
2019 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
2020 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
2021 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
2022 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
2023 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
2024 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
2025
2026 /* Local memory controller registers. */
2027 iter_reg = fw->lmc_reg;
2028 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
2029 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
2030 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
2031 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
2032 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
2033 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
2034 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
2035 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
2036
2037 /* Fibre Protocol Module registers. */
2038 iter_reg = fw->fpm_hdw_reg;
2039 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
2040 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
2041 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
2042 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
2043 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
2044 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
2045 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
2046 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
2047 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
2048 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
2049 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
2050 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
2051 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
2052 iter_reg = qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
2053 iter_reg = qla24xx_read_window(reg, 0x40E0, 16, iter_reg);
2054 qla24xx_read_window(reg, 0x40F0, 16, iter_reg);
2055
2056 /* RQ0 Array registers. */
2057 iter_reg = fw->rq0_array_reg;
2058 iter_reg = qla24xx_read_window(reg, 0x5C00, 16, iter_reg);
2059 iter_reg = qla24xx_read_window(reg, 0x5C10, 16, iter_reg);
2060 iter_reg = qla24xx_read_window(reg, 0x5C20, 16, iter_reg);
2061 iter_reg = qla24xx_read_window(reg, 0x5C30, 16, iter_reg);
2062 iter_reg = qla24xx_read_window(reg, 0x5C40, 16, iter_reg);
2063 iter_reg = qla24xx_read_window(reg, 0x5C50, 16, iter_reg);
2064 iter_reg = qla24xx_read_window(reg, 0x5C60, 16, iter_reg);
2065 iter_reg = qla24xx_read_window(reg, 0x5C70, 16, iter_reg);
2066 iter_reg = qla24xx_read_window(reg, 0x5C80, 16, iter_reg);
2067 iter_reg = qla24xx_read_window(reg, 0x5C90, 16, iter_reg);
2068 iter_reg = qla24xx_read_window(reg, 0x5CA0, 16, iter_reg);
2069 iter_reg = qla24xx_read_window(reg, 0x5CB0, 16, iter_reg);
2070 iter_reg = qla24xx_read_window(reg, 0x5CC0, 16, iter_reg);
2071 iter_reg = qla24xx_read_window(reg, 0x5CD0, 16, iter_reg);
2072 iter_reg = qla24xx_read_window(reg, 0x5CE0, 16, iter_reg);
2073 qla24xx_read_window(reg, 0x5CF0, 16, iter_reg);
2074
2075 /* RQ1 Array registers. */
2076 iter_reg = fw->rq1_array_reg;
2077 iter_reg = qla24xx_read_window(reg, 0x5D00, 16, iter_reg);
2078 iter_reg = qla24xx_read_window(reg, 0x5D10, 16, iter_reg);
2079 iter_reg = qla24xx_read_window(reg, 0x5D20, 16, iter_reg);
2080 iter_reg = qla24xx_read_window(reg, 0x5D30, 16, iter_reg);
2081 iter_reg = qla24xx_read_window(reg, 0x5D40, 16, iter_reg);
2082 iter_reg = qla24xx_read_window(reg, 0x5D50, 16, iter_reg);
2083 iter_reg = qla24xx_read_window(reg, 0x5D60, 16, iter_reg);
2084 iter_reg = qla24xx_read_window(reg, 0x5D70, 16, iter_reg);
2085 iter_reg = qla24xx_read_window(reg, 0x5D80, 16, iter_reg);
2086 iter_reg = qla24xx_read_window(reg, 0x5D90, 16, iter_reg);
2087 iter_reg = qla24xx_read_window(reg, 0x5DA0, 16, iter_reg);
2088 iter_reg = qla24xx_read_window(reg, 0x5DB0, 16, iter_reg);
2089 iter_reg = qla24xx_read_window(reg, 0x5DC0, 16, iter_reg);
2090 iter_reg = qla24xx_read_window(reg, 0x5DD0, 16, iter_reg);
2091 iter_reg = qla24xx_read_window(reg, 0x5DE0, 16, iter_reg);
2092 qla24xx_read_window(reg, 0x5DF0, 16, iter_reg);
2093
2094 /* RP0 Array registers. */
2095 iter_reg = fw->rp0_array_reg;
2096 iter_reg = qla24xx_read_window(reg, 0x5E00, 16, iter_reg);
2097 iter_reg = qla24xx_read_window(reg, 0x5E10, 16, iter_reg);
2098 iter_reg = qla24xx_read_window(reg, 0x5E20, 16, iter_reg);
2099 iter_reg = qla24xx_read_window(reg, 0x5E30, 16, iter_reg);
2100 iter_reg = qla24xx_read_window(reg, 0x5E40, 16, iter_reg);
2101 iter_reg = qla24xx_read_window(reg, 0x5E50, 16, iter_reg);
2102 iter_reg = qla24xx_read_window(reg, 0x5E60, 16, iter_reg);
2103 iter_reg = qla24xx_read_window(reg, 0x5E70, 16, iter_reg);
2104 iter_reg = qla24xx_read_window(reg, 0x5E80, 16, iter_reg);
2105 iter_reg = qla24xx_read_window(reg, 0x5E90, 16, iter_reg);
2106 iter_reg = qla24xx_read_window(reg, 0x5EA0, 16, iter_reg);
2107 iter_reg = qla24xx_read_window(reg, 0x5EB0, 16, iter_reg);
2108 iter_reg = qla24xx_read_window(reg, 0x5EC0, 16, iter_reg);
2109 iter_reg = qla24xx_read_window(reg, 0x5ED0, 16, iter_reg);
2110 iter_reg = qla24xx_read_window(reg, 0x5EE0, 16, iter_reg);
2111 qla24xx_read_window(reg, 0x5EF0, 16, iter_reg);
2112
2113 /* RP1 Array registers. */
2114 iter_reg = fw->rp1_array_reg;
2115 iter_reg = qla24xx_read_window(reg, 0x5F00, 16, iter_reg);
2116 iter_reg = qla24xx_read_window(reg, 0x5F10, 16, iter_reg);
2117 iter_reg = qla24xx_read_window(reg, 0x5F20, 16, iter_reg);
2118 iter_reg = qla24xx_read_window(reg, 0x5F30, 16, iter_reg);
2119 iter_reg = qla24xx_read_window(reg, 0x5F40, 16, iter_reg);
2120 iter_reg = qla24xx_read_window(reg, 0x5F50, 16, iter_reg);
2121 iter_reg = qla24xx_read_window(reg, 0x5F60, 16, iter_reg);
2122 iter_reg = qla24xx_read_window(reg, 0x5F70, 16, iter_reg);
2123 iter_reg = qla24xx_read_window(reg, 0x5F80, 16, iter_reg);
2124 iter_reg = qla24xx_read_window(reg, 0x5F90, 16, iter_reg);
2125 iter_reg = qla24xx_read_window(reg, 0x5FA0, 16, iter_reg);
2126 iter_reg = qla24xx_read_window(reg, 0x5FB0, 16, iter_reg);
2127 iter_reg = qla24xx_read_window(reg, 0x5FC0, 16, iter_reg);
2128 iter_reg = qla24xx_read_window(reg, 0x5FD0, 16, iter_reg);
2129 iter_reg = qla24xx_read_window(reg, 0x5FE0, 16, iter_reg);
2130 qla24xx_read_window(reg, 0x5FF0, 16, iter_reg);
2131
2132 iter_reg = fw->at0_array_reg;
2133 iter_reg = qla24xx_read_window(reg, 0x7080, 16, iter_reg);
2134 iter_reg = qla24xx_read_window(reg, 0x7090, 16, iter_reg);
2135 iter_reg = qla24xx_read_window(reg, 0x70A0, 16, iter_reg);
2136 iter_reg = qla24xx_read_window(reg, 0x70B0, 16, iter_reg);
2137 iter_reg = qla24xx_read_window(reg, 0x70C0, 16, iter_reg);
2138 iter_reg = qla24xx_read_window(reg, 0x70D0, 16, iter_reg);
2139 iter_reg = qla24xx_read_window(reg, 0x70E0, 16, iter_reg);
2140 qla24xx_read_window(reg, 0x70F0, 16, iter_reg);
2141
2142 /* I/O Queue Control registers. */
2143 qla24xx_read_window(reg, 0x7800, 16, fw->queue_control_reg);
2144
2145 /* Frame Buffer registers. */
2146 iter_reg = fw->fb_hdw_reg;
2147 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
2148 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
2149 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
2150 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
2151 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
2152 iter_reg = qla24xx_read_window(reg, 0x6060, 16, iter_reg);
2153 iter_reg = qla24xx_read_window(reg, 0x6070, 16, iter_reg);
2154 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
2155 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
2156 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
2157 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
2158 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
2159 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
2160 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
2161 iter_reg = qla24xx_read_window(reg, 0x6530, 16, iter_reg);
2162 iter_reg = qla24xx_read_window(reg, 0x6540, 16, iter_reg);
2163 iter_reg = qla24xx_read_window(reg, 0x6550, 16, iter_reg);
2164 iter_reg = qla24xx_read_window(reg, 0x6560, 16, iter_reg);
2165 iter_reg = qla24xx_read_window(reg, 0x6570, 16, iter_reg);
2166 iter_reg = qla24xx_read_window(reg, 0x6580, 16, iter_reg);
2167 iter_reg = qla24xx_read_window(reg, 0x6590, 16, iter_reg);
2168 iter_reg = qla24xx_read_window(reg, 0x65A0, 16, iter_reg);
2169 iter_reg = qla24xx_read_window(reg, 0x65B0, 16, iter_reg);
2170 iter_reg = qla24xx_read_window(reg, 0x65C0, 16, iter_reg);
2171 iter_reg = qla24xx_read_window(reg, 0x65D0, 16, iter_reg);
2172 iter_reg = qla24xx_read_window(reg, 0x65E0, 16, iter_reg);
2173 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
2174
2175 /* Multi queue registers */
2176 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
2177 &last_chain);
2178
2179 rval = qla24xx_soft_reset(ha);
2180 if (rval != QLA_SUCCESS) {
2181 ql_log(ql_log_warn, vha, 0xd00e,
2182 "SOFT RESET FAILED, forcing continuation of dump!!!\n");
2183 rval = QLA_SUCCESS;
2184
2185 ql_log(ql_log_warn, vha, 0xd00f, "try a bigger hammer!!!\n");
2186
2187 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2188 RD_REG_DWORD(&reg->hccr);
2189
2190 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2191 RD_REG_DWORD(&reg->hccr);
2192
2193 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2194 RD_REG_DWORD(&reg->hccr);
2195
2196 for (cnt = 30000; cnt && (RD_REG_WORD(&reg->mailbox0)); cnt--)
2197 udelay(5);
2198
2199 if (!cnt) {
2200 nxt = fw->code_ram;
2201 nxt += sizeof(fw->code_ram),
2202 nxt += (ha->fw_memory_size - 0x100000 + 1);
2203 goto copy_queue;
2204 } else
2205 ql_log(ql_log_warn, vha, 0xd010,
2206 "bigger hammer success?\n");
2207 }
2208
2209 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
2210 &nxt);
2211 if (rval != QLA_SUCCESS)
2212 goto qla83xx_fw_dump_failed_0;
2213
2214copy_queue:
2215 nxt = qla2xxx_copy_queues(ha, nxt);
2216
2217 nxt = qla24xx_copy_eft(ha, nxt);
2218
2219 /* Chain entries -- started with MQ. */
2220 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
2221 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
2222 if (last_chain) {
2223 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
2224 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
2225 }
2226
2227 /* Adjust valid length. */
2228 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
2229
2230qla83xx_fw_dump_failed_0:
2231 qla2xxx_dump_post_process(base_vha, rval);
2232
2233qla83xx_fw_dump_failed:
2234 if (!hardware_locked)
2235 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2236}
2237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238/****************************************************************************/
2239/* Driver Debug Functions. */
2240/****************************************************************************/
Chad Dupuiscfb09192011-11-18 09:03:07 -08002241
2242static inline int
2243ql_mask_match(uint32_t level)
2244{
2245 if (ql2xextended_error_logging == 1)
2246 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2247 return (level & ql2xextended_error_logging) == level;
2248}
2249
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002250/*
2251 * This function is for formatting and logging debug information.
2252 * It is to be used when vha is available. It formats the message
2253 * and logs it to the messages file.
2254 * parameters:
2255 * level: The level of the debug messages to be printed.
2256 * If ql2xextended_error_logging value is correctly set,
2257 * this message will appear in the messages file.
2258 * vha: Pointer to the scsi_qla_host_t.
2259 * id: This is a unique identifier for the level. It identifies the
2260 * part of the code from where the message originated.
2261 * msg: The message to be displayed.
2262 */
2263void
Joe Perches086b3e82011-11-18 09:03:05 -08002264ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2265{
2266 va_list va;
2267 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002268
Chad Dupuiscfb09192011-11-18 09:03:07 -08002269 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002270 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002271
Joe Perches086b3e82011-11-18 09:03:05 -08002272 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002273
Joe Perches086b3e82011-11-18 09:03:05 -08002274 vaf.fmt = fmt;
2275 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002276
Joe Perches086b3e82011-11-18 09:03:05 -08002277 if (vha != NULL) {
2278 const struct pci_dev *pdev = vha->hw->pdev;
2279 /* <module-name> <pci-name> <msg-id>:<host> Message */
2280 pr_warn("%s [%s]-%04x:%ld: %pV",
2281 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset,
2282 vha->host_no, &vaf);
2283 } else {
2284 pr_warn("%s [%s]-%04x: : %pV",
2285 QL_MSGHDR, "0000:00:00.0", id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002286 }
2287
Joe Perches086b3e82011-11-18 09:03:05 -08002288 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002289
2290}
2291
2292/*
2293 * This function is for formatting and logging debug information.
2294 * It is to be used when vha is not available and pci is availble,
2295 * i.e., before host allocation. It formats the message and logs it
2296 * to the messages file.
2297 * parameters:
2298 * level: The level of the debug messages to be printed.
2299 * If ql2xextended_error_logging value is correctly set,
2300 * this message will appear in the messages file.
2301 * pdev: Pointer to the struct pci_dev.
2302 * id: This is a unique id for the level. It identifies the part
2303 * of the code from where the message originated.
2304 * msg: The message to be displayed.
2305 */
2306void
Joe Perches086b3e82011-11-18 09:03:05 -08002307ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2308 const char *fmt, ...)
2309{
2310 va_list va;
2311 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002312
2313 if (pdev == NULL)
2314 return;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002315 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002316 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002317
Joe Perches086b3e82011-11-18 09:03:05 -08002318 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002319
Joe Perches086b3e82011-11-18 09:03:05 -08002320 vaf.fmt = fmt;
2321 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002322
Joe Perches086b3e82011-11-18 09:03:05 -08002323 /* <module-name> <dev-name>:<msg-id> Message */
2324 pr_warn("%s [%s]-%04x: : %pV",
2325 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002326
Joe Perches086b3e82011-11-18 09:03:05 -08002327 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002328}
2329
2330/*
2331 * This function is for formatting and logging log messages.
2332 * It is to be used when vha is available. It formats the message
2333 * and logs it to the messages file. All the messages will be logged
2334 * irrespective of value of ql2xextended_error_logging.
2335 * parameters:
2336 * level: The level of the log messages to be printed in the
2337 * messages file.
2338 * vha: Pointer to the scsi_qla_host_t
2339 * id: This is a unique id for the level. It identifies the
2340 * part of the code from where the message originated.
2341 * msg: The message to be displayed.
2342 */
2343void
Joe Perches086b3e82011-11-18 09:03:05 -08002344ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2345{
2346 va_list va;
2347 struct va_format vaf;
2348 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002349
Joe Perches086b3e82011-11-18 09:03:05 -08002350 if (level > ql_errlev)
2351 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002352
Joe Perches086b3e82011-11-18 09:03:05 -08002353 if (vha != NULL) {
2354 const struct pci_dev *pdev = vha->hw->pdev;
2355 /* <module-name> <msg-id>:<host> Message */
2356 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x:%ld: ",
2357 QL_MSGHDR, dev_name(&(pdev->dev)), id, vha->host_no);
2358 } else {
2359 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2360 QL_MSGHDR, "0000:00:00.0", id);
2361 }
2362 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002363
Joe Perches086b3e82011-11-18 09:03:05 -08002364 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002365
Joe Perches086b3e82011-11-18 09:03:05 -08002366 vaf.fmt = fmt;
2367 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002368
Joe Perches086b3e82011-11-18 09:03:05 -08002369 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002370 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002371 pr_crit("%s%pV", pbuf, &vaf);
2372 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002373 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002374 pr_err("%s%pV", pbuf, &vaf);
2375 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002376 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002377 pr_warn("%s%pV", pbuf, &vaf);
2378 break;
2379 default:
2380 pr_info("%s%pV", pbuf, &vaf);
2381 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002382 }
2383
Joe Perches086b3e82011-11-18 09:03:05 -08002384 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002385}
2386
2387/*
2388 * This function is for formatting and logging log messages.
2389 * It is to be used when vha is not available and pci is availble,
2390 * i.e., before host allocation. It formats the message and logs
2391 * it to the messages file. All the messages are logged irrespective
2392 * of the value of ql2xextended_error_logging.
2393 * parameters:
2394 * level: The level of the log messages to be printed in the
2395 * messages file.
2396 * pdev: Pointer to the struct pci_dev.
2397 * id: This is a unique id for the level. It identifies the
2398 * part of the code from where the message originated.
2399 * msg: The message to be displayed.
2400 */
2401void
Joe Perches086b3e82011-11-18 09:03:05 -08002402ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2403 const char *fmt, ...)
2404{
2405 va_list va;
2406 struct va_format vaf;
2407 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002408
2409 if (pdev == NULL)
2410 return;
Joe Perches086b3e82011-11-18 09:03:05 -08002411 if (level > ql_errlev)
2412 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002413
Joe Perches086b3e82011-11-18 09:03:05 -08002414 /* <module-name> <dev-name>:<msg-id> Message */
2415 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2416 QL_MSGHDR, dev_name(&(pdev->dev)), id);
2417 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002418
Joe Perches086b3e82011-11-18 09:03:05 -08002419 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002420
Joe Perches086b3e82011-11-18 09:03:05 -08002421 vaf.fmt = fmt;
2422 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002423
Joe Perches086b3e82011-11-18 09:03:05 -08002424 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002425 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002426 pr_crit("%s%pV", pbuf, &vaf);
2427 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002428 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002429 pr_err("%s%pV", pbuf, &vaf);
2430 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002431 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002432 pr_warn("%s%pV", pbuf, &vaf);
2433 break;
2434 default:
2435 pr_info("%s%pV", pbuf, &vaf);
2436 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002437 }
2438
Joe Perches086b3e82011-11-18 09:03:05 -08002439 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002440}
2441
2442void
2443ql_dump_regs(uint32_t level, scsi_qla_host_t *vha, int32_t id)
2444{
2445 int i;
2446 struct qla_hw_data *ha = vha->hw;
2447 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2448 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2449 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
2450 uint16_t __iomem *mbx_reg;
2451
Chad Dupuiscfb09192011-11-18 09:03:07 -08002452 if (!ql_mask_match(level))
2453 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002454
Chad Dupuiscfb09192011-11-18 09:03:07 -08002455 if (IS_QLA82XX(ha))
2456 mbx_reg = &reg82->mailbox_in[0];
2457 else if (IS_FWI2_CAPABLE(ha))
2458 mbx_reg = &reg24->mailbox0;
2459 else
2460 mbx_reg = MAILBOX_REG(ha, reg, 0);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002461
Chad Dupuiscfb09192011-11-18 09:03:07 -08002462 ql_dbg(level, vha, id, "Mailbox registers:\n");
2463 for (i = 0; i < 6; i++)
2464 ql_dbg(level, vha, id,
2465 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002466}
2467
2468
2469void
2470ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, int32_t id,
2471 uint8_t *b, uint32_t size)
2472{
2473 uint32_t cnt;
2474 uint8_t c;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002475
Chad Dupuiscfb09192011-11-18 09:03:07 -08002476 if (!ql_mask_match(level))
2477 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002478
Chad Dupuiscfb09192011-11-18 09:03:07 -08002479 ql_dbg(level, vha, id, " 0 1 2 3 4 5 6 7 8 "
2480 "9 Ah Bh Ch Dh Eh Fh\n");
2481 ql_dbg(level, vha, id, "----------------------------------"
2482 "----------------------------\n");
2483
2484 ql_dbg(level, vha, id, " ");
2485 for (cnt = 0; cnt < size;) {
2486 c = *b++;
2487 printk("%02x", (uint32_t) c);
2488 cnt++;
2489 if (!(cnt % 16))
2490 printk("\n");
2491 else
2492 printk(" ");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002493 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002494 if (cnt % 16)
2495 ql_dbg(level, vha, id, "\n");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002496}