blob: 907a7acb163960d204df86273fb51321618d62a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07007
8/*
9 * Table for showing the current message id in use for particular level
10 * Change this table for addition of log/debug messages.
Arun Easie02587d2011-08-16 11:29:23 -070011 * ----------------------------------------------------------------------
12 * | Level | Last Value Used | Holes |
13 * ----------------------------------------------------------------------
Sawan Chandak4243c112016-01-27 12:03:31 -050014 * | Module Init and Probe | 0x018f | 0x0146 |
Chad Dupuisf73cb692014-02-26 04:15:06 -050015 * | | | 0x015b-0x0160 |
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040016 * | | | 0x016e-0x0170 |
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -050017 * | Mailbox commands | 0x1192 | |
18 * | | | |
Giridhar Malavali088d09d2016-07-06 11:14:20 -040019 * | Device Discovery | 0x2003 | 0x2016 |
Bart Van Assche6593d5b2013-06-25 11:27:24 -040020 * | | | 0x2011-0x2012, |
Himanshu Madhanidf57cab2014-09-25 05:16:46 -040021 * | | | 0x2099-0x20a4 |
Himanshu Madhani6eb54712015-12-17 14:57:00 -050022 * | Queue Command and IO tracing | 0x3074 | 0x300b |
Arun Easi9e522cd2012-08-22 14:21:31 -040023 * | | | 0x3027-0x3028 |
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040024 * | | | 0x303d-0x3041 |
25 * | | | 0x302d,0x3033 |
26 * | | | 0x3036,0x3038 |
27 * | | | 0x303a |
Armen Baloyane8f5e952013-10-30 03:38:17 -040028 * | DPC Thread | 0x4023 | 0x4002,0x4013 |
Alexei Potashnikb7bd1042015-12-17 14:57:02 -050029 * | Async Events | 0x5089 | 0x502b-0x502f |
Joe Carnuccioa29b3dd2016-07-06 11:14:19 -040030 * | | | 0x5047 |
Saurav Kashyap6ddcfef2013-08-27 01:37:53 -040031 * | | | 0x5084,0x5075 |
Chad Dupuisa78951b2013-08-27 01:37:34 -040032 * | | | 0x503d,0x5044 |
Chad Dupuis8e5a9482014-08-08 07:38:09 -040033 * | | | 0x507b,0x505f |
Armen Baloyan71e56002013-08-27 01:37:38 -040034 * | Timer Routines | 0x6012 | |
Harish Zunjarrao243de672016-01-27 12:03:33 -050035 * | User Space Interactions | 0x70e3 | 0x7018,0x702e |
Chad Dupuisf73cb692014-02-26 04:15:06 -050036 * | | | 0x7020,0x7024 |
37 * | | | 0x7039,0x7045 |
38 * | | | 0x7073-0x7075 |
39 * | | | 0x70a5-0x70a6 |
40 * | | | 0x70a8,0x70ab |
41 * | | | 0x70ad-0x70ae |
Joe Carnucciof1d7ce62016-07-06 11:14:17 -040042 * | | | 0x70d0-0x70d6 |
Chad Dupuisf73cb692014-02-26 04:15:06 -050043 * | | | 0x70d7-0x70db |
44 * | | | 0x70de-0x70df |
Chad Dupuis7108b762014-04-11 16:54:45 -040045 * | Task Management | 0x803d | 0x8000,0x800b |
Chad Dupuis63ee7072014-04-11 16:54:46 -040046 * | | | 0x8019 |
Chad Dupuis7108b762014-04-11 16:54:45 -040047 * | | | 0x8025,0x8026 |
48 * | | | 0x8031,0x8032 |
49 * | | | 0x8039,0x803c |
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -040050 * | AER/EEH | 0x9011 | |
Arun Easie02587d2011-08-16 11:29:23 -070051 * | Virtual Port | 0xa007 | |
Atul Deshmukh27f4b722014-04-11 16:54:26 -040052 * | ISP82XX Specific | 0xb157 | 0xb002,0xb024 |
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -040053 * | | | 0xb09e,0xb0ae |
Hiral Patela018d8f2014-04-11 16:54:34 -040054 * | | | 0xb0c3,0xb0c6 |
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -040055 * | | | 0xb0e0-0xb0ef |
56 * | | | 0xb085,0xb0dc |
57 * | | | 0xb107,0xb108 |
58 * | | | 0xb111,0xb11e |
59 * | | | 0xb12c,0xb12d |
60 * | | | 0xb13a,0xb142 |
61 * | | | 0xb13c-0xb140 |
Saurav Kashyap6ddcfef2013-08-27 01:37:53 -040062 * | | | 0xb149 |
Giridhar Malavali6246b8a2012-02-09 11:15:34 -080063 * | MultiQ | 0xc00c | |
Himanshu Madhanice1025c2015-12-17 14:56:58 -050064 * | Misc | 0xd301 | 0xd031-0xd0ff |
Chad Dupuisf73cb692014-02-26 04:15:06 -050065 * | | | 0xd101-0xd1fe |
Joe Carnuccio2ac224b2014-09-25 05:16:36 -040066 * | | | 0xd214-0xd2fe |
Alexei Potashnika6ca8872015-07-14 16:00:44 -040067 * | Target Mode | 0xe080 | |
Alexei Potashnikb7bd1042015-12-17 14:57:02 -050068 * | Target Mode Management | 0xf09b | 0xf002 |
Saurav Kashyap6ddcfef2013-08-27 01:37:53 -040069 * | | | 0xf046-0xf049 |
Alexei Potashnika6ca8872015-07-14 16:00:44 -040070 * | Target Mode Task Management | 0x1000d | |
Arun Easie02587d2011-08-16 11:29:23 -070071 * ----------------------------------------------------------------------
Saurav Kashyap3ce88662011-07-14 12:00:12 -070072 */
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#include "qla_def.h"
75
76#include <linux/delay.h>
77
Saurav Kashyap3ce88662011-07-14 12:00:12 -070078static uint32_t ql_dbg_offset = 0x800;
79
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070080static inline void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080081qla2xxx_prep_dump(struct qla_hw_data *ha, struct qla2xxx_fw_dump *fw_dump)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070082{
83 fw_dump->fw_major_version = htonl(ha->fw_major_version);
84 fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
85 fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
86 fw_dump->fw_attributes = htonl(ha->fw_attributes);
87
88 fw_dump->vendor = htonl(ha->pdev->vendor);
89 fw_dump->device = htonl(ha->pdev->device);
90 fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
91 fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
92}
93
94static inline void *
Anirban Chakraborty73208df2008-12-09 16:45:39 -080095qla2xxx_copy_queues(struct qla_hw_data *ha, void *ptr)
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070096{
Anirban Chakraborty73208df2008-12-09 16:45:39 -080097 struct req_que *req = ha->req_q_map[0];
98 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070099 /* Request queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800100 memcpy(ptr, req->ring, req->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700101 sizeof(request_t));
102
103 /* Response queue. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800104 ptr += req->length * sizeof(request_t);
105 memcpy(ptr, rsp->ring, rsp->length *
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700106 sizeof(response_t));
107
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800108 return ptr + (rsp->length * sizeof(response_t));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700109}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Chad Dupuisf73cb692014-02-26 04:15:06 -0500111int
112qla27xx_dump_mpi_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
113 uint32_t ram_dwords, void **nxt)
114{
115 int rval;
116 uint32_t cnt, stat, timer, dwords, idx;
Bart Van Assche52c82822015-07-09 07:23:26 -0700117 uint16_t mb0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500118 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
119 dma_addr_t dump_dma = ha->gid_list_dma;
120 uint32_t *dump = (uint32_t *)ha->gid_list;
121
122 rval = QLA_SUCCESS;
123 mb0 = 0;
124
125 WRT_REG_WORD(&reg->mailbox0, MBC_LOAD_DUMP_MPI_RAM);
126 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
127
128 dwords = qla2x00_gid_list_size(ha) / 4;
129 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
130 cnt += dwords, addr += dwords) {
131 if (cnt + dwords > ram_dwords)
132 dwords = ram_dwords - cnt;
133
134 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
135 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
136
137 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
138 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
139 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
140 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
141
142 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
143 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
144
145 WRT_REG_WORD(&reg->mailbox9, 0);
146 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
147
148 ha->flags.mbox_int = 0;
149 for (timer = 6000000; timer; timer--) {
150 /* Check for pending interrupts. */
151 stat = RD_REG_DWORD(&reg->host_status);
152 if (stat & HSRX_RISC_INT) {
153 stat &= 0xff;
154
155 if (stat == 0x1 || stat == 0x2 ||
156 stat == 0x10 || stat == 0x11) {
157 set_bit(MBX_INTERRUPT,
158 &ha->mbx_cmd_flags);
159
160 mb0 = RD_REG_WORD(&reg->mailbox0);
Bart Van Assche52c82822015-07-09 07:23:26 -0700161 RD_REG_WORD(&reg->mailbox1);
Chad Dupuisf73cb692014-02-26 04:15:06 -0500162
163 WRT_REG_DWORD(&reg->hccr,
164 HCCRX_CLR_RISC_INT);
165 RD_REG_DWORD(&reg->hccr);
166 break;
167 }
168
169 /* Clear this intr; it wasn't a mailbox intr */
170 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
171 RD_REG_DWORD(&reg->hccr);
172 }
173 udelay(5);
174 }
175 ha->flags.mbox_int = 1;
176
177 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
178 rval = mb0 & MBS_MASK;
179 for (idx = 0; idx < dwords; idx++)
180 ram[cnt + idx] = IS_QLA27XX(ha) ?
181 le32_to_cpu(dump[idx]) : swab32(dump[idx]);
182 } else {
183 rval = QLA_FUNCTION_FAILED;
184 }
185 }
186
187 *nxt = rval == QLA_SUCCESS ? &ram[cnt] : NULL;
188 return rval;
189}
190
191int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800192qla24xx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint32_t *ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700193 uint32_t ram_dwords, void **nxt)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700194{
195 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700196 uint32_t cnt, stat, timer, dwords, idx;
197 uint16_t mb0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700198 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700199 dma_addr_t dump_dma = ha->gid_list_dma;
200 uint32_t *dump = (uint32_t *)ha->gid_list;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700201
202 rval = QLA_SUCCESS;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700203 mb0 = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700204
Andrew Vasquezc5722702008-04-24 15:21:22 -0700205 WRT_REG_WORD(&reg->mailbox0, MBC_DUMP_RISC_RAM_EXTENDED);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700206 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
207
Chad Dupuis642ef982012-02-09 11:15:57 -0800208 dwords = qla2x00_gid_list_size(ha) / 4;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700209 for (cnt = 0; cnt < ram_dwords && rval == QLA_SUCCESS;
210 cnt += dwords, addr += dwords) {
211 if (cnt + dwords > ram_dwords)
212 dwords = ram_dwords - cnt;
213
214 WRT_REG_WORD(&reg->mailbox1, LSW(addr));
215 WRT_REG_WORD(&reg->mailbox8, MSW(addr));
216
217 WRT_REG_WORD(&reg->mailbox2, MSW(dump_dma));
218 WRT_REG_WORD(&reg->mailbox3, LSW(dump_dma));
219 WRT_REG_WORD(&reg->mailbox6, MSW(MSD(dump_dma)));
220 WRT_REG_WORD(&reg->mailbox7, LSW(MSD(dump_dma)));
221
222 WRT_REG_WORD(&reg->mailbox4, MSW(dwords));
223 WRT_REG_WORD(&reg->mailbox5, LSW(dwords));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700224 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
225
Chad Dupuisf73cb692014-02-26 04:15:06 -0500226 ha->flags.mbox_int = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700227 for (timer = 6000000; timer; timer--) {
228 /* Check for pending interrupts. */
229 stat = RD_REG_DWORD(&reg->host_status);
230 if (stat & HSRX_RISC_INT) {
231 stat &= 0xff;
232
233 if (stat == 0x1 || stat == 0x2 ||
234 stat == 0x10 || stat == 0x11) {
235 set_bit(MBX_INTERRUPT,
236 &ha->mbx_cmd_flags);
237
Andrew Vasquezc5722702008-04-24 15:21:22 -0700238 mb0 = RD_REG_WORD(&reg->mailbox0);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700239
240 WRT_REG_DWORD(&reg->hccr,
241 HCCRX_CLR_RISC_INT);
242 RD_REG_DWORD(&reg->hccr);
243 break;
244 }
245
246 /* Clear this intr; it wasn't a mailbox intr */
247 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
248 RD_REG_DWORD(&reg->hccr);
249 }
250 udelay(5);
251 }
Chad Dupuisf73cb692014-02-26 04:15:06 -0500252 ha->flags.mbox_int = 1;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700253
254 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
Andrew Vasquezc5722702008-04-24 15:21:22 -0700255 rval = mb0 & MBS_MASK;
256 for (idx = 0; idx < dwords; idx++)
Chad Dupuisf73cb692014-02-26 04:15:06 -0500257 ram[cnt + idx] = IS_QLA27XX(ha) ?
258 le32_to_cpu(dump[idx]) : swab32(dump[idx]);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700259 } else {
260 rval = QLA_FUNCTION_FAILED;
261 }
262 }
263
Andrew Vasquezc5722702008-04-24 15:21:22 -0700264 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700265 return rval;
266}
267
Andrew Vasquezc5722702008-04-24 15:21:22 -0700268static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800269qla24xx_dump_memory(struct qla_hw_data *ha, uint32_t *code_ram,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700270 uint32_t cram_size, void **nxt)
271{
272 int rval;
273
274 /* Code RAM. */
275 rval = qla24xx_dump_ram(ha, 0x20000, code_ram, cram_size / 4, nxt);
276 if (rval != QLA_SUCCESS)
277 return rval;
278
Hiral Patel61f098d2014-04-11 16:54:21 -0400279 set_bit(RISC_SRAM_DUMP_CMPL, &ha->fw_dump_cap_flags);
280
Andrew Vasquezc5722702008-04-24 15:21:22 -0700281 /* External Memory. */
Hiral Patel61f098d2014-04-11 16:54:21 -0400282 rval = qla24xx_dump_ram(ha, 0x100000, *nxt,
Andrew Vasquezc5722702008-04-24 15:21:22 -0700283 ha->fw_memory_size - 0x100000 + 1, nxt);
Hiral Patel61f098d2014-04-11 16:54:21 -0400284 if (rval == QLA_SUCCESS)
285 set_bit(RISC_EXT_MEM_DUMP_CMPL, &ha->fw_dump_cap_flags);
286
287 return rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700288}
289
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700290static uint32_t *
291qla24xx_read_window(struct device_reg_24xx __iomem *reg, uint32_t iobase,
292 uint32_t count, uint32_t *buf)
293{
294 uint32_t __iomem *dmp_reg;
295
296 WRT_REG_DWORD(&reg->iobase_addr, iobase);
297 dmp_reg = &reg->iobase_window;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500298 for ( ; count--; dmp_reg++)
299 *buf++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700300
301 return buf;
302}
303
Hiral Patel2f389fc2014-04-11 16:54:20 -0400304void
Hiral Patel61f098d2014-04-11 16:54:21 -0400305qla24xx_pause_risc(struct device_reg_24xx __iomem *reg, struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700306{
Andrew Vasquezc3b058a2007-09-20 14:07:38 -0700307 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700308
Hiral Patel2f389fc2014-04-11 16:54:20 -0400309 /* 100 usec delay is sufficient enough for hardware to pause RISC */
310 udelay(100);
Hiral Patel61f098d2014-04-11 16:54:21 -0400311 if (RD_REG_DWORD(&reg->host_status) & HSRX_RISC_PAUSED)
312 set_bit(RISC_PAUSE_CMPL, &ha->fw_dump_cap_flags);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700313}
314
Chad Dupuisf73cb692014-02-26 04:15:06 -0500315int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800316qla24xx_soft_reset(struct qla_hw_data *ha)
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700317{
318 int rval = QLA_SUCCESS;
319 uint32_t cnt;
Hiral Patel2f389fc2014-04-11 16:54:20 -0400320 uint16_t wd;
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700321 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
322
Hiral Patel2f389fc2014-04-11 16:54:20 -0400323 /*
324 * Reset RISC. The delay is dependent on system architecture.
325 * Driver can proceed with the reset sequence after waiting
326 * for a timeout period.
327 */
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700328 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
329 for (cnt = 0; cnt < 30000; cnt++) {
330 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
331 break;
332
333 udelay(10);
334 }
Hiral Patel61f098d2014-04-11 16:54:21 -0400335 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
336 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700337
338 WRT_REG_DWORD(&reg->ctrl_status,
339 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
340 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
341
342 udelay(100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700343
344 /* Wait for soft-reset to complete. */
345 for (cnt = 0; cnt < 30000; cnt++) {
346 if ((RD_REG_DWORD(&reg->ctrl_status) &
347 CSRX_ISP_SOFT_RESET) == 0)
348 break;
349
350 udelay(10);
351 }
Hiral Patel61f098d2014-04-11 16:54:21 -0400352 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
353 set_bit(ISP_RESET_CMPL, &ha->fw_dump_cap_flags);
354
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700355 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
356 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
357
Hiral Patel2f389fc2014-04-11 16:54:20 -0400358 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700359 rval == QLA_SUCCESS; cnt--) {
360 if (cnt)
Hiral Patel2f389fc2014-04-11 16:54:20 -0400361 udelay(10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700362 else
363 rval = QLA_FUNCTION_TIMEOUT;
364 }
Hiral Patel61f098d2014-04-11 16:54:21 -0400365 if (rval == QLA_SUCCESS)
366 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700367
368 return rval;
369}
370
Andrew Vasquezc5722702008-04-24 15:21:22 -0700371static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800372qla2xxx_dump_ram(struct qla_hw_data *ha, uint32_t addr, uint16_t *ram,
Andrew Vasqueze18e9632009-06-17 10:30:31 -0700373 uint32_t ram_words, void **nxt)
Andrew Vasquezc5722702008-04-24 15:21:22 -0700374{
375 int rval;
376 uint32_t cnt, stat, timer, words, idx;
377 uint16_t mb0;
378 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
379 dma_addr_t dump_dma = ha->gid_list_dma;
380 uint16_t *dump = (uint16_t *)ha->gid_list;
381
382 rval = QLA_SUCCESS;
383 mb0 = 0;
384
385 WRT_MAILBOX_REG(ha, reg, 0, MBC_DUMP_RISC_RAM_EXTENDED);
386 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
387
Chad Dupuis642ef982012-02-09 11:15:57 -0800388 words = qla2x00_gid_list_size(ha) / 2;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700389 for (cnt = 0; cnt < ram_words && rval == QLA_SUCCESS;
390 cnt += words, addr += words) {
391 if (cnt + words > ram_words)
392 words = ram_words - cnt;
393
394 WRT_MAILBOX_REG(ha, reg, 1, LSW(addr));
395 WRT_MAILBOX_REG(ha, reg, 8, MSW(addr));
396
397 WRT_MAILBOX_REG(ha, reg, 2, MSW(dump_dma));
398 WRT_MAILBOX_REG(ha, reg, 3, LSW(dump_dma));
399 WRT_MAILBOX_REG(ha, reg, 6, MSW(MSD(dump_dma)));
400 WRT_MAILBOX_REG(ha, reg, 7, LSW(MSD(dump_dma)));
401
402 WRT_MAILBOX_REG(ha, reg, 4, words);
403 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
404
405 for (timer = 6000000; timer; timer--) {
406 /* Check for pending interrupts. */
407 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
408 if (stat & HSR_RISC_INT) {
409 stat &= 0xff;
410
411 if (stat == 0x1 || stat == 0x2) {
412 set_bit(MBX_INTERRUPT,
413 &ha->mbx_cmd_flags);
414
415 mb0 = RD_MAILBOX_REG(ha, reg, 0);
416
417 /* Release mailbox registers. */
418 WRT_REG_WORD(&reg->semaphore, 0);
419 WRT_REG_WORD(&reg->hccr,
420 HCCR_CLR_RISC_INT);
421 RD_REG_WORD(&reg->hccr);
422 break;
423 } else if (stat == 0x10 || stat == 0x11) {
424 set_bit(MBX_INTERRUPT,
425 &ha->mbx_cmd_flags);
426
427 mb0 = RD_MAILBOX_REG(ha, reg, 0);
428
429 WRT_REG_WORD(&reg->hccr,
430 HCCR_CLR_RISC_INT);
431 RD_REG_WORD(&reg->hccr);
432 break;
433 }
434
435 /* clear this intr; it wasn't a mailbox intr */
436 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
437 RD_REG_WORD(&reg->hccr);
438 }
439 udelay(5);
440 }
441
442 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
443 rval = mb0 & MBS_MASK;
444 for (idx = 0; idx < words; idx++)
445 ram[cnt + idx] = swab16(dump[idx]);
446 } else {
447 rval = QLA_FUNCTION_FAILED;
448 }
449 }
450
451 *nxt = rval == QLA_SUCCESS ? &ram[cnt]: NULL;
452 return rval;
453}
454
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700455static inline void
456qla2xxx_read_window(struct device_reg_2xxx __iomem *reg, uint32_t count,
457 uint16_t *buf)
458{
459 uint16_t __iomem *dmp_reg = &reg->u.isp2300.fb_cmd;
460
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500461 for ( ; count--; dmp_reg++)
462 *buf++ = htons(RD_REG_WORD(dmp_reg));
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700463}
464
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800465static inline void *
466qla24xx_copy_eft(struct qla_hw_data *ha, void *ptr)
467{
468 if (!ha->eft)
469 return ptr;
470
471 memcpy(ptr, ha->eft, ntohl(ha->fw_dump->eft_size));
472 return ptr + ntohl(ha->fw_dump->eft_size);
473}
474
475static inline void *
476qla25xx_copy_fce(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
477{
478 uint32_t cnt;
479 uint32_t *iter_reg;
480 struct qla2xxx_fce_chain *fcec = ptr;
481
482 if (!ha->fce)
483 return ptr;
484
485 *last_chain = &fcec->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700486 fcec->type = htonl(DUMP_CHAIN_FCE);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800487 fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
488 fce_calc_size(ha->fce_bufs));
489 fcec->size = htonl(fce_calc_size(ha->fce_bufs));
490 fcec->addr_l = htonl(LSD(ha->fce_dma));
491 fcec->addr_h = htonl(MSD(ha->fce_dma));
492
493 iter_reg = fcec->eregs;
494 for (cnt = 0; cnt < 8; cnt++)
495 *iter_reg++ = htonl(ha->fce_mb[cnt]);
496
497 memcpy(iter_reg, ha->fce, ntohl(fcec->size));
498
Giridhar Malavali3cb0a672011-11-18 09:03:11 -0800499 return (char *)iter_reg + ntohl(fcec->size);
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800500}
501
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800502static inline void *
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400503qla2xxx_copy_atioqueues(struct qla_hw_data *ha, void *ptr,
504 uint32_t **last_chain)
505{
506 struct qla2xxx_mqueue_chain *q;
507 struct qla2xxx_mqueue_header *qh;
508 uint32_t num_queues;
509 int que;
510 struct {
511 int length;
512 void *ring;
513 } aq, *aqp;
514
Arun Easi00876ae2013-03-25 02:21:37 -0400515 if (!ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400516 return ptr;
517
518 num_queues = 1;
519 aqp = &aq;
520 aqp->length = ha->tgt.atio_q_length;
521 aqp->ring = ha->tgt.atio_ring;
522
523 for (que = 0; que < num_queues; que++) {
524 /* aqp = ha->atio_q_map[que]; */
525 q = ptr;
526 *last_chain = &q->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700527 q->type = htonl(DUMP_CHAIN_QUEUE);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400528 q->chain_size = htonl(
529 sizeof(struct qla2xxx_mqueue_chain) +
530 sizeof(struct qla2xxx_mqueue_header) +
531 (aqp->length * sizeof(request_t)));
532 ptr += sizeof(struct qla2xxx_mqueue_chain);
533
534 /* Add header. */
535 qh = ptr;
Bart Van Asschead950362015-07-09 07:24:08 -0700536 qh->queue = htonl(TYPE_ATIO_QUEUE);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400537 qh->number = htonl(que);
538 qh->size = htonl(aqp->length * sizeof(request_t));
539 ptr += sizeof(struct qla2xxx_mqueue_header);
540
541 /* Add data. */
542 memcpy(ptr, aqp->ring, aqp->length * sizeof(request_t));
543
544 ptr += aqp->length * sizeof(request_t);
545 }
546
547 return ptr;
548}
549
550static inline void *
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800551qla25xx_copy_mqueues(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
552{
553 struct qla2xxx_mqueue_chain *q;
554 struct qla2xxx_mqueue_header *qh;
555 struct req_que *req;
556 struct rsp_que *rsp;
557 int que;
558
559 if (!ha->mqenable)
560 return ptr;
561
562 /* Request queues */
563 for (que = 1; que < ha->max_req_queues; que++) {
564 req = ha->req_q_map[que];
565 if (!req)
566 break;
567
568 /* Add chain. */
569 q = ptr;
570 *last_chain = &q->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700571 q->type = htonl(DUMP_CHAIN_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800572 q->chain_size = htonl(
573 sizeof(struct qla2xxx_mqueue_chain) +
574 sizeof(struct qla2xxx_mqueue_header) +
575 (req->length * sizeof(request_t)));
576 ptr += sizeof(struct qla2xxx_mqueue_chain);
577
578 /* Add header. */
579 qh = ptr;
Bart Van Asschead950362015-07-09 07:24:08 -0700580 qh->queue = htonl(TYPE_REQUEST_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800581 qh->number = htonl(que);
582 qh->size = htonl(req->length * sizeof(request_t));
583 ptr += sizeof(struct qla2xxx_mqueue_header);
584
585 /* Add data. */
586 memcpy(ptr, req->ring, req->length * sizeof(request_t));
587 ptr += req->length * sizeof(request_t);
588 }
589
590 /* Response queues */
591 for (que = 1; que < ha->max_rsp_queues; que++) {
592 rsp = ha->rsp_q_map[que];
593 if (!rsp)
594 break;
595
596 /* Add chain. */
597 q = ptr;
598 *last_chain = &q->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700599 q->type = htonl(DUMP_CHAIN_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800600 q->chain_size = htonl(
601 sizeof(struct qla2xxx_mqueue_chain) +
602 sizeof(struct qla2xxx_mqueue_header) +
603 (rsp->length * sizeof(response_t)));
604 ptr += sizeof(struct qla2xxx_mqueue_chain);
605
606 /* Add header. */
607 qh = ptr;
Bart Van Asschead950362015-07-09 07:24:08 -0700608 qh->queue = htonl(TYPE_RESPONSE_QUEUE);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -0800609 qh->number = htonl(que);
610 qh->size = htonl(rsp->length * sizeof(response_t));
611 ptr += sizeof(struct qla2xxx_mqueue_header);
612
613 /* Add data. */
614 memcpy(ptr, rsp->ring, rsp->length * sizeof(response_t));
615 ptr += rsp->length * sizeof(response_t);
616 }
617
618 return ptr;
619}
620
621static inline void *
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800622qla25xx_copy_mq(struct qla_hw_data *ha, void *ptr, uint32_t **last_chain)
623{
624 uint32_t cnt, que_idx;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700625 uint8_t que_cnt;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800626 struct qla2xxx_mq_chain *mq = ptr;
Bart Van Assche118e2ef2015-07-09 07:24:27 -0700627 device_reg_t *reg;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800628
Chad Dupuisf73cb692014-02-26 04:15:06 -0500629 if (!ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800630 return ptr;
631
632 mq = ptr;
633 *last_chain = &mq->type;
Bart Van Asschead950362015-07-09 07:24:08 -0700634 mq->type = htonl(DUMP_CHAIN_MQ);
635 mq->chain_size = htonl(sizeof(struct qla2xxx_mq_chain));
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800636
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700637 que_cnt = ha->max_req_queues > ha->max_rsp_queues ?
638 ha->max_req_queues : ha->max_rsp_queues;
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800639 mq->count = htonl(que_cnt);
640 for (cnt = 0; cnt < que_cnt; cnt++) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -0400641 reg = ISP_QUE_REG(ha, cnt);
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800642 que_idx = cnt * 4;
Andrew Vasquezda9b1d52013-08-27 01:37:30 -0400643 mq->qregs[que_idx] =
644 htonl(RD_REG_DWORD(&reg->isp25mq.req_q_in));
645 mq->qregs[que_idx+1] =
646 htonl(RD_REG_DWORD(&reg->isp25mq.req_q_out));
647 mq->qregs[que_idx+2] =
648 htonl(RD_REG_DWORD(&reg->isp25mq.rsp_q_in));
649 mq->qregs[que_idx+3] =
650 htonl(RD_REG_DWORD(&reg->isp25mq.rsp_q_out));
Andrew Vasquezd63ab532009-01-05 11:18:09 -0800651 }
652
653 return ptr + sizeof(struct qla2xxx_mq_chain);
654}
655
Giridhar Malavali08de2842011-08-16 11:31:44 -0700656void
Andrew Vasquez3420d362009-10-13 15:16:45 -0700657qla2xxx_dump_post_process(scsi_qla_host_t *vha, int rval)
658{
659 struct qla_hw_data *ha = vha->hw;
660
661 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700662 ql_log(ql_log_warn, vha, 0xd000,
Hiral Patel61f098d2014-04-11 16:54:21 -0400663 "Failed to dump firmware (%x), dump status flags (0x%lx).\n",
664 rval, ha->fw_dump_cap_flags);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700665 ha->fw_dumped = 0;
666 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700667 ql_log(ql_log_info, vha, 0xd001,
Hiral Patel61f098d2014-04-11 16:54:21 -0400668 "Firmware dump saved to temp buffer (%ld/%p), dump status flags (0x%lx).\n",
669 vha->host_no, ha->fw_dump, ha->fw_dump_cap_flags);
Andrew Vasquez3420d362009-10-13 15:16:45 -0700670 ha->fw_dumped = 1;
671 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
672 }
673}
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675/**
676 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
677 * @ha: HA context
678 * @hardware_locked: Called with the hardware_lock
679 */
680void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800681qla2300_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 int rval;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700684 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800685 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700686 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 uint16_t __iomem *dmp_reg;
688 unsigned long flags;
689 struct qla2300_fw_dump *fw;
Andrew Vasquezc5722702008-04-24 15:21:22 -0700690 void *nxt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800691 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 flags = 0;
694
Bart Van Assche8d163662015-07-09 07:25:46 -0700695#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (!hardware_locked)
697 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -0700698#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700700 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700701 ql_log(ql_log_warn, vha, 0xd002,
702 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 goto qla2300_fw_dump_failed;
704 }
705
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700706 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700707 ql_log(ql_log_warn, vha, 0xd003,
708 "Firmware has been previously dumped (%p) "
709 "-- ignoring request.\n",
710 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 goto qla2300_fw_dump_failed;
712 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700713 fw = &ha->fw_dump->isp.isp23;
714 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700717 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700720 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 if (IS_QLA2300(ha)) {
722 for (cnt = 30000;
723 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
724 rval == QLA_SUCCESS; cnt--) {
725 if (cnt)
726 udelay(100);
727 else
728 rval = QLA_FUNCTION_TIMEOUT;
729 }
730 } else {
731 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
732 udelay(10);
733 }
734
735 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700736 dmp_reg = &reg->flash_address;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500737 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++, dmp_reg++)
738 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700740 dmp_reg = &reg->u.isp2300.req_q_in;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500741 for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2;
742 cnt++, dmp_reg++)
743 fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700745 dmp_reg = &reg->u.isp2300.mailbox0;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500746 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2;
747 cnt++, dmp_reg++)
748 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 WRT_REG_WORD(&reg->ctrl_status, 0x40);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700751 qla2xxx_read_window(reg, 32, fw->resp_dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 WRT_REG_WORD(&reg->ctrl_status, 0x50);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700754 qla2xxx_read_window(reg, 48, fw->dma_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700757 dmp_reg = &reg->risc_hw;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500758 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2;
759 cnt++, dmp_reg++)
760 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700762 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700763 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700765 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700766 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700768 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700769 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700771 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700772 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700774 WRT_REG_WORD(&reg->pcr, 0x2800);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700775 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700777 WRT_REG_WORD(&reg->pcr, 0x2A00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700778 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700780 WRT_REG_WORD(&reg->pcr, 0x2C00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700781 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700783 WRT_REG_WORD(&reg->pcr, 0x2E00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700784 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700786 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700787 qla2xxx_read_window(reg, 64, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700789 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700790 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700792 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700793 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 /* Reset RISC. */
796 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
797 for (cnt = 0; cnt < 30000; cnt++) {
798 if ((RD_REG_WORD(&reg->ctrl_status) &
799 CSR_ISP_SOFT_RESET) == 0)
800 break;
801
802 udelay(10);
803 }
804 }
805
806 if (!IS_QLA2300(ha)) {
807 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
808 rval == QLA_SUCCESS; cnt--) {
809 if (cnt)
810 udelay(100);
811 else
812 rval = QLA_FUNCTION_TIMEOUT;
813 }
814 }
815
Andrew Vasquezc5722702008-04-24 15:21:22 -0700816 /* Get RISC SRAM. */
817 if (rval == QLA_SUCCESS)
818 rval = qla2xxx_dump_ram(ha, 0x800, fw->risc_ram,
819 sizeof(fw->risc_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Andrew Vasquezc5722702008-04-24 15:21:22 -0700821 /* Get stack SRAM. */
822 if (rval == QLA_SUCCESS)
823 rval = qla2xxx_dump_ram(ha, 0x10000, fw->stack_ram,
824 sizeof(fw->stack_ram) / 2, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Andrew Vasquezc5722702008-04-24 15:21:22 -0700826 /* Get data SRAM. */
827 if (rval == QLA_SUCCESS)
828 rval = qla2xxx_dump_ram(ha, 0x11000, fw->data_ram,
829 ha->fw_memory_size - 0x11000 + 1, &nxt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700831 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800832 qla2xxx_copy_queues(ha, nxt);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700833
Andrew Vasquez3420d362009-10-13 15:16:45 -0700834 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836qla2300_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -0700837#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 if (!hardware_locked)
839 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -0700840#else
841 ;
842#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
845/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
847 * @ha: HA context
848 * @hardware_locked: Called with the hardware_lock
849 */
850void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800851qla2100_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
853 int rval;
854 uint32_t cnt, timer;
855 uint16_t risc_address;
856 uint16_t mb0, mb2;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800857 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700858 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 uint16_t __iomem *dmp_reg;
860 unsigned long flags;
861 struct qla2100_fw_dump *fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800862 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 risc_address = 0;
865 mb0 = mb2 = 0;
866 flags = 0;
867
Bart Van Assche8d163662015-07-09 07:25:46 -0700868#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 if (!hardware_locked)
870 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -0700871#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700873 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700874 ql_log(ql_log_warn, vha, 0xd004,
875 "No buffer available for dump.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 goto qla2100_fw_dump_failed;
877 }
878
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700879 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700880 ql_log(ql_log_warn, vha, 0xd005,
881 "Firmware has been previously dumped (%p) "
882 "-- ignoring request.\n",
883 ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 goto qla2100_fw_dump_failed;
885 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700886 fw = &ha->fw_dump->isp.isp21;
887 qla2xxx_prep_dump(ha, ha->fw_dump);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 rval = QLA_SUCCESS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700890 fw->hccr = htons(RD_REG_WORD(&reg->hccr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 /* Pause RISC. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700893 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
895 rval == QLA_SUCCESS; cnt--) {
896 if (cnt)
897 udelay(100);
898 else
899 rval = QLA_FUNCTION_TIMEOUT;
900 }
901 if (rval == QLA_SUCCESS) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700902 dmp_reg = &reg->flash_address;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500903 for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++, dmp_reg++)
904 fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700906 dmp_reg = &reg->u.isp2100.mailbox0;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500907 for (cnt = 0; cnt < ha->mbx_count; cnt++, dmp_reg++) {
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700908 if (cnt == 8)
909 dmp_reg = &reg->u_end.isp2200.mailbox8;
910
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500911 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
913
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700914 dmp_reg = &reg->u.isp2100.unused_2[0];
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500915 for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++, dmp_reg++)
916 fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 WRT_REG_WORD(&reg->ctrl_status, 0x00);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700919 dmp_reg = &reg->risc_hw;
Joe Carnuccioda08ef52016-01-27 12:03:34 -0500920 for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++, dmp_reg++)
921 fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700923 WRT_REG_WORD(&reg->pcr, 0x2000);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700924 qla2xxx_read_window(reg, 16, fw->risc_gp0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700926 WRT_REG_WORD(&reg->pcr, 0x2100);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700927 qla2xxx_read_window(reg, 16, fw->risc_gp1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700929 WRT_REG_WORD(&reg->pcr, 0x2200);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700930 qla2xxx_read_window(reg, 16, fw->risc_gp2_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700932 WRT_REG_WORD(&reg->pcr, 0x2300);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700933 qla2xxx_read_window(reg, 16, fw->risc_gp3_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700935 WRT_REG_WORD(&reg->pcr, 0x2400);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700936 qla2xxx_read_window(reg, 16, fw->risc_gp4_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700938 WRT_REG_WORD(&reg->pcr, 0x2500);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700939 qla2xxx_read_window(reg, 16, fw->risc_gp5_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700941 WRT_REG_WORD(&reg->pcr, 0x2600);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700942 qla2xxx_read_window(reg, 16, fw->risc_gp6_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700944 WRT_REG_WORD(&reg->pcr, 0x2700);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700945 qla2xxx_read_window(reg, 16, fw->risc_gp7_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700947 WRT_REG_WORD(&reg->ctrl_status, 0x10);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700948 qla2xxx_read_window(reg, 16, fw->frame_buf_hdw_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700950 WRT_REG_WORD(&reg->ctrl_status, 0x20);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700951 qla2xxx_read_window(reg, 64, fw->fpm_b0_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700953 WRT_REG_WORD(&reg->ctrl_status, 0x30);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -0700954 qla2xxx_read_window(reg, 64, fw->fpm_b1_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 /* Reset the ISP. */
957 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
958 }
959
960 for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
961 rval == QLA_SUCCESS; cnt--) {
962 if (cnt)
963 udelay(100);
964 else
965 rval = QLA_FUNCTION_TIMEOUT;
966 }
967
968 /* Pause RISC. */
969 if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
970 (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {
971
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700972 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 for (cnt = 30000;
974 (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
975 rval == QLA_SUCCESS; cnt--) {
976 if (cnt)
977 udelay(100);
978 else
979 rval = QLA_FUNCTION_TIMEOUT;
980 }
981 if (rval == QLA_SUCCESS) {
982 /* Set memory configuration and timing. */
983 if (IS_QLA2100(ha))
984 WRT_REG_WORD(&reg->mctr, 0xf1);
985 else
986 WRT_REG_WORD(&reg->mctr, 0xf2);
987 RD_REG_WORD(&reg->mctr); /* PCI Posting. */
988
989 /* Release RISC. */
990 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
991 }
992 }
993
994 if (rval == QLA_SUCCESS) {
995 /* Get RISC SRAM. */
996 risc_address = 0x1000;
997 WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
998 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
999 }
1000 for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
1001 cnt++, risc_address++) {
1002 WRT_MAILBOX_REG(ha, reg, 1, risc_address);
1003 WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);
1004
1005 for (timer = 6000000; timer != 0; timer--) {
1006 /* Check for pending interrupts. */
1007 if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
1008 if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
1009 set_bit(MBX_INTERRUPT,
1010 &ha->mbx_cmd_flags);
1011
1012 mb0 = RD_MAILBOX_REG(ha, reg, 0);
1013 mb2 = RD_MAILBOX_REG(ha, reg, 2);
1014
1015 WRT_REG_WORD(&reg->semaphore, 0);
1016 WRT_REG_WORD(&reg->hccr,
1017 HCCR_CLR_RISC_INT);
1018 RD_REG_WORD(&reg->hccr);
1019 break;
1020 }
1021 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1022 RD_REG_WORD(&reg->hccr);
1023 }
1024 udelay(5);
1025 }
1026
1027 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
1028 rval = mb0 & MBS_MASK;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001029 fw->risc_ram[cnt] = htons(mb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 } else {
1031 rval = QLA_FUNCTION_FAILED;
1032 }
1033 }
1034
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001035 if (rval == QLA_SUCCESS)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001036 qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001037
Andrew Vasquez3420d362009-10-13 15:16:45 -07001038 qla2xxx_dump_post_process(base_vha, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040qla2100_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001041#ifndef __CHECKER__
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (!hardware_locked)
1043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001044#else
1045 ;
1046#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001049void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001050qla24xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001051{
1052 int rval;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001053 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001054 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001055 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1056 uint32_t __iomem *dmp_reg;
1057 uint32_t *iter_reg;
1058 uint16_t __iomem *mbx_reg;
1059 unsigned long flags;
1060 struct qla24xx_fw_dump *fw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001061 void *nxt;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001062 void *nxt_chain;
1063 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001064 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001065
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001066 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001067 return;
1068
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001069 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001070 ha->fw_dump_cap_flags = 0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001071
Bart Van Assche8d163662015-07-09 07:25:46 -07001072#ifndef __CHECKER__
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001073 if (!hardware_locked)
1074 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001075#endif
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001076
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001077 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001078 ql_log(ql_log_warn, vha, 0xd006,
1079 "No buffer available for dump.\n");
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001080 goto qla24xx_fw_dump_failed;
1081 }
1082
1083 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001084 ql_log(ql_log_warn, vha, 0xd007,
1085 "Firmware has been previously dumped (%p) "
1086 "-- ignoring request.\n",
1087 ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001088 goto qla24xx_fw_dump_failed;
1089 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001090 fw = &ha->fw_dump->isp.isp24;
1091 qla2xxx_prep_dump(ha, ha->fw_dump);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001092
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001093 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001094
Hiral Patel2f389fc2014-04-11 16:54:20 -04001095 /*
1096 * Pause RISC. No need to track timeout, as resetting the chip
1097 * is the right approach incase of pause timeout
1098 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001099 qla24xx_pause_risc(reg, ha);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001100
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001101 /* Host interface registers. */
1102 dmp_reg = &reg->flash_addr;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001103 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++, dmp_reg++)
1104 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001105
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001106 /* Disable interrupts. */
1107 WRT_REG_DWORD(&reg->ictrl, 0);
1108 RD_REG_DWORD(&reg->ictrl);
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001109
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001110 /* Shadow registers. */
1111 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1112 RD_REG_DWORD(&reg->iobase_addr);
1113 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1114 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001115
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001116 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1117 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001118
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001119 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1120 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001121
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001122 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1123 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001124
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001125 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1126 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001127
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001128 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1129 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001130
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001131 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1132 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
andrew.vasquez@qlogic.com210d5352006-01-13 17:05:21 -08001133
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001134 /* Mailbox registers. */
1135 mbx_reg = &reg->mailbox0;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001136 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++, dmp_reg++)
1137 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001138
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001139 /* Transfer sequence registers. */
1140 iter_reg = fw->xseq_gp_reg;
1141 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1142 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1143 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1144 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1145 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1146 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1147 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1148 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001149
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001150 qla24xx_read_window(reg, 0xBFE0, 16, fw->xseq_0_reg);
1151 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001152
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001153 /* Receive sequence registers. */
1154 iter_reg = fw->rseq_gp_reg;
1155 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1156 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1157 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1158 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1159 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1160 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1161 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1162 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001163
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001164 qla24xx_read_window(reg, 0xFFD0, 16, fw->rseq_0_reg);
1165 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1166 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001167
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001168 /* Command DMA registers. */
1169 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001170
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001171 /* Queues. */
1172 iter_reg = fw->req0_dma_reg;
1173 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1174 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001175 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1176 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001177
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001178 iter_reg = fw->resp0_dma_reg;
1179 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1180 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001181 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1182 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001183
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001184 iter_reg = fw->req1_dma_reg;
1185 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1186 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001187 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1188 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001189
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001190 /* Transmit DMA registers. */
1191 iter_reg = fw->xmt0_dma_reg;
1192 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1193 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001194
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001195 iter_reg = fw->xmt1_dma_reg;
1196 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1197 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001198
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001199 iter_reg = fw->xmt2_dma_reg;
1200 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1201 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001202
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001203 iter_reg = fw->xmt3_dma_reg;
1204 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1205 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001206
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001207 iter_reg = fw->xmt4_dma_reg;
1208 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1209 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001210
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001211 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001212
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001213 /* Receive DMA registers. */
1214 iter_reg = fw->rcvt0_data_dma_reg;
1215 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1216 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001217
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001218 iter_reg = fw->rcvt1_data_dma_reg;
1219 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1220 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001221
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001222 /* RISC registers. */
1223 iter_reg = fw->risc_gp_reg;
1224 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1225 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1226 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1227 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1228 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1229 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1230 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1231 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001232
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001233 /* Local memory controller registers. */
1234 iter_reg = fw->lmc_reg;
1235 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1236 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1237 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1238 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1239 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1240 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1241 qla24xx_read_window(reg, 0x3060, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001242
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001243 /* Fibre Protocol Module registers. */
1244 iter_reg = fw->fpm_hdw_reg;
1245 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1246 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1247 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1248 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1249 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1250 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1251 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1252 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1253 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1254 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1255 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1256 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001257
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001258 /* Frame Buffer registers. */
1259 iter_reg = fw->fb_hdw_reg;
1260 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1261 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1262 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1263 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1264 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1265 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1266 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1267 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1268 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1269 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1270 qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001271
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001272 rval = qla24xx_soft_reset(ha);
1273 if (rval != QLA_SUCCESS)
1274 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001275
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001276 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001277 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001278 if (rval != QLA_SUCCESS)
1279 goto qla24xx_fw_dump_failed_0;
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001280
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001281 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001282
1283 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001284
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001285 nxt_chain = (void *)ha->fw_dump + ha->chain_offset;
1286 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
1287 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07001288 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1289 *last_chain |= htonl(DUMP_CHAIN_LAST);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001290 }
1291
1292 /* Adjust valid length. */
1293 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1294
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001295qla24xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001296 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001297
1298qla24xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001299#ifndef __CHECKER__
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001300 if (!hardware_locked)
1301 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001302#else
1303 ;
1304#endif
Andrew Vasquez6d9b61e2005-07-06 10:30:36 -07001305}
1306
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001307void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001308qla25xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001309{
1310 int rval;
1311 uint32_t cnt;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001312 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001313 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1314 uint32_t __iomem *dmp_reg;
1315 uint32_t *iter_reg;
1316 uint16_t __iomem *mbx_reg;
1317 unsigned long flags;
1318 struct qla25xx_fw_dump *fw;
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001319 void *nxt, *nxt_chain;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001320 uint32_t *last_chain = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001321 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001322
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001323 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001324 ha->fw_dump_cap_flags = 0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001325
Bart Van Assche8d163662015-07-09 07:25:46 -07001326#ifndef __CHECKER__
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001327 if (!hardware_locked)
1328 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001329#endif
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001330
1331 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001332 ql_log(ql_log_warn, vha, 0xd008,
1333 "No buffer available for dump.\n");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001334 goto qla25xx_fw_dump_failed;
1335 }
1336
1337 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001338 ql_log(ql_log_warn, vha, 0xd009,
1339 "Firmware has been previously dumped (%p) "
1340 "-- ignoring request.\n",
1341 ha->fw_dump);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001342 goto qla25xx_fw_dump_failed;
1343 }
1344 fw = &ha->fw_dump->isp.isp25;
1345 qla2xxx_prep_dump(ha, ha->fw_dump);
Bart Van Asschead950362015-07-09 07:24:08 -07001346 ha->fw_dump->version = htonl(2);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001347
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001348 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1349
Hiral Patel2f389fc2014-04-11 16:54:20 -04001350 /*
1351 * Pause RISC. No need to track timeout, as resetting the chip
1352 * is the right approach incase of pause timeout
1353 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001354 qla24xx_pause_risc(reg, ha);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001355
Andrew Vasquezb5836922007-09-20 14:07:39 -07001356 /* Host/Risc registers. */
1357 iter_reg = fw->host_risc_reg;
1358 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1359 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1360
1361 /* PCIe registers. */
1362 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1363 RD_REG_DWORD(&reg->iobase_addr);
1364 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1365 dmp_reg = &reg->iobase_c4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001366 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg));
1367 dmp_reg++;
1368 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg));
1369 dmp_reg++;
Andrew Vasquezb5836922007-09-20 14:07:39 -07001370 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1371 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001372
Andrew Vasquezb5836922007-09-20 14:07:39 -07001373 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1374 RD_REG_DWORD(&reg->iobase_window);
1375
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001376 /* Host interface registers. */
1377 dmp_reg = &reg->flash_addr;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001378 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++, dmp_reg++)
1379 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001380
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001381 /* Disable interrupts. */
1382 WRT_REG_DWORD(&reg->ictrl, 0);
1383 RD_REG_DWORD(&reg->ictrl);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001384
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001385 /* Shadow registers. */
1386 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1387 RD_REG_DWORD(&reg->iobase_addr);
1388 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1389 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001390
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001391 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1392 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001393
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001394 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1395 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001396
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001397 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1398 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001399
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001400 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1401 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001402
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001403 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1404 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001405
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001406 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1407 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001408
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001409 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1410 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001411
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001412 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1413 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001414
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001415 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1416 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001417
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001418 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1419 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001420
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001421 /* RISC I/O register. */
1422 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1423 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001424
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001425 /* Mailbox registers. */
1426 mbx_reg = &reg->mailbox0;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001427 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++, mbx_reg++)
1428 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001429
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001430 /* Transfer sequence registers. */
1431 iter_reg = fw->xseq_gp_reg;
1432 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1433 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1434 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1435 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1436 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1437 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1438 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1439 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001440
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001441 iter_reg = fw->xseq_0_reg;
1442 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1443 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1444 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001445
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001446 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001447
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001448 /* Receive sequence registers. */
1449 iter_reg = fw->rseq_gp_reg;
1450 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1451 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1452 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1453 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1454 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1455 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1456 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1457 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001458
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001459 iter_reg = fw->rseq_0_reg;
1460 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1461 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001462
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001463 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1464 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001465
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001466 /* Auxiliary sequence registers. */
1467 iter_reg = fw->aseq_gp_reg;
1468 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1469 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1470 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1471 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1472 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1473 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1474 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1475 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001476
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001477 iter_reg = fw->aseq_0_reg;
1478 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1479 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001480
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001481 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1482 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001483
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001484 /* Command DMA registers. */
1485 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001486
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001487 /* Queues. */
1488 iter_reg = fw->req0_dma_reg;
1489 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1490 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001491 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1492 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001493
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001494 iter_reg = fw->resp0_dma_reg;
1495 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1496 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001497 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1498 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001499
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001500 iter_reg = fw->req1_dma_reg;
1501 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1502 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001503 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1504 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001505
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001506 /* Transmit DMA registers. */
1507 iter_reg = fw->xmt0_dma_reg;
1508 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1509 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001510
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001511 iter_reg = fw->xmt1_dma_reg;
1512 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1513 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001514
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001515 iter_reg = fw->xmt2_dma_reg;
1516 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1517 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001518
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001519 iter_reg = fw->xmt3_dma_reg;
1520 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1521 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001522
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001523 iter_reg = fw->xmt4_dma_reg;
1524 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1525 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001526
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001527 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001528
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001529 /* Receive DMA registers. */
1530 iter_reg = fw->rcvt0_data_dma_reg;
1531 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1532 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001533
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001534 iter_reg = fw->rcvt1_data_dma_reg;
1535 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1536 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001537
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001538 /* RISC registers. */
1539 iter_reg = fw->risc_gp_reg;
1540 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1541 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1542 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1543 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1544 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1545 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1546 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1547 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001548
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001549 /* Local memory controller registers. */
1550 iter_reg = fw->lmc_reg;
1551 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1552 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1553 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1554 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1555 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1556 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1557 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1558 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001559
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001560 /* Fibre Protocol Module registers. */
1561 iter_reg = fw->fpm_hdw_reg;
1562 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1563 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1564 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1565 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1566 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1567 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1568 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1569 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1570 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1571 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1572 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1573 qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001574
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001575 /* Frame Buffer registers. */
1576 iter_reg = fw->fb_hdw_reg;
1577 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1578 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1579 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1580 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1581 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1582 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1583 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1584 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1585 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1586 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1587 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1588 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001589
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001590 /* Multi queue registers */
1591 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1592 &last_chain);
1593
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001594 rval = qla24xx_soft_reset(ha);
1595 if (rval != QLA_SUCCESS)
1596 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001597
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001598 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
Andrew Vasquezc5722702008-04-24 15:21:22 -07001599 &nxt);
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001600 if (rval != QLA_SUCCESS)
1601 goto qla25xx_fw_dump_failed_0;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001602
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001603 nxt = qla2xxx_copy_queues(ha, nxt);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001604
Bart Van Assche7f544d02013-06-25 11:27:27 -04001605 qla24xx_copy_eft(ha, nxt);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001606
Andrew Vasquezd63ab532009-01-05 11:18:09 -08001607 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001608 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1609 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001610 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001611 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07001612 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1613 *last_chain |= htonl(DUMP_CHAIN_LAST);
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001614 }
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001615
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001616 /* Adjust valid length. */
1617 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1618
Andrew Vasquezc81d04c2007-07-26 11:41:13 -07001619qla25xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001620 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001621
1622qla25xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001623#ifndef __CHECKER__
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001624 if (!hardware_locked)
1625 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001626#else
1627 ;
1628#endif
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001629}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001630
1631void
1632qla81xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1633{
1634 int rval;
1635 uint32_t cnt;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001636 struct qla_hw_data *ha = vha->hw;
1637 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1638 uint32_t __iomem *dmp_reg;
1639 uint32_t *iter_reg;
1640 uint16_t __iomem *mbx_reg;
1641 unsigned long flags;
1642 struct qla81xx_fw_dump *fw;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001643 void *nxt, *nxt_chain;
1644 uint32_t *last_chain = NULL;
1645 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1646
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001647 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001648 ha->fw_dump_cap_flags = 0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001649
Bart Van Assche8d163662015-07-09 07:25:46 -07001650#ifndef __CHECKER__
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001651 if (!hardware_locked)
1652 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001653#endif
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001654
1655 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001656 ql_log(ql_log_warn, vha, 0xd00a,
1657 "No buffer available for dump.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001658 goto qla81xx_fw_dump_failed;
1659 }
1660
1661 if (ha->fw_dumped) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001662 ql_log(ql_log_warn, vha, 0xd00b,
1663 "Firmware has been previously dumped (%p) "
1664 "-- ignoring request.\n",
1665 ha->fw_dump);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001666 goto qla81xx_fw_dump_failed;
1667 }
1668 fw = &ha->fw_dump->isp.isp81;
1669 qla2xxx_prep_dump(ha, ha->fw_dump);
1670
1671 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1672
Hiral Patel2f389fc2014-04-11 16:54:20 -04001673 /*
1674 * Pause RISC. No need to track timeout, as resetting the chip
1675 * is the right approach incase of pause timeout
1676 */
Hiral Patel61f098d2014-04-11 16:54:21 -04001677 qla24xx_pause_risc(reg, ha);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001678
1679 /* Host/Risc registers. */
1680 iter_reg = fw->host_risc_reg;
1681 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
1682 qla24xx_read_window(reg, 0x7010, 16, iter_reg);
1683
1684 /* PCIe registers. */
1685 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
1686 RD_REG_DWORD(&reg->iobase_addr);
1687 WRT_REG_DWORD(&reg->iobase_window, 0x01);
1688 dmp_reg = &reg->iobase_c4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001689 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg));
1690 dmp_reg++;
1691 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg));
1692 dmp_reg++;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001693 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
1694 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
1695
1696 WRT_REG_DWORD(&reg->iobase_window, 0x00);
1697 RD_REG_DWORD(&reg->iobase_window);
1698
1699 /* Host interface registers. */
1700 dmp_reg = &reg->flash_addr;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001701 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++, dmp_reg++)
1702 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001703
1704 /* Disable interrupts. */
1705 WRT_REG_DWORD(&reg->ictrl, 0);
1706 RD_REG_DWORD(&reg->ictrl);
1707
1708 /* Shadow registers. */
1709 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
1710 RD_REG_DWORD(&reg->iobase_addr);
1711 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
1712 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1713
1714 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
1715 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1716
1717 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
1718 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1719
1720 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
1721 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1722
1723 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
1724 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1725
1726 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
1727 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1728
1729 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
1730 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1731
1732 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
1733 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1734
1735 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
1736 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1737
1738 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
1739 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1740
1741 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
1742 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
1743
1744 /* RISC I/O register. */
1745 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
1746 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
1747
1748 /* Mailbox registers. */
1749 mbx_reg = &reg->mailbox0;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001750 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++, mbx_reg++)
1751 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001752
1753 /* Transfer sequence registers. */
1754 iter_reg = fw->xseq_gp_reg;
1755 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
1756 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
1757 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
1758 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
1759 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
1760 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
1761 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
1762 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
1763
1764 iter_reg = fw->xseq_0_reg;
1765 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
1766 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
1767 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
1768
1769 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
1770
1771 /* Receive sequence registers. */
1772 iter_reg = fw->rseq_gp_reg;
1773 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
1774 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
1775 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
1776 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
1777 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
1778 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
1779 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
1780 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
1781
1782 iter_reg = fw->rseq_0_reg;
1783 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
1784 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
1785
1786 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
1787 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
1788
1789 /* Auxiliary sequence registers. */
1790 iter_reg = fw->aseq_gp_reg;
1791 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
1792 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
1793 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
1794 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
1795 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
1796 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
1797 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
1798 qla24xx_read_window(reg, 0xB070, 16, iter_reg);
1799
1800 iter_reg = fw->aseq_0_reg;
1801 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
1802 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
1803
1804 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
1805 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
1806
1807 /* Command DMA registers. */
1808 qla24xx_read_window(reg, 0x7100, 16, fw->cmd_dma_reg);
1809
1810 /* Queues. */
1811 iter_reg = fw->req0_dma_reg;
1812 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
1813 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001814 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1815 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001816
1817 iter_reg = fw->resp0_dma_reg;
1818 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
1819 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001820 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1821 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001822
1823 iter_reg = fw->req1_dma_reg;
1824 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
1825 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05001826 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
1827 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001828
1829 /* Transmit DMA registers. */
1830 iter_reg = fw->xmt0_dma_reg;
1831 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
1832 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
1833
1834 iter_reg = fw->xmt1_dma_reg;
1835 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
1836 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
1837
1838 iter_reg = fw->xmt2_dma_reg;
1839 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
1840 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
1841
1842 iter_reg = fw->xmt3_dma_reg;
1843 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
1844 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
1845
1846 iter_reg = fw->xmt4_dma_reg;
1847 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
1848 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
1849
1850 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
1851
1852 /* Receive DMA registers. */
1853 iter_reg = fw->rcvt0_data_dma_reg;
1854 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
1855 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
1856
1857 iter_reg = fw->rcvt1_data_dma_reg;
1858 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
1859 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
1860
1861 /* RISC registers. */
1862 iter_reg = fw->risc_gp_reg;
1863 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
1864 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
1865 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
1866 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
1867 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
1868 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
1869 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
1870 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
1871
1872 /* Local memory controller registers. */
1873 iter_reg = fw->lmc_reg;
1874 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
1875 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
1876 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
1877 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
1878 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
1879 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
1880 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
1881 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
1882
1883 /* Fibre Protocol Module registers. */
1884 iter_reg = fw->fpm_hdw_reg;
1885 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
1886 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
1887 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
1888 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
1889 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
1890 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
1891 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
1892 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
1893 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
1894 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
1895 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
1896 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
1897 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
1898 qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
1899
1900 /* Frame Buffer registers. */
1901 iter_reg = fw->fb_hdw_reg;
1902 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
1903 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
1904 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
1905 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
1906 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
1907 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
1908 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
1909 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
1910 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
1911 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
1912 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
1913 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
1914 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
1915
1916 /* Multi queue registers */
1917 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
1918 &last_chain);
1919
1920 rval = qla24xx_soft_reset(ha);
1921 if (rval != QLA_SUCCESS)
1922 goto qla81xx_fw_dump_failed_0;
1923
1924 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
1925 &nxt);
1926 if (rval != QLA_SUCCESS)
1927 goto qla81xx_fw_dump_failed_0;
1928
1929 nxt = qla2xxx_copy_queues(ha, nxt);
1930
Bart Van Assche7f544d02013-06-25 11:27:27 -04001931 qla24xx_copy_eft(ha, nxt);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001932
1933 /* Chain entries -- started with MQ. */
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001934 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
1935 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001936 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001937 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07001938 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
1939 *last_chain |= htonl(DUMP_CHAIN_LAST);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001940 }
1941
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001942 /* Adjust valid length. */
1943 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
1944
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001945qla81xx_fw_dump_failed_0:
Andrew Vasquez3420d362009-10-13 15:16:45 -07001946 qla2xxx_dump_post_process(base_vha, rval);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001947
1948qla81xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07001949#ifndef __CHECKER__
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001950 if (!hardware_locked)
1951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001952#else
1953 ;
1954#endif
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001955}
1956
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001957void
1958qla83xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
1959{
1960 int rval;
Bart Van Assche52c82822015-07-09 07:23:26 -07001961 uint32_t cnt;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001962 struct qla_hw_data *ha = vha->hw;
1963 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1964 uint32_t __iomem *dmp_reg;
1965 uint32_t *iter_reg;
1966 uint16_t __iomem *mbx_reg;
1967 unsigned long flags;
1968 struct qla83xx_fw_dump *fw;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001969 void *nxt, *nxt_chain;
1970 uint32_t *last_chain = NULL;
1971 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1972
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001973 flags = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001974 ha->fw_dump_cap_flags = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001975
Bart Van Assche8d163662015-07-09 07:25:46 -07001976#ifndef __CHECKER__
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001977 if (!hardware_locked)
1978 spin_lock_irqsave(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07001979#endif
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001980
1981 if (!ha->fw_dump) {
1982 ql_log(ql_log_warn, vha, 0xd00c,
1983 "No buffer available for dump!!!\n");
1984 goto qla83xx_fw_dump_failed;
1985 }
1986
1987 if (ha->fw_dumped) {
1988 ql_log(ql_log_warn, vha, 0xd00d,
1989 "Firmware has been previously dumped (%p) -- ignoring "
1990 "request...\n", ha->fw_dump);
1991 goto qla83xx_fw_dump_failed;
1992 }
1993 fw = &ha->fw_dump->isp.isp83;
1994 qla2xxx_prep_dump(ha, ha->fw_dump);
1995
1996 fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
1997
Hiral Patel2f389fc2014-04-11 16:54:20 -04001998 /*
1999 * Pause RISC. No need to track timeout, as resetting the chip
2000 * is the right approach incase of pause timeout
2001 */
Hiral Patel61f098d2014-04-11 16:54:21 -04002002 qla24xx_pause_risc(reg, ha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002003
2004 WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
2005 dmp_reg = &reg->iobase_window;
Bart Van Assche52c82822015-07-09 07:23:26 -07002006 RD_REG_DWORD(dmp_reg);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002007 WRT_REG_DWORD(dmp_reg, 0);
2008
2009 dmp_reg = &reg->unused_4_1[0];
Bart Van Assche52c82822015-07-09 07:23:26 -07002010 RD_REG_DWORD(dmp_reg);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002011 WRT_REG_DWORD(dmp_reg, 0);
2012
2013 WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
2014 dmp_reg = &reg->unused_4_1[2];
Bart Van Assche52c82822015-07-09 07:23:26 -07002015 RD_REG_DWORD(dmp_reg);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002016 WRT_REG_DWORD(dmp_reg, 0);
2017
2018 /* select PCR and disable ecc checking and correction */
2019 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
2020 RD_REG_DWORD(&reg->iobase_addr);
2021 WRT_REG_DWORD(&reg->iobase_select, 0x60000000); /* write to F0h = PCR */
2022
2023 /* Host/Risc registers. */
2024 iter_reg = fw->host_risc_reg;
2025 iter_reg = qla24xx_read_window(reg, 0x7000, 16, iter_reg);
2026 iter_reg = qla24xx_read_window(reg, 0x7010, 16, iter_reg);
2027 qla24xx_read_window(reg, 0x7040, 16, iter_reg);
2028
2029 /* PCIe registers. */
2030 WRT_REG_DWORD(&reg->iobase_addr, 0x7C00);
2031 RD_REG_DWORD(&reg->iobase_addr);
2032 WRT_REG_DWORD(&reg->iobase_window, 0x01);
2033 dmp_reg = &reg->iobase_c4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002034 fw->pcie_regs[0] = htonl(RD_REG_DWORD(dmp_reg));
2035 dmp_reg++;
2036 fw->pcie_regs[1] = htonl(RD_REG_DWORD(dmp_reg));
2037 dmp_reg++;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002038 fw->pcie_regs[2] = htonl(RD_REG_DWORD(dmp_reg));
2039 fw->pcie_regs[3] = htonl(RD_REG_DWORD(&reg->iobase_window));
2040
2041 WRT_REG_DWORD(&reg->iobase_window, 0x00);
2042 RD_REG_DWORD(&reg->iobase_window);
2043
2044 /* Host interface registers. */
2045 dmp_reg = &reg->flash_addr;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002046 for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++, dmp_reg++)
2047 fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg));
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002048
2049 /* Disable interrupts. */
2050 WRT_REG_DWORD(&reg->ictrl, 0);
2051 RD_REG_DWORD(&reg->ictrl);
2052
2053 /* Shadow registers. */
2054 WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
2055 RD_REG_DWORD(&reg->iobase_addr);
2056 WRT_REG_DWORD(&reg->iobase_select, 0xB0000000);
2057 fw->shadow_reg[0] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2058
2059 WRT_REG_DWORD(&reg->iobase_select, 0xB0100000);
2060 fw->shadow_reg[1] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2061
2062 WRT_REG_DWORD(&reg->iobase_select, 0xB0200000);
2063 fw->shadow_reg[2] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2064
2065 WRT_REG_DWORD(&reg->iobase_select, 0xB0300000);
2066 fw->shadow_reg[3] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2067
2068 WRT_REG_DWORD(&reg->iobase_select, 0xB0400000);
2069 fw->shadow_reg[4] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2070
2071 WRT_REG_DWORD(&reg->iobase_select, 0xB0500000);
2072 fw->shadow_reg[5] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2073
2074 WRT_REG_DWORD(&reg->iobase_select, 0xB0600000);
2075 fw->shadow_reg[6] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2076
2077 WRT_REG_DWORD(&reg->iobase_select, 0xB0700000);
2078 fw->shadow_reg[7] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2079
2080 WRT_REG_DWORD(&reg->iobase_select, 0xB0800000);
2081 fw->shadow_reg[8] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2082
2083 WRT_REG_DWORD(&reg->iobase_select, 0xB0900000);
2084 fw->shadow_reg[9] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2085
2086 WRT_REG_DWORD(&reg->iobase_select, 0xB0A00000);
2087 fw->shadow_reg[10] = htonl(RD_REG_DWORD(&reg->iobase_sdata));
2088
2089 /* RISC I/O register. */
2090 WRT_REG_DWORD(&reg->iobase_addr, 0x0010);
2091 fw->risc_io_reg = htonl(RD_REG_DWORD(&reg->iobase_window));
2092
2093 /* Mailbox registers. */
2094 mbx_reg = &reg->mailbox0;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002095 for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++, dmp_reg++)
2096 fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg));
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002097
2098 /* Transfer sequence registers. */
2099 iter_reg = fw->xseq_gp_reg;
2100 iter_reg = qla24xx_read_window(reg, 0xBE00, 16, iter_reg);
2101 iter_reg = qla24xx_read_window(reg, 0xBE10, 16, iter_reg);
2102 iter_reg = qla24xx_read_window(reg, 0xBE20, 16, iter_reg);
2103 iter_reg = qla24xx_read_window(reg, 0xBE30, 16, iter_reg);
2104 iter_reg = qla24xx_read_window(reg, 0xBE40, 16, iter_reg);
2105 iter_reg = qla24xx_read_window(reg, 0xBE50, 16, iter_reg);
2106 iter_reg = qla24xx_read_window(reg, 0xBE60, 16, iter_reg);
2107 iter_reg = qla24xx_read_window(reg, 0xBE70, 16, iter_reg);
2108 iter_reg = qla24xx_read_window(reg, 0xBF00, 16, iter_reg);
2109 iter_reg = qla24xx_read_window(reg, 0xBF10, 16, iter_reg);
2110 iter_reg = qla24xx_read_window(reg, 0xBF20, 16, iter_reg);
2111 iter_reg = qla24xx_read_window(reg, 0xBF30, 16, iter_reg);
2112 iter_reg = qla24xx_read_window(reg, 0xBF40, 16, iter_reg);
2113 iter_reg = qla24xx_read_window(reg, 0xBF50, 16, iter_reg);
2114 iter_reg = qla24xx_read_window(reg, 0xBF60, 16, iter_reg);
2115 qla24xx_read_window(reg, 0xBF70, 16, iter_reg);
2116
2117 iter_reg = fw->xseq_0_reg;
2118 iter_reg = qla24xx_read_window(reg, 0xBFC0, 16, iter_reg);
2119 iter_reg = qla24xx_read_window(reg, 0xBFD0, 16, iter_reg);
2120 qla24xx_read_window(reg, 0xBFE0, 16, iter_reg);
2121
2122 qla24xx_read_window(reg, 0xBFF0, 16, fw->xseq_1_reg);
2123
2124 qla24xx_read_window(reg, 0xBEF0, 16, fw->xseq_2_reg);
2125
2126 /* Receive sequence registers. */
2127 iter_reg = fw->rseq_gp_reg;
2128 iter_reg = qla24xx_read_window(reg, 0xFE00, 16, iter_reg);
2129 iter_reg = qla24xx_read_window(reg, 0xFE10, 16, iter_reg);
2130 iter_reg = qla24xx_read_window(reg, 0xFE20, 16, iter_reg);
2131 iter_reg = qla24xx_read_window(reg, 0xFE30, 16, iter_reg);
2132 iter_reg = qla24xx_read_window(reg, 0xFE40, 16, iter_reg);
2133 iter_reg = qla24xx_read_window(reg, 0xFE50, 16, iter_reg);
2134 iter_reg = qla24xx_read_window(reg, 0xFE60, 16, iter_reg);
2135 iter_reg = qla24xx_read_window(reg, 0xFE70, 16, iter_reg);
2136 iter_reg = qla24xx_read_window(reg, 0xFF00, 16, iter_reg);
2137 iter_reg = qla24xx_read_window(reg, 0xFF10, 16, iter_reg);
2138 iter_reg = qla24xx_read_window(reg, 0xFF20, 16, iter_reg);
2139 iter_reg = qla24xx_read_window(reg, 0xFF30, 16, iter_reg);
2140 iter_reg = qla24xx_read_window(reg, 0xFF40, 16, iter_reg);
2141 iter_reg = qla24xx_read_window(reg, 0xFF50, 16, iter_reg);
2142 iter_reg = qla24xx_read_window(reg, 0xFF60, 16, iter_reg);
2143 qla24xx_read_window(reg, 0xFF70, 16, iter_reg);
2144
2145 iter_reg = fw->rseq_0_reg;
2146 iter_reg = qla24xx_read_window(reg, 0xFFC0, 16, iter_reg);
2147 qla24xx_read_window(reg, 0xFFD0, 16, iter_reg);
2148
2149 qla24xx_read_window(reg, 0xFFE0, 16, fw->rseq_1_reg);
2150 qla24xx_read_window(reg, 0xFFF0, 16, fw->rseq_2_reg);
2151 qla24xx_read_window(reg, 0xFEF0, 16, fw->rseq_3_reg);
2152
2153 /* Auxiliary sequence registers. */
2154 iter_reg = fw->aseq_gp_reg;
2155 iter_reg = qla24xx_read_window(reg, 0xB000, 16, iter_reg);
2156 iter_reg = qla24xx_read_window(reg, 0xB010, 16, iter_reg);
2157 iter_reg = qla24xx_read_window(reg, 0xB020, 16, iter_reg);
2158 iter_reg = qla24xx_read_window(reg, 0xB030, 16, iter_reg);
2159 iter_reg = qla24xx_read_window(reg, 0xB040, 16, iter_reg);
2160 iter_reg = qla24xx_read_window(reg, 0xB050, 16, iter_reg);
2161 iter_reg = qla24xx_read_window(reg, 0xB060, 16, iter_reg);
2162 iter_reg = qla24xx_read_window(reg, 0xB070, 16, iter_reg);
2163 iter_reg = qla24xx_read_window(reg, 0xB100, 16, iter_reg);
2164 iter_reg = qla24xx_read_window(reg, 0xB110, 16, iter_reg);
2165 iter_reg = qla24xx_read_window(reg, 0xB120, 16, iter_reg);
2166 iter_reg = qla24xx_read_window(reg, 0xB130, 16, iter_reg);
2167 iter_reg = qla24xx_read_window(reg, 0xB140, 16, iter_reg);
2168 iter_reg = qla24xx_read_window(reg, 0xB150, 16, iter_reg);
2169 iter_reg = qla24xx_read_window(reg, 0xB160, 16, iter_reg);
2170 qla24xx_read_window(reg, 0xB170, 16, iter_reg);
2171
2172 iter_reg = fw->aseq_0_reg;
2173 iter_reg = qla24xx_read_window(reg, 0xB0C0, 16, iter_reg);
2174 qla24xx_read_window(reg, 0xB0D0, 16, iter_reg);
2175
2176 qla24xx_read_window(reg, 0xB0E0, 16, fw->aseq_1_reg);
2177 qla24xx_read_window(reg, 0xB0F0, 16, fw->aseq_2_reg);
2178 qla24xx_read_window(reg, 0xB1F0, 16, fw->aseq_3_reg);
2179
2180 /* Command DMA registers. */
2181 iter_reg = fw->cmd_dma_reg;
2182 iter_reg = qla24xx_read_window(reg, 0x7100, 16, iter_reg);
2183 iter_reg = qla24xx_read_window(reg, 0x7120, 16, iter_reg);
2184 iter_reg = qla24xx_read_window(reg, 0x7130, 16, iter_reg);
2185 qla24xx_read_window(reg, 0x71F0, 16, iter_reg);
2186
2187 /* Queues. */
2188 iter_reg = fw->req0_dma_reg;
2189 iter_reg = qla24xx_read_window(reg, 0x7200, 8, iter_reg);
2190 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002191 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
2192 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002193
2194 iter_reg = fw->resp0_dma_reg;
2195 iter_reg = qla24xx_read_window(reg, 0x7300, 8, iter_reg);
2196 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002197 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
2198 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002199
2200 iter_reg = fw->req1_dma_reg;
2201 iter_reg = qla24xx_read_window(reg, 0x7400, 8, iter_reg);
2202 dmp_reg = &reg->iobase_q;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002203 for (cnt = 0; cnt < 7; cnt++, dmp_reg++)
2204 *iter_reg++ = htonl(RD_REG_DWORD(dmp_reg));
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002205
2206 /* Transmit DMA registers. */
2207 iter_reg = fw->xmt0_dma_reg;
2208 iter_reg = qla24xx_read_window(reg, 0x7600, 16, iter_reg);
2209 qla24xx_read_window(reg, 0x7610, 16, iter_reg);
2210
2211 iter_reg = fw->xmt1_dma_reg;
2212 iter_reg = qla24xx_read_window(reg, 0x7620, 16, iter_reg);
2213 qla24xx_read_window(reg, 0x7630, 16, iter_reg);
2214
2215 iter_reg = fw->xmt2_dma_reg;
2216 iter_reg = qla24xx_read_window(reg, 0x7640, 16, iter_reg);
2217 qla24xx_read_window(reg, 0x7650, 16, iter_reg);
2218
2219 iter_reg = fw->xmt3_dma_reg;
2220 iter_reg = qla24xx_read_window(reg, 0x7660, 16, iter_reg);
2221 qla24xx_read_window(reg, 0x7670, 16, iter_reg);
2222
2223 iter_reg = fw->xmt4_dma_reg;
2224 iter_reg = qla24xx_read_window(reg, 0x7680, 16, iter_reg);
2225 qla24xx_read_window(reg, 0x7690, 16, iter_reg);
2226
2227 qla24xx_read_window(reg, 0x76A0, 16, fw->xmt_data_dma_reg);
2228
2229 /* Receive DMA registers. */
2230 iter_reg = fw->rcvt0_data_dma_reg;
2231 iter_reg = qla24xx_read_window(reg, 0x7700, 16, iter_reg);
2232 qla24xx_read_window(reg, 0x7710, 16, iter_reg);
2233
2234 iter_reg = fw->rcvt1_data_dma_reg;
2235 iter_reg = qla24xx_read_window(reg, 0x7720, 16, iter_reg);
2236 qla24xx_read_window(reg, 0x7730, 16, iter_reg);
2237
2238 /* RISC registers. */
2239 iter_reg = fw->risc_gp_reg;
2240 iter_reg = qla24xx_read_window(reg, 0x0F00, 16, iter_reg);
2241 iter_reg = qla24xx_read_window(reg, 0x0F10, 16, iter_reg);
2242 iter_reg = qla24xx_read_window(reg, 0x0F20, 16, iter_reg);
2243 iter_reg = qla24xx_read_window(reg, 0x0F30, 16, iter_reg);
2244 iter_reg = qla24xx_read_window(reg, 0x0F40, 16, iter_reg);
2245 iter_reg = qla24xx_read_window(reg, 0x0F50, 16, iter_reg);
2246 iter_reg = qla24xx_read_window(reg, 0x0F60, 16, iter_reg);
2247 qla24xx_read_window(reg, 0x0F70, 16, iter_reg);
2248
2249 /* Local memory controller registers. */
2250 iter_reg = fw->lmc_reg;
2251 iter_reg = qla24xx_read_window(reg, 0x3000, 16, iter_reg);
2252 iter_reg = qla24xx_read_window(reg, 0x3010, 16, iter_reg);
2253 iter_reg = qla24xx_read_window(reg, 0x3020, 16, iter_reg);
2254 iter_reg = qla24xx_read_window(reg, 0x3030, 16, iter_reg);
2255 iter_reg = qla24xx_read_window(reg, 0x3040, 16, iter_reg);
2256 iter_reg = qla24xx_read_window(reg, 0x3050, 16, iter_reg);
2257 iter_reg = qla24xx_read_window(reg, 0x3060, 16, iter_reg);
2258 qla24xx_read_window(reg, 0x3070, 16, iter_reg);
2259
2260 /* Fibre Protocol Module registers. */
2261 iter_reg = fw->fpm_hdw_reg;
2262 iter_reg = qla24xx_read_window(reg, 0x4000, 16, iter_reg);
2263 iter_reg = qla24xx_read_window(reg, 0x4010, 16, iter_reg);
2264 iter_reg = qla24xx_read_window(reg, 0x4020, 16, iter_reg);
2265 iter_reg = qla24xx_read_window(reg, 0x4030, 16, iter_reg);
2266 iter_reg = qla24xx_read_window(reg, 0x4040, 16, iter_reg);
2267 iter_reg = qla24xx_read_window(reg, 0x4050, 16, iter_reg);
2268 iter_reg = qla24xx_read_window(reg, 0x4060, 16, iter_reg);
2269 iter_reg = qla24xx_read_window(reg, 0x4070, 16, iter_reg);
2270 iter_reg = qla24xx_read_window(reg, 0x4080, 16, iter_reg);
2271 iter_reg = qla24xx_read_window(reg, 0x4090, 16, iter_reg);
2272 iter_reg = qla24xx_read_window(reg, 0x40A0, 16, iter_reg);
2273 iter_reg = qla24xx_read_window(reg, 0x40B0, 16, iter_reg);
2274 iter_reg = qla24xx_read_window(reg, 0x40C0, 16, iter_reg);
2275 iter_reg = qla24xx_read_window(reg, 0x40D0, 16, iter_reg);
2276 iter_reg = qla24xx_read_window(reg, 0x40E0, 16, iter_reg);
2277 qla24xx_read_window(reg, 0x40F0, 16, iter_reg);
2278
2279 /* RQ0 Array registers. */
2280 iter_reg = fw->rq0_array_reg;
2281 iter_reg = qla24xx_read_window(reg, 0x5C00, 16, iter_reg);
2282 iter_reg = qla24xx_read_window(reg, 0x5C10, 16, iter_reg);
2283 iter_reg = qla24xx_read_window(reg, 0x5C20, 16, iter_reg);
2284 iter_reg = qla24xx_read_window(reg, 0x5C30, 16, iter_reg);
2285 iter_reg = qla24xx_read_window(reg, 0x5C40, 16, iter_reg);
2286 iter_reg = qla24xx_read_window(reg, 0x5C50, 16, iter_reg);
2287 iter_reg = qla24xx_read_window(reg, 0x5C60, 16, iter_reg);
2288 iter_reg = qla24xx_read_window(reg, 0x5C70, 16, iter_reg);
2289 iter_reg = qla24xx_read_window(reg, 0x5C80, 16, iter_reg);
2290 iter_reg = qla24xx_read_window(reg, 0x5C90, 16, iter_reg);
2291 iter_reg = qla24xx_read_window(reg, 0x5CA0, 16, iter_reg);
2292 iter_reg = qla24xx_read_window(reg, 0x5CB0, 16, iter_reg);
2293 iter_reg = qla24xx_read_window(reg, 0x5CC0, 16, iter_reg);
2294 iter_reg = qla24xx_read_window(reg, 0x5CD0, 16, iter_reg);
2295 iter_reg = qla24xx_read_window(reg, 0x5CE0, 16, iter_reg);
2296 qla24xx_read_window(reg, 0x5CF0, 16, iter_reg);
2297
2298 /* RQ1 Array registers. */
2299 iter_reg = fw->rq1_array_reg;
2300 iter_reg = qla24xx_read_window(reg, 0x5D00, 16, iter_reg);
2301 iter_reg = qla24xx_read_window(reg, 0x5D10, 16, iter_reg);
2302 iter_reg = qla24xx_read_window(reg, 0x5D20, 16, iter_reg);
2303 iter_reg = qla24xx_read_window(reg, 0x5D30, 16, iter_reg);
2304 iter_reg = qla24xx_read_window(reg, 0x5D40, 16, iter_reg);
2305 iter_reg = qla24xx_read_window(reg, 0x5D50, 16, iter_reg);
2306 iter_reg = qla24xx_read_window(reg, 0x5D60, 16, iter_reg);
2307 iter_reg = qla24xx_read_window(reg, 0x5D70, 16, iter_reg);
2308 iter_reg = qla24xx_read_window(reg, 0x5D80, 16, iter_reg);
2309 iter_reg = qla24xx_read_window(reg, 0x5D90, 16, iter_reg);
2310 iter_reg = qla24xx_read_window(reg, 0x5DA0, 16, iter_reg);
2311 iter_reg = qla24xx_read_window(reg, 0x5DB0, 16, iter_reg);
2312 iter_reg = qla24xx_read_window(reg, 0x5DC0, 16, iter_reg);
2313 iter_reg = qla24xx_read_window(reg, 0x5DD0, 16, iter_reg);
2314 iter_reg = qla24xx_read_window(reg, 0x5DE0, 16, iter_reg);
2315 qla24xx_read_window(reg, 0x5DF0, 16, iter_reg);
2316
2317 /* RP0 Array registers. */
2318 iter_reg = fw->rp0_array_reg;
2319 iter_reg = qla24xx_read_window(reg, 0x5E00, 16, iter_reg);
2320 iter_reg = qla24xx_read_window(reg, 0x5E10, 16, iter_reg);
2321 iter_reg = qla24xx_read_window(reg, 0x5E20, 16, iter_reg);
2322 iter_reg = qla24xx_read_window(reg, 0x5E30, 16, iter_reg);
2323 iter_reg = qla24xx_read_window(reg, 0x5E40, 16, iter_reg);
2324 iter_reg = qla24xx_read_window(reg, 0x5E50, 16, iter_reg);
2325 iter_reg = qla24xx_read_window(reg, 0x5E60, 16, iter_reg);
2326 iter_reg = qla24xx_read_window(reg, 0x5E70, 16, iter_reg);
2327 iter_reg = qla24xx_read_window(reg, 0x5E80, 16, iter_reg);
2328 iter_reg = qla24xx_read_window(reg, 0x5E90, 16, iter_reg);
2329 iter_reg = qla24xx_read_window(reg, 0x5EA0, 16, iter_reg);
2330 iter_reg = qla24xx_read_window(reg, 0x5EB0, 16, iter_reg);
2331 iter_reg = qla24xx_read_window(reg, 0x5EC0, 16, iter_reg);
2332 iter_reg = qla24xx_read_window(reg, 0x5ED0, 16, iter_reg);
2333 iter_reg = qla24xx_read_window(reg, 0x5EE0, 16, iter_reg);
2334 qla24xx_read_window(reg, 0x5EF0, 16, iter_reg);
2335
2336 /* RP1 Array registers. */
2337 iter_reg = fw->rp1_array_reg;
2338 iter_reg = qla24xx_read_window(reg, 0x5F00, 16, iter_reg);
2339 iter_reg = qla24xx_read_window(reg, 0x5F10, 16, iter_reg);
2340 iter_reg = qla24xx_read_window(reg, 0x5F20, 16, iter_reg);
2341 iter_reg = qla24xx_read_window(reg, 0x5F30, 16, iter_reg);
2342 iter_reg = qla24xx_read_window(reg, 0x5F40, 16, iter_reg);
2343 iter_reg = qla24xx_read_window(reg, 0x5F50, 16, iter_reg);
2344 iter_reg = qla24xx_read_window(reg, 0x5F60, 16, iter_reg);
2345 iter_reg = qla24xx_read_window(reg, 0x5F70, 16, iter_reg);
2346 iter_reg = qla24xx_read_window(reg, 0x5F80, 16, iter_reg);
2347 iter_reg = qla24xx_read_window(reg, 0x5F90, 16, iter_reg);
2348 iter_reg = qla24xx_read_window(reg, 0x5FA0, 16, iter_reg);
2349 iter_reg = qla24xx_read_window(reg, 0x5FB0, 16, iter_reg);
2350 iter_reg = qla24xx_read_window(reg, 0x5FC0, 16, iter_reg);
2351 iter_reg = qla24xx_read_window(reg, 0x5FD0, 16, iter_reg);
2352 iter_reg = qla24xx_read_window(reg, 0x5FE0, 16, iter_reg);
2353 qla24xx_read_window(reg, 0x5FF0, 16, iter_reg);
2354
2355 iter_reg = fw->at0_array_reg;
2356 iter_reg = qla24xx_read_window(reg, 0x7080, 16, iter_reg);
2357 iter_reg = qla24xx_read_window(reg, 0x7090, 16, iter_reg);
2358 iter_reg = qla24xx_read_window(reg, 0x70A0, 16, iter_reg);
2359 iter_reg = qla24xx_read_window(reg, 0x70B0, 16, iter_reg);
2360 iter_reg = qla24xx_read_window(reg, 0x70C0, 16, iter_reg);
2361 iter_reg = qla24xx_read_window(reg, 0x70D0, 16, iter_reg);
2362 iter_reg = qla24xx_read_window(reg, 0x70E0, 16, iter_reg);
2363 qla24xx_read_window(reg, 0x70F0, 16, iter_reg);
2364
2365 /* I/O Queue Control registers. */
2366 qla24xx_read_window(reg, 0x7800, 16, fw->queue_control_reg);
2367
2368 /* Frame Buffer registers. */
2369 iter_reg = fw->fb_hdw_reg;
2370 iter_reg = qla24xx_read_window(reg, 0x6000, 16, iter_reg);
2371 iter_reg = qla24xx_read_window(reg, 0x6010, 16, iter_reg);
2372 iter_reg = qla24xx_read_window(reg, 0x6020, 16, iter_reg);
2373 iter_reg = qla24xx_read_window(reg, 0x6030, 16, iter_reg);
2374 iter_reg = qla24xx_read_window(reg, 0x6040, 16, iter_reg);
2375 iter_reg = qla24xx_read_window(reg, 0x6060, 16, iter_reg);
2376 iter_reg = qla24xx_read_window(reg, 0x6070, 16, iter_reg);
2377 iter_reg = qla24xx_read_window(reg, 0x6100, 16, iter_reg);
2378 iter_reg = qla24xx_read_window(reg, 0x6130, 16, iter_reg);
2379 iter_reg = qla24xx_read_window(reg, 0x6150, 16, iter_reg);
2380 iter_reg = qla24xx_read_window(reg, 0x6170, 16, iter_reg);
2381 iter_reg = qla24xx_read_window(reg, 0x6190, 16, iter_reg);
2382 iter_reg = qla24xx_read_window(reg, 0x61B0, 16, iter_reg);
2383 iter_reg = qla24xx_read_window(reg, 0x61C0, 16, iter_reg);
2384 iter_reg = qla24xx_read_window(reg, 0x6530, 16, iter_reg);
2385 iter_reg = qla24xx_read_window(reg, 0x6540, 16, iter_reg);
2386 iter_reg = qla24xx_read_window(reg, 0x6550, 16, iter_reg);
2387 iter_reg = qla24xx_read_window(reg, 0x6560, 16, iter_reg);
2388 iter_reg = qla24xx_read_window(reg, 0x6570, 16, iter_reg);
2389 iter_reg = qla24xx_read_window(reg, 0x6580, 16, iter_reg);
2390 iter_reg = qla24xx_read_window(reg, 0x6590, 16, iter_reg);
2391 iter_reg = qla24xx_read_window(reg, 0x65A0, 16, iter_reg);
2392 iter_reg = qla24xx_read_window(reg, 0x65B0, 16, iter_reg);
2393 iter_reg = qla24xx_read_window(reg, 0x65C0, 16, iter_reg);
2394 iter_reg = qla24xx_read_window(reg, 0x65D0, 16, iter_reg);
2395 iter_reg = qla24xx_read_window(reg, 0x65E0, 16, iter_reg);
2396 qla24xx_read_window(reg, 0x6F00, 16, iter_reg);
2397
2398 /* Multi queue registers */
2399 nxt_chain = qla25xx_copy_mq(ha, (void *)ha->fw_dump + ha->chain_offset,
2400 &last_chain);
2401
2402 rval = qla24xx_soft_reset(ha);
2403 if (rval != QLA_SUCCESS) {
2404 ql_log(ql_log_warn, vha, 0xd00e,
2405 "SOFT RESET FAILED, forcing continuation of dump!!!\n");
2406 rval = QLA_SUCCESS;
2407
2408 ql_log(ql_log_warn, vha, 0xd00f, "try a bigger hammer!!!\n");
2409
2410 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2411 RD_REG_DWORD(&reg->hccr);
2412
2413 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2414 RD_REG_DWORD(&reg->hccr);
2415
2416 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2417 RD_REG_DWORD(&reg->hccr);
2418
2419 for (cnt = 30000; cnt && (RD_REG_WORD(&reg->mailbox0)); cnt--)
2420 udelay(5);
2421
2422 if (!cnt) {
2423 nxt = fw->code_ram;
Saurav Kashyap8c0bc702012-11-21 02:40:35 -05002424 nxt += sizeof(fw->code_ram);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002425 nxt += (ha->fw_memory_size - 0x100000 + 1);
2426 goto copy_queue;
Hiral Patel61f098d2014-04-11 16:54:21 -04002427 } else {
2428 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002429 ql_log(ql_log_warn, vha, 0xd010,
2430 "bigger hammer success?\n");
Hiral Patel61f098d2014-04-11 16:54:21 -04002431 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002432 }
2433
2434 rval = qla24xx_dump_memory(ha, fw->code_ram, sizeof(fw->code_ram),
2435 &nxt);
2436 if (rval != QLA_SUCCESS)
2437 goto qla83xx_fw_dump_failed_0;
2438
2439copy_queue:
2440 nxt = qla2xxx_copy_queues(ha, nxt);
2441
Bart Van Assche7f544d02013-06-25 11:27:27 -04002442 qla24xx_copy_eft(ha, nxt);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002443
2444 /* Chain entries -- started with MQ. */
2445 nxt_chain = qla25xx_copy_fce(ha, nxt_chain, &last_chain);
2446 nxt_chain = qla25xx_copy_mqueues(ha, nxt_chain, &last_chain);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002447 nxt_chain = qla2xxx_copy_atioqueues(ha, nxt_chain, &last_chain);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002448 if (last_chain) {
Bart Van Asschead950362015-07-09 07:24:08 -07002449 ha->fw_dump->version |= htonl(DUMP_CHAIN_VARIANT);
2450 *last_chain |= htonl(DUMP_CHAIN_LAST);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002451 }
2452
2453 /* Adjust valid length. */
2454 ha->fw_dump_len = (nxt_chain - (void *)ha->fw_dump);
2455
2456qla83xx_fw_dump_failed_0:
2457 qla2xxx_dump_post_process(base_vha, rval);
2458
2459qla83xx_fw_dump_failed:
Bart Van Assche8d163662015-07-09 07:25:46 -07002460#ifndef __CHECKER__
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002461 if (!hardware_locked)
2462 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Bart Van Assche8d163662015-07-09 07:25:46 -07002463#else
2464 ;
2465#endif
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002466}
2467
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468/****************************************************************************/
2469/* Driver Debug Functions. */
2470/****************************************************************************/
Chad Dupuiscfb09192011-11-18 09:03:07 -08002471
2472static inline int
2473ql_mask_match(uint32_t level)
2474{
2475 if (ql2xextended_error_logging == 1)
2476 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
2477 return (level & ql2xextended_error_logging) == level;
2478}
2479
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002480/*
2481 * This function is for formatting and logging debug information.
2482 * It is to be used when vha is available. It formats the message
2483 * and logs it to the messages file.
2484 * parameters:
2485 * level: The level of the debug messages to be printed.
2486 * If ql2xextended_error_logging value is correctly set,
2487 * this message will appear in the messages file.
2488 * vha: Pointer to the scsi_qla_host_t.
2489 * id: This is a unique identifier for the level. It identifies the
2490 * part of the code from where the message originated.
2491 * msg: The message to be displayed.
2492 */
2493void
Joe Perches086b3e82011-11-18 09:03:05 -08002494ql_dbg(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2495{
2496 va_list va;
2497 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002498
Chad Dupuiscfb09192011-11-18 09:03:07 -08002499 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002500 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002501
Joe Perches086b3e82011-11-18 09:03:05 -08002502 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002503
Joe Perches086b3e82011-11-18 09:03:05 -08002504 vaf.fmt = fmt;
2505 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002506
Joe Perches086b3e82011-11-18 09:03:05 -08002507 if (vha != NULL) {
2508 const struct pci_dev *pdev = vha->hw->pdev;
2509 /* <module-name> <pci-name> <msg-id>:<host> Message */
2510 pr_warn("%s [%s]-%04x:%ld: %pV",
2511 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset,
2512 vha->host_no, &vaf);
2513 } else {
2514 pr_warn("%s [%s]-%04x: : %pV",
2515 QL_MSGHDR, "0000:00:00.0", id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002516 }
2517
Joe Perches086b3e82011-11-18 09:03:05 -08002518 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002519
2520}
2521
2522/*
2523 * This function is for formatting and logging debug information.
Masanari Iidad6a03582012-08-22 14:20:58 -04002524 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002525 * i.e., before host allocation. It formats the message and logs it
2526 * to the messages file.
2527 * parameters:
2528 * level: The level of the debug messages to be printed.
2529 * If ql2xextended_error_logging value is correctly set,
2530 * this message will appear in the messages file.
2531 * pdev: Pointer to the struct pci_dev.
2532 * id: This is a unique id for the level. It identifies the part
2533 * of the code from where the message originated.
2534 * msg: The message to be displayed.
2535 */
2536void
Joe Perches086b3e82011-11-18 09:03:05 -08002537ql_dbg_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2538 const char *fmt, ...)
2539{
2540 va_list va;
2541 struct va_format vaf;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002542
2543 if (pdev == NULL)
2544 return;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002545 if (!ql_mask_match(level))
Joe Perches086b3e82011-11-18 09:03:05 -08002546 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002547
Joe Perches086b3e82011-11-18 09:03:05 -08002548 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002549
Joe Perches086b3e82011-11-18 09:03:05 -08002550 vaf.fmt = fmt;
2551 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002552
Joe Perches086b3e82011-11-18 09:03:05 -08002553 /* <module-name> <dev-name>:<msg-id> Message */
2554 pr_warn("%s [%s]-%04x: : %pV",
2555 QL_MSGHDR, dev_name(&(pdev->dev)), id + ql_dbg_offset, &vaf);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002556
Joe Perches086b3e82011-11-18 09:03:05 -08002557 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002558}
2559
2560/*
2561 * This function is for formatting and logging log messages.
2562 * It is to be used when vha is available. It formats the message
2563 * and logs it to the messages file. All the messages will be logged
2564 * irrespective of value of ql2xextended_error_logging.
2565 * parameters:
2566 * level: The level of the log messages to be printed in the
2567 * messages file.
2568 * vha: Pointer to the scsi_qla_host_t
2569 * id: This is a unique id for the level. It identifies the
2570 * part of the code from where the message originated.
2571 * msg: The message to be displayed.
2572 */
2573void
Joe Perches086b3e82011-11-18 09:03:05 -08002574ql_log(uint32_t level, scsi_qla_host_t *vha, int32_t id, const char *fmt, ...)
2575{
2576 va_list va;
2577 struct va_format vaf;
2578 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002579
Joe Perches086b3e82011-11-18 09:03:05 -08002580 if (level > ql_errlev)
2581 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002582
Joe Perches086b3e82011-11-18 09:03:05 -08002583 if (vha != NULL) {
2584 const struct pci_dev *pdev = vha->hw->pdev;
2585 /* <module-name> <msg-id>:<host> Message */
2586 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x:%ld: ",
2587 QL_MSGHDR, dev_name(&(pdev->dev)), id, vha->host_no);
2588 } else {
2589 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2590 QL_MSGHDR, "0000:00:00.0", id);
2591 }
2592 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002593
Joe Perches086b3e82011-11-18 09:03:05 -08002594 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002595
Joe Perches086b3e82011-11-18 09:03:05 -08002596 vaf.fmt = fmt;
2597 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002598
Joe Perches086b3e82011-11-18 09:03:05 -08002599 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002600 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002601 pr_crit("%s%pV", pbuf, &vaf);
2602 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002603 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002604 pr_err("%s%pV", pbuf, &vaf);
2605 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002606 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002607 pr_warn("%s%pV", pbuf, &vaf);
2608 break;
2609 default:
2610 pr_info("%s%pV", pbuf, &vaf);
2611 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002612 }
2613
Joe Perches086b3e82011-11-18 09:03:05 -08002614 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002615}
2616
2617/*
2618 * This function is for formatting and logging log messages.
Masanari Iidad6a03582012-08-22 14:20:58 -04002619 * It is to be used when vha is not available and pci is available,
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002620 * i.e., before host allocation. It formats the message and logs
2621 * it to the messages file. All the messages are logged irrespective
2622 * of the value of ql2xextended_error_logging.
2623 * parameters:
2624 * level: The level of the log messages to be printed in the
2625 * messages file.
2626 * pdev: Pointer to the struct pci_dev.
2627 * id: This is a unique id for the level. It identifies the
2628 * part of the code from where the message originated.
2629 * msg: The message to be displayed.
2630 */
2631void
Joe Perches086b3e82011-11-18 09:03:05 -08002632ql_log_pci(uint32_t level, struct pci_dev *pdev, int32_t id,
2633 const char *fmt, ...)
2634{
2635 va_list va;
2636 struct va_format vaf;
2637 char pbuf[128];
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002638
2639 if (pdev == NULL)
2640 return;
Joe Perches086b3e82011-11-18 09:03:05 -08002641 if (level > ql_errlev)
2642 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002643
Joe Perches086b3e82011-11-18 09:03:05 -08002644 /* <module-name> <dev-name>:<msg-id> Message */
2645 snprintf(pbuf, sizeof(pbuf), "%s [%s]-%04x: : ",
2646 QL_MSGHDR, dev_name(&(pdev->dev)), id);
2647 pbuf[sizeof(pbuf) - 1] = 0;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002648
Joe Perches086b3e82011-11-18 09:03:05 -08002649 va_start(va, fmt);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002650
Joe Perches086b3e82011-11-18 09:03:05 -08002651 vaf.fmt = fmt;
2652 vaf.va = &va;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002653
Joe Perches086b3e82011-11-18 09:03:05 -08002654 switch (level) {
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002655 case ql_log_fatal: /* FATAL LOG */
Joe Perches086b3e82011-11-18 09:03:05 -08002656 pr_crit("%s%pV", pbuf, &vaf);
2657 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002658 case ql_log_warn:
Joe Perches086b3e82011-11-18 09:03:05 -08002659 pr_err("%s%pV", pbuf, &vaf);
2660 break;
Chad Dupuis70a3fc72012-02-09 11:15:48 -08002661 case ql_log_info:
Joe Perches086b3e82011-11-18 09:03:05 -08002662 pr_warn("%s%pV", pbuf, &vaf);
2663 break;
2664 default:
2665 pr_info("%s%pV", pbuf, &vaf);
2666 break;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002667 }
2668
Joe Perches086b3e82011-11-18 09:03:05 -08002669 va_end(va);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002670}
2671
2672void
2673ql_dump_regs(uint32_t level, scsi_qla_host_t *vha, int32_t id)
2674{
2675 int i;
2676 struct qla_hw_data *ha = vha->hw;
2677 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2678 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2679 struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
2680 uint16_t __iomem *mbx_reg;
2681
Chad Dupuiscfb09192011-11-18 09:03:07 -08002682 if (!ql_mask_match(level))
2683 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002684
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002685 if (IS_P3P_TYPE(ha))
Chad Dupuiscfb09192011-11-18 09:03:07 -08002686 mbx_reg = &reg82->mailbox_in[0];
2687 else if (IS_FWI2_CAPABLE(ha))
2688 mbx_reg = &reg24->mailbox0;
2689 else
2690 mbx_reg = MAILBOX_REG(ha, reg, 0);
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002691
Chad Dupuiscfb09192011-11-18 09:03:07 -08002692 ql_dbg(level, vha, id, "Mailbox registers:\n");
2693 for (i = 0; i < 6; i++)
2694 ql_dbg(level, vha, id,
2695 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002696}
2697
2698
2699void
2700ql_dump_buffer(uint32_t level, scsi_qla_host_t *vha, int32_t id,
2701 uint8_t *b, uint32_t size)
2702{
2703 uint32_t cnt;
2704 uint8_t c;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002705
Chad Dupuiscfb09192011-11-18 09:03:07 -08002706 if (!ql_mask_match(level))
2707 return;
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002708
Chad Dupuiscfb09192011-11-18 09:03:07 -08002709 ql_dbg(level, vha, id, " 0 1 2 3 4 5 6 7 8 "
2710 "9 Ah Bh Ch Dh Eh Fh\n");
2711 ql_dbg(level, vha, id, "----------------------------------"
2712 "----------------------------\n");
2713
2714 ql_dbg(level, vha, id, " ");
2715 for (cnt = 0; cnt < size;) {
2716 c = *b++;
2717 printk("%02x", (uint32_t) c);
2718 cnt++;
2719 if (!(cnt % 16))
2720 printk("\n");
2721 else
2722 printk(" ");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002723 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002724 if (cnt % 16)
2725 ql_dbg(level, vha, id, "\n");
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002726}