blob: df132fec6d86c98c29417c38f63eaf3a9df3e504 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 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 * ----------------------------------------------------------------------
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040014 * | Module Init and Probe | 0x014f | 0x4b,0xba,0xfa |
Giridhar Malavali754d1242013-06-25 11:27:16 -040015 * | Mailbox commands | 0x117a | 0x111a-0x111b |
Joe Carnuccioe9f4f412013-03-25 02:21:36 -040016 * | | | 0x1155-0x1158 |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040017 * | Device Discovery | 0x2095 | 0x2020-0x2022, |
Bart Van Assche6593d5b2013-06-25 11:27:24 -040018 * | | | 0x2011-0x2012, |
Saurav Kashyap2a8593f2012-08-22 14:21:27 -040019 * | | | 0x2016 |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040020 * | Queue Command and IO tracing | 0x3058 | 0x3006-0x300b |
Arun Easi9e522cd2012-08-22 14:21:31 -040021 * | | | 0x3027-0x3028 |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040022 * | | | 0x303d-0x3041 |
23 * | | | 0x302d,0x3033 |
24 * | | | 0x3036,0x3038 |
25 * | | | 0x303a |
26 * | DPC Thread | 0x4022 | 0x4002,0x4013 |
27 * | Async Events | 0x5081 | 0x502b-0x502f |
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080028 * | | | 0x5047,0x5052 |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040029 * | | | 0x5040,0x5075 |
Giridhar Malavali5988aeb2012-05-15 14:34:12 -040030 * | Timer Routines | 0x6011 | |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040031 * | User Space Interactions | 0x70dd | 0x7018,0x702e, |
Saurav Kashyap78d56df2013-01-30 03:34:42 -050032 * | | | 0x7020,0x7024, |
Joe Carnuccio733a95b2012-02-09 11:15:55 -080033 * | | | 0x7039,0x7045, |
34 * | | | 0x7073-0x7075, |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040035 * | | | 0x707b,0x708c, |
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040036 * | | | 0x70a5,0x70a6, |
37 * | | | 0x70a8,0x70ab, |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040038 * | | | 0x70ad-0x70ae, |
Bart Van Assche090fc2e2013-06-25 11:27:22 -040039 * | | | 0x70d1-0x70da, |
Bart Van Asschea44c72f2013-06-25 11:27:23 -040040 * | | | 0x7047,0x703b |
Chad Dupuiscfb09192011-11-18 09:03:07 -080041 * | Task Management | 0x803c | 0x8025-0x8026 |
42 * | | | 0x800b,0x8039 |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040043 * | AER/EEH | 0x9011 | |
Arun Easie02587d2011-08-16 11:29:23 -070044 * | Virtual Port | 0xa007 | |
Saurav Kashyap6c315552013-02-08 01:57:53 -050045 * | ISP82XX Specific | 0xb086 | 0xb002,0xb024 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080046 * | MultiQ | 0xc00c | |
47 * | Misc | 0xd010 | |
Arun Easi33c36c02013-01-30 03:34:41 -050048 * | Target Mode | 0xe070 | |
Arun Easiaa230bc2013-01-30 03:34:39 -050049 * | Target Mode Management | 0xf072 | |
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040050 * | Target Mode Task Management | 0x1000b | |
Arun Easie02587d2011-08-16 11:29:23 -070051 * ----------------------------------------------------------------------
Saurav Kashyap3ce88662011-07-14 12:00:12 -070052 */
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "qla_def.h"
55
56#include <linux/delay.h>
57
Saurav Kashyap3ce88662011-07-14 12:00:12 -070058static uint32_t ql_dbg_offset = 0x800;
59
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070060static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080061qla2xxx_prep_dump(struct qla_hw_data *ha, struct qla2xxx_fw_dump *fw_dump)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070062{
63 fw_dump->fw_major_version = htonl(ha->fw_major_version);
64 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
65 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
66 fw_dump->fw_attributes = htonl(ha->fw_attributes);
67
68 fw_dump->vendor = htonl(ha->pdev->vendor);
69 fw_dump->device = htonl(ha->pdev->device);
70 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
71 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
72}
73
74static inline void *
Anirban Chakraborty73208df2008-12-09 16:45:39 -080075qla2xxx_copy_queues(struct qla_hw_data *ha, void *ptr)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070076{
Anirban Chakraborty73208df2008-12-09 16:45:39 -080077 struct req_que *req = ha->req_q_map[0];
78 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070079 /* Request queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080080 memcpy(ptr, req->ring, req->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070081 sizeof(request_t));
82
83 /* Response queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080084 ptr += req->length * sizeof(request_t);
85 memcpy(ptr, rsp->ring, rsp->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070086 sizeof(response_t));
87
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080088 return ptr + (rsp->length * sizeof(response_t));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070089}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070091static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080092qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -070093 uint32_t ram_dwords, void **nxt)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070094{
95 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -070096 uint32_t cnt, stat, timer, dwords, idx;
97 uint16_t mb0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -070098 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquezc5722702008-04-24 15:21:22 -070099 dma_addr_t dump_dma = ha->gid_list_dma;
100 uint32_t *dump = (uint32_t *)ha->gid_list;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700101
102 rval = QLA_SUCCESS;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700103 mb0 = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700104
Andrew Vasquezc5722702008-04-24 15:21:22 -0700105 WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700106 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
107
Chad Dupuis642ef982012-02-09 11:15:57 -0800108 dwords = qla2x00_gid_list_size(ha) / 4;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700109 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
110 cnt += dwords, addr += dwords) {
111 if (cnt + dwords > ram_dwords)
112 dwords = ram_dwords - cnt;
113
114 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
115 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
116
117 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
118 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
119 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
120 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
121
122 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
123 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700124 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
125
126 for (timer = 6000000; timer; timer--) {
127 /* Check for pending interrupts. */
128 stat = RD_REG_DWORD(&reg->host_status);
129 if (stat & HSRX_RISC_INT) {
130 stat &= 0xff;
131
132 if (stat == 0x1 || stat == 0x2 ||
133 stat == 0x10 || stat == 0x11) {
134 set_bit(MBX_INTERRUPT,
135 &ha->mbx_cmd_flags);
136
Andrew Vasquezc5722702008-04-24 15:21:22 -0700137 mb0 = RD_REG_WORD(&reg->mailbox0);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700138
139 WRT_REG_DWORD(&reg->hccr,
140 HCCRX_CLR_RISC_INT);
141 RD_REG_DWORD(&reg->hccr);
142 break;
143 }
144
145 /* Clear this intr; it wasn't a mailbox intr */
146 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
147 RD_REG_DWORD(&reg->hccr);
148 }
149 udelay(5);
150 }
151
152 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
Andrew Vasquezc5722702008-04-24 15:21:22 -0700153 rval = mb0 & MBS_MASK;
154 for (idx = 0; idx < dwords; idx++)
155 ram[cnt + idx] = swab32(dump[idx]);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700156 } else {
157 rval = QLA_FUNCTION_FAILED;
158 }
159 }
160
Andrew Vasquezc5722702008-04-24 15:21:22 -0700161 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700162 return rval;
163}
164
Andrew Vasquezc5722702008-04-24 15:21:22 -0700165static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800166qla24xx_dump_memory(struct qla_hw_data *ha, uint32_t *code_ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700167 uint32_t cram_size, void **nxt)
168{
169 int rval;
170
171 /* Code RAM. */
172 rval = qla24xx_dump_ram(ha, 0x20000, code_ram, cram_size / 4, nxt);
173 if (rval != QLA_SUCCESS)
174 return rval;
175
176 /* External Memory. */
177 return qla24xx_dump_ram(ha, 0x100000, *nxt,
178 ha->fw_memory_size - 0x100000 + 1, nxt);
179}
180
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700181static uint32_t *
182qla24xx_read_window(struct device_reg_24xx __iomem *reg, uint32_t iobase,
183 uint32_t count, uint32_t *buf)
184{
185 uint32_t __iomem *dmp_reg;
186
187 WRT_REG_DWORD(&reg->iobase_addr, iobase);
188 dmp_reg = &reg->iobase_window;
189 while (count--)
190 *buf++ = htonl(RD_REG_DWORD(dmp_reg++));
191
192 return buf;
193}
194
195static inline int
196qla24xx_pause_risc(struct device_reg_24xx __iomem *reg)
197{
198 int rval = QLA_SUCCESS;
199 uint32_t cnt;
200
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700201 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
Andrew Vasquezaed10882009-06-03 09:55:26 -0700202 for (cnt = 30000;
203 ((RD_REG_DWORD(&reg->host_status) & HSRX_RISC_PAUSED) == 0) &&
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700204 rval == QLA_SUCCESS; cnt--) {
205 if (cnt)
206 udelay(100);
207 else
208 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700209 }
210
211 return rval;
212}
213
214static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800215qla24xx_soft_reset(struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700216{
217 int rval = QLA_SUCCESS;
218 uint32_t cnt;
219 uint16_t mb0, wd;
220 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
221
222 /* Reset RISC. */
223 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
224 for (cnt = 0; cnt < 30000; cnt++) {
225 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
226 break;
227
228 udelay(10);
229 }
230
231 WRT_REG_DWORD(&reg->ctrl_status,
232 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
233 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
234
235 udelay(100);
236 /* Wait for firmware to complete NVRAM accesses. */
237 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
238 for (cnt = 10000 ; cnt && mb0; cnt--) {
239 udelay(5);
240 mb0 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
241 barrier();
242 }
243
244 /* Wait for soft-reset to complete. */
245 for (cnt = 0; cnt < 30000; cnt++) {
246 if ((RD_REG_DWORD(&reg->ctrl_status) &
247 CSRX_ISP_SOFT_RESET) == 0)
248 break;
249
250 udelay(10);
251 }
252 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
253 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
254
255 for (cnt = 30000; RD_REG_WORD(&reg->mailbox0) != 0 &&
256 rval == QLA_SUCCESS; cnt--) {
257 if (cnt)
258 udelay(100);
259 else
260 rval = QLA_FUNCTION_TIMEOUT;
261 }
262
263 return rval;
264}
265
Andrew Vasquezc5722702008-04-24 15:21:22 -0700266static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800267qla2xxx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint16_t *ram,
Andrew Vasqueze18e9632009-06-17 10:30:31 -0700268 uint32_t ram_words, void **nxt)
Andrew Vasquezc5722702008-04-24 15:21:22 -0700269{
270 int rval;
271 uint32_t cnt, stat, timer, words, idx;
272 uint16_t mb0;
273 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
274 dma_addr_t dump_dma = ha->gid_list_dma;
275 uint16_t *dump = (uint16_t *)ha->gid_list;
276
277 rval = QLA_SUCCESS;
278 mb0 = 0;
279
280 WRT_MAILBOX_REG(ha, reg, 0, MBC_DUMP_RISC_RAM_EXTENDED);
281 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
282
Chad Dupuis642ef982012-02-09 11:15:57 -0800283 words = qla2x00_gid_list_size(ha) / 2;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700284 for (cnt = 0; cnt < ram_words && rval == QLA_SUCCESS;
285 cnt += words, addr += words) {
286 if (cnt + words > ram_words)
287 words = ram_words - cnt;
288
289 WRT_MAILBOX_REG(ha, reg, 1, LSW(addr));
290 WRT_MAILBOX_REG(ha, reg, 8, MSW(addr));
291
292 WRT_MAILBOX_REG(ha, reg, 2, MSW(dump_dma));
293 WRT_MAILBOX_REG(ha, reg, 3, LSW(dump_dma));
294 WRT_MAILBOX_REG(ha, reg, 6, MSW(MSD(dump_dma)));
295 WRT_MAILBOX_REG(ha, reg, 7, LSW(MSD(dump_dma)));
296
297 WRT_MAILBOX_REG(ha, reg, 4, words);
298 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
299
300 for (timer = 6000000; timer; timer--) {
301 /* Check for pending interrupts. */
302 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
303 if (stat & HSR_RISC_INT) {
304 stat &= 0xff;
305
306 if (stat == 0x1 || stat == 0x2) {
307 set_bit(MBX_INTERRUPT,
308 &ha->mbx_cmd_flags);
309
310 mb0 = RD_MAILBOX_REG(ha, reg, 0);
311
312 /* Release mailbox registers. */
313 WRT_REG_WORD(&reg->semaphore, 0);
314 WRT_REG_WORD(&reg->hccr,
315 HCCR_CLR_RISC_INT);
316 RD_REG_WORD(&reg->hccr);
317 break;
318 } else if (stat == 0x10 || stat == 0x11) {
319 set_bit(MBX_INTERRUPT,
320 &ha->mbx_cmd_flags);
321
322 mb0 = RD_MAILBOX_REG(ha, reg, 0);
323
324 WRT_REG_WORD(&reg->hccr,
325 HCCR_CLR_RISC_INT);
326 RD_REG_WORD(&reg->hccr);
327 break;
328 }
329
330 /* clear this intr; it wasn't a mailbox intr */
331 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
332 RD_REG_WORD(&reg->hccr);
333 }
334 udelay(5);
335 }
336
337 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
338 rval = mb0 & MBS_MASK;
339 for (idx = 0; idx < words; idx++)
340 ram[cnt + idx] = swab16(dump[idx]);
341 } else {
342 rval = QLA_FUNCTION_FAILED;
343 }
344 }
345
346 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
347 return rval;
348}
349
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700350static inline void
351qla2xxx_read_window(struct device_reg_2xxx __iomem *reg, uint32_t count,
352 uint16_t *buf)
353{
354 uint16_t __iomem *dmp_reg = &reg->u.isp2300.fb_cmd;
355
356 while (count--)
357 *buf++ = htons(RD_REG_WORD(dmp_reg++));
358}
359
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800360static inline void *
361qla24xx_copy_eft(struct qla_hw_data *ha, void *ptr)
362{
363 if (!ha->eft)
364 return ptr;
365
366 memcpy(ptr, ha->eft, ntohl(ha->fw_dump->eft_size));
367 return ptr + ntohl(ha->fw_dump->eft_size);
368}
369
370static inline void *
371qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
372{
373 uint32_t cnt;
374 uint32_t *iter_reg;
375 struct qla2xxx_fce_chain *fcec = ptr;
376
377 if (!ha->fce)
378 return ptr;
379
380 *last_chain = &fcec->type;
381 fcec->type = __constant_htonl(DUMP_CHAIN_FCE);
382 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
383 fce_calc_size(ha->fce_bufs));
384 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
385 fcec->addr_l = htonl(LSD(ha->fce_dma));
386 fcec->addr_h = htonl(MSD(ha->fce_dma));
387
388 iter_reg = fcec->eregs;
389 for (cnt = 0; cnt < 8; cnt++)
390 *iter_reg++ = htonl(ha->fce_mb[cnt]);
391
392 memcpy(iter_reg, ha->fce, ntohl(fcec->size));
393
Giridhar Malavali3cb0a672011-11-18 09:03:11 -0800394 return (char *)iter_reg + ntohl(fcec->size);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800395}
396
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800397static inline void *
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400398qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr,
399 uint32_t **last_chain)
400{
401 struct qla2xxx_mqueue_chain *q;
402 struct qla2xxx_mqueue_header *qh;
403 uint32_t num_queues;
404 int que;
405 struct {
406 int length;
407 void *ring;
408 } aq, *aqp;
409
Arun Easi00876ae2013-03-25 02:21:37 -0400410 if (!ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400411 return ptr;
412
413 num_queues = 1;
414 aqp = &aq;
415 aqp->length = ha->tgt.atio_q_length;
416 aqp->ring = ha->tgt.atio_ring;
417
418 for (que = 0; que < num_queues; que++) {
419 /* aqp = ha->atio_q_map[que]; */
420 q = ptr;
421 *last_chain = &q->type;
422 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
423 q->chain_size = htonl(
424 sizeof(struct qla2xxx_mqueue_chain) +
425 sizeof(struct qla2xxx_mqueue_header) +
426 (aqp->length * sizeof(request_t)));
427 ptr += sizeof(struct qla2xxx_mqueue_chain);
428
429 /* Add header. */
430 qh = ptr;
431 qh->queue = __constant_htonl(TYPE_ATIO_QUEUE);
432 qh->number = htonl(que);
433 qh->size = htonl(aqp->length * sizeof(request_t));
434 ptr += sizeof(struct qla2xxx_mqueue_header);
435
436 /* Add data. */
437 memcpy(ptr, aqp->ring, aqp->length * sizeof(request_t));
438
439 ptr += aqp->length * sizeof(request_t);
440 }
441
442 return ptr;
443}
444
445static inline void *
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800446qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
447{
448 struct qla2xxx_mqueue_chain *q;
449 struct qla2xxx_mqueue_header *qh;
450 struct req_que *req;
451 struct rsp_que *rsp;
452 int que;
453
454 if (!ha->mqenable)
455 return ptr;
456
457 /* Request queues */
458 for (que = 1; que < ha->max_req_queues; que++) {
459 req = ha->req_q_map[que];
460 if (!req)
461 break;
462
463 /* Add chain. */
464 q = ptr;
465 *last_chain = &q->type;
466 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
467 q->chain_size = htonl(
468 sizeof(struct qla2xxx_mqueue_chain) +
469 sizeof(struct qla2xxx_mqueue_header) +
470 (req->length * sizeof(request_t)));
471 ptr += sizeof(struct qla2xxx_mqueue_chain);
472
473 /* Add header. */
474 qh = ptr;
475 qh->queue = __constant_htonl(TYPE_REQUEST_QUEUE);
476 qh->number = htonl(que);
477 qh->size = htonl(req->length * sizeof(request_t));
478 ptr += sizeof(struct qla2xxx_mqueue_header);
479
480 /* Add data. */
481 memcpy(ptr, req->ring, req->length * sizeof(request_t));
482 ptr += req->length * sizeof(request_t);
483 }
484
485 /* Response queues */
486 for (que = 1; que < ha->max_rsp_queues; que++) {
487 rsp = ha->rsp_q_map[que];
488 if (!rsp)
489 break;
490
491 /* Add chain. */
492 q = ptr;
493 *last_chain = &q->type;
494 q->type = __constant_htonl(DUMP_CHAIN_QUEUE);
495 q->chain_size = htonl(
496 sizeof(struct qla2xxx_mqueue_chain) +
497 sizeof(struct qla2xxx_mqueue_header) +
498 (rsp->length * sizeof(response_t)));
499 ptr += sizeof(struct qla2xxx_mqueue_chain);
500
501 /* Add header. */
502 qh = ptr;
503 qh->queue = __constant_htonl(TYPE_RESPONSE_QUEUE);
504 qh->number = htonl(que);
505 qh->size = htonl(rsp->length * sizeof(response_t));
506 ptr += sizeof(struct qla2xxx_mqueue_header);
507
508 /* Add data. */
509 memcpy(ptr, rsp->ring, rsp->length * sizeof(response_t));
510 ptr += rsp->length * sizeof(response_t);
511 }
512
513 return ptr;
514}
515
516static inline void *
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800517qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
518{
519 uint32_t cnt, que_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700520 uint8_t que_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800521 struct qla2xxx_mq_chain *mq = ptr;
522 struct device_reg_25xxmq __iomem *reg;
523
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800524 if (!ha->mqenable || IS_QLA83XX(ha))
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800525 return ptr;
526
527 mq = ptr;
528 *last_chain = &mq->type;
529 mq->type = __constant_htonl(DUMP_CHAIN_MQ);
530 mq->chain_size = __constant_htonl(sizeof(struct qla2xxx_mq_chain));
531
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700532 que_cnt = ha->max_req_queues > ha->max_rsp_queues ?
533 ha->max_req_queues : ha->max_rsp_queues;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800534 mq->count = htonl(que_cnt);
535 for (cnt = 0; cnt < que_cnt; cnt++) {
Saurav Kashyapfa492632012-11-21 02:40:29 -0500536 reg = (struct device_reg_25xxmq __iomem *)
537 (ha->mqiobase + cnt * QLA_QUE_PAGE);
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800538 que_idx = cnt * 4;
539 mq->qregs[que_idx] = htonl(RD_REG_DWORD(&reg->req_q_in));
540 mq->qregs[que_idx+1] = htonl(RD_REG_DWORD(&reg->req_q_out));
541 mq->qregs[que_idx+2] = htonl(RD_REG_DWORD(&reg->rsp_q_in));
542 mq->qregs[que_idx+3] = htonl(RD_REG_DWORD(&reg->rsp_q_out));
543 }
544
545 return ptr + sizeof(struct qla2xxx_mq_chain);
546}
547
Giridhar Malavali08de2842011-08-16 11:31:44 -0700548void
Andrew Vasquez3420d362009-10-13 15:16:45 -0700549qla2xxx_dump_post_process(scsi_qla_host_t *vha, int rval)
550{
551 struct qla_hw_data *ha = vha->hw;
552
553 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700554 ql_log(ql_log_warn, vha, 0xd000,
555 "Failed to dump firmware (%x).\n", rval);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700556 ha->fw_dumped = 0;
557 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700558 ql_log(ql_log_info, vha, 0xd001,
Andrew Vasquez3420d362009-10-13 15:16:45 -0700559 "Firmware dump saved to temp buffer (%ld/%p).\n",
560 vha->host_no, ha->fw_dump);
561 ha->fw_dumped = 1;
562 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
563 }
564}
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/**
567 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
568 * @ha: HA context
569 * @hardware_locked: Called with the hardware_lock
570 */
571void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800572qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
574 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700575 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800576 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700577 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 uint16_t __iomem *dmp_reg;
579 unsigned long flags;
580 struct qla2300_fw_dump *fw;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700581 void *nxt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800582 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 flags = 0;
585
586 if (!hardware_locked)
587 spin_lock_irqsave(&ha->hardware_lock, flags);
588
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700589 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700590 ql_log(ql_log_warn, vha, 0xd002,
591 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 goto qla2300_fw_dump_failed;
593 }
594
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700595 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700596 ql_log(ql_log_warn, vha, 0xd003,
597 "Firmware has been previously dumped (%p) "
598 "-- ignoring request.\n",
599 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 goto qla2300_fw_dump_failed;
601 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700602 fw = &ha->fw_dump->isp.isp23;
603 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700606 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700609 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 if (IS_QLA2300(ha)) {
611 for (cnt = 30000;
612 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
613 rval == QLA_SUCCESS; cnt--) {
614 if (cnt)
615 udelay(100);
616 else
617 rval = QLA_FUNCTION_TIMEOUT;
618 }
619 } else {
620 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
621 udelay(10);
622 }
623
624 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700625 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700626 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700627 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700629 dmp_reg = &reg->u.isp2300.req_q_in;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700630 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700631 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700633 dmp_reg = &reg->u.isp2300.mailbox0;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700634 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700635 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 WRT_REG_WORD(&reg->ctrl_status, 0x40);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700638 qla2xxx_read_window(reg, 32, fw->resp_dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 WRT_REG_WORD(&reg->ctrl_status, 0x50);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700641 qla2xxx_read_window(reg, 48, fw->dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700644 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700645 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700646 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700648 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700649 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700651 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700652 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700654 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700655 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700657 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700658 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700660 WRT_REG_WORD(&reg->pcr, 0x2800);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700661 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700663 WRT_REG_WORD(&reg->pcr, 0x2A00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700664 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700666 WRT_REG_WORD(&reg->pcr, 0x2C00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700667 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700669 WRT_REG_WORD(&reg->pcr, 0x2E00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700670 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700672 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700673 qla2xxx_read_window(reg, 64, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700675 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700676 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700678 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700679 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 /* Reset RISC. */
682 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
683 for (cnt = 0; cnt < 30000; cnt++) {
684 if ((RD_REG_WORD(&reg->ctrl_status) &
685 CSR_ISP_SOFT_RESET) == 0)
686 break;
687
688 udelay(10);
689 }
690 }
691
692 if (!IS_QLA2300(ha)) {
693 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
694 rval == QLA_SUCCESS; cnt--) {
695 if (cnt)
696 udelay(100);
697 else
698 rval = QLA_FUNCTION_TIMEOUT;
699 }
700 }
701
Andrew Vasquezc5722702008-04-24 15:21:22 -0700702 /* Get RISC SRAM. */
703 if (rval == QLA_SUCCESS)
704 rval = qla2xxx_dump_ram(ha, 0x800, fw->risc_ram,
705 sizeof(fw->risc_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Andrew Vasquezc5722702008-04-24 15:21:22 -0700707 /* Get stack SRAM. */
708 if (rval == QLA_SUCCESS)
709 rval = qla2xxx_dump_ram(ha, 0x10000, fw->stack_ram,
710 sizeof(fw->stack_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Andrew Vasquezc5722702008-04-24 15:21:22 -0700712 /* Get data SRAM. */
713 if (rval == QLA_SUCCESS)
714 rval = qla2xxx_dump_ram(ha, 0x11000, fw->data_ram,
715 ha->fw_memory_size - 0x11000 + 1, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700717 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800718 qla2xxx_copy_queues(ha, nxt);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700719
Andrew Vasquez3420d362009-10-13 15:16:45 -0700720 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722qla2300_fw_dump_failed:
723 if (!hardware_locked)
724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
725}
726
727/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
729 * @ha: HA context
730 * @hardware_locked: Called with the hardware_lock
731 */
732void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800733qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
735 int rval;
736 uint32_t cnt, timer;
737 uint16_t risc_address;
738 uint16_t mb0, mb2;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800739 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700740 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 uint16_t __iomem *dmp_reg;
742 unsigned long flags;
743 struct qla2100_fw_dump *fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800744 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 risc_address = 0;
747 mb0 = mb2 = 0;
748 flags = 0;
749
750 if (!hardware_locked)
751 spin_lock_irqsave(&ha->hardware_lock, flags);
752
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700753 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700754 ql_log(ql_log_warn, vha, 0xd004,
755 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 goto qla2100_fw_dump_failed;
757 }
758
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700759 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700760 ql_log(ql_log_warn, vha, 0xd005,
761 "Firmware has been previously dumped (%p) "
762 "-- ignoring request.\n",
763 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 goto qla2100_fw_dump_failed;
765 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700766 fw = &ha->fw_dump->isp.isp21;
767 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700770 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700773 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
775 rval == QLA_SUCCESS; cnt--) {
776 if (cnt)
777 udelay(100);
778 else
779 rval = QLA_FUNCTION_TIMEOUT;
780 }
781 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700782 dmp_reg = &reg->flash_address;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700783 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700784 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700786 dmp_reg = &reg->u.isp2100.mailbox0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700788 if (cnt == 8)
789 dmp_reg = &reg->u_end.isp2200.mailbox8;
790
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700791 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700794 dmp_reg = &reg->u.isp2100.unused_2[0];
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700795 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700796 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700799 dmp_reg = &reg->risc_hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700800 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700801 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700803 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700804 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700806 WRT_REG_WORD(&reg->pcr, 0x2100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700807 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700809 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700810 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700812 WRT_REG_WORD(&reg->pcr, 0x2300);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700813 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700815 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700816 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700818 WRT_REG_WORD(&reg->pcr, 0x2500);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700819 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700821 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700822 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700824 WRT_REG_WORD(&reg->pcr, 0x2700);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700825 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700827 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700828 qla2xxx_read_window(reg, 16, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700830 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700831 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700833 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700834 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 /* Reset the ISP. */
837 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
838 }
839
840 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
841 rval == QLA_SUCCESS; cnt--) {
842 if (cnt)
843 udelay(100);
844 else
845 rval = QLA_FUNCTION_TIMEOUT;
846 }
847
848 /* Pause RISC. */
849 if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
850 (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {
851
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700852 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 for (cnt = 30000;
854 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
855 rval == QLA_SUCCESS; cnt--) {
856 if (cnt)
857 udelay(100);
858 else
859 rval = QLA_FUNCTION_TIMEOUT;
860 }
861 if (rval == QLA_SUCCESS) {
862 /* Set memory configuration and timing. */
863 if (IS_QLA2100(ha))
864 WRT_REG_WORD(&reg->mctr, 0xf1);
865 else
866 WRT_REG_WORD(&reg->mctr, 0xf2);
867 RD_REG_WORD(&reg->mctr); /* PCI Posting. */
868
869 /* Release RISC. */
870 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
871 }
872 }
873
874 if (rval == QLA_SUCCESS) {
875 /* Get RISC SRAM. */
876 risc_address = 0x1000;
877 WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
878 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
879 }
880 for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
881 cnt++, risc_address++) {
882 WRT_MAILBOX_REG(ha, reg, 1, risc_address);
883 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
884
885 for (timer = 6000000; timer != 0; timer--) {
886 /* Check for pending interrupts. */
887 if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
888 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
889 set_bit(MBX_INTERRUPT,
890 &ha->mbx_cmd_flags);
891
892 mb0 = RD_MAILBOX_REG(ha, reg, 0);
893 mb2 = RD_MAILBOX_REG(ha, reg, 2);
894
895 WRT_REG_WORD(&reg->semaphore, 0);
896 WRT_REG_WORD(&reg->hccr,
897 HCCR_CLR_RISC_INT);
898 RD_REG_WORD(&reg->hccr);
899 break;
900 }
901 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
902 RD_REG_WORD(&reg->hccr);
903 }
904 udelay(5);
905 }
906
907 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
908 rval = mb0 & MBS_MASK;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700909 fw->risc_ram[cnt] = htons(mb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 } else {
911 rval = QLA_FUNCTION_FAILED;
912 }
913 }
914
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700915 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800916 qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700917
Andrew Vasquez3420d362009-10-13 15:16:45 -0700918 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920qla2100_fw_dump_failed:
921 if (!hardware_locked)
922 spin_unlock_irqrestore(&ha->hardware_lock, flags);
923}
924
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700925void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800926qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700927{
928 int rval;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700929 uint32_t cnt;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700930 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800931 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700932 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
933 uint32_t __iomem *dmp_reg;
934 uint32_t *iter_reg;
935 uint16_t __iomem *mbx_reg;
936 unsigned long flags;
937 struct qla24xx_fw_dump *fw;
938 uint32_t ext_mem_cnt;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700939 void *nxt;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400940 void *nxt_chain;
941 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800942 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700943
Giridhar Malavalia9083012010-04-12 17:59:55 -0700944 if (IS_QLA82XX(ha))
945 return;
946
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700947 risc_address = ext_mem_cnt = 0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700948 flags = 0;
949
950 if (!hardware_locked)
951 spin_lock_irqsave(&ha->hardware_lock, flags);
952
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700953 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700954 ql_log(ql_log_warn, vha, 0xd006,
955 "No buffer available for dump.\n");
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700956 goto qla24xx_fw_dump_failed;
957 }
958
959 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700960 ql_log(ql_log_warn, vha, 0xd007,
961 "Firmware has been previously dumped (%p) "
962 "-- ignoring request.\n",
963 ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700964 goto qla24xx_fw_dump_failed;
965 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700966 fw = &ha->fw_dump->isp.isp24;
967 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700968
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700969 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700970
971 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700972 rval = qla24xx_pause_risc(reg);
973 if (rval != QLA_SUCCESS)
974 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700975
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700976 /* Host interface registers. */
977 dmp_reg = &reg->flash_addr;
978 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
979 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -0700980
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700981 /* Disable interrupts. */
982 WRT_REG_DWORD(&reg->ictrl, 0);
983 RD_REG_DWORD(&reg->ictrl);
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800984
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700985 /* Shadow registers. */
986 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
987 RD_REG_DWORD(&reg->iobase_addr);
988 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
989 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800990
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700991 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
992 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800993
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700994 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
995 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800996
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700997 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
998 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -0800999
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001000 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1001 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001002
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001003 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1004 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001005
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001006 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1007 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001008
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001009 /* Mailbox registers. */
1010 mbx_reg = &reg->mailbox0;
1011 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1012 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001013
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001014 /* Transfer sequence registers. */
1015 iter_reg = fw->xseq_gp_reg;
1016 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1017 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1018 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1019 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1020 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1021 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1022 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1023 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001024
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001025 qla24xx_read_window(reg, 0xBFE0, 16, fw->xseq_0_reg);
1026 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001027
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001028 /* Receive sequence registers. */
1029 iter_reg = fw->rseq_gp_reg;
1030 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1031 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1032 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1033 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1034 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1035 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1036 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1037 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001038
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001039 qla24xx_read_window(reg, 0xFFD0, 16, fw->rseq_0_reg);
1040 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1041 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001042
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001043 /* Command DMA registers. */
1044 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001045
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001046 /* Queues. */
1047 iter_reg = fw->req0_dma_reg;
1048 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1049 dmp_reg = &reg->iobase_q;
1050 for (cnt = 0; cnt < 7; cnt++)
1051 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001052
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001053 iter_reg = fw->resp0_dma_reg;
1054 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1055 dmp_reg = &reg->iobase_q;
1056 for (cnt = 0; cnt < 7; cnt++)
1057 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001058
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001059 iter_reg = fw->req1_dma_reg;
1060 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1061 dmp_reg = &reg->iobase_q;
1062 for (cnt = 0; cnt < 7; cnt++)
1063 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001064
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001065 /* Transmit DMA registers. */
1066 iter_reg = fw->xmt0_dma_reg;
1067 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1068 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001069
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001070 iter_reg = fw->xmt1_dma_reg;
1071 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1072 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001073
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001074 iter_reg = fw->xmt2_dma_reg;
1075 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1076 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001077
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001078 iter_reg = fw->xmt3_dma_reg;
1079 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1080 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001081
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001082 iter_reg = fw->xmt4_dma_reg;
1083 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1084 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001085
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001086 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001087
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001088 /* Receive DMA registers. */
1089 iter_reg = fw->rcvt0_data_dma_reg;
1090 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1091 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001092
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001093 iter_reg = fw->rcvt1_data_dma_reg;
1094 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1095 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001096
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001097 /* RISC registers. */
1098 iter_reg = fw->risc_gp_reg;
1099 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1100 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1101 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1102 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1103 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1104 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1105 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1106 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001107
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001108 /* Local memory controller registers. */
1109 iter_reg = fw->lmc_reg;
1110 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1111 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1112 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1113 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1114 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1115 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1116 qla24xx_read_window(reg, 0x3060, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001117
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001118 /* Fibre Protocol Module registers. */
1119 iter_reg = fw->fpm_hdw_reg;
1120 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1121 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1122 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1123 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1124 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1125 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1126 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1127 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1128 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1129 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1130 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1131 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001132
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001133 /* Frame Buffer registers. */
1134 iter_reg = fw->fb_hdw_reg;
1135 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1136 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1137 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1138 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1139 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1140 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1141 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1142 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1143 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1144 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1145 qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001146
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001147 rval = qla24xx_soft_reset(ha);
1148 if (rval != QLA_SUCCESS)
1149 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001150
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001151 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001152 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001153 if (rval != QLA_SUCCESS)
1154 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001155
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001156 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001157
1158 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001159
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001160 nxt_chain = (void *)ha->fw_dump + ha->chain_offset;
1161 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
1162 if (last_chain) {
1163 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1164 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1165 }
1166
1167 /* Adjust valid length. */
1168 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1169
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001170qla24xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001171 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001172
1173qla24xx_fw_dump_failed:
1174 if (!hardware_locked)
1175 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1176}
1177
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001178void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001179qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001180{
1181 int rval;
1182 uint32_t cnt;
1183 uint32_t risc_address;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001184 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001185 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1186 uint32_t __iomem *dmp_reg;
1187 uint32_t *iter_reg;
1188 uint16_t __iomem *mbx_reg;
1189 unsigned long flags;
1190 struct qla25xx_fw_dump *fw;
1191 uint32_t ext_mem_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001192 void *nxt, *nxt_chain;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001193 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001194 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001195
1196 risc_address = ext_mem_cnt = 0;
1197 flags = 0;
1198
1199 if (!hardware_locked)
1200 spin_lock_irqsave(&ha->hardware_lock, flags);
1201
1202 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001203 ql_log(ql_log_warn, vha, 0xd008,
1204 "No buffer available for dump.\n");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001205 goto qla25xx_fw_dump_failed;
1206 }
1207
1208 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001209 ql_log(ql_log_warn, vha, 0xd009,
1210 "Firmware has been previously dumped (%p) "
1211 "-- ignoring request.\n",
1212 ha->fw_dump);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001213 goto qla25xx_fw_dump_failed;
1214 }
1215 fw = &ha->fw_dump->isp.isp25;
1216 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquezb5836922007-09-20 14:07:39 -07001217 ha->fw_dump->version = __constant_htonl(2);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001218
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001219 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1220
1221 /* Pause RISC. */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001222 rval = qla24xx_pause_risc(reg);
1223 if (rval != QLA_SUCCESS)
1224 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001225
Andrew Vasquezb5836922007-09-20 14:07:39 -07001226 /* Host/Risc registers. */
1227 iter_reg = fw->host_risc_reg;
1228 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1229 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1230
1231 /* PCIe registers. */
1232 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1233 RD_REG_DWORD(&reg->iobase_addr);
1234 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1235 dmp_reg = &reg->iobase_c4;
1236 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1237 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1238 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1239 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001240
Andrew Vasquezb5836922007-09-20 14:07:39 -07001241 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1242 RD_REG_DWORD(&reg->iobase_window);
1243
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001244 /* Host interface registers. */
1245 dmp_reg = &reg->flash_addr;
1246 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1247 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001248
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001249 /* Disable interrupts. */
1250 WRT_REG_DWORD(&reg->ictrl, 0);
1251 RD_REG_DWORD(&reg->ictrl);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001252
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001253 /* Shadow registers. */
1254 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1255 RD_REG_DWORD(&reg->iobase_addr);
1256 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1257 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001258
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001259 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1260 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001261
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001262 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1263 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001264
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001265 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1266 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001267
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001268 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1269 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001270
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001271 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1272 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001273
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001274 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1275 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001276
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001277 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1278 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001279
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001280 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1281 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001282
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001283 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1284 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001285
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001286 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1287 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001288
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001289 /* RISC I/O register. */
1290 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1291 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001292
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001293 /* Mailbox registers. */
1294 mbx_reg = &reg->mailbox0;
1295 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1296 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001297
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001298 /* Transfer sequence registers. */
1299 iter_reg = fw->xseq_gp_reg;
1300 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1301 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1302 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1303 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1304 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1305 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1306 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1307 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001308
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001309 iter_reg = fw->xseq_0_reg;
1310 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1311 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1312 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001313
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001314 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001315
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001316 /* Receive sequence registers. */
1317 iter_reg = fw->rseq_gp_reg;
1318 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1319 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1320 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1321 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1322 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1323 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1324 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1325 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001326
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001327 iter_reg = fw->rseq_0_reg;
1328 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1329 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001330
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001331 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1332 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001333
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001334 /* Auxiliary sequence registers. */
1335 iter_reg = fw->aseq_gp_reg;
1336 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1337 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1338 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1339 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1340 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1341 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1342 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1343 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001344
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001345 iter_reg = fw->aseq_0_reg;
1346 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1347 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001348
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001349 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1350 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001351
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001352 /* Command DMA registers. */
1353 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001354
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001355 /* Queues. */
1356 iter_reg = fw->req0_dma_reg;
1357 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1358 dmp_reg = &reg->iobase_q;
1359 for (cnt = 0; cnt < 7; cnt++)
1360 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001361
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001362 iter_reg = fw->resp0_dma_reg;
1363 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1364 dmp_reg = &reg->iobase_q;
1365 for (cnt = 0; cnt < 7; cnt++)
1366 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001367
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001368 iter_reg = fw->req1_dma_reg;
1369 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1370 dmp_reg = &reg->iobase_q;
1371 for (cnt = 0; cnt < 7; cnt++)
1372 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001373
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001374 /* Transmit DMA registers. */
1375 iter_reg = fw->xmt0_dma_reg;
1376 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1377 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001378
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001379 iter_reg = fw->xmt1_dma_reg;
1380 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1381 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001382
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001383 iter_reg = fw->xmt2_dma_reg;
1384 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1385 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001386
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001387 iter_reg = fw->xmt3_dma_reg;
1388 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1389 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001390
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001391 iter_reg = fw->xmt4_dma_reg;
1392 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1393 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001394
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001395 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001396
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001397 /* Receive DMA registers. */
1398 iter_reg = fw->rcvt0_data_dma_reg;
1399 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1400 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001401
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001402 iter_reg = fw->rcvt1_data_dma_reg;
1403 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1404 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001405
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001406 /* RISC registers. */
1407 iter_reg = fw->risc_gp_reg;
1408 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1409 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1410 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1411 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1412 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1413 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1414 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1415 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001416
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001417 /* Local memory controller registers. */
1418 iter_reg = fw->lmc_reg;
1419 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1420 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1421 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1422 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1423 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1424 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1425 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1426 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001427
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001428 /* Fibre Protocol Module registers. */
1429 iter_reg = fw->fpm_hdw_reg;
1430 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1431 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1432 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1433 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1434 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1435 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1436 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1437 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1438 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1439 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1440 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1441 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001442
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001443 /* Frame Buffer registers. */
1444 iter_reg = fw->fb_hdw_reg;
1445 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1446 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1447 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1448 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1449 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1450 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1451 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1452 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1453 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1454 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1455 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1456 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001457
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001458 /* Multi queue registers */
1459 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1460 &last_chain);
1461
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001462 rval = qla24xx_soft_reset(ha);
1463 if (rval != QLA_SUCCESS)
1464 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001465
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001466 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001467 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001468 if (rval != QLA_SUCCESS)
1469 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001470
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001471 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001472
Bart Van Assche7f544d02013-06-25 11:27:27 -04001473 qla24xx_copy_eft(ha, nxt);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001474
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001475 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001476 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1477 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001478 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001479 if (last_chain) {
1480 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1481 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1482 }
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001483
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001484 /* Adjust valid length. */
1485 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1486
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001487qla25xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001488 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001489
1490qla25xx_fw_dump_failed:
1491 if (!hardware_locked)
1492 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1493}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001494
1495void
1496qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1497{
1498 int rval;
1499 uint32_t cnt;
1500 uint32_t risc_address;
1501 struct qla_hw_data *ha = vha->hw;
1502 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1503 uint32_t __iomem *dmp_reg;
1504 uint32_t *iter_reg;
1505 uint16_t __iomem *mbx_reg;
1506 unsigned long flags;
1507 struct qla81xx_fw_dump *fw;
1508 uint32_t ext_mem_cnt;
1509 void *nxt, *nxt_chain;
1510 uint32_t *last_chain = NULL;
1511 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1512
1513 risc_address = ext_mem_cnt = 0;
1514 flags = 0;
1515
1516 if (!hardware_locked)
1517 spin_lock_irqsave(&ha->hardware_lock, flags);
1518
1519 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001520 ql_log(ql_log_warn, vha, 0xd00a,
1521 "No buffer available for dump.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001522 goto qla81xx_fw_dump_failed;
1523 }
1524
1525 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001526 ql_log(ql_log_warn, vha, 0xd00b,
1527 "Firmware has been previously dumped (%p) "
1528 "-- ignoring request.\n",
1529 ha->fw_dump);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001530 goto qla81xx_fw_dump_failed;
1531 }
1532 fw = &ha->fw_dump->isp.isp81;
1533 qla2xxx_prep_dump(ha, ha->fw_dump);
1534
1535 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1536
1537 /* Pause RISC. */
1538 rval = qla24xx_pause_risc(reg);
1539 if (rval != QLA_SUCCESS)
1540 goto qla81xx_fw_dump_failed_0;
1541
1542 /* Host/Risc registers. */
1543 iter_reg = fw->host_risc_reg;
1544 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1545 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1546
1547 /* PCIe registers. */
1548 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1549 RD_REG_DWORD(&reg->iobase_addr);
1550 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1551 dmp_reg = &reg->iobase_c4;
1552 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1553 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1554 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1555 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1556
1557 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1558 RD_REG_DWORD(&reg->iobase_window);
1559
1560 /* Host interface registers. */
1561 dmp_reg = &reg->flash_addr;
1562 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1563 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1564
1565 /* Disable interrupts. */
1566 WRT_REG_DWORD(&reg->ictrl, 0);
1567 RD_REG_DWORD(&reg->ictrl);
1568
1569 /* Shadow registers. */
1570 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1571 RD_REG_DWORD(&reg->iobase_addr);
1572 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1573 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1574
1575 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1576 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1577
1578 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1579 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1580
1581 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1582 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1583
1584 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1585 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1586
1587 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1588 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1589
1590 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1591 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1592
1593 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1594 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1595
1596 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1597 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1598
1599 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1600 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1601
1602 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1603 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1604
1605 /* RISC I/O register. */
1606 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1607 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1608
1609 /* Mailbox registers. */
1610 mbx_reg = &reg->mailbox0;
1611 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1612 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1613
1614 /* Transfer sequence registers. */
1615 iter_reg = fw->xseq_gp_reg;
1616 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1617 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1618 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1619 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1620 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1621 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1622 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1623 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1624
1625 iter_reg = fw->xseq_0_reg;
1626 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1627 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1628 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1629
1630 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1631
1632 /* Receive sequence registers. */
1633 iter_reg = fw->rseq_gp_reg;
1634 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1635 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1636 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1637 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1638 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1639 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1640 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1641 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1642
1643 iter_reg = fw->rseq_0_reg;
1644 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1645 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1646
1647 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1648 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1649
1650 /* Auxiliary sequence registers. */
1651 iter_reg = fw->aseq_gp_reg;
1652 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1653 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1654 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1655 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1656 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1657 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1658 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1659 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
1660
1661 iter_reg = fw->aseq_0_reg;
1662 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1663 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
1664
1665 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1666 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
1667
1668 /* Command DMA registers. */
1669 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
1670
1671 /* Queues. */
1672 iter_reg = fw->req0_dma_reg;
1673 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1674 dmp_reg = &reg->iobase_q;
1675 for (cnt = 0; cnt < 7; cnt++)
1676 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1677
1678 iter_reg = fw->resp0_dma_reg;
1679 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1680 dmp_reg = &reg->iobase_q;
1681 for (cnt = 0; cnt < 7; cnt++)
1682 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1683
1684 iter_reg = fw->req1_dma_reg;
1685 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1686 dmp_reg = &reg->iobase_q;
1687 for (cnt = 0; cnt < 7; cnt++)
1688 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1689
1690 /* Transmit DMA registers. */
1691 iter_reg = fw->xmt0_dma_reg;
1692 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1693 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
1694
1695 iter_reg = fw->xmt1_dma_reg;
1696 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1697 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
1698
1699 iter_reg = fw->xmt2_dma_reg;
1700 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1701 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
1702
1703 iter_reg = fw->xmt3_dma_reg;
1704 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1705 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
1706
1707 iter_reg = fw->xmt4_dma_reg;
1708 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1709 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
1710
1711 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
1712
1713 /* Receive DMA registers. */
1714 iter_reg = fw->rcvt0_data_dma_reg;
1715 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1716 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
1717
1718 iter_reg = fw->rcvt1_data_dma_reg;
1719 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1720 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
1721
1722 /* RISC registers. */
1723 iter_reg = fw->risc_gp_reg;
1724 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1725 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1726 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1727 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1728 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1729 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1730 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1731 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
1732
1733 /* Local memory controller registers. */
1734 iter_reg = fw->lmc_reg;
1735 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1736 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1737 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1738 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1739 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1740 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1741 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1742 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
1743
1744 /* Fibre Protocol Module registers. */
1745 iter_reg = fw->fpm_hdw_reg;
1746 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1747 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1748 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1749 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1750 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1751 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1752 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1753 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1754 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1755 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1756 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1757 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
1758 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
1759 qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
1760
1761 /* Frame Buffer registers. */
1762 iter_reg = fw->fb_hdw_reg;
1763 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1764 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1765 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1766 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1767 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1768 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1769 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1770 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1771 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1772 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1773 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1774 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
1775 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
1776
1777 /* Multi queue registers */
1778 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1779 &last_chain);
1780
1781 rval = qla24xx_soft_reset(ha);
1782 if (rval != QLA_SUCCESS)
1783 goto qla81xx_fw_dump_failed_0;
1784
1785 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
1786 &nxt);
1787 if (rval != QLA_SUCCESS)
1788 goto qla81xx_fw_dump_failed_0;
1789
1790 nxt = qla2xxx_copy_queues(ha, nxt);
1791
Bart Van Assche7f544d02013-06-25 11:27:27 -04001792 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001793
1794 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001795 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1796 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001797 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001798 if (last_chain) {
1799 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
1800 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
1801 }
1802
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001803 /* Adjust valid length. */
1804 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1805
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001806qla81xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001807 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001808
1809qla81xx_fw_dump_failed:
1810 if (!hardware_locked)
1811 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1812}
1813
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001814void
1815qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1816{
1817 int rval;
1818 uint32_t cnt, reg_data;
1819 uint32_t risc_address;
1820 struct qla_hw_data *ha = vha->hw;
1821 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1822 uint32_t __iomem *dmp_reg;
1823 uint32_t *iter_reg;
1824 uint16_t __iomem *mbx_reg;
1825 unsigned long flags;
1826 struct qla83xx_fw_dump *fw;
1827 uint32_t ext_mem_cnt;
1828 void *nxt, *nxt_chain;
1829 uint32_t *last_chain = NULL;
1830 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1831
1832 risc_address = ext_mem_cnt = 0;
1833 flags = 0;
1834
1835 if (!hardware_locked)
1836 spin_lock_irqsave(&ha->hardware_lock, flags);
1837
1838 if (!ha->fw_dump) {
1839 ql_log(ql_log_warn, vha, 0xd00c,
1840 "No buffer available for dump!!!\n");
1841 goto qla83xx_fw_dump_failed;
1842 }
1843
1844 if (ha->fw_dumped) {
1845 ql_log(ql_log_warn, vha, 0xd00d,
1846 "Firmware has been previously dumped (%p) -- ignoring "
1847 "request...\n", ha->fw_dump);
1848 goto qla83xx_fw_dump_failed;
1849 }
1850 fw = &ha->fw_dump->isp.isp83;
1851 qla2xxx_prep_dump(ha, ha->fw_dump);
1852
1853 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1854
1855 /* Pause RISC. */
1856 rval = qla24xx_pause_risc(reg);
1857 if (rval != QLA_SUCCESS)
1858 goto qla83xx_fw_dump_failed_0;
1859
1860 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
1861 dmp_reg = &reg->iobase_window;
1862 reg_data = RD_REG_DWORD(dmp_reg);
1863 WRT_REG_DWORD(dmp_reg, 0);
1864
1865 dmp_reg = &reg->unused_4_1[0];
1866 reg_data = RD_REG_DWORD(dmp_reg);
1867 WRT_REG_DWORD(dmp_reg, 0);
1868
1869 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
1870 dmp_reg = &reg->unused_4_1[2];
1871 reg_data = RD_REG_DWORD(dmp_reg);
1872 WRT_REG_DWORD(dmp_reg, 0);
1873
1874 /* select PCR and disable ecc checking and correction */
1875 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1876 RD_REG_DWORD(&reg->iobase_addr);
1877 WRT_REG_DWORD(&reg->iobase_select, 0x60000000); /* write to F0h = PCR */
1878
1879 /* Host/Risc registers. */
1880 iter_reg = fw->host_risc_reg;
1881 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1882 iter_reg = qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1883 qla24xx_read_window(reg, 0x7040, 16, iter_reg);
1884
1885 /* PCIe registers. */
1886 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1887 RD_REG_DWORD(&reg->iobase_addr);
1888 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1889 dmp_reg = &reg->iobase_c4;
1890 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg++));
1891 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg++));
1892 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1893 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1894
1895 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1896 RD_REG_DWORD(&reg->iobase_window);
1897
1898 /* Host interface registers. */
1899 dmp_reg = &reg->flash_addr;
1900 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
1901 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
1902
1903 /* Disable interrupts. */
1904 WRT_REG_DWORD(&reg->ictrl, 0);
1905 RD_REG_DWORD(&reg->ictrl);
1906
1907 /* Shadow registers. */
1908 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1909 RD_REG_DWORD(&reg->iobase_addr);
1910 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1911 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1912
1913 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1914 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1915
1916 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1917 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1918
1919 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1920 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1921
1922 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1923 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1924
1925 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1926 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1927
1928 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1929 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1930
1931 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1932 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1933
1934 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1935 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1936
1937 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1938 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1939
1940 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1941 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1942
1943 /* RISC I/O register. */
1944 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1945 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1946
1947 /* Mailbox registers. */
1948 mbx_reg = &reg->mailbox0;
1949 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
1950 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
1951
1952 /* Transfer sequence registers. */
1953 iter_reg = fw->xseq_gp_reg;
1954 iter_reg = qla24xx_read_window(reg, 0xBE00, 16, iter_reg);
1955 iter_reg = qla24xx_read_window(reg, 0xBE10, 16, iter_reg);
1956 iter_reg = qla24xx_read_window(reg, 0xBE20, 16, iter_reg);
1957 iter_reg = qla24xx_read_window(reg, 0xBE30, 16, iter_reg);
1958 iter_reg = qla24xx_read_window(reg, 0xBE40, 16, iter_reg);
1959 iter_reg = qla24xx_read_window(reg, 0xBE50, 16, iter_reg);
1960 iter_reg = qla24xx_read_window(reg, 0xBE60, 16, iter_reg);
1961 iter_reg = qla24xx_read_window(reg, 0xBE70, 16, iter_reg);
1962 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1963 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1964 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1965 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1966 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1967 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1968 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1969 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1970
1971 iter_reg = fw->xseq_0_reg;
1972 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1973 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1974 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1975
1976 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1977
1978 qla24xx_read_window(reg, 0xBEF0, 16, fw->xseq_2_reg);
1979
1980 /* Receive sequence registers. */
1981 iter_reg = fw->rseq_gp_reg;
1982 iter_reg = qla24xx_read_window(reg, 0xFE00, 16, iter_reg);
1983 iter_reg = qla24xx_read_window(reg, 0xFE10, 16, iter_reg);
1984 iter_reg = qla24xx_read_window(reg, 0xFE20, 16, iter_reg);
1985 iter_reg = qla24xx_read_window(reg, 0xFE30, 16, iter_reg);
1986 iter_reg = qla24xx_read_window(reg, 0xFE40, 16, iter_reg);
1987 iter_reg = qla24xx_read_window(reg, 0xFE50, 16, iter_reg);
1988 iter_reg = qla24xx_read_window(reg, 0xFE60, 16, iter_reg);
1989 iter_reg = qla24xx_read_window(reg, 0xFE70, 16, iter_reg);
1990 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1991 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1992 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1993 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1994 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1995 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1996 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1997 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1998
1999 iter_reg = fw->rseq_0_reg;
2000 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
2001 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
2002
2003 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
2004 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
2005 qla24xx_read_window(reg, 0xFEF0, 16, fw->rseq_3_reg);
2006
2007 /* Auxiliary sequence registers. */
2008 iter_reg = fw->aseq_gp_reg;
2009 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
2010 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
2011 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
2012 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
2013 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
2014 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
2015 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
2016 iter_reg = qla24xx_read_window(reg, 0xB070, 16, iter_reg);
2017 iter_reg = qla24xx_read_window(reg, 0xB100, 16, iter_reg);
2018 iter_reg = qla24xx_read_window(reg, 0xB110, 16, iter_reg);
2019 iter_reg = qla24xx_read_window(reg, 0xB120, 16, iter_reg);
2020 iter_reg = qla24xx_read_window(reg, 0xB130, 16, iter_reg);
2021 iter_reg = qla24xx_read_window(reg, 0xB140, 16, iter_reg);
2022 iter_reg = qla24xx_read_window(reg, 0xB150, 16, iter_reg);
2023 iter_reg = qla24xx_read_window(reg, 0xB160, 16, iter_reg);
2024 qla24xx_read_window(reg, 0xB170, 16, iter_reg);
2025
2026 iter_reg = fw->aseq_0_reg;
2027 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
2028 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
2029
2030 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
2031 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
2032 qla24xx_read_window(reg, 0xB1F0, 16, fw->aseq_3_reg);
2033
2034 /* Command DMA registers. */
2035 iter_reg = fw->cmd_dma_reg;
2036 iter_reg = qla24xx_read_window(reg, 0x7100, 16, iter_reg);
2037 iter_reg = qla24xx_read_window(reg, 0x7120, 16, iter_reg);
2038 iter_reg = qla24xx_read_window(reg, 0x7130, 16, iter_reg);
2039 qla24xx_read_window(reg, 0x71F0, 16, iter_reg);
2040
2041 /* Queues. */
2042 iter_reg = fw->req0_dma_reg;
2043 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
2044 dmp_reg = &reg->iobase_q;
2045 for (cnt = 0; cnt < 7; cnt++)
2046 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2047
2048 iter_reg = fw->resp0_dma_reg;
2049 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
2050 dmp_reg = &reg->iobase_q;
2051 for (cnt = 0; cnt < 7; cnt++)
2052 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2053
2054 iter_reg = fw->req1_dma_reg;
2055 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
2056 dmp_reg = &reg->iobase_q;
2057 for (cnt = 0; cnt < 7; cnt++)
2058 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
2059
2060 /* Transmit DMA registers. */
2061 iter_reg = fw->xmt0_dma_reg;
2062 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
2063 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
2064
2065 iter_reg = fw->xmt1_dma_reg;
2066 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
2067 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
2068
2069 iter_reg = fw->xmt2_dma_reg;
2070 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
2071 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
2072
2073 iter_reg = fw->xmt3_dma_reg;
2074 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
2075 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
2076
2077 iter_reg = fw->xmt4_dma_reg;
2078 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
2079 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
2080
2081 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
2082
2083 /* Receive DMA registers. */
2084 iter_reg = fw->rcvt0_data_dma_reg;
2085 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
2086 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
2087
2088 iter_reg = fw->rcvt1_data_dma_reg;
2089 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
2090 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
2091
2092 /* RISC registers. */
2093 iter_reg = fw->risc_gp_reg;
2094 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
2095 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
2096 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
2097 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
2098 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
2099 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
2100 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
2101 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
2102
2103 /* Local memory controller registers. */
2104 iter_reg = fw->lmc_reg;
2105 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
2106 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
2107 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
2108 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
2109 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
2110 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
2111 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
2112 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
2113
2114 /* Fibre Protocol Module registers. */
2115 iter_reg = fw->fpm_hdw_reg;
2116 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
2117 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
2118 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
2119 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
2120 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
2121 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
2122 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
2123 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
2124 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
2125 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
2126 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
2127 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
2128 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
2129 iter_reg = qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
2130 iter_reg = qla24xx_read_window(reg, 0x40E0, 16, iter_reg);
2131 qla24xx_read_window(reg, 0x40F0, 16, iter_reg);
2132
2133 /* RQ0 Array registers. */
2134 iter_reg = fw->rq0_array_reg;
2135 iter_reg = qla24xx_read_window(reg, 0x5C00, 16, iter_reg);
2136 iter_reg = qla24xx_read_window(reg, 0x5C10, 16, iter_reg);
2137 iter_reg = qla24xx_read_window(reg, 0x5C20, 16, iter_reg);
2138 iter_reg = qla24xx_read_window(reg, 0x5C30, 16, iter_reg);
2139 iter_reg = qla24xx_read_window(reg, 0x5C40, 16, iter_reg);
2140 iter_reg = qla24xx_read_window(reg, 0x5C50, 16, iter_reg);
2141 iter_reg = qla24xx_read_window(reg, 0x5C60, 16, iter_reg);
2142 iter_reg = qla24xx_read_window(reg, 0x5C70, 16, iter_reg);
2143 iter_reg = qla24xx_read_window(reg, 0x5C80, 16, iter_reg);
2144 iter_reg = qla24xx_read_window(reg, 0x5C90, 16, iter_reg);
2145 iter_reg = qla24xx_read_window(reg, 0x5CA0, 16, iter_reg);
2146 iter_reg = qla24xx_read_window(reg, 0x5CB0, 16, iter_reg);
2147 iter_reg = qla24xx_read_window(reg, 0x5CC0, 16, iter_reg);
2148 iter_reg = qla24xx_read_window(reg, 0x5CD0, 16, iter_reg);
2149 iter_reg = qla24xx_read_window(reg, 0x5CE0, 16, iter_reg);
2150 qla24xx_read_window(reg, 0x5CF0, 16, iter_reg);
2151
2152 /* RQ1 Array registers. */
2153 iter_reg = fw->rq1_array_reg;
2154 iter_reg = qla24xx_read_window(reg, 0x5D00, 16, iter_reg);
2155 iter_reg = qla24xx_read_window(reg, 0x5D10, 16, iter_reg);
2156 iter_reg = qla24xx_read_window(reg, 0x5D20, 16, iter_reg);
2157 iter_reg = qla24xx_read_window(reg, 0x5D30, 16, iter_reg);
2158 iter_reg = qla24xx_read_window(reg, 0x5D40, 16, iter_reg);
2159 iter_reg = qla24xx_read_window(reg, 0x5D50, 16, iter_reg);
2160 iter_reg = qla24xx_read_window(reg, 0x5D60, 16, iter_reg);
2161 iter_reg = qla24xx_read_window(reg, 0x5D70, 16, iter_reg);
2162 iter_reg = qla24xx_read_window(reg, 0x5D80, 16, iter_reg);
2163 iter_reg = qla24xx_read_window(reg, 0x5D90, 16, iter_reg);
2164 iter_reg = qla24xx_read_window(reg, 0x5DA0, 16, iter_reg);
2165 iter_reg = qla24xx_read_window(reg, 0x5DB0, 16, iter_reg);
2166 iter_reg = qla24xx_read_window(reg, 0x5DC0, 16, iter_reg);
2167 iter_reg = qla24xx_read_window(reg, 0x5DD0, 16, iter_reg);
2168 iter_reg = qla24xx_read_window(reg, 0x5DE0, 16, iter_reg);
2169 qla24xx_read_window(reg, 0x5DF0, 16, iter_reg);
2170
2171 /* RP0 Array registers. */
2172 iter_reg = fw->rp0_array_reg;
2173 iter_reg = qla24xx_read_window(reg, 0x5E00, 16, iter_reg);
2174 iter_reg = qla24xx_read_window(reg, 0x5E10, 16, iter_reg);
2175 iter_reg = qla24xx_read_window(reg, 0x5E20, 16, iter_reg);
2176 iter_reg = qla24xx_read_window(reg, 0x5E30, 16, iter_reg);
2177 iter_reg = qla24xx_read_window(reg, 0x5E40, 16, iter_reg);
2178 iter_reg = qla24xx_read_window(reg, 0x5E50, 16, iter_reg);
2179 iter_reg = qla24xx_read_window(reg, 0x5E60, 16, iter_reg);
2180 iter_reg = qla24xx_read_window(reg, 0x5E70, 16, iter_reg);
2181 iter_reg = qla24xx_read_window(reg, 0x5E80, 16, iter_reg);
2182 iter_reg = qla24xx_read_window(reg, 0x5E90, 16, iter_reg);
2183 iter_reg = qla24xx_read_window(reg, 0x5EA0, 16, iter_reg);
2184 iter_reg = qla24xx_read_window(reg, 0x5EB0, 16, iter_reg);
2185 iter_reg = qla24xx_read_window(reg, 0x5EC0, 16, iter_reg);
2186 iter_reg = qla24xx_read_window(reg, 0x5ED0, 16, iter_reg);
2187 iter_reg = qla24xx_read_window(reg, 0x5EE0, 16, iter_reg);
2188 qla24xx_read_window(reg, 0x5EF0, 16, iter_reg);
2189
2190 /* RP1 Array registers. */
2191 iter_reg = fw->rp1_array_reg;
2192 iter_reg = qla24xx_read_window(reg, 0x5F00, 16, iter_reg);
2193 iter_reg = qla24xx_read_window(reg, 0x5F10, 16, iter_reg);
2194 iter_reg = qla24xx_read_window(reg, 0x5F20, 16, iter_reg);
2195 iter_reg = qla24xx_read_window(reg, 0x5F30, 16, iter_reg);
2196 iter_reg = qla24xx_read_window(reg, 0x5F40, 16, iter_reg);
2197 iter_reg = qla24xx_read_window(reg, 0x5F50, 16, iter_reg);
2198 iter_reg = qla24xx_read_window(reg, 0x5F60, 16, iter_reg);
2199 iter_reg = qla24xx_read_window(reg, 0x5F70, 16, iter_reg);
2200 iter_reg = qla24xx_read_window(reg, 0x5F80, 16, iter_reg);
2201 iter_reg = qla24xx_read_window(reg, 0x5F90, 16, iter_reg);
2202 iter_reg = qla24xx_read_window(reg, 0x5FA0, 16, iter_reg);
2203 iter_reg = qla24xx_read_window(reg, 0x5FB0, 16, iter_reg);
2204 iter_reg = qla24xx_read_window(reg, 0x5FC0, 16, iter_reg);
2205 iter_reg = qla24xx_read_window(reg, 0x5FD0, 16, iter_reg);
2206 iter_reg = qla24xx_read_window(reg, 0x5FE0, 16, iter_reg);
2207 qla24xx_read_window(reg, 0x5FF0, 16, iter_reg);
2208
2209 iter_reg = fw->at0_array_reg;
2210 iter_reg = qla24xx_read_window(reg, 0x7080, 16, iter_reg);
2211 iter_reg = qla24xx_read_window(reg, 0x7090, 16, iter_reg);
2212 iter_reg = qla24xx_read_window(reg, 0x70A0, 16, iter_reg);
2213 iter_reg = qla24xx_read_window(reg, 0x70B0, 16, iter_reg);
2214 iter_reg = qla24xx_read_window(reg, 0x70C0, 16, iter_reg);
2215 iter_reg = qla24xx_read_window(reg, 0x70D0, 16, iter_reg);
2216 iter_reg = qla24xx_read_window(reg, 0x70E0, 16, iter_reg);
2217 qla24xx_read_window(reg, 0x70F0, 16, iter_reg);
2218
2219 /* I/O Queue Control registers. */
2220 qla24xx_read_window(reg, 0x7800, 16, fw->queue_control_reg);
2221
2222 /* Frame Buffer registers. */
2223 iter_reg = fw->fb_hdw_reg;
2224 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
2225 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
2226 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
2227 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
2228 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
2229 iter_reg = qla24xx_read_window(reg, 0x6060, 16, iter_reg);
2230 iter_reg = qla24xx_read_window(reg, 0x6070, 16, iter_reg);
2231 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
2232 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
2233 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
2234 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
2235 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
2236 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
2237 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
2238 iter_reg = qla24xx_read_window(reg, 0x6530, 16, iter_reg);
2239 iter_reg = qla24xx_read_window(reg, 0x6540, 16, iter_reg);
2240 iter_reg = qla24xx_read_window(reg, 0x6550, 16, iter_reg);
2241 iter_reg = qla24xx_read_window(reg, 0x6560, 16, iter_reg);
2242 iter_reg = qla24xx_read_window(reg, 0x6570, 16, iter_reg);
2243 iter_reg = qla24xx_read_window(reg, 0x6580, 16, iter_reg);
2244 iter_reg = qla24xx_read_window(reg, 0x6590, 16, iter_reg);
2245 iter_reg = qla24xx_read_window(reg, 0x65A0, 16, iter_reg);
2246 iter_reg = qla24xx_read_window(reg, 0x65B0, 16, iter_reg);
2247 iter_reg = qla24xx_read_window(reg, 0x65C0, 16, iter_reg);
2248 iter_reg = qla24xx_read_window(reg, 0x65D0, 16, iter_reg);
2249 iter_reg = qla24xx_read_window(reg, 0x65E0, 16, iter_reg);
2250 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
2251
2252 /* Multi queue registers */
2253 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
2254 &last_chain);
2255
2256 rval = qla24xx_soft_reset(ha);
2257 if (rval != QLA_SUCCESS) {
2258 ql_log(ql_log_warn, vha, 0xd00e,
2259 "SOFT RESET FAILED, forcing continuation of dump!!!\n");
2260 rval = QLA_SUCCESS;
2261
2262 ql_log(ql_log_warn, vha, 0xd00f, "try a bigger hammer!!!\n");
2263
2264 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2265 RD_REG_DWORD(&reg->hccr);
2266
2267 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2268 RD_REG_DWORD(&reg->hccr);
2269
2270 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2271 RD_REG_DWORD(&reg->hccr);
2272
2273 for (cnt = 30000; cnt && (RD_REG_WORD(&reg->mailbox0)); cnt--)
2274 udelay(5);
2275
2276 if (!cnt) {
2277 nxt = fw->code_ram;
Saurav Kashyap8c0bc702012-11-21 02:40:35 -05002278 nxt += sizeof(fw->code_ram);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002279 nxt += (ha->fw_memory_size - 0x100000 + 1);
2280 goto copy_queue;
2281 } else
2282 ql_log(ql_log_warn, vha, 0xd010,
2283 "bigger hammer success?\n");
2284 }
2285
2286 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
2287 &nxt);
2288 if (rval != QLA_SUCCESS)
2289 goto qla83xx_fw_dump_failed_0;
2290
2291copy_queue:
2292 nxt = qla2xxx_copy_queues(ha, nxt);
2293
Bart Van Assche7f544d02013-06-25 11:27:27 -04002294 qla24xx_copy_eft(ha, nxt);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002295
2296 /* Chain entries -- started with MQ. */
2297 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
2298 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002299 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002300 if (last_chain) {
2301 ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);
2302 *last_chain |= __constant_htonl(DUMP_CHAIN_LAST);
2303 }
2304
2305 /* Adjust valid length. */
2306 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
2307
2308qla83xx_fw_dump_failed_0:
2309 qla2xxx_dump_post_process(base_vha, rval);
2310
2311qla83xx_fw_dump_failed:
2312 if (!hardware_locked)
2313 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2314}
2315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316/****************************************************************************/
2317/* Driver Debug Functions. */
2318/****************************************************************************/
Chad Dupuiscfb09192011-11-18 09:03:07 -08002319
2320static inline int
2321ql_mask_match(uint32_t level)
2322{
2323 if (ql2xextended_error_logging == 1)
2324 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2325 return (level & ql2xextended_error_logging) == level;
2326}
2327
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002328/*
2329 * This function is for formatting and logging debug information.
2330 * It is to be used when vha is available. It formats the message
2331 * and logs it to the messages file.
2332 * parameters:
2333 * level: The level of the debug messages to be printed.
2334 * If ql2xextended_error_logging value is correctly set,
2335 * this message will appear in the messages file.
2336 * vha: Pointer to the scsi_qla_host_t.
2337 * id: This is a unique identifier for the level. It identifies the
2338 * part of the code from where the message originated.
2339 * msg: The message to be displayed.
2340 */
2341void
Joe Perches086b3e82011-11-18 09:03:05 -08002342ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2343{
2344 va_list va;
2345 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002346
Chad Dupuiscfb09192011-11-18 09:03:07 -08002347 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002348 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002349
Joe Perches086b3e82011-11-18 09:03:05 -08002350 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002351
Joe Perches086b3e82011-11-18 09:03:05 -08002352 vaf.fmt = fmt;
2353 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002354
Joe Perches086b3e82011-11-18 09:03:05 -08002355 if (vha != NULL) {
2356 const struct pci_dev *pdev = vha->hw->pdev;
2357 /* <module-name> <pci-name> <msg-id>:<host> Message */
2358 pr_warn("%s [%s]-%04x:%ld: %pV",
2359 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset,
2360 vha->host_no, &vaf);
2361 } else {
2362 pr_warn("%s [%s]-%04x: : %pV",
2363 QL_MSGHDR, "0000:00:00.0", id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002364 }
2365
Joe Perches086b3e82011-11-18 09:03:05 -08002366 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002367
2368}
2369
2370/*
2371 * This function is for formatting and logging debug information.
Masanari Iidad6a03582012-08-22 14:20:58 -04002372 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002373 * i.e., before host allocation. It formats the message and logs it
2374 * to the messages file.
2375 * parameters:
2376 * level: The level of the debug messages to be printed.
2377 * If ql2xextended_error_logging value is correctly set,
2378 * this message will appear in the messages file.
2379 * pdev: Pointer to the struct pci_dev.
2380 * id: This is a unique id for the level. It identifies the part
2381 * of the code from where the message originated.
2382 * msg: The message to be displayed.
2383 */
2384void
Joe Perches086b3e82011-11-18 09:03:05 -08002385ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2386 const char *fmt, ...)
2387{
2388 va_list va;
2389 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002390
2391 if (pdev == NULL)
2392 return;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002393 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002394 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002395
Joe Perches086b3e82011-11-18 09:03:05 -08002396 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002397
Joe Perches086b3e82011-11-18 09:03:05 -08002398 vaf.fmt = fmt;
2399 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002400
Joe Perches086b3e82011-11-18 09:03:05 -08002401 /* <module-name> <dev-name>:<msg-id> Message */
2402 pr_warn("%s [%s]-%04x: : %pV",
2403 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002404
Joe Perches086b3e82011-11-18 09:03:05 -08002405 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002406}
2407
2408/*
2409 * This function is for formatting and logging log messages.
2410 * It is to be used when vha is available. It formats the message
2411 * and logs it to the messages file. All the messages will be logged
2412 * irrespective of value of ql2xextended_error_logging.
2413 * parameters:
2414 * level: The level of the log messages to be printed in the
2415 * messages file.
2416 * vha: Pointer to the scsi_qla_host_t
2417 * id: This is a unique id for the level. It identifies the
2418 * part of the code from where the message originated.
2419 * msg: The message to be displayed.
2420 */
2421void
Joe Perches086b3e82011-11-18 09:03:05 -08002422ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2423{
2424 va_list va;
2425 struct va_format vaf;
2426 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002427
Joe Perches086b3e82011-11-18 09:03:05 -08002428 if (level > ql_errlev)
2429 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002430
Joe Perches086b3e82011-11-18 09:03:05 -08002431 if (vha != NULL) {
2432 const struct pci_dev *pdev = vha->hw->pdev;
2433 /* <module-name> <msg-id>:<host> Message */
2434 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x:%ld: ",
2435 QL_MSGHDR, dev_name(&(pdev->dev)), id, vha->host_no);
2436 } else {
2437 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2438 QL_MSGHDR, "0000:00:00.0", id);
2439 }
2440 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002441
Joe Perches086b3e82011-11-18 09:03:05 -08002442 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002443
Joe Perches086b3e82011-11-18 09:03:05 -08002444 vaf.fmt = fmt;
2445 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002446
Joe Perches086b3e82011-11-18 09:03:05 -08002447 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002448 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002449 pr_crit("%s%pV", pbuf, &vaf);
2450 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002451 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002452 pr_err("%s%pV", pbuf, &vaf);
2453 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002454 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002455 pr_warn("%s%pV", pbuf, &vaf);
2456 break;
2457 default:
2458 pr_info("%s%pV", pbuf, &vaf);
2459 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002460 }
2461
Joe Perches086b3e82011-11-18 09:03:05 -08002462 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002463}
2464
2465/*
2466 * This function is for formatting and logging log messages.
Masanari Iidad6a03582012-08-22 14:20:58 -04002467 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002468 * i.e., before host allocation. It formats the message and logs
2469 * it to the messages file. All the messages are logged irrespective
2470 * of the value of ql2xextended_error_logging.
2471 * parameters:
2472 * level: The level of the log messages to be printed in the
2473 * messages file.
2474 * pdev: Pointer to the struct pci_dev.
2475 * id: This is a unique id for the level. It identifies the
2476 * part of the code from where the message originated.
2477 * msg: The message to be displayed.
2478 */
2479void
Joe Perches086b3e82011-11-18 09:03:05 -08002480ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2481 const char *fmt, ...)
2482{
2483 va_list va;
2484 struct va_format vaf;
2485 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002486
2487 if (pdev == NULL)
2488 return;
Joe Perches086b3e82011-11-18 09:03:05 -08002489 if (level > ql_errlev)
2490 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002491
Joe Perches086b3e82011-11-18 09:03:05 -08002492 /* <module-name> <dev-name>:<msg-id> Message */
2493 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2494 QL_MSGHDR, dev_name(&(pdev->dev)), id);
2495 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002496
Joe Perches086b3e82011-11-18 09:03:05 -08002497 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002498
Joe Perches086b3e82011-11-18 09:03:05 -08002499 vaf.fmt = fmt;
2500 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002501
Joe Perches086b3e82011-11-18 09:03:05 -08002502 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002503 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002504 pr_crit("%s%pV", pbuf, &vaf);
2505 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002506 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002507 pr_err("%s%pV", pbuf, &vaf);
2508 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002509 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002510 pr_warn("%s%pV", pbuf, &vaf);
2511 break;
2512 default:
2513 pr_info("%s%pV", pbuf, &vaf);
2514 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002515 }
2516
Joe Perches086b3e82011-11-18 09:03:05 -08002517 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002518}
2519
2520void
2521ql_dump_regs(uint32_t level, scsi_qla_host_t *vha, int32_t id)
2522{
2523 int i;
2524 struct qla_hw_data *ha = vha->hw;
2525 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2526 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2527 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
2528 uint16_t __iomem *mbx_reg;
2529
Chad Dupuiscfb09192011-11-18 09:03:07 -08002530 if (!ql_mask_match(level))
2531 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002532
Chad Dupuiscfb09192011-11-18 09:03:07 -08002533 if (IS_QLA82XX(ha))
2534 mbx_reg = &reg82->mailbox_in[0];
2535 else if (IS_FWI2_CAPABLE(ha))
2536 mbx_reg = &reg24->mailbox0;
2537 else
2538 mbx_reg = MAILBOX_REG(ha, reg, 0);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002539
Chad Dupuiscfb09192011-11-18 09:03:07 -08002540 ql_dbg(level, vha, id, "Mailbox registers:\n");
2541 for (i = 0; i < 6; i++)
2542 ql_dbg(level, vha, id,
2543 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002544}
2545
2546
2547void
2548ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, int32_t id,
2549 uint8_t *b, uint32_t size)
2550{
2551 uint32_t cnt;
2552 uint8_t c;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002553
Chad Dupuiscfb09192011-11-18 09:03:07 -08002554 if (!ql_mask_match(level))
2555 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002556
Chad Dupuiscfb09192011-11-18 09:03:07 -08002557 ql_dbg(level, vha, id, " 0 1 2 3 4 5 6 7 8 "
2558 "9 Ah Bh Ch Dh Eh Fh\n");
2559 ql_dbg(level, vha, id, "----------------------------------"
2560 "----------------------------\n");
2561
2562 ql_dbg(level, vha, id, " ");
2563 for (cnt = 0; cnt < size;) {
2564 c = *b++;
2565 printk("%02x", (uint32_t) c);
2566 cnt++;
2567 if (!(cnt % 16))
2568 printk("\n");
2569 else
2570 printk(" ");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002571 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002572 if (cnt % 16)
2573 ql_dbg(level, vha, id, "\n");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002574}