blob: 53f9e492f9dc842167c60c7d3c033cd0a8386df7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Chad Dupuis46152ce2012-08-22 14:21:08 -04003 * Copyright (c) 2003-2012 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 * ----------------------------------------------------------------------
Saurav Kashyap68d91cb2012-11-21 02:40:44 -050014 * | Module Init and Probe | 0x0125 | 0x4b,0xba,0xfa |
Saurav Kashyap81178772012-08-22 14:21:04 -040015 * | Mailbox commands | 0x114f | 0x111a-0x111b |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040016 * | | | 0x112c-0x112e |
Andrew Vasquezaf11f642012-02-09 11:15:43 -080017 * | | | 0x113a |
Saurav Kashyap2a8593f2012-08-22 14:21:27 -040018 * | Device Discovery | 0x2087 | 0x2020-0x2022, |
19 * | | | 0x2016 |
Arun Easi9e522cd2012-08-22 14:21:31 -040020 * | Queue Command and IO tracing | 0x3030 | 0x3006-0x300b |
21 * | | | 0x3027-0x3028 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080022 * | | | 0x302d-0x302e |
Chad Dupuis8fcd6b82012-08-22 14:21:06 -040023 * | DPC Thread | 0x401d | 0x4002,0x4013 |
Saurav Kashyap81178772012-08-22 14:21:04 -040024 * | Async Events | 0x5071 | 0x502b-0x502f |
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080025 * | | | 0x5047,0x5052 |
Giridhar Malavali5988aeb2012-05-15 14:34:12 -040026 * | Timer Routines | 0x6011 | |
Chad Dupuisbf5b8ad2012-08-22 14:21:24 -040027 * | User Space Interactions | 0x70c3 | 0x7018,0x702e, |
Joe Carnuccio733a95b2012-02-09 11:15:55 -080028 * | | | 0x7039,0x7045, |
29 * | | | 0x7073-0x7075, |
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040030 * | | | 0x708c, |
31 * | | | 0x70a5,0x70a6, |
32 * | | | 0x70a8,0x70ab, |
33 * | | | 0x70ad-0x70ae |
Chad Dupuiscfb09192011-11-18 09:03:07 -080034 * | Task Management | 0x803c | 0x8025-0x8026 |
35 * | | | 0x800b,0x8039 |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040036 * | AER/EEH | 0x9011 | |
Arun Easie02587d2011-08-16 11:29:23 -070037 * | Virtual Port | 0xa007 | |
Chad Dupuis8fcd6b82012-08-22 14:21:06 -040038 * | ISP82XX Specific | 0xb084 | 0xb002,0xb024 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080039 * | MultiQ | 0xc00c | |
40 * | Misc | 0xd010 | |
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040041 * | Target Mode | 0xe06f | |
42 * | Target Mode Management | 0xf071 | |
43 * | Target Mode Task Management | 0x1000b | |
Arun Easie02587d2011-08-16 11:29:23 -070044 * ----------------------------------------------------------------------
Saurav Kashyap3ce88662011-07-14 12:00:12 -070045 */
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include "qla_def.h"
48
49#include <linux/delay.h>
50
Saurav Kashyap3ce88662011-07-14 12:00:12 -070051static uint32_t ql_dbg_offset = 0x800;
52
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070053static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080054qla2xxx_prep_dump(struct qla_hw_data *ha, struct qla2xxx_fw_dump *fw_dump)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070055{
56 fw_dump->fw_major_version = htonl(ha->fw_major_version);
57 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
58 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
59 fw_dump->fw_attributes = htonl(ha->fw_attributes);
60
61 fw_dump->vendor = htonl(ha->pdev->vendor);
62 fw_dump->device = htonl(ha->pdev->device);
63 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
64 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
65}
66
67static inline void *
Anirban Chakraborty73208df2008-12-09 16:45:39 -080068qla2xxx_copy_queues(struct qla_hw_data *ha, void *ptr)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070069{
Anirban Chakraborty73208df2008-12-09 16:45:39 -080070 struct req_que *req = ha->req_q_map[0];
71 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070072 /* Request queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080073 memcpy(ptr, req->ring, req->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070074 sizeof(request_t));
75
76 /* Response queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080077 ptr += req->length * sizeof(request_t);
78 memcpy(ptr, rsp->ring, rsp->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070079 sizeof(response_t));
80
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080081 return ptr + (rsp->length * sizeof(response_t));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070082}
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070084static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080085qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -070086 uint32_t ram_dwords, void **nxt)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070087{
88 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -070089 uint32_t cnt, stat, timer, dwords, idx;
90 uint16_t mb0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070091 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquezc5722702008-04-24 15:21:22 -070092 dma_addr_t dump_dma = ha->gid_list_dma;
93 uint32_t *dump = (uint32_t *)ha->gid_list;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070094
95 rval = QLA_SUCCESS;
Andrew Vasquezc5722702008-04-24 15:21:22 -070096 mb0 = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070097
Andrew Vasquezc5722702008-04-24 15:21:22 -070098 WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070099 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
100
Chad Dupuis642ef982012-02-09 11:15:57 -0800101 dwords = qla2x00_gid_list_size(ha) / 4;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700102 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
103 cnt += dwords, addr += dwords) {
104 if (cnt + dwords > ram_dwords)
105 dwords = ram_dwords - cnt;
106
107 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
108 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
109
110 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
111 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
112 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
113 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
114
115 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
116 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700117 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
118
119 for (timer = 6000000; timer; timer--) {
120 /* Check for pending interrupts. */
121 stat = RD_REG_DWORD(&reg->host_status);
122 if (stat & HSRX_RISC_INT) {
123 stat &= 0xff;
124
125 if (stat == 0x1 || stat == 0x2 ||
126 stat == 0x10 || stat == 0x11) {
127 set_bit(MBX_INTERRUPT,
128 &ha->mbx_cmd_flags);
129
Andrew Vasquezc5722702008-04-24 15:21:22 -0700130 mb0 = RD_REG_WORD(&reg->mailbox0);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700131
132 WRT_REG_DWORD(&reg->hccr,
133 HCCRX_CLR_RISC_INT);
134 RD_REG_DWORD(&reg->hccr);
135 break;
136 }
137
138 /* Clear this intr; it wasn't a mailbox intr */
139 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
140 RD_REG_DWORD(&reg->hccr);
141 }
142 udelay(5);
143 }
144
145 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
Andrew Vasquezc5722702008-04-24 15:21:22 -0700146 rval = mb0 & MBS_MASK;
147 for (idx = 0; idx < dwords; idx++)
148 ram[cnt + idx] = swab32(dump[idx]);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700149 } else {
150 rval = QLA_FUNCTION_FAILED;
151 }
152 }
153
Andrew Vasquezc5722702008-04-24 15:21:22 -0700154 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700155 return rval;
156}
157
Andrew Vasquezc5722702008-04-24 15:21:22 -0700158static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800159qla24xx_dump_memory(struct qla_hw_data *ha, uint32_t *code_ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700160 uint32_t cram_size, void **nxt)
161{
162 int rval;
163
164 /* Code RAM. */
165 rval = qla24xx_dump_ram(ha, 0x20000, code_ram, cram_size / 4, nxt);
166 if (rval != QLA_SUCCESS)
167 return rval;
168
169 /* External Memory. */
170 return qla24xx_dump_ram(ha, 0x100000, *nxt,
171 ha->fw_memory_size - 0x100000 + 1, nxt);
172}
173
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700174static uint32_t *
175qla24xx_read_window(struct device_reg_24xx __iomem *reg, uint32_t iobase,
176 uint32_t count, uint32_t *buf)
177{
178 uint32_t __iomem *dmp_reg;
179
180 WRT_REG_DWORD(&reg->iobase_addr, iobase);
181 dmp_reg = &reg->iobase_window;
182 while (count--)
183 *buf++ = htonl(RD_REG_DWORD(dmp_reg++));
184
185 return buf;
186}
187
188static inline int
189qla24xx_pause_risc(struct device_reg_24xx __iomem *reg)
190{
191 int rval = QLA_SUCCESS;
192 uint32_t cnt;
193
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700194 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
Andrew Vasquezaed10882009-06-03 09:55:26 -0700195 for (cnt = 30000;
196 ((RD_REG_DWORD(&reg->host_status) & HSRX_RISC_PAUSED) == 0) &&
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700197 rval == QLA_SUCCESS; cnt--) {
198 if (cnt)
199 udelay(100);
200 else
201 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700202 }
203
204 return rval;
205}
206
207static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800208qla24xx_soft_reset(struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700209{
210 int rval = QLA_SUCCESS;
211 uint32_t cnt;
212 uint16_t mb0, wd;
213 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
214
215 /* Reset RISC. */
216 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
217 for (cnt = 0; cnt < 30000; cnt++) {
218 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
219 break;
220
221 udelay(10);
222 }
223
224 WRT_REG_DWORD(&reg->ctrl_status,
225 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
226 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
227
228 udelay(100);
229 /* Wait for firmware to complete NVRAM accesses. */
230 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
231 for (cnt = 10000 ; cnt && mb0; cnt--) {
232 udelay(5);
233 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
234 barrier();
235 }
236
237 /* Wait for soft-reset to complete. */
238 for (cnt = 0; cnt < 30000; cnt++) {
239 if ((RD_REG_DWORD(&reg->ctrl_status) &
240 CSRX_ISP_SOFT_RESET) == 0)
241 break;
242
243 udelay(10);
244 }
245 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
246 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
247
248 for (cnt = 30000; RD_REG_WORD(&reg->mailbox0) != 0 &&
249 rval == QLA_SUCCESS; cnt--) {
250 if (cnt)
251 udelay(100);
252 else
253 rval = QLA_FUNCTION_TIMEOUT;
254 }
255
256 return rval;
257}
258
Andrew Vasquezc5722702008-04-24 15:21:22 -0700259static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800260qla2xxx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint16_t *ram,
Andrew Vasqueze18e9632009-06-17 10:30:31 -0700261 uint32_t ram_words, void **nxt)
Andrew Vasquezc5722702008-04-24 15:21:22 -0700262{
263 int rval;
264 uint32_t cnt, stat, timer, words, idx;
265 uint16_t mb0;
266 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
267 dma_addr_t dump_dma = ha->gid_list_dma;
268 uint16_t *dump = (uint16_t *)ha->gid_list;
269
270 rval = QLA_SUCCESS;
271 mb0 = 0;
272
273 WRT_MAILBOX_REG(ha, reg, 0, MBC_DUMP_RISC_RAM_EXTENDED);
274 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
275
Chad Dupuis642ef982012-02-09 11:15:57 -0800276 words = qla2x00_gid_list_size(ha) / 2;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700277 for (cnt = 0; cnt < ram_words && rval == QLA_SUCCESS;
278 cnt += words, addr += words) {
279 if (cnt + words > ram_words)
280 words = ram_words - cnt;
281
282 WRT_MAILBOX_REG(ha, reg, 1, LSW(addr));
283 WRT_MAILBOX_REG(ha, reg, 8, MSW(addr));
284
285 WRT_MAILBOX_REG(ha, reg, 2, MSW(dump_dma));
286 WRT_MAILBOX_REG(ha, reg, 3, LSW(dump_dma));
287 WRT_MAILBOX_REG(ha, reg, 6, MSW(MSD(dump_dma)));
288 WRT_MAILBOX_REG(ha, reg, 7, LSW(MSD(dump_dma)));
289
290 WRT_MAILBOX_REG(ha, reg, 4, words);
291 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
292
293 for (timer = 6000000; timer; timer--) {
294 /* Check for pending interrupts. */
295 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
296 if (stat & HSR_RISC_INT) {
297 stat &= 0xff;
298
299 if (stat == 0x1 || stat == 0x2) {
300 set_bit(MBX_INTERRUPT,
301 &ha->mbx_cmd_flags);
302
303 mb0 = RD_MAILBOX_REG(ha, reg, 0);
304
305 /* Release mailbox registers. */
306 WRT_REG_WORD(&reg->semaphore, 0);
307 WRT_REG_WORD(&reg->hccr,
308 HCCR_CLR_RISC_INT);
309 RD_REG_WORD(&reg->hccr);
310 break;
311 } else if (stat == 0x10 || stat == 0x11) {
312 set_bit(MBX_INTERRUPT,
313 &ha->mbx_cmd_flags);
314
315 mb0 = RD_MAILBOX_REG(ha, reg, 0);
316
317 WRT_REG_WORD(&reg->hccr,
318 HCCR_CLR_RISC_INT);
319 RD_REG_WORD(&reg->hccr);
320 break;
321 }
322
323 /* clear this intr; it wasn't a mailbox intr */
324 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
325 RD_REG_WORD(&reg->hccr);
326 }
327 udelay(5);
328 }
329
330 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
331 rval = mb0 & MBS_MASK;
332 for (idx = 0; idx < words; idx++)
333 ram[cnt + idx] = swab16(dump[idx]);
334 } else {
335 rval = QLA_FUNCTION_FAILED;
336 }
337 }
338
339 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
340 return rval;
341}
342
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700343static inline void
344qla2xxx_read_window(struct device_reg_2xxx __iomem *reg, uint32_t count,
345 uint16_t *buf)
346{
347 uint16_t __iomem *dmp_reg = &reg->u.isp2300.fb_cmd;
348
349 while (count--)
350 *buf++ = htons(RD_REG_WORD(dmp_reg++));
351}
352
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800353static inline void *
354qla24xx_copy_eft(struct qla_hw_data *ha, void *ptr)
355{
356 if (!ha->eft)
357 return ptr;
358
359 memcpy(ptr, ha->eft, ntohl(ha->fw_dump->eft_size));
360 return ptr + ntohl(ha->fw_dump->eft_size);
361}
362
363static inline void *
364qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
365{
366 uint32_t cnt;
367 uint32_t *iter_reg;
368 struct qla2xxx_fce_chain *fcec = ptr;
369
370 if (!ha->fce)
371 return ptr;
372
373 *last_chain = &fcec->type;
374 fcec->type = __constant_htonl(DUMP_CHAIN_FCE);
375 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
376 fce_calc_size(ha->fce_bufs));
377 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
378 fcec->addr_l = htonl(LSD(ha->fce_dma));
379 fcec->addr_h = htonl(MSD(ha->fce_dma));
380
381 iter_reg = fcec->eregs;
382 for (cnt = 0; cnt < 8; cnt++)
383 *iter_reg++ = htonl(ha->fce_mb[cnt]);
384
385 memcpy(iter_reg, ha->fce, ntohl(fcec->size));
386
Giridhar Malavali3cb0a672011-11-18 09:03:11 -0800387 return (char *)iter_reg + ntohl(fcec->size);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800388}
389
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800390static inline void *
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400391qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr,
392 uint32_t **last_chain)
393{
394 struct qla2xxx_mqueue_chain *q;
395 struct qla2xxx_mqueue_header *qh;
396 uint32_t num_queues;
397 int que;
398 struct {
399 int length;
400 void *ring;
401 } aq, *aqp;
402
403 if (!ha->tgt.atio_q_length)
404 return ptr;
405
406 num_queues = 1;
407 aqp = &aq;
408 aqp->length = ha->tgt.atio_q_length;
409 aqp->ring = ha->tgt.atio_ring;
410
411 for (que = 0; que < num_queues; que++) {
412 /* aqp = ha->atio_q_map[que]; */
413 q = ptr;
414 *last_chain = &q->type;
415 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
416 q->chain_size = htonl(
417 sizeof(struct qla2xxx_mqueue_chain) +
418 sizeof(struct qla2xxx_mqueue_header) +
419 (aqp->length * sizeof(request_t)));
420 ptr += sizeof(struct qla2xxx_mqueue_chain);
421
422 /* Add header. */
423 qh = ptr;
424 qh->queue = __constant_htonl(TYPE_ATIO_QUEUE);
425 qh->number = htonl(que);
426 qh->size = htonl(aqp->length * sizeof(request_t));
427 ptr += sizeof(struct qla2xxx_mqueue_header);
428
429 /* Add data. */
430 memcpy(ptr, aqp->ring, aqp->length * sizeof(request_t));
431
432 ptr += aqp->length * sizeof(request_t);
433 }
434
435 return ptr;
436}
437
438static inline void *
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800439qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
440{
441 struct qla2xxx_mqueue_chain *q;
442 struct qla2xxx_mqueue_header *qh;
443 struct req_que *req;
444 struct rsp_que *rsp;
445 int que;
446
447 if (!ha->mqenable)
448 return ptr;
449
450 /* Request queues */
451 for (que = 1; que < ha->max_req_queues; que++) {
452 req = ha->req_q_map[que];
453 if (!req)
454 break;
455
456 /* Add chain. */
457 q = ptr;
458 *last_chain = &q->type;
459 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
460 q->chain_size = htonl(
461 sizeof(struct qla2xxx_mqueue_chain) +
462 sizeof(struct qla2xxx_mqueue_header) +
463 (req->length * sizeof(request_t)));
464 ptr += sizeof(struct qla2xxx_mqueue_chain);
465
466 /* Add header. */
467 qh = ptr;
468 qh->queue = __constant_htonl(TYPE_REQUEST_QUEUE);
469 qh->number = htonl(que);
470 qh->size = htonl(req->length * sizeof(request_t));
471 ptr += sizeof(struct qla2xxx_mqueue_header);
472
473 /* Add data. */
474 memcpy(ptr, req->ring, req->length * sizeof(request_t));
475 ptr += req->length * sizeof(request_t);
476 }
477
478 /* Response queues */
479 for (que = 1; que < ha->max_rsp_queues; que++) {
480 rsp = ha->rsp_q_map[que];
481 if (!rsp)
482 break;
483
484 /* Add chain. */
485 q = ptr;
486 *last_chain = &q->type;
487 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
488 q->chain_size = htonl(
489 sizeof(struct qla2xxx_mqueue_chain) +
490 sizeof(struct qla2xxx_mqueue_header) +
491 (rsp->length * sizeof(response_t)));
492 ptr += sizeof(struct qla2xxx_mqueue_chain);
493
494 /* Add header. */
495 qh = ptr;
496 qh->queue = __constant_htonl(TYPE_RESPONSE_QUEUE);
497 qh->number = htonl(que);
498 qh->size = htonl(rsp->length * sizeof(response_t));
499 ptr += sizeof(struct qla2xxx_mqueue_header);
500
501 /* Add data. */
502 memcpy(ptr, rsp->ring, rsp->length * sizeof(response_t));
503 ptr += rsp->length * sizeof(response_t);
504 }
505
506 return ptr;
507}
508
509static inline void *
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800510qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
511{
512 uint32_t cnt, que_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700513 uint8_t que_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800514 struct qla2xxx_mq_chain *mq = ptr;
515 struct device_reg_25xxmq __iomem *reg;
516
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800517 if (!ha->mqenable || IS_QLA83XX(ha))
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800518 return ptr;
519
520 mq = ptr;
521 *last_chain = &mq->type;
522 mq->type = __constant_htonl(DUMP_CHAIN_MQ);
523 mq->chain_size = __constant_htonl(sizeof(struct qla2xxx_mq_chain));
524
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700525 que_cnt = ha->max_req_queues > ha->max_rsp_queues ?
526 ha->max_req_queues : ha->max_rsp_queues;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800527 mq->count = htonl(que_cnt);
528 for (cnt = 0; cnt < que_cnt; cnt++) {
Saurav Kashyapfa492632012-11-21 02:40:29 -0500529 reg = (struct device_reg_25xxmq __iomem *)
530 (ha->mqiobase + cnt * QLA_QUE_PAGE);
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800531 que_idx = cnt * 4;
532 mq->qregs[que_idx] = htonl(RD_REG_DWORD(&reg->req_q_in));
533 mq->qregs[que_idx+1] = htonl(RD_REG_DWORD(&reg->req_q_out));
534 mq->qregs[que_idx+2] = htonl(RD_REG_DWORD(&reg->rsp_q_in));
535 mq->qregs[que_idx+3] = htonl(RD_REG_DWORD(&reg->rsp_q_out));
536 }
537
538 return ptr + sizeof(struct qla2xxx_mq_chain);
539}
540
Giridhar Malavali08de2842011-08-16 11:31:44 -0700541void
Andrew Vasquez3420d362009-10-13 15:16:45 -0700542qla2xxx_dump_post_process(scsi_qla_host_t *vha, int rval)
543{
544 struct qla_hw_data *ha = vha->hw;
545
546 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700547 ql_log(ql_log_warn, vha, 0xd000,
548 "Failed to dump firmware (%x).\n", rval);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700549 ha->fw_dumped = 0;
550 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700551 ql_log(ql_log_info, vha, 0xd001,
Andrew Vasquez3420d362009-10-13 15:16:45 -0700552 "Firmware dump saved to temp buffer (%ld/%p).\n",
553 vha->host_no, ha->fw_dump);
554 ha->fw_dumped = 1;
555 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
556 }
557}
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559/**
560 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
561 * @ha: HA context
562 * @hardware_locked: Called with the hardware_lock
563 */
564void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800565qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
567 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700568 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800569 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700570 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 uint16_t __iomem *dmp_reg;
572 unsigned long flags;
573 struct qla2300_fw_dump *fw;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700574 void *nxt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800575 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 flags = 0;
578
579 if (!hardware_locked)
580 spin_lock_irqsave(&ha->hardware_lock, flags);
581
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700582 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700583 ql_log(ql_log_warn, vha, 0xd002,
584 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 goto qla2300_fw_dump_failed;
586 }
587
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700588 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700589 ql_log(ql_log_warn, vha, 0xd003,
590 "Firmware has been previously dumped (%p) "
591 "-- ignoring request.\n",
592 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 goto qla2300_fw_dump_failed;
594 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700595 fw = &ha->fw_dump->isp.isp23;
596 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700599 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700602 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (IS_QLA2300(ha)) {
604 for (cnt = 30000;
605 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
606 rval == QLA_SUCCESS; cnt--) {
607 if (cnt)
608 udelay(100);
609 else
610 rval = QLA_FUNCTION_TIMEOUT;
611 }
612 } else {
613 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
614 udelay(10);
615 }
616
617 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700618 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700619 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700620 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700622 dmp_reg = &reg->u.isp2300.req_q_in;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700623 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700624 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700626 dmp_reg = &reg->u.isp2300.mailbox0;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700627 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700628 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 WRT_REG_WORD(&reg->ctrl_status, 0x40);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700631 qla2xxx_read_window(reg, 32, fw->resp_dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 WRT_REG_WORD(&reg->ctrl_status, 0x50);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700634 qla2xxx_read_window(reg, 48, fw->dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700637 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700638 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700639 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700641 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700642 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700644 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700645 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700647 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700648 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700650 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700651 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700653 WRT_REG_WORD(&reg->pcr, 0x2800);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700654 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700656 WRT_REG_WORD(&reg->pcr, 0x2A00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700657 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700659 WRT_REG_WORD(&reg->pcr, 0x2C00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700660 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700662 WRT_REG_WORD(&reg->pcr, 0x2E00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700663 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700665 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700666 qla2xxx_read_window(reg, 64, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700668 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700669 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700671 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700672 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674 /* Reset RISC. */
675 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
676 for (cnt = 0; cnt < 30000; cnt++) {
677 if ((RD_REG_WORD(&reg->ctrl_status) &
678 CSR_ISP_SOFT_RESET) == 0)
679 break;
680
681 udelay(10);
682 }
683 }
684
685 if (!IS_QLA2300(ha)) {
686 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
687 rval == QLA_SUCCESS; cnt--) {
688 if (cnt)
689 udelay(100);
690 else
691 rval = QLA_FUNCTION_TIMEOUT;
692 }
693 }
694
Andrew Vasquezc5722702008-04-24 15:21:22 -0700695 /* Get RISC SRAM. */
696 if (rval == QLA_SUCCESS)
697 rval = qla2xxx_dump_ram(ha, 0x800, fw->risc_ram,
698 sizeof(fw->risc_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Andrew Vasquezc5722702008-04-24 15:21:22 -0700700 /* Get stack SRAM. */
701 if (rval == QLA_SUCCESS)
702 rval = qla2xxx_dump_ram(ha, 0x10000, fw->stack_ram,
703 sizeof(fw->stack_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Andrew Vasquezc5722702008-04-24 15:21:22 -0700705 /* Get data SRAM. */
706 if (rval == QLA_SUCCESS)
707 rval = qla2xxx_dump_ram(ha, 0x11000, fw->data_ram,
708 ha->fw_memory_size - 0x11000 + 1, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700710 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800711 qla2xxx_copy_queues(ha, nxt);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700712
Andrew Vasquez3420d362009-10-13 15:16:45 -0700713 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715qla2300_fw_dump_failed:
716 if (!hardware_locked)
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
718}
719
720/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
722 * @ha: HA context
723 * @hardware_locked: Called with the hardware_lock
724 */
725void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800726qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
728 int rval;
729 uint32_t cnt, timer;
730 uint16_t risc_address;
731 uint16_t mb0, mb2;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800732 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700733 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 uint16_t __iomem *dmp_reg;
735 unsigned long flags;
736 struct qla2100_fw_dump *fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800737 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 risc_address = 0;
740 mb0 = mb2 = 0;
741 flags = 0;
742
743 if (!hardware_locked)
744 spin_lock_irqsave(&ha->hardware_lock, flags);
745
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700746 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700747 ql_log(ql_log_warn, vha, 0xd004,
748 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 goto qla2100_fw_dump_failed;
750 }
751
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700752 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700753 ql_log(ql_log_warn, vha, 0xd005,
754 "Firmware has been previously dumped (%p) "
755 "-- ignoring request.\n",
756 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 goto qla2100_fw_dump_failed;
758 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700759 fw = &ha->fw_dump->isp.isp21;
760 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700763 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700766 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
768 rval == QLA_SUCCESS; cnt--) {
769 if (cnt)
770 udelay(100);
771 else
772 rval = QLA_FUNCTION_TIMEOUT;
773 }
774 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700775 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700776 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700777 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700779 dmp_reg = &reg->u.isp2100.mailbox0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700781 if (cnt == 8)
782 dmp_reg = &reg->u_end.isp2200.mailbox8;
783
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700784 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 }
786
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700787 dmp_reg = &reg->u.isp2100.unused_2[0];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700788 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700789 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700792 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700793 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700794 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700796 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700797 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700799 WRT_REG_WORD(&reg->pcr, 0x2100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700800 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700802 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700803 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700805 WRT_REG_WORD(&reg->pcr, 0x2300);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700806 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700808 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700809 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700811 WRT_REG_WORD(&reg->pcr, 0x2500);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700812 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700814 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700815 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700817 WRT_REG_WORD(&reg->pcr, 0x2700);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700818 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700820 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700821 qla2xxx_read_window(reg, 16, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700823 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700824 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700826 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700827 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* Reset the ISP. */
830 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
831 }
832
833 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
834 rval == QLA_SUCCESS; cnt--) {
835 if (cnt)
836 udelay(100);
837 else
838 rval = QLA_FUNCTION_TIMEOUT;
839 }
840
841 /* Pause RISC. */
842 if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
843 (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {
844
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700845 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 for (cnt = 30000;
847 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
848 rval == QLA_SUCCESS; cnt--) {
849 if (cnt)
850 udelay(100);
851 else
852 rval = QLA_FUNCTION_TIMEOUT;
853 }
854 if (rval == QLA_SUCCESS) {
855 /* Set memory configuration and timing. */
856 if (IS_QLA2100(ha))
857 WRT_REG_WORD(&reg->mctr, 0xf1);
858 else
859 WRT_REG_WORD(&reg->mctr, 0xf2);
860 RD_REG_WORD(&reg->mctr); /* PCI Posting. */
861
862 /* Release RISC. */
863 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
864 }
865 }
866
867 if (rval == QLA_SUCCESS) {
868 /* Get RISC SRAM. */
869 risc_address = 0x1000;
870 WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
871 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
872 }
873 for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
874 cnt++, risc_address++) {
875 WRT_MAILBOX_REG(ha, reg, 1, risc_address);
876 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
877
878 for (timer = 6000000; timer != 0; timer--) {
879 /* Check for pending interrupts. */
880 if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
881 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
882 set_bit(MBX_INTERRUPT,
883 &ha->mbx_cmd_flags);
884
885 mb0 = RD_MAILBOX_REG(ha, reg, 0);
886 mb2 = RD_MAILBOX_REG(ha, reg, 2);
887
888 WRT_REG_WORD(&reg->semaphore, 0);
889 WRT_REG_WORD(&reg->hccr,
890 HCCR_CLR_RISC_INT);
891 RD_REG_WORD(&reg->hccr);
892 break;
893 }
894 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
895 RD_REG_WORD(&reg->hccr);
896 }
897 udelay(5);
898 }
899
900 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
901 rval = mb0 & MBS_MASK;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700902 fw->risc_ram[cnt] = htons(mb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 } else {
904 rval = QLA_FUNCTION_FAILED;
905 }
906 }
907
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700908 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800909 qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700910
Andrew Vasquez3420d362009-10-13 15:16:45 -0700911 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913qla2100_fw_dump_failed:
914 if (!hardware_locked)
915 spin_unlock_irqrestore(&ha->hardware_lock, flags);
916}
917
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700918void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800919qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700920{
921 int rval;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700922 uint32_t cnt;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700923 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800924 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700925 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
926 uint32_t __iomem *dmp_reg;
927 uint32_t *iter_reg;
928 uint16_t __iomem *mbx_reg;
929 unsigned long flags;
930 struct qla24xx_fw_dump *fw;
931 uint32_t ext_mem_cnt;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700932 void *nxt;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400933 void *nxt_chain;
934 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800935 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700936
Giridhar Malavalia9083012010-04-12 17:59:55 -0700937 if (IS_QLA82XX(ha))
938 return;
939
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700940 risc_address = ext_mem_cnt = 0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700941 flags = 0;
942
943 if (!hardware_locked)
944 spin_lock_irqsave(&ha->hardware_lock, flags);
945
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700946 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700947 ql_log(ql_log_warn, vha, 0xd006,
948 "No buffer available for dump.\n");
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700949 goto qla24xx_fw_dump_failed;
950 }
951
952 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700953 ql_log(ql_log_warn, vha, 0xd007,
954 "Firmware has been previously dumped (%p) "
955 "-- ignoring request.\n",
956 ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700957 goto qla24xx_fw_dump_failed;
958 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700959 fw = &ha->fw_dump->isp.isp24;
960 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700961
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700962 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700963
964 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700965 rval = qla24xx_pause_risc(reg);
966 if (rval != QLA_SUCCESS)
967 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700968
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700969 /* Host interface registers. */
970 dmp_reg = &reg->flash_addr;
971 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
972 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700973
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700974 /* Disable interrupts. */
975 WRT_REG_DWORD(&reg->ictrl, 0);
976 RD_REG_DWORD(&reg->ictrl);
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800977
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700978 /* Shadow registers. */
979 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
980 RD_REG_DWORD(&reg->iobase_addr);
981 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
982 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800983
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700984 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
985 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800986
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700987 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
988 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800989
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700990 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
991 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800992
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700993 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
994 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800995
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700996 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
997 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800998
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700999 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1000 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001001
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001002 /* Mailbox registers. */
1003 mbx_reg = &reg->mailbox0;
1004 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1005 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001006
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001007 /* Transfer sequence registers. */
1008 iter_reg = fw->xseq_gp_reg;
1009 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1010 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1011 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1012 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1013 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1014 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1015 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1016 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001017
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001018 qla24xx_read_window(reg, 0xBFE0, 16, fw->xseq_0_reg);
1019 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001020
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001021 /* Receive sequence registers. */
1022 iter_reg = fw->rseq_gp_reg;
1023 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1024 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1025 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1026 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1027 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1028 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1029 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1030 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001031
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001032 qla24xx_read_window(reg, 0xFFD0, 16, fw->rseq_0_reg);
1033 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1034 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001035
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001036 /* Command DMA registers. */
1037 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001038
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001039 /* Queues. */
1040 iter_reg = fw->req0_dma_reg;
1041 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1042 dmp_reg = &reg->iobase_q;
1043 for (cnt = 0; cnt < 7; cnt++)
1044 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001045
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001046 iter_reg = fw->resp0_dma_reg;
1047 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1048 dmp_reg = &reg->iobase_q;
1049 for (cnt = 0; cnt < 7; cnt++)
1050 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001051
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001052 iter_reg = fw->req1_dma_reg;
1053 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1054 dmp_reg = &reg->iobase_q;
1055 for (cnt = 0; cnt < 7; cnt++)
1056 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001057
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001058 /* Transmit DMA registers. */
1059 iter_reg = fw->xmt0_dma_reg;
1060 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1061 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001062
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001063 iter_reg = fw->xmt1_dma_reg;
1064 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1065 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001066
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001067 iter_reg = fw->xmt2_dma_reg;
1068 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1069 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001070
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001071 iter_reg = fw->xmt3_dma_reg;
1072 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1073 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001074
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001075 iter_reg = fw->xmt4_dma_reg;
1076 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1077 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001078
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001079 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001080
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001081 /* Receive DMA registers. */
1082 iter_reg = fw->rcvt0_data_dma_reg;
1083 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1084 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001085
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001086 iter_reg = fw->rcvt1_data_dma_reg;
1087 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1088 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001089
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001090 /* RISC registers. */
1091 iter_reg = fw->risc_gp_reg;
1092 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1093 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1094 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1095 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1096 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1097 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1098 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1099 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001100
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001101 /* Local memory controller registers. */
1102 iter_reg = fw->lmc_reg;
1103 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1104 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1105 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1106 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1107 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1108 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1109 qla24xx_read_window(reg, 0x3060, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001110
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001111 /* Fibre Protocol Module registers. */
1112 iter_reg = fw->fpm_hdw_reg;
1113 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1114 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1115 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1116 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1117 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1118 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1119 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1120 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1121 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1122 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1123 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1124 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001125
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001126 /* Frame Buffer registers. */
1127 iter_reg = fw->fb_hdw_reg;
1128 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1129 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1130 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1131 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1132 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1133 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1134 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1135 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1136 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1137 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1138 qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001139
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001140 rval = qla24xx_soft_reset(ha);
1141 if (rval != QLA_SUCCESS)
1142 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001143
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001144 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001145 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001146 if (rval != QLA_SUCCESS)
1147 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001148
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001149 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001150
1151 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001152
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001153 nxt_chain = (void *)ha->fw_dump + ha->chain_offset;
1154 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
1155 if (last_chain) {
1156 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1157 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1158 }
1159
1160 /* Adjust valid length. */
1161 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1162
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001163qla24xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001164 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001165
1166qla24xx_fw_dump_failed:
1167 if (!hardware_locked)
1168 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1169}
1170
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001171void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001172qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001173{
1174 int rval;
1175 uint32_t cnt;
1176 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001177 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001178 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1179 uint32_t __iomem *dmp_reg;
1180 uint32_t *iter_reg;
1181 uint16_t __iomem *mbx_reg;
1182 unsigned long flags;
1183 struct qla25xx_fw_dump *fw;
1184 uint32_t ext_mem_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001185 void *nxt, *nxt_chain;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001186 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001187 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001188
1189 risc_address = ext_mem_cnt = 0;
1190 flags = 0;
1191
1192 if (!hardware_locked)
1193 spin_lock_irqsave(&ha->hardware_lock, flags);
1194
1195 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001196 ql_log(ql_log_warn, vha, 0xd008,
1197 "No buffer available for dump.\n");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001198 goto qla25xx_fw_dump_failed;
1199 }
1200
1201 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001202 ql_log(ql_log_warn, vha, 0xd009,
1203 "Firmware has been previously dumped (%p) "
1204 "-- ignoring request.\n",
1205 ha->fw_dump);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001206 goto qla25xx_fw_dump_failed;
1207 }
1208 fw = &ha->fw_dump->isp.isp25;
1209 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquezb5836922007-09-20 14:07:39 -07001210 ha->fw_dump->version = __constant_htonl(2);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001211
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001212 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1213
1214 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001215 rval = qla24xx_pause_risc(reg);
1216 if (rval != QLA_SUCCESS)
1217 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001218
Andrew Vasquezb5836922007-09-20 14:07:39 -07001219 /* Host/Risc registers. */
1220 iter_reg = fw->host_risc_reg;
1221 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1222 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1223
1224 /* PCIe registers. */
1225 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1226 RD_REG_DWORD(&reg->iobase_addr);
1227 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1228 dmp_reg = &reg->iobase_c4;
1229 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1230 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1231 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1232 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001233
Andrew Vasquezb5836922007-09-20 14:07:39 -07001234 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1235 RD_REG_DWORD(&reg->iobase_window);
1236
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001237 /* Host interface registers. */
1238 dmp_reg = &reg->flash_addr;
1239 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1240 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001241
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001242 /* Disable interrupts. */
1243 WRT_REG_DWORD(&reg->ictrl, 0);
1244 RD_REG_DWORD(&reg->ictrl);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001245
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001246 /* Shadow registers. */
1247 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1248 RD_REG_DWORD(&reg->iobase_addr);
1249 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1250 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001251
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001252 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1253 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001254
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001255 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1256 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001257
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001258 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1259 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001260
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001261 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1262 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001263
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001264 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1265 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001266
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001267 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1268 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001269
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001270 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1271 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001272
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001273 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1274 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001275
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001276 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1277 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001278
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001279 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1280 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001281
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001282 /* RISC I/O register. */
1283 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1284 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001285
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001286 /* Mailbox registers. */
1287 mbx_reg = &reg->mailbox0;
1288 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1289 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001290
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001291 /* Transfer sequence registers. */
1292 iter_reg = fw->xseq_gp_reg;
1293 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1294 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1295 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1296 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1297 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1298 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1299 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1300 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001301
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001302 iter_reg = fw->xseq_0_reg;
1303 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1304 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1305 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001306
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001307 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001308
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001309 /* Receive sequence registers. */
1310 iter_reg = fw->rseq_gp_reg;
1311 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1312 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1313 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1314 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1315 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1316 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1317 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1318 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001319
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001320 iter_reg = fw->rseq_0_reg;
1321 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1322 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001323
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001324 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1325 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001326
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001327 /* Auxiliary sequence registers. */
1328 iter_reg = fw->aseq_gp_reg;
1329 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1330 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1331 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1332 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1333 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1334 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1335 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1336 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001337
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001338 iter_reg = fw->aseq_0_reg;
1339 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1340 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001341
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001342 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1343 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001344
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001345 /* Command DMA registers. */
1346 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001347
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001348 /* Queues. */
1349 iter_reg = fw->req0_dma_reg;
1350 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1351 dmp_reg = &reg->iobase_q;
1352 for (cnt = 0; cnt < 7; cnt++)
1353 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001354
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001355 iter_reg = fw->resp0_dma_reg;
1356 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1357 dmp_reg = &reg->iobase_q;
1358 for (cnt = 0; cnt < 7; cnt++)
1359 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001360
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001361 iter_reg = fw->req1_dma_reg;
1362 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1363 dmp_reg = &reg->iobase_q;
1364 for (cnt = 0; cnt < 7; cnt++)
1365 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001366
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001367 /* Transmit DMA registers. */
1368 iter_reg = fw->xmt0_dma_reg;
1369 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1370 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001371
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001372 iter_reg = fw->xmt1_dma_reg;
1373 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1374 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001375
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001376 iter_reg = fw->xmt2_dma_reg;
1377 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1378 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001379
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001380 iter_reg = fw->xmt3_dma_reg;
1381 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1382 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001383
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001384 iter_reg = fw->xmt4_dma_reg;
1385 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1386 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001387
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001388 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001389
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001390 /* Receive DMA registers. */
1391 iter_reg = fw->rcvt0_data_dma_reg;
1392 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1393 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001394
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001395 iter_reg = fw->rcvt1_data_dma_reg;
1396 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1397 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001398
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001399 /* RISC registers. */
1400 iter_reg = fw->risc_gp_reg;
1401 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1402 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1403 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1404 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1405 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1406 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1407 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1408 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001409
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001410 /* Local memory controller registers. */
1411 iter_reg = fw->lmc_reg;
1412 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1413 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1414 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1415 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1416 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1417 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1418 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1419 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001420
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001421 /* Fibre Protocol Module registers. */
1422 iter_reg = fw->fpm_hdw_reg;
1423 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1424 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1425 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1426 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1427 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1428 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1429 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1430 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1431 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1432 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1433 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1434 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001435
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001436 /* Frame Buffer registers. */
1437 iter_reg = fw->fb_hdw_reg;
1438 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1439 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1440 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1441 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1442 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1443 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1444 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1445 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1446 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1447 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1448 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1449 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001450
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001451 /* Multi queue registers */
1452 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1453 &last_chain);
1454
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001455 rval = qla24xx_soft_reset(ha);
1456 if (rval != QLA_SUCCESS)
1457 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001458
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001459 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001460 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001461 if (rval != QLA_SUCCESS)
1462 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001463
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001464 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001465
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001466 nxt = qla24xx_copy_eft(ha, nxt);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001467
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001468 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001469 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1470 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001471 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001472 if (last_chain) {
1473 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1474 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1475 }
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001476
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001477 /* Adjust valid length. */
1478 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1479
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001480qla25xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001481 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001482
1483qla25xx_fw_dump_failed:
1484 if (!hardware_locked)
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1486}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001487
1488void
1489qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1490{
1491 int rval;
1492 uint32_t cnt;
1493 uint32_t risc_address;
1494 struct qla_hw_data *ha = vha->hw;
1495 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1496 uint32_t __iomem *dmp_reg;
1497 uint32_t *iter_reg;
1498 uint16_t __iomem *mbx_reg;
1499 unsigned long flags;
1500 struct qla81xx_fw_dump *fw;
1501 uint32_t ext_mem_cnt;
1502 void *nxt, *nxt_chain;
1503 uint32_t *last_chain = NULL;
1504 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1505
1506 risc_address = ext_mem_cnt = 0;
1507 flags = 0;
1508
1509 if (!hardware_locked)
1510 spin_lock_irqsave(&ha->hardware_lock, flags);
1511
1512 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001513 ql_log(ql_log_warn, vha, 0xd00a,
1514 "No buffer available for dump.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001515 goto qla81xx_fw_dump_failed;
1516 }
1517
1518 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001519 ql_log(ql_log_warn, vha, 0xd00b,
1520 "Firmware has been previously dumped (%p) "
1521 "-- ignoring request.\n",
1522 ha->fw_dump);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001523 goto qla81xx_fw_dump_failed;
1524 }
1525 fw = &ha->fw_dump->isp.isp81;
1526 qla2xxx_prep_dump(ha, ha->fw_dump);
1527
1528 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1529
1530 /* Pause RISC. */
1531 rval = qla24xx_pause_risc(reg);
1532 if (rval != QLA_SUCCESS)
1533 goto qla81xx_fw_dump_failed_0;
1534
1535 /* Host/Risc registers. */
1536 iter_reg = fw->host_risc_reg;
1537 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1538 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1539
1540 /* PCIe registers. */
1541 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1542 RD_REG_DWORD(&reg->iobase_addr);
1543 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1544 dmp_reg = &reg->iobase_c4;
1545 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1546 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1547 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1548 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1549
1550 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1551 RD_REG_DWORD(&reg->iobase_window);
1552
1553 /* Host interface registers. */
1554 dmp_reg = &reg->flash_addr;
1555 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1556 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1557
1558 /* Disable interrupts. */
1559 WRT_REG_DWORD(&reg->ictrl, 0);
1560 RD_REG_DWORD(&reg->ictrl);
1561
1562 /* Shadow registers. */
1563 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1564 RD_REG_DWORD(&reg->iobase_addr);
1565 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1566 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1567
1568 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1569 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1570
1571 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1572 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1573
1574 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1575 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1576
1577 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1578 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1579
1580 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1581 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1582
1583 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1584 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1585
1586 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1587 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1588
1589 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1590 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1591
1592 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1593 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1594
1595 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1596 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1597
1598 /* RISC I/O register. */
1599 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1600 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1601
1602 /* Mailbox registers. */
1603 mbx_reg = &reg->mailbox0;
1604 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1605 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1606
1607 /* Transfer sequence registers. */
1608 iter_reg = fw->xseq_gp_reg;
1609 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1610 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1611 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1612 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1613 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1614 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1615 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1616 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1617
1618 iter_reg = fw->xseq_0_reg;
1619 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1620 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1621 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1622
1623 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1624
1625 /* Receive sequence registers. */
1626 iter_reg = fw->rseq_gp_reg;
1627 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1628 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1629 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1630 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1631 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1632 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1633 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1634 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1635
1636 iter_reg = fw->rseq_0_reg;
1637 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1638 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1639
1640 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1641 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1642
1643 /* Auxiliary sequence registers. */
1644 iter_reg = fw->aseq_gp_reg;
1645 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1646 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1647 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1648 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1649 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1650 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1651 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1652 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
1653
1654 iter_reg = fw->aseq_0_reg;
1655 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1656 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
1657
1658 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1659 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
1660
1661 /* Command DMA registers. */
1662 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
1663
1664 /* Queues. */
1665 iter_reg = fw->req0_dma_reg;
1666 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1667 dmp_reg = &reg->iobase_q;
1668 for (cnt = 0; cnt < 7; cnt++)
1669 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1670
1671 iter_reg = fw->resp0_dma_reg;
1672 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1673 dmp_reg = &reg->iobase_q;
1674 for (cnt = 0; cnt < 7; cnt++)
1675 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1676
1677 iter_reg = fw->req1_dma_reg;
1678 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1679 dmp_reg = &reg->iobase_q;
1680 for (cnt = 0; cnt < 7; cnt++)
1681 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1682
1683 /* Transmit DMA registers. */
1684 iter_reg = fw->xmt0_dma_reg;
1685 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1686 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
1687
1688 iter_reg = fw->xmt1_dma_reg;
1689 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1690 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
1691
1692 iter_reg = fw->xmt2_dma_reg;
1693 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1694 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
1695
1696 iter_reg = fw->xmt3_dma_reg;
1697 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1698 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
1699
1700 iter_reg = fw->xmt4_dma_reg;
1701 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1702 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
1703
1704 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
1705
1706 /* Receive DMA registers. */
1707 iter_reg = fw->rcvt0_data_dma_reg;
1708 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1709 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
1710
1711 iter_reg = fw->rcvt1_data_dma_reg;
1712 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1713 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
1714
1715 /* RISC registers. */
1716 iter_reg = fw->risc_gp_reg;
1717 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1718 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1719 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1720 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1721 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1722 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1723 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1724 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
1725
1726 /* Local memory controller registers. */
1727 iter_reg = fw->lmc_reg;
1728 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1729 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1730 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1731 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1732 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1733 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1734 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1735 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
1736
1737 /* Fibre Protocol Module registers. */
1738 iter_reg = fw->fpm_hdw_reg;
1739 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1740 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1741 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1742 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1743 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1744 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1745 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1746 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1747 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1748 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1749 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1750 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
1751 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
1752 qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
1753
1754 /* Frame Buffer registers. */
1755 iter_reg = fw->fb_hdw_reg;
1756 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1757 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1758 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1759 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1760 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1761 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1762 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1763 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1764 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1765 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1766 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1767 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
1768 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
1769
1770 /* Multi queue registers */
1771 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1772 &last_chain);
1773
1774 rval = qla24xx_soft_reset(ha);
1775 if (rval != QLA_SUCCESS)
1776 goto qla81xx_fw_dump_failed_0;
1777
1778 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
1779 &nxt);
1780 if (rval != QLA_SUCCESS)
1781 goto qla81xx_fw_dump_failed_0;
1782
1783 nxt = qla2xxx_copy_queues(ha, nxt);
1784
1785 nxt = qla24xx_copy_eft(ha, nxt);
1786
1787 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001788 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1789 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001790 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001791 if (last_chain) {
1792 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1793 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1794 }
1795
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001796 /* Adjust valid length. */
1797 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1798
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001799qla81xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001800 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001801
1802qla81xx_fw_dump_failed:
1803 if (!hardware_locked)
1804 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1805}
1806
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001807void
1808qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1809{
1810 int rval;
1811 uint32_t cnt, reg_data;
1812 uint32_t risc_address;
1813 struct qla_hw_data *ha = vha->hw;
1814 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1815 uint32_t __iomem *dmp_reg;
1816 uint32_t *iter_reg;
1817 uint16_t __iomem *mbx_reg;
1818 unsigned long flags;
1819 struct qla83xx_fw_dump *fw;
1820 uint32_t ext_mem_cnt;
1821 void *nxt, *nxt_chain;
1822 uint32_t *last_chain = NULL;
1823 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1824
1825 risc_address = ext_mem_cnt = 0;
1826 flags = 0;
1827
1828 if (!hardware_locked)
1829 spin_lock_irqsave(&ha->hardware_lock, flags);
1830
1831 if (!ha->fw_dump) {
1832 ql_log(ql_log_warn, vha, 0xd00c,
1833 "No buffer available for dump!!!\n");
1834 goto qla83xx_fw_dump_failed;
1835 }
1836
1837 if (ha->fw_dumped) {
1838 ql_log(ql_log_warn, vha, 0xd00d,
1839 "Firmware has been previously dumped (%p) -- ignoring "
1840 "request...\n", ha->fw_dump);
1841 goto qla83xx_fw_dump_failed;
1842 }
1843 fw = &ha->fw_dump->isp.isp83;
1844 qla2xxx_prep_dump(ha, ha->fw_dump);
1845
1846 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1847
1848 /* Pause RISC. */
1849 rval = qla24xx_pause_risc(reg);
1850 if (rval != QLA_SUCCESS)
1851 goto qla83xx_fw_dump_failed_0;
1852
1853 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
1854 dmp_reg = &reg->iobase_window;
1855 reg_data = RD_REG_DWORD(dmp_reg);
1856 WRT_REG_DWORD(dmp_reg, 0);
1857
1858 dmp_reg = &reg->unused_4_1[0];
1859 reg_data = RD_REG_DWORD(dmp_reg);
1860 WRT_REG_DWORD(dmp_reg, 0);
1861
1862 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
1863 dmp_reg = &reg->unused_4_1[2];
1864 reg_data = RD_REG_DWORD(dmp_reg);
1865 WRT_REG_DWORD(dmp_reg, 0);
1866
1867 /* select PCR and disable ecc checking and correction */
1868 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1869 RD_REG_DWORD(&reg->iobase_addr);
1870 WRT_REG_DWORD(&reg->iobase_select, 0x60000000); /* write to F0h = PCR */
1871
1872 /* Host/Risc registers. */
1873 iter_reg = fw->host_risc_reg;
1874 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1875 iter_reg = qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1876 qla24xx_read_window(reg, 0x7040, 16, iter_reg);
1877
1878 /* PCIe registers. */
1879 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1880 RD_REG_DWORD(&reg->iobase_addr);
1881 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1882 dmp_reg = &reg->iobase_c4;
1883 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1884 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1885 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1886 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1887
1888 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1889 RD_REG_DWORD(&reg->iobase_window);
1890
1891 /* Host interface registers. */
1892 dmp_reg = &reg->flash_addr;
1893 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1894 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1895
1896 /* Disable interrupts. */
1897 WRT_REG_DWORD(&reg->ictrl, 0);
1898 RD_REG_DWORD(&reg->ictrl);
1899
1900 /* Shadow registers. */
1901 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1902 RD_REG_DWORD(&reg->iobase_addr);
1903 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1904 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1905
1906 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1907 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1908
1909 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1910 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1911
1912 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1913 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1914
1915 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1916 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1917
1918 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1919 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1920
1921 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1922 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1923
1924 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1925 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1926
1927 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1928 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1929
1930 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1931 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1932
1933 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1934 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1935
1936 /* RISC I/O register. */
1937 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1938 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1939
1940 /* Mailbox registers. */
1941 mbx_reg = &reg->mailbox0;
1942 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1943 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1944
1945 /* Transfer sequence registers. */
1946 iter_reg = fw->xseq_gp_reg;
1947 iter_reg = qla24xx_read_window(reg, 0xBE00, 16, iter_reg);
1948 iter_reg = qla24xx_read_window(reg, 0xBE10, 16, iter_reg);
1949 iter_reg = qla24xx_read_window(reg, 0xBE20, 16, iter_reg);
1950 iter_reg = qla24xx_read_window(reg, 0xBE30, 16, iter_reg);
1951 iter_reg = qla24xx_read_window(reg, 0xBE40, 16, iter_reg);
1952 iter_reg = qla24xx_read_window(reg, 0xBE50, 16, iter_reg);
1953 iter_reg = qla24xx_read_window(reg, 0xBE60, 16, iter_reg);
1954 iter_reg = qla24xx_read_window(reg, 0xBE70, 16, iter_reg);
1955 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1956 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1957 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1958 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1959 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1960 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1961 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1962 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1963
1964 iter_reg = fw->xseq_0_reg;
1965 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1966 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1967 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1968
1969 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1970
1971 qla24xx_read_window(reg, 0xBEF0, 16, fw->xseq_2_reg);
1972
1973 /* Receive sequence registers. */
1974 iter_reg = fw->rseq_gp_reg;
1975 iter_reg = qla24xx_read_window(reg, 0xFE00, 16, iter_reg);
1976 iter_reg = qla24xx_read_window(reg, 0xFE10, 16, iter_reg);
1977 iter_reg = qla24xx_read_window(reg, 0xFE20, 16, iter_reg);
1978 iter_reg = qla24xx_read_window(reg, 0xFE30, 16, iter_reg);
1979 iter_reg = qla24xx_read_window(reg, 0xFE40, 16, iter_reg);
1980 iter_reg = qla24xx_read_window(reg, 0xFE50, 16, iter_reg);
1981 iter_reg = qla24xx_read_window(reg, 0xFE60, 16, iter_reg);
1982 iter_reg = qla24xx_read_window(reg, 0xFE70, 16, iter_reg);
1983 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1984 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1985 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1986 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1987 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1988 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1989 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1990 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1991
1992 iter_reg = fw->rseq_0_reg;
1993 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1994 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1995
1996 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1997 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1998 qla24xx_read_window(reg, 0xFEF0, 16, fw->rseq_3_reg);
1999
2000 /* Auxiliary sequence registers. */
2001 iter_reg = fw->aseq_gp_reg;
2002 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
2003 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
2004 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
2005 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
2006 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
2007 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
2008 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
2009 iter_reg = qla24xx_read_window(reg, 0xB070, 16, iter_reg);
2010 iter_reg = qla24xx_read_window(reg, 0xB100, 16, iter_reg);
2011 iter_reg = qla24xx_read_window(reg, 0xB110, 16, iter_reg);
2012 iter_reg = qla24xx_read_window(reg, 0xB120, 16, iter_reg);
2013 iter_reg = qla24xx_read_window(reg, 0xB130, 16, iter_reg);
2014 iter_reg = qla24xx_read_window(reg, 0xB140, 16, iter_reg);
2015 iter_reg = qla24xx_read_window(reg, 0xB150, 16, iter_reg);
2016 iter_reg = qla24xx_read_window(reg, 0xB160, 16, iter_reg);
2017 qla24xx_read_window(reg, 0xB170, 16, iter_reg);
2018
2019 iter_reg = fw->aseq_0_reg;
2020 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
2021 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
2022
2023 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
2024 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
2025 qla24xx_read_window(reg, 0xB1F0, 16, fw->aseq_3_reg);
2026
2027 /* Command DMA registers. */
2028 iter_reg = fw->cmd_dma_reg;
2029 iter_reg = qla24xx_read_window(reg, 0x7100, 16, iter_reg);
2030 iter_reg = qla24xx_read_window(reg, 0x7120, 16, iter_reg);
2031 iter_reg = qla24xx_read_window(reg, 0x7130, 16, iter_reg);
2032 qla24xx_read_window(reg, 0x71F0, 16, iter_reg);
2033
2034 /* Queues. */
2035 iter_reg = fw->req0_dma_reg;
2036 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
2037 dmp_reg = &reg->iobase_q;
2038 for (cnt = 0; cnt < 7; cnt++)
2039 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2040
2041 iter_reg = fw->resp0_dma_reg;
2042 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
2043 dmp_reg = &reg->iobase_q;
2044 for (cnt = 0; cnt < 7; cnt++)
2045 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2046
2047 iter_reg = fw->req1_dma_reg;
2048 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
2049 dmp_reg = &reg->iobase_q;
2050 for (cnt = 0; cnt < 7; cnt++)
2051 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2052
2053 /* Transmit DMA registers. */
2054 iter_reg = fw->xmt0_dma_reg;
2055 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
2056 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
2057
2058 iter_reg = fw->xmt1_dma_reg;
2059 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
2060 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
2061
2062 iter_reg = fw->xmt2_dma_reg;
2063 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
2064 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
2065
2066 iter_reg = fw->xmt3_dma_reg;
2067 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
2068 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
2069
2070 iter_reg = fw->xmt4_dma_reg;
2071 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
2072 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
2073
2074 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
2075
2076 /* Receive DMA registers. */
2077 iter_reg = fw->rcvt0_data_dma_reg;
2078 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
2079 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
2080
2081 iter_reg = fw->rcvt1_data_dma_reg;
2082 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
2083 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
2084
2085 /* RISC registers. */
2086 iter_reg = fw->risc_gp_reg;
2087 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
2088 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
2089 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
2090 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
2091 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
2092 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
2093 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
2094 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
2095
2096 /* Local memory controller registers. */
2097 iter_reg = fw->lmc_reg;
2098 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
2099 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
2100 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
2101 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
2102 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
2103 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
2104 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
2105 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
2106
2107 /* Fibre Protocol Module registers. */
2108 iter_reg = fw->fpm_hdw_reg;
2109 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
2110 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
2111 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
2112 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
2113 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
2114 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
2115 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
2116 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
2117 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
2118 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
2119 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
2120 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
2121 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
2122 iter_reg = qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
2123 iter_reg = qla24xx_read_window(reg, 0x40E0, 16, iter_reg);
2124 qla24xx_read_window(reg, 0x40F0, 16, iter_reg);
2125
2126 /* RQ0 Array registers. */
2127 iter_reg = fw->rq0_array_reg;
2128 iter_reg = qla24xx_read_window(reg, 0x5C00, 16, iter_reg);
2129 iter_reg = qla24xx_read_window(reg, 0x5C10, 16, iter_reg);
2130 iter_reg = qla24xx_read_window(reg, 0x5C20, 16, iter_reg);
2131 iter_reg = qla24xx_read_window(reg, 0x5C30, 16, iter_reg);
2132 iter_reg = qla24xx_read_window(reg, 0x5C40, 16, iter_reg);
2133 iter_reg = qla24xx_read_window(reg, 0x5C50, 16, iter_reg);
2134 iter_reg = qla24xx_read_window(reg, 0x5C60, 16, iter_reg);
2135 iter_reg = qla24xx_read_window(reg, 0x5C70, 16, iter_reg);
2136 iter_reg = qla24xx_read_window(reg, 0x5C80, 16, iter_reg);
2137 iter_reg = qla24xx_read_window(reg, 0x5C90, 16, iter_reg);
2138 iter_reg = qla24xx_read_window(reg, 0x5CA0, 16, iter_reg);
2139 iter_reg = qla24xx_read_window(reg, 0x5CB0, 16, iter_reg);
2140 iter_reg = qla24xx_read_window(reg, 0x5CC0, 16, iter_reg);
2141 iter_reg = qla24xx_read_window(reg, 0x5CD0, 16, iter_reg);
2142 iter_reg = qla24xx_read_window(reg, 0x5CE0, 16, iter_reg);
2143 qla24xx_read_window(reg, 0x5CF0, 16, iter_reg);
2144
2145 /* RQ1 Array registers. */
2146 iter_reg = fw->rq1_array_reg;
2147 iter_reg = qla24xx_read_window(reg, 0x5D00, 16, iter_reg);
2148 iter_reg = qla24xx_read_window(reg, 0x5D10, 16, iter_reg);
2149 iter_reg = qla24xx_read_window(reg, 0x5D20, 16, iter_reg);
2150 iter_reg = qla24xx_read_window(reg, 0x5D30, 16, iter_reg);
2151 iter_reg = qla24xx_read_window(reg, 0x5D40, 16, iter_reg);
2152 iter_reg = qla24xx_read_window(reg, 0x5D50, 16, iter_reg);
2153 iter_reg = qla24xx_read_window(reg, 0x5D60, 16, iter_reg);
2154 iter_reg = qla24xx_read_window(reg, 0x5D70, 16, iter_reg);
2155 iter_reg = qla24xx_read_window(reg, 0x5D80, 16, iter_reg);
2156 iter_reg = qla24xx_read_window(reg, 0x5D90, 16, iter_reg);
2157 iter_reg = qla24xx_read_window(reg, 0x5DA0, 16, iter_reg);
2158 iter_reg = qla24xx_read_window(reg, 0x5DB0, 16, iter_reg);
2159 iter_reg = qla24xx_read_window(reg, 0x5DC0, 16, iter_reg);
2160 iter_reg = qla24xx_read_window(reg, 0x5DD0, 16, iter_reg);
2161 iter_reg = qla24xx_read_window(reg, 0x5DE0, 16, iter_reg);
2162 qla24xx_read_window(reg, 0x5DF0, 16, iter_reg);
2163
2164 /* RP0 Array registers. */
2165 iter_reg = fw->rp0_array_reg;
2166 iter_reg = qla24xx_read_window(reg, 0x5E00, 16, iter_reg);
2167 iter_reg = qla24xx_read_window(reg, 0x5E10, 16, iter_reg);
2168 iter_reg = qla24xx_read_window(reg, 0x5E20, 16, iter_reg);
2169 iter_reg = qla24xx_read_window(reg, 0x5E30, 16, iter_reg);
2170 iter_reg = qla24xx_read_window(reg, 0x5E40, 16, iter_reg);
2171 iter_reg = qla24xx_read_window(reg, 0x5E50, 16, iter_reg);
2172 iter_reg = qla24xx_read_window(reg, 0x5E60, 16, iter_reg);
2173 iter_reg = qla24xx_read_window(reg, 0x5E70, 16, iter_reg);
2174 iter_reg = qla24xx_read_window(reg, 0x5E80, 16, iter_reg);
2175 iter_reg = qla24xx_read_window(reg, 0x5E90, 16, iter_reg);
2176 iter_reg = qla24xx_read_window(reg, 0x5EA0, 16, iter_reg);
2177 iter_reg = qla24xx_read_window(reg, 0x5EB0, 16, iter_reg);
2178 iter_reg = qla24xx_read_window(reg, 0x5EC0, 16, iter_reg);
2179 iter_reg = qla24xx_read_window(reg, 0x5ED0, 16, iter_reg);
2180 iter_reg = qla24xx_read_window(reg, 0x5EE0, 16, iter_reg);
2181 qla24xx_read_window(reg, 0x5EF0, 16, iter_reg);
2182
2183 /* RP1 Array registers. */
2184 iter_reg = fw->rp1_array_reg;
2185 iter_reg = qla24xx_read_window(reg, 0x5F00, 16, iter_reg);
2186 iter_reg = qla24xx_read_window(reg, 0x5F10, 16, iter_reg);
2187 iter_reg = qla24xx_read_window(reg, 0x5F20, 16, iter_reg);
2188 iter_reg = qla24xx_read_window(reg, 0x5F30, 16, iter_reg);
2189 iter_reg = qla24xx_read_window(reg, 0x5F40, 16, iter_reg);
2190 iter_reg = qla24xx_read_window(reg, 0x5F50, 16, iter_reg);
2191 iter_reg = qla24xx_read_window(reg, 0x5F60, 16, iter_reg);
2192 iter_reg = qla24xx_read_window(reg, 0x5F70, 16, iter_reg);
2193 iter_reg = qla24xx_read_window(reg, 0x5F80, 16, iter_reg);
2194 iter_reg = qla24xx_read_window(reg, 0x5F90, 16, iter_reg);
2195 iter_reg = qla24xx_read_window(reg, 0x5FA0, 16, iter_reg);
2196 iter_reg = qla24xx_read_window(reg, 0x5FB0, 16, iter_reg);
2197 iter_reg = qla24xx_read_window(reg, 0x5FC0, 16, iter_reg);
2198 iter_reg = qla24xx_read_window(reg, 0x5FD0, 16, iter_reg);
2199 iter_reg = qla24xx_read_window(reg, 0x5FE0, 16, iter_reg);
2200 qla24xx_read_window(reg, 0x5FF0, 16, iter_reg);
2201
2202 iter_reg = fw->at0_array_reg;
2203 iter_reg = qla24xx_read_window(reg, 0x7080, 16, iter_reg);
2204 iter_reg = qla24xx_read_window(reg, 0x7090, 16, iter_reg);
2205 iter_reg = qla24xx_read_window(reg, 0x70A0, 16, iter_reg);
2206 iter_reg = qla24xx_read_window(reg, 0x70B0, 16, iter_reg);
2207 iter_reg = qla24xx_read_window(reg, 0x70C0, 16, iter_reg);
2208 iter_reg = qla24xx_read_window(reg, 0x70D0, 16, iter_reg);
2209 iter_reg = qla24xx_read_window(reg, 0x70E0, 16, iter_reg);
2210 qla24xx_read_window(reg, 0x70F0, 16, iter_reg);
2211
2212 /* I/O Queue Control registers. */
2213 qla24xx_read_window(reg, 0x7800, 16, fw->queue_control_reg);
2214
2215 /* Frame Buffer registers. */
2216 iter_reg = fw->fb_hdw_reg;
2217 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
2218 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
2219 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
2220 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
2221 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
2222 iter_reg = qla24xx_read_window(reg, 0x6060, 16, iter_reg);
2223 iter_reg = qla24xx_read_window(reg, 0x6070, 16, iter_reg);
2224 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
2225 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
2226 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
2227 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
2228 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
2229 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
2230 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
2231 iter_reg = qla24xx_read_window(reg, 0x6530, 16, iter_reg);
2232 iter_reg = qla24xx_read_window(reg, 0x6540, 16, iter_reg);
2233 iter_reg = qla24xx_read_window(reg, 0x6550, 16, iter_reg);
2234 iter_reg = qla24xx_read_window(reg, 0x6560, 16, iter_reg);
2235 iter_reg = qla24xx_read_window(reg, 0x6570, 16, iter_reg);
2236 iter_reg = qla24xx_read_window(reg, 0x6580, 16, iter_reg);
2237 iter_reg = qla24xx_read_window(reg, 0x6590, 16, iter_reg);
2238 iter_reg = qla24xx_read_window(reg, 0x65A0, 16, iter_reg);
2239 iter_reg = qla24xx_read_window(reg, 0x65B0, 16, iter_reg);
2240 iter_reg = qla24xx_read_window(reg, 0x65C0, 16, iter_reg);
2241 iter_reg = qla24xx_read_window(reg, 0x65D0, 16, iter_reg);
2242 iter_reg = qla24xx_read_window(reg, 0x65E0, 16, iter_reg);
2243 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
2244
2245 /* Multi queue registers */
2246 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
2247 &last_chain);
2248
2249 rval = qla24xx_soft_reset(ha);
2250 if (rval != QLA_SUCCESS) {
2251 ql_log(ql_log_warn, vha, 0xd00e,
2252 "SOFT RESET FAILED, forcing continuation of dump!!!\n");
2253 rval = QLA_SUCCESS;
2254
2255 ql_log(ql_log_warn, vha, 0xd00f, "try a bigger hammer!!!\n");
2256
2257 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2258 RD_REG_DWORD(&reg->hccr);
2259
2260 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2261 RD_REG_DWORD(&reg->hccr);
2262
2263 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2264 RD_REG_DWORD(&reg->hccr);
2265
2266 for (cnt = 30000; cnt && (RD_REG_WORD(&reg->mailbox0)); cnt--)
2267 udelay(5);
2268
2269 if (!cnt) {
2270 nxt = fw->code_ram;
Saurav Kashyap8c0bc702012-11-21 02:40:35 -05002271 nxt += sizeof(fw->code_ram);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002272 nxt += (ha->fw_memory_size - 0x100000 + 1);
2273 goto copy_queue;
2274 } else
2275 ql_log(ql_log_warn, vha, 0xd010,
2276 "bigger hammer success?\n");
2277 }
2278
2279 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
2280 &nxt);
2281 if (rval != QLA_SUCCESS)
2282 goto qla83xx_fw_dump_failed_0;
2283
2284copy_queue:
2285 nxt = qla2xxx_copy_queues(ha, nxt);
2286
2287 nxt = qla24xx_copy_eft(ha, nxt);
2288
2289 /* Chain entries -- started with MQ. */
2290 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
2291 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002292 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002293 if (last_chain) {
2294 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
2295 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
2296 }
2297
2298 /* Adjust valid length. */
2299 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
2300
2301qla83xx_fw_dump_failed_0:
2302 qla2xxx_dump_post_process(base_vha, rval);
2303
2304qla83xx_fw_dump_failed:
2305 if (!hardware_locked)
2306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2307}
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309/****************************************************************************/
2310/* Driver Debug Functions. */
2311/****************************************************************************/
Chad Dupuiscfb09192011-11-18 09:03:07 -08002312
2313static inline int
2314ql_mask_match(uint32_t level)
2315{
2316 if (ql2xextended_error_logging == 1)
2317 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2318 return (level & ql2xextended_error_logging) == level;
2319}
2320
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002321/*
2322 * This function is for formatting and logging debug information.
2323 * It is to be used when vha is available. It formats the message
2324 * and logs it to the messages file.
2325 * parameters:
2326 * level: The level of the debug messages to be printed.
2327 * If ql2xextended_error_logging value is correctly set,
2328 * this message will appear in the messages file.
2329 * vha: Pointer to the scsi_qla_host_t.
2330 * id: This is a unique identifier for the level. It identifies the
2331 * part of the code from where the message originated.
2332 * msg: The message to be displayed.
2333 */
2334void
Joe Perches086b3e82011-11-18 09:03:05 -08002335ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2336{
2337 va_list va;
2338 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002339
Chad Dupuiscfb09192011-11-18 09:03:07 -08002340 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002341 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002342
Joe Perches086b3e82011-11-18 09:03:05 -08002343 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002344
Joe Perches086b3e82011-11-18 09:03:05 -08002345 vaf.fmt = fmt;
2346 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002347
Joe Perches086b3e82011-11-18 09:03:05 -08002348 if (vha != NULL) {
2349 const struct pci_dev *pdev = vha->hw->pdev;
2350 /* <module-name> <pci-name> <msg-id>:<host> Message */
2351 pr_warn("%s [%s]-%04x:%ld: %pV",
2352 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset,
2353 vha->host_no, &vaf);
2354 } else {
2355 pr_warn("%s [%s]-%04x: : %pV",
2356 QL_MSGHDR, "0000:00:00.0", id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002357 }
2358
Joe Perches086b3e82011-11-18 09:03:05 -08002359 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002360
2361}
2362
2363/*
2364 * This function is for formatting and logging debug information.
Masanari Iidad6a03582012-08-22 14:20:58 -04002365 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002366 * i.e., before host allocation. It formats the message and logs it
2367 * to the messages file.
2368 * parameters:
2369 * level: The level of the debug messages to be printed.
2370 * If ql2xextended_error_logging value is correctly set,
2371 * this message will appear in the messages file.
2372 * pdev: Pointer to the struct pci_dev.
2373 * id: This is a unique id for the level. It identifies the part
2374 * of the code from where the message originated.
2375 * msg: The message to be displayed.
2376 */
2377void
Joe Perches086b3e82011-11-18 09:03:05 -08002378ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2379 const char *fmt, ...)
2380{
2381 va_list va;
2382 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002383
2384 if (pdev == NULL)
2385 return;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002386 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002387 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002388
Joe Perches086b3e82011-11-18 09:03:05 -08002389 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002390
Joe Perches086b3e82011-11-18 09:03:05 -08002391 vaf.fmt = fmt;
2392 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002393
Joe Perches086b3e82011-11-18 09:03:05 -08002394 /* <module-name> <dev-name>:<msg-id> Message */
2395 pr_warn("%s [%s]-%04x: : %pV",
2396 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002397
Joe Perches086b3e82011-11-18 09:03:05 -08002398 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002399}
2400
2401/*
2402 * This function is for formatting and logging log messages.
2403 * It is to be used when vha is available. It formats the message
2404 * and logs it to the messages file. All the messages will be logged
2405 * irrespective of value of ql2xextended_error_logging.
2406 * parameters:
2407 * level: The level of the log messages to be printed in the
2408 * messages file.
2409 * vha: Pointer to the scsi_qla_host_t
2410 * id: This is a unique id for the level. It identifies the
2411 * part of the code from where the message originated.
2412 * msg: The message to be displayed.
2413 */
2414void
Joe Perches086b3e82011-11-18 09:03:05 -08002415ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2416{
2417 va_list va;
2418 struct va_format vaf;
2419 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002420
Joe Perches086b3e82011-11-18 09:03:05 -08002421 if (level > ql_errlev)
2422 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002423
Joe Perches086b3e82011-11-18 09:03:05 -08002424 if (vha != NULL) {
2425 const struct pci_dev *pdev = vha->hw->pdev;
2426 /* <module-name> <msg-id>:<host> Message */
2427 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x:%ld: ",
2428 QL_MSGHDR, dev_name(&(pdev->dev)), id, vha->host_no);
2429 } else {
2430 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2431 QL_MSGHDR, "0000:00:00.0", id);
2432 }
2433 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002434
Joe Perches086b3e82011-11-18 09:03:05 -08002435 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002436
Joe Perches086b3e82011-11-18 09:03:05 -08002437 vaf.fmt = fmt;
2438 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002439
Joe Perches086b3e82011-11-18 09:03:05 -08002440 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002441 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002442 pr_crit("%s%pV", pbuf, &vaf);
2443 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002444 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002445 pr_err("%s%pV", pbuf, &vaf);
2446 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002447 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002448 pr_warn("%s%pV", pbuf, &vaf);
2449 break;
2450 default:
2451 pr_info("%s%pV", pbuf, &vaf);
2452 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002453 }
2454
Joe Perches086b3e82011-11-18 09:03:05 -08002455 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002456}
2457
2458/*
2459 * This function is for formatting and logging log messages.
Masanari Iidad6a03582012-08-22 14:20:58 -04002460 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002461 * i.e., before host allocation. It formats the message and logs
2462 * it to the messages file. All the messages are logged irrespective
2463 * of the value of ql2xextended_error_logging.
2464 * parameters:
2465 * level: The level of the log messages to be printed in the
2466 * messages file.
2467 * pdev: Pointer to the struct pci_dev.
2468 * id: This is a unique id for the level. It identifies the
2469 * part of the code from where the message originated.
2470 * msg: The message to be displayed.
2471 */
2472void
Joe Perches086b3e82011-11-18 09:03:05 -08002473ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2474 const char *fmt, ...)
2475{
2476 va_list va;
2477 struct va_format vaf;
2478 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002479
2480 if (pdev == NULL)
2481 return;
Joe Perches086b3e82011-11-18 09:03:05 -08002482 if (level > ql_errlev)
2483 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002484
Joe Perches086b3e82011-11-18 09:03:05 -08002485 /* <module-name> <dev-name>:<msg-id> Message */
2486 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2487 QL_MSGHDR, dev_name(&(pdev->dev)), id);
2488 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002489
Joe Perches086b3e82011-11-18 09:03:05 -08002490 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002491
Joe Perches086b3e82011-11-18 09:03:05 -08002492 vaf.fmt = fmt;
2493 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002494
Joe Perches086b3e82011-11-18 09:03:05 -08002495 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002496 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002497 pr_crit("%s%pV", pbuf, &vaf);
2498 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002499 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002500 pr_err("%s%pV", pbuf, &vaf);
2501 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002502 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002503 pr_warn("%s%pV", pbuf, &vaf);
2504 break;
2505 default:
2506 pr_info("%s%pV", pbuf, &vaf);
2507 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002508 }
2509
Joe Perches086b3e82011-11-18 09:03:05 -08002510 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002511}
2512
2513void
2514ql_dump_regs(uint32_t level, scsi_qla_host_t *vha, int32_t id)
2515{
2516 int i;
2517 struct qla_hw_data *ha = vha->hw;
2518 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2519 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2520 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
2521 uint16_t __iomem *mbx_reg;
2522
Chad Dupuiscfb09192011-11-18 09:03:07 -08002523 if (!ql_mask_match(level))
2524 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002525
Chad Dupuiscfb09192011-11-18 09:03:07 -08002526 if (IS_QLA82XX(ha))
2527 mbx_reg = &reg82->mailbox_in[0];
2528 else if (IS_FWI2_CAPABLE(ha))
2529 mbx_reg = &reg24->mailbox0;
2530 else
2531 mbx_reg = MAILBOX_REG(ha, reg, 0);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002532
Chad Dupuiscfb09192011-11-18 09:03:07 -08002533 ql_dbg(level, vha, id, "Mailbox registers:\n");
2534 for (i = 0; i < 6; i++)
2535 ql_dbg(level, vha, id,
2536 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002537}
2538
2539
2540void
2541ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, int32_t id,
2542 uint8_t *b, uint32_t size)
2543{
2544 uint32_t cnt;
2545 uint8_t c;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002546
Chad Dupuiscfb09192011-11-18 09:03:07 -08002547 if (!ql_mask_match(level))
2548 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002549
Chad Dupuiscfb09192011-11-18 09:03:07 -08002550 ql_dbg(level, vha, id, " 0 1 2 3 4 5 6 7 8 "
2551 "9 Ah Bh Ch Dh Eh Fh\n");
2552 ql_dbg(level, vha, id, "----------------------------------"
2553 "----------------------------\n");
2554
2555 ql_dbg(level, vha, id, " ");
2556 for (cnt = 0; cnt < size;) {
2557 c = *b++;
2558 printk("%02x", (uint32_t) c);
2559 cnt++;
2560 if (!(cnt % 16))
2561 printk("\n");
2562 else
2563 printk(" ");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002564 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002565 if (cnt % 16)
2566 ql_dbg(level, vha, id, "\n");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002567}