qla_dbg.c 46.8 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
A
Andrew Vasquez 已提交
2 3
 * QLogic Fibre Channel HBA Driver
 * Copyright (c)  2003-2005 QLogic Corporation
L
Linus Torvalds 已提交
4
 *
A
Andrew Vasquez 已提交
5
 * See LICENSE.qla2xxx for copyright and licensing details.
L
Linus Torvalds 已提交
6 7 8 9 10
 */
#include "qla_def.h"

#include <linux/delay.h>

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
static inline void
qla2xxx_prep_dump(scsi_qla_host_t *ha, struct qla2xxx_fw_dump *fw_dump)
{
	fw_dump->fw_major_version = htonl(ha->fw_major_version);
	fw_dump->fw_minor_version = htonl(ha->fw_minor_version);
	fw_dump->fw_subminor_version = htonl(ha->fw_subminor_version);
	fw_dump->fw_attributes = htonl(ha->fw_attributes);

	fw_dump->vendor = htonl(ha->pdev->vendor);
	fw_dump->device = htonl(ha->pdev->device);
	fw_dump->subsystem_vendor = htonl(ha->pdev->subsystem_vendor);
	fw_dump->subsystem_device = htonl(ha->pdev->subsystem_device);
}

static inline void *
qla2xxx_copy_queues(scsi_qla_host_t *ha, void *ptr)
{
	/* Request queue. */
	memcpy(ptr, ha->request_ring, ha->request_q_length *
	    sizeof(request_t));

	/* Response queue. */
	ptr += ha->request_q_length * sizeof(request_t);
	memcpy(ptr, ha->response_ring, ha->response_q_length  *
	    sizeof(response_t));

	return ptr + (ha->response_q_length * sizeof(response_t));
}
L
Linus Torvalds 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

/**
 * qla2300_fw_dump() - Dumps binary data from the 2300 firmware.
 * @ha: HA context
 * @hardware_locked: Called with the hardware_lock
 */
void
qla2300_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
{
	int		rval;
	uint32_t	cnt, timer;
	uint32_t	risc_address;
	uint16_t	mb0, mb2;

	uint32_t	stat;
54
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
L
Linus Torvalds 已提交
55 56 57
	uint16_t __iomem *dmp_reg;
	unsigned long	flags;
	struct qla2300_fw_dump	*fw;
58
	uint32_t	data_ram_cnt;
L
Linus Torvalds 已提交
59 60 61 62 63 64 65 66

	risc_address = data_ram_cnt = 0;
	mb0 = mb2 = 0;
	flags = 0;

	if (!hardware_locked)
		spin_lock_irqsave(&ha->hardware_lock, flags);

67
	if (!ha->fw_dump) {
L
Linus Torvalds 已提交
68
		qla_printk(KERN_WARNING, ha,
69
		    "No buffer available for dump!!!\n");
L
Linus Torvalds 已提交
70 71 72
		goto qla2300_fw_dump_failed;
	}

73
	if (ha->fw_dumped) {
L
Linus Torvalds 已提交
74
		qla_printk(KERN_WARNING, ha,
75 76
		    "Firmware has been previously dumped (%p) -- ignoring "
		    "request...\n", ha->fw_dump);
L
Linus Torvalds 已提交
77 78
		goto qla2300_fw_dump_failed;
	}
79 80
	fw = &ha->fw_dump->isp.isp23;
	qla2xxx_prep_dump(ha, ha->fw_dump);
L
Linus Torvalds 已提交
81 82

	rval = QLA_SUCCESS;
83
	fw->hccr = htons(RD_REG_WORD(&reg->hccr));
L
Linus Torvalds 已提交
84 85

	/* Pause RISC. */
A
Andrew Vasquez 已提交
86
	WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
L
Linus Torvalds 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	if (IS_QLA2300(ha)) {
		for (cnt = 30000;
		    (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
			rval == QLA_SUCCESS; cnt--) {
			if (cnt)
				udelay(100);
			else
				rval = QLA_FUNCTION_TIMEOUT;
		}
	} else {
		RD_REG_WORD(&reg->hccr);		/* PCI Posting. */
		udelay(10);
	}

	if (rval == QLA_SUCCESS) {
		dmp_reg = (uint16_t __iomem *)(reg + 0);
A
Andrew Vasquez 已提交
103
		for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
104
			fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
105 106

		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x10);
A
Andrew Vasquez 已提交
107
		for (cnt = 0; cnt < sizeof(fw->risc_host_reg) / 2; cnt++)
108
			fw->risc_host_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
109 110

		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x40);
A
Andrew Vasquez 已提交
111
		for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
112
			fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
113 114 115

		WRT_REG_WORD(&reg->ctrl_status, 0x40);
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
116
		for (cnt = 0; cnt < sizeof(fw->resp_dma_reg) / 2; cnt++)
117
			fw->resp_dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
118 119 120

		WRT_REG_WORD(&reg->ctrl_status, 0x50);
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
121
		for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
122
			fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
123 124 125

		WRT_REG_WORD(&reg->ctrl_status, 0x00);
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xA0);
A
Andrew Vasquez 已提交
126
		for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
127
			fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
128

A
Andrew Vasquez 已提交
129
		WRT_REG_WORD(&reg->pcr, 0x2000);
L
Linus Torvalds 已提交
130
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
131
		for (cnt = 0; cnt < sizeof(fw->risc_gp0_reg) / 2; cnt++)
132
			fw->risc_gp0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
133

A
Andrew Vasquez 已提交
134
		WRT_REG_WORD(&reg->pcr, 0x2200);
L
Linus Torvalds 已提交
135
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
136
		for (cnt = 0; cnt < sizeof(fw->risc_gp1_reg) / 2; cnt++)
137
			fw->risc_gp1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
138

A
Andrew Vasquez 已提交
139
		WRT_REG_WORD(&reg->pcr, 0x2400);
L
Linus Torvalds 已提交
140
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
141
		for (cnt = 0; cnt < sizeof(fw->risc_gp2_reg) / 2; cnt++)
142
			fw->risc_gp2_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
143

A
Andrew Vasquez 已提交
144
		WRT_REG_WORD(&reg->pcr, 0x2600);
L
Linus Torvalds 已提交
145
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
146
		for (cnt = 0; cnt < sizeof(fw->risc_gp3_reg) / 2; cnt++)
147
			fw->risc_gp3_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
148

A
Andrew Vasquez 已提交
149
		WRT_REG_WORD(&reg->pcr, 0x2800);
L
Linus Torvalds 已提交
150
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
151
		for (cnt = 0; cnt < sizeof(fw->risc_gp4_reg) / 2; cnt++)
152
			fw->risc_gp4_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
153

A
Andrew Vasquez 已提交
154
		WRT_REG_WORD(&reg->pcr, 0x2A00);
L
Linus Torvalds 已提交
155
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
156
		for (cnt = 0; cnt < sizeof(fw->risc_gp5_reg) / 2; cnt++)
157
			fw->risc_gp5_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
158

A
Andrew Vasquez 已提交
159
		WRT_REG_WORD(&reg->pcr, 0x2C00);
L
Linus Torvalds 已提交
160
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
161
		for (cnt = 0; cnt < sizeof(fw->risc_gp6_reg) / 2; cnt++)
162
			fw->risc_gp6_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
163

A
Andrew Vasquez 已提交
164
		WRT_REG_WORD(&reg->pcr, 0x2E00);
L
Linus Torvalds 已提交
165
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
166
		for (cnt = 0; cnt < sizeof(fw->risc_gp7_reg) / 2; cnt++)
167
			fw->risc_gp7_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
168

A
Andrew Vasquez 已提交
169
		WRT_REG_WORD(&reg->ctrl_status, 0x10);
L
Linus Torvalds 已提交
170
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
171
		for (cnt = 0; cnt < sizeof(fw->frame_buf_hdw_reg) / 2; cnt++)
172 173
			fw->frame_buf_hdw_reg[cnt] =
			    htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
174

A
Andrew Vasquez 已提交
175
		WRT_REG_WORD(&reg->ctrl_status, 0x20);
L
Linus Torvalds 已提交
176
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
177
		for (cnt = 0; cnt < sizeof(fw->fpm_b0_reg) / 2; cnt++)
178
			fw->fpm_b0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
179

A
Andrew Vasquez 已提交
180
		WRT_REG_WORD(&reg->ctrl_status, 0x30);
L
Linus Torvalds 已提交
181
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
182
		for (cnt = 0; cnt < sizeof(fw->fpm_b1_reg) / 2; cnt++)
183
			fw->fpm_b1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

		/* Reset RISC. */
		WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
		for (cnt = 0; cnt < 30000; cnt++) {
			if ((RD_REG_WORD(&reg->ctrl_status) &
			    CSR_ISP_SOFT_RESET) == 0)
				break;

			udelay(10);
		}
	}

	if (!IS_QLA2300(ha)) {
		for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
		    rval == QLA_SUCCESS; cnt--) {
			if (cnt)
				udelay(100);
			else
				rval = QLA_FUNCTION_TIMEOUT;
		}
	}

	if (rval == QLA_SUCCESS) {
		/* Get RISC SRAM. */
		risc_address = 0x800;
 		WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
		clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
	}
	for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
	    cnt++, risc_address++) {
 		WRT_MAILBOX_REG(ha, reg, 1, (uint16_t)risc_address);
		WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);

		for (timer = 6000000; timer; timer--) {
			/* Check for pending interrupts. */
 			stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
			if (stat & HSR_RISC_INT) {
				stat &= 0xff;

				if (stat == 0x1 || stat == 0x2) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					/* Release mailbox registers. */
					WRT_REG_WORD(&reg->semaphore, 0);
					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				} else if (stat == 0x10 || stat == 0x11) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				}

				/* clear this intr; it wasn't a mailbox intr */
				WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
				RD_REG_WORD(&reg->hccr);
			}
			udelay(5);
		}

		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
			rval = mb0 & MBS_MASK;
258
			fw->risc_ram[cnt] = htons(mb2);
L
Linus Torvalds 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
		} else {
			rval = QLA_FUNCTION_FAILED;
		}
	}

	if (rval == QLA_SUCCESS) {
		/* Get stack SRAM. */
		risc_address = 0x10000;
 		WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_EXTENDED);
		clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
	}
	for (cnt = 0; cnt < sizeof(fw->stack_ram) / 2 && rval == QLA_SUCCESS;
	    cnt++, risc_address++) {
 		WRT_MAILBOX_REG(ha, reg, 1, LSW(risc_address));
 		WRT_MAILBOX_REG(ha, reg, 8, MSW(risc_address));
		WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);

		for (timer = 6000000; timer; timer--) {
			/* Check for pending interrupts. */
 			stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
			if (stat & HSR_RISC_INT) {
				stat &= 0xff;

				if (stat == 0x1 || stat == 0x2) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					/* Release mailbox registers. */
					WRT_REG_WORD(&reg->semaphore, 0);
					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				} else if (stat == 0x10 || stat == 0x11) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				}

				/* clear this intr; it wasn't a mailbox intr */
				WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
				RD_REG_WORD(&reg->hccr);
			}
			udelay(5);
		}

		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
			rval = mb0 & MBS_MASK;
317
			fw->stack_ram[cnt] = htons(mb2);
L
Linus Torvalds 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
		} else {
			rval = QLA_FUNCTION_FAILED;
		}
	}

	if (rval == QLA_SUCCESS) {
		/* Get data SRAM. */
		risc_address = 0x11000;
		data_ram_cnt = ha->fw_memory_size - risc_address + 1;
 		WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_EXTENDED);
		clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
	}
	for (cnt = 0; cnt < data_ram_cnt && rval == QLA_SUCCESS;
	    cnt++, risc_address++) {
 		WRT_MAILBOX_REG(ha, reg, 1, LSW(risc_address));
 		WRT_MAILBOX_REG(ha, reg, 8, MSW(risc_address));
		WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);

		for (timer = 6000000; timer; timer--) {
			/* Check for pending interrupts. */
 			stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
			if (stat & HSR_RISC_INT) {
				stat &= 0xff;

				if (stat == 0x1 || stat == 0x2) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					/* Release mailbox registers. */
					WRT_REG_WORD(&reg->semaphore, 0);
					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				} else if (stat == 0x10 || stat == 0x11) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				}

				/* clear this intr; it wasn't a mailbox intr */
				WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
				RD_REG_WORD(&reg->hccr);
			}
			udelay(5);
		}

		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
			rval = mb0 & MBS_MASK;
377
			fw->data_ram[cnt] = htons(mb2);
L
Linus Torvalds 已提交
378 379 380 381 382
		} else {
			rval = QLA_FUNCTION_FAILED;
		}
	}

383 384 385
	if (rval == QLA_SUCCESS)
		qla2xxx_copy_queues(ha, &fw->data_ram[cnt]);

L
Linus Torvalds 已提交
386 387 388
	if (rval != QLA_SUCCESS) {
		qla_printk(KERN_WARNING, ha,
		    "Failed to dump firmware (%x)!!!\n", rval);
389
		ha->fw_dumped = 0;
L
Linus Torvalds 已提交
390 391 392 393 394

	} else {
		qla_printk(KERN_INFO, ha,
		    "Firmware dump saved to temp buffer (%ld/%p).\n",
		    ha->host_no, ha->fw_dump);
395
		ha->fw_dumped = 1;
L
Linus Torvalds 已提交
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
	}

qla2300_fw_dump_failed:
	if (!hardware_locked)
		spin_unlock_irqrestore(&ha->hardware_lock, flags);
}

/**
 * qla2100_fw_dump() - Dumps binary data from the 2100/2200 firmware.
 * @ha: HA context
 * @hardware_locked: Called with the hardware_lock
 */
void
qla2100_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
{
	int		rval;
	uint32_t	cnt, timer;
	uint16_t	risc_address;
	uint16_t	mb0, mb2;
415
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
L
Linus Torvalds 已提交
416 417 418 419 420 421 422 423 424 425 426
	uint16_t __iomem *dmp_reg;
	unsigned long	flags;
	struct qla2100_fw_dump	*fw;

	risc_address = 0;
	mb0 = mb2 = 0;
	flags = 0;

	if (!hardware_locked)
		spin_lock_irqsave(&ha->hardware_lock, flags);

427
	if (!ha->fw_dump) {
L
Linus Torvalds 已提交
428
		qla_printk(KERN_WARNING, ha,
429
		    "No buffer available for dump!!!\n");
L
Linus Torvalds 已提交
430 431 432
		goto qla2100_fw_dump_failed;
	}

433
	if (ha->fw_dumped) {
L
Linus Torvalds 已提交
434
		qla_printk(KERN_WARNING, ha,
435 436
		    "Firmware has been previously dumped (%p) -- ignoring "
		    "request...\n", ha->fw_dump);
L
Linus Torvalds 已提交
437 438
		goto qla2100_fw_dump_failed;
	}
439 440
	fw = &ha->fw_dump->isp.isp21;
	qla2xxx_prep_dump(ha, ha->fw_dump);
L
Linus Torvalds 已提交
441 442

	rval = QLA_SUCCESS;
443
	fw->hccr = htons(RD_REG_WORD(&reg->hccr));
L
Linus Torvalds 已提交
444 445

	/* Pause RISC. */
A
Andrew Vasquez 已提交
446
	WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
L
Linus Torvalds 已提交
447 448 449 450 451 452 453 454 455
	for (cnt = 30000; (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
	    rval == QLA_SUCCESS; cnt--) {
		if (cnt)
			udelay(100);
		else
			rval = QLA_FUNCTION_TIMEOUT;
	}
	if (rval == QLA_SUCCESS) {
		dmp_reg = (uint16_t __iomem *)(reg + 0);
A
Andrew Vasquez 已提交
456
		for (cnt = 0; cnt < sizeof(fw->pbiu_reg) / 2; cnt++)
457
			fw->pbiu_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
458 459 460 461

		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x10);
		for (cnt = 0; cnt < ha->mbx_count; cnt++) {
			if (cnt == 8) {
462 463
				dmp_reg = (uint16_t __iomem *)
					((uint8_t __iomem *)reg + 0xe0);
L
Linus Torvalds 已提交
464
			}
465
			fw->mailbox_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
466 467 468
		}

		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x20);
A
Andrew Vasquez 已提交
469
		for (cnt = 0; cnt < sizeof(fw->dma_reg) / 2; cnt++)
470
			fw->dma_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
471 472 473

		WRT_REG_WORD(&reg->ctrl_status, 0x00);
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0xA0);
A
Andrew Vasquez 已提交
474
		for (cnt = 0; cnt < sizeof(fw->risc_hdw_reg) / 2; cnt++)
475
			fw->risc_hdw_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
476

A
Andrew Vasquez 已提交
477
		WRT_REG_WORD(&reg->pcr, 0x2000);
L
Linus Torvalds 已提交
478
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
479
		for (cnt = 0; cnt < sizeof(fw->risc_gp0_reg) / 2; cnt++)
480
			fw->risc_gp0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
481

A
Andrew Vasquez 已提交
482
		WRT_REG_WORD(&reg->pcr, 0x2100);
L
Linus Torvalds 已提交
483
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
484
		for (cnt = 0; cnt < sizeof(fw->risc_gp1_reg) / 2; cnt++)
485
			fw->risc_gp1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
486

A
Andrew Vasquez 已提交
487
		WRT_REG_WORD(&reg->pcr, 0x2200);
L
Linus Torvalds 已提交
488
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
489
		for (cnt = 0; cnt < sizeof(fw->risc_gp2_reg) / 2; cnt++)
490
			fw->risc_gp2_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
491

A
Andrew Vasquez 已提交
492
		WRT_REG_WORD(&reg->pcr, 0x2300);
L
Linus Torvalds 已提交
493
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
494
		for (cnt = 0; cnt < sizeof(fw->risc_gp3_reg) / 2; cnt++)
495
			fw->risc_gp3_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
496

A
Andrew Vasquez 已提交
497
		WRT_REG_WORD(&reg->pcr, 0x2400);
L
Linus Torvalds 已提交
498
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
499
		for (cnt = 0; cnt < sizeof(fw->risc_gp4_reg) / 2; cnt++)
500
			fw->risc_gp4_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
501

A
Andrew Vasquez 已提交
502
		WRT_REG_WORD(&reg->pcr, 0x2500);
L
Linus Torvalds 已提交
503
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
504
		for (cnt = 0; cnt < sizeof(fw->risc_gp5_reg) / 2; cnt++)
505
			fw->risc_gp5_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
506

A
Andrew Vasquez 已提交
507
		WRT_REG_WORD(&reg->pcr, 0x2600);
L
Linus Torvalds 已提交
508
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
509
		for (cnt = 0; cnt < sizeof(fw->risc_gp6_reg) / 2; cnt++)
510
			fw->risc_gp6_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
511

A
Andrew Vasquez 已提交
512
		WRT_REG_WORD(&reg->pcr, 0x2700);
L
Linus Torvalds 已提交
513
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
514
		for (cnt = 0; cnt < sizeof(fw->risc_gp7_reg) / 2; cnt++)
515
			fw->risc_gp7_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
516

A
Andrew Vasquez 已提交
517
		WRT_REG_WORD(&reg->ctrl_status, 0x10);
L
Linus Torvalds 已提交
518
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
519
		for (cnt = 0; cnt < sizeof(fw->frame_buf_hdw_reg) / 2; cnt++)
520 521
			fw->frame_buf_hdw_reg[cnt] =
			    htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
522

A
Andrew Vasquez 已提交
523
		WRT_REG_WORD(&reg->ctrl_status, 0x20);
L
Linus Torvalds 已提交
524
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
525
		for (cnt = 0; cnt < sizeof(fw->fpm_b0_reg) / 2; cnt++)
526
			fw->fpm_b0_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
527

A
Andrew Vasquez 已提交
528
		WRT_REG_WORD(&reg->ctrl_status, 0x30);
L
Linus Torvalds 已提交
529
		dmp_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
A
Andrew Vasquez 已提交
530
		for (cnt = 0; cnt < sizeof(fw->fpm_b1_reg) / 2; cnt++)
531
			fw->fpm_b1_reg[cnt] = htons(RD_REG_WORD(dmp_reg++));
L
Linus Torvalds 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548

		/* Reset the ISP. */
		WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
	}

	for (cnt = 30000; RD_MAILBOX_REG(ha, reg, 0) != 0 &&
	    rval == QLA_SUCCESS; cnt--) {
		if (cnt)
			udelay(100);
		else
			rval = QLA_FUNCTION_TIMEOUT;
	}

	/* Pause RISC. */
	if (rval == QLA_SUCCESS && (IS_QLA2200(ha) || (IS_QLA2100(ha) &&
	    (RD_REG_WORD(&reg->mctr) & (BIT_1 | BIT_0)) != 0))) {

A
Andrew Vasquez 已提交
549
		WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
L
Linus Torvalds 已提交
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
		for (cnt = 30000;
		    (RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0 &&
		    rval == QLA_SUCCESS; cnt--) {
			if (cnt)
				udelay(100);
			else
				rval = QLA_FUNCTION_TIMEOUT;
		}
		if (rval == QLA_SUCCESS) {
			/* Set memory configuration and timing. */
			if (IS_QLA2100(ha))
				WRT_REG_WORD(&reg->mctr, 0xf1);
			else
				WRT_REG_WORD(&reg->mctr, 0xf2);
			RD_REG_WORD(&reg->mctr);	/* PCI Posting. */

			/* Release RISC. */
			WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
		}
	}

	if (rval == QLA_SUCCESS) {
		/* Get RISC SRAM. */
		risc_address = 0x1000;
 		WRT_MAILBOX_REG(ha, reg, 0, MBC_READ_RAM_WORD);
		clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
	}
	for (cnt = 0; cnt < sizeof(fw->risc_ram) / 2 && rval == QLA_SUCCESS;
	    cnt++, risc_address++) {
 		WRT_MAILBOX_REG(ha, reg, 1, risc_address);
		WRT_REG_WORD(&reg->hccr, HCCR_SET_HOST_INT);

		for (timer = 6000000; timer != 0; timer--) {
			/* Check for pending interrupts. */
			if (RD_REG_WORD(&reg->istatus) & ISR_RISC_INT) {
				if (RD_REG_WORD(&reg->semaphore) & BIT_0) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb0 = RD_MAILBOX_REG(ha, reg, 0);
					mb2 = RD_MAILBOX_REG(ha, reg, 2);

					WRT_REG_WORD(&reg->semaphore, 0);
					WRT_REG_WORD(&reg->hccr,
					    HCCR_CLR_RISC_INT);
					RD_REG_WORD(&reg->hccr);
					break;
				}
				WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
				RD_REG_WORD(&reg->hccr);
			}
			udelay(5);
		}

		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
			rval = mb0 & MBS_MASK;
606
			fw->risc_ram[cnt] = htons(mb2);
L
Linus Torvalds 已提交
607 608 609 610 611
		} else {
			rval = QLA_FUNCTION_FAILED;
		}
	}

612 613 614
	if (rval == QLA_SUCCESS)
		qla2xxx_copy_queues(ha, &fw->risc_ram[cnt]);

L
Linus Torvalds 已提交
615 616 617
	if (rval != QLA_SUCCESS) {
		qla_printk(KERN_WARNING, ha,
		    "Failed to dump firmware (%x)!!!\n", rval);
618
		ha->fw_dumped = 0;
L
Linus Torvalds 已提交
619 620 621 622 623

	} else {
		qla_printk(KERN_INFO, ha,
		    "Firmware dump saved to temp buffer (%ld/%p).\n",
		    ha->host_no, ha->fw_dump);
624
		ha->fw_dumped = 1;
L
Linus Torvalds 已提交
625 626 627 628 629 630 631
	}

qla2100_fw_dump_failed:
	if (!hardware_locked)
		spin_unlock_irqrestore(&ha->hardware_lock, flags);
}

632 633 634 635 636 637
void
qla24xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
{
	int		rval;
	uint32_t	cnt, timer;
	uint32_t	risc_address;
638
	uint16_t	mb[4], wd;
639 640 641 642 643 644 645 646 647

	uint32_t	stat;
	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
	uint32_t __iomem *dmp_reg;
	uint32_t	*iter_reg;
	uint16_t __iomem *mbx_reg;
	unsigned long	flags;
	struct qla24xx_fw_dump *fw;
	uint32_t	ext_mem_cnt;
648
	void		*eft;
649 650 651 652 653 654 655 656

	risc_address = ext_mem_cnt = 0;
	memset(mb, 0, sizeof(mb));
	flags = 0;

	if (!hardware_locked)
		spin_lock_irqsave(&ha->hardware_lock, flags);

657
	if (!ha->fw_dump) {
658 659 660 661 662 663 664 665
		qla_printk(KERN_WARNING, ha,
		    "No buffer available for dump!!!\n");
		goto qla24xx_fw_dump_failed;
	}

	if (ha->fw_dumped) {
		qla_printk(KERN_WARNING, ha,
		    "Firmware has been previously dumped (%p) -- ignoring "
666
		    "request...\n", ha->fw_dump);
667 668
		goto qla24xx_fw_dump_failed;
	}
669 670
	fw = &ha->fw_dump->isp.isp24;
	qla2xxx_prep_dump(ha, ha->fw_dump);
671 672

	rval = QLA_SUCCESS;
673
	fw->host_status = htonl(RD_REG_DWORD(&reg->host_status));
674 675

	/* Pause RISC. */
676
	if ((RD_REG_DWORD(&reg->hccr) & HCCRX_RISC_PAUSE) == 0) {
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
		WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET |
		    HCCRX_CLR_HOST_INT);
		RD_REG_DWORD(&reg->hccr);		/* PCI Posting. */
		WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
		for (cnt = 30000;
		    (RD_REG_DWORD(&reg->hccr) & HCCRX_RISC_PAUSE) == 0 &&
		    rval == QLA_SUCCESS; cnt--) {
			if (cnt)
				udelay(100);
			else
				rval = QLA_FUNCTION_TIMEOUT;
		}
	}

	if (rval == QLA_SUCCESS) {
		/* Host interface registers. */
		dmp_reg = (uint32_t __iomem *)(reg + 0);
		for (cnt = 0; cnt < sizeof(fw->host_reg) / 4; cnt++)
695
			fw->host_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
696

697 698 699 700 701 702 703 704 705 706
		/* Disable interrupts. */
		WRT_REG_DWORD(&reg->ictrl, 0);
		RD_REG_DWORD(&reg->ictrl);

		/* Shadow registers. */
		WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
		RD_REG_DWORD(&reg->iobase_addr);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0000000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
707
		fw->shadow_reg[0] = htonl(RD_REG_DWORD(dmp_reg));
708 709 710 711

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0100000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
712
		fw->shadow_reg[1] = htonl(RD_REG_DWORD(dmp_reg));
713 714 715 716

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0200000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
717
		fw->shadow_reg[2] = htonl(RD_REG_DWORD(dmp_reg));
718 719 720 721

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0300000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
722
		fw->shadow_reg[3] = htonl(RD_REG_DWORD(dmp_reg));
723 724 725 726

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0400000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
727
		fw->shadow_reg[4] = htonl(RD_REG_DWORD(dmp_reg));
728 729 730 731

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0500000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
732
		fw->shadow_reg[5] = htonl(RD_REG_DWORD(dmp_reg));
733 734 735 736

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xF0);
		WRT_REG_DWORD(dmp_reg, 0xB0600000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xFC);
737
		fw->shadow_reg[6] = htonl(RD_REG_DWORD(dmp_reg));
738

739 740 741
		/* Mailbox registers. */
		mbx_reg = (uint16_t __iomem *)((uint8_t __iomem *)reg + 0x80);
		for (cnt = 0; cnt < sizeof(fw->mailbox_reg) / 2; cnt++)
742
			fw->mailbox_reg[cnt] = htons(RD_REG_WORD(mbx_reg++));
743 744 745 746 747 748

		/* Transfer sequence registers. */
		iter_reg = fw->xseq_gp_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0xBF00);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
749
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
750 751 752 753

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF10);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
754
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
755 756 757 758

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF20);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
759
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
760 761 762 763

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF30);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
764
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
765 766 767 768

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF40);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
769
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
770 771 772 773

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF50);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
774
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
775 776 777 778

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF60);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
779
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
780 781 782 783

		WRT_REG_DWORD(&reg->iobase_addr, 0xBF70);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
784
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
785 786 787 788

		WRT_REG_DWORD(&reg->iobase_addr, 0xBFE0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->xseq_0_reg) / 4; cnt++)
789
			fw->xseq_0_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
790 791 792 793

		WRT_REG_DWORD(&reg->iobase_addr, 0xBFF0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->xseq_1_reg) / 4; cnt++)
794
			fw->xseq_1_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
795 796 797 798 799 800

		/* Receive sequence registers. */
		iter_reg = fw->rseq_gp_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0xFF00);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
801
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
802 803 804 805

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF10);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
806
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
807 808 809 810

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF20);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
811
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
812 813 814 815

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF30);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
816
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
817 818 819 820

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF40);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
821
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
822 823 824 825

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF50);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
826
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
827 828 829 830

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF60);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
831
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
832 833 834 835

		WRT_REG_DWORD(&reg->iobase_addr, 0xFF70);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
836
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
837 838 839 840

		WRT_REG_DWORD(&reg->iobase_addr, 0xFFD0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->rseq_0_reg) / 4; cnt++)
841
			fw->rseq_0_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
842 843 844 845

		WRT_REG_DWORD(&reg->iobase_addr, 0xFFE0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->rseq_1_reg) / 4; cnt++)
846
			fw->rseq_1_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
847 848 849 850

		WRT_REG_DWORD(&reg->iobase_addr, 0xFFF0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->rseq_2_reg) / 4; cnt++)
851
			fw->rseq_2_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
852 853 854 855 856

		/* Command DMA registers. */
		WRT_REG_DWORD(&reg->iobase_addr, 0x7100);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->cmd_dma_reg) / 4; cnt++)
857
			fw->cmd_dma_reg[cnt] = htonl(RD_REG_DWORD(dmp_reg++));
858 859 860 861 862 863

		/* Queues. */
		iter_reg = fw->req0_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7200);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 8; cnt++)
864
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
865 866 867

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4);
		for (cnt = 0; cnt < 7; cnt++)
868
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
869 870 871 872 873

		iter_reg = fw->resp0_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7300);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 8; cnt++)
874
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
875 876 877

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4);
		for (cnt = 0; cnt < 7; cnt++)
878
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
879 880 881 882 883

		iter_reg = fw->req1_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7400);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 8; cnt++)
884
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
885 886 887

		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xE4);
		for (cnt = 0; cnt < 7; cnt++)
888
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
889 890 891 892 893 894

		/* Transmit DMA registers. */
		iter_reg = fw->xmt0_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7600);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
895
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
896 897 898 899

		WRT_REG_DWORD(&reg->iobase_addr, 0x7610);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
900
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
901 902 903 904 905

		iter_reg = fw->xmt1_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7620);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
906
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
907 908 909 910

		WRT_REG_DWORD(&reg->iobase_addr, 0x7630);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
911
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
912 913 914 915 916

		iter_reg = fw->xmt2_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7640);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
917
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
918 919 920 921

		WRT_REG_DWORD(&reg->iobase_addr, 0x7650);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
922
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
923 924 925 926 927

		iter_reg = fw->xmt3_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7660);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
928
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
929 930 931 932

		WRT_REG_DWORD(&reg->iobase_addr, 0x7670);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
933
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
934 935 936 937 938

		iter_reg = fw->xmt4_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7680);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
939
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
940 941 942 943

		WRT_REG_DWORD(&reg->iobase_addr, 0x7690);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
944
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
945 946 947 948

		WRT_REG_DWORD(&reg->iobase_addr, 0x76A0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < sizeof(fw->xmt_data_dma_reg) / 4; cnt++)
949 950
			fw->xmt_data_dma_reg[cnt] =
			    htonl(RD_REG_DWORD(dmp_reg++));
951 952 953 954 955 956

		/* Receive DMA registers. */
		iter_reg = fw->rcvt0_data_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7700);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
957
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
958 959 960 961

		WRT_REG_DWORD(&reg->iobase_addr, 0x7710);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
962
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
963 964 965 966 967

		iter_reg = fw->rcvt1_data_dma_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x7720);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
968
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
969 970 971 972

		WRT_REG_DWORD(&reg->iobase_addr, 0x7730);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
973
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
974 975 976 977 978 979

		/* RISC registers. */
		iter_reg = fw->risc_gp_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x0F00);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
980
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
981 982 983 984

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F10);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
985
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
986 987 988 989

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F20);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
990
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
991 992 993 994

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F30);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
995
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
996 997 998 999

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F40);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1000
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1001 1002 1003 1004

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F50);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1005
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1006 1007 1008 1009

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F60);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1010
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1011 1012 1013 1014

		WRT_REG_DWORD(&reg->iobase_addr, 0x0F70);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1015
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1016 1017 1018 1019 1020 1021

		/* Local memory controller registers. */
		iter_reg = fw->lmc_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x3000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1022
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1023 1024 1025 1026

		WRT_REG_DWORD(&reg->iobase_addr, 0x3010);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1027
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1028 1029 1030 1031

		WRT_REG_DWORD(&reg->iobase_addr, 0x3020);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1032
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1033 1034 1035 1036

		WRT_REG_DWORD(&reg->iobase_addr, 0x3030);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1037
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1038 1039 1040 1041

		WRT_REG_DWORD(&reg->iobase_addr, 0x3040);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1042
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1043 1044 1045 1046

		WRT_REG_DWORD(&reg->iobase_addr, 0x3050);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1047
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1048 1049 1050 1051

		WRT_REG_DWORD(&reg->iobase_addr, 0x3060);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1052
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1053 1054 1055 1056 1057 1058

		/* Fibre Protocol Module registers. */
		iter_reg = fw->fpm_hdw_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x4000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1059
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1060 1061 1062 1063

		WRT_REG_DWORD(&reg->iobase_addr, 0x4010);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1064
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1065 1066 1067 1068

		WRT_REG_DWORD(&reg->iobase_addr, 0x4020);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1069
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1070 1071 1072 1073

		WRT_REG_DWORD(&reg->iobase_addr, 0x4030);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1074
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1075 1076 1077 1078

		WRT_REG_DWORD(&reg->iobase_addr, 0x4040);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1079
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1080 1081 1082 1083

		WRT_REG_DWORD(&reg->iobase_addr, 0x4050);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1084
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1085 1086 1087 1088

		WRT_REG_DWORD(&reg->iobase_addr, 0x4060);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1089
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1090 1091 1092 1093

		WRT_REG_DWORD(&reg->iobase_addr, 0x4070);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1094
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1095 1096 1097 1098

		WRT_REG_DWORD(&reg->iobase_addr, 0x4080);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1099
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1100 1101 1102 1103

		WRT_REG_DWORD(&reg->iobase_addr, 0x4090);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1104
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1105 1106 1107 1108

		WRT_REG_DWORD(&reg->iobase_addr, 0x40A0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1109
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1110 1111 1112 1113

		WRT_REG_DWORD(&reg->iobase_addr, 0x40B0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1114
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1115 1116 1117 1118 1119 1120

		/* Frame Buffer registers. */
		iter_reg = fw->fb_hdw_reg;
		WRT_REG_DWORD(&reg->iobase_addr, 0x6000);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1121
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1122 1123 1124 1125

		WRT_REG_DWORD(&reg->iobase_addr, 0x6010);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1126
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1127 1128 1129 1130

		WRT_REG_DWORD(&reg->iobase_addr, 0x6020);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1131
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1132 1133 1134 1135

		WRT_REG_DWORD(&reg->iobase_addr, 0x6030);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1136
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1137 1138 1139 1140

		WRT_REG_DWORD(&reg->iobase_addr, 0x6040);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1141
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1142 1143 1144 1145

		WRT_REG_DWORD(&reg->iobase_addr, 0x6100);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1146
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1147 1148 1149 1150

		WRT_REG_DWORD(&reg->iobase_addr, 0x6130);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1151
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1152 1153 1154 1155

		WRT_REG_DWORD(&reg->iobase_addr, 0x6150);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1156
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1157 1158 1159 1160

		WRT_REG_DWORD(&reg->iobase_addr, 0x6170);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1161
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1162 1163 1164 1165

		WRT_REG_DWORD(&reg->iobase_addr, 0x6190);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1166
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1167 1168 1169 1170

		WRT_REG_DWORD(&reg->iobase_addr, 0x61B0);
		dmp_reg = (uint32_t __iomem *)((uint8_t __iomem *)reg + 0xC0);
		for (cnt = 0; cnt < 16; cnt++)
1171
			*iter_reg++ = htonl(RD_REG_DWORD(dmp_reg++));
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

		/* Reset RISC. */
		WRT_REG_DWORD(&reg->ctrl_status,
		    CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
		for (cnt = 0; cnt < 30000; cnt++) {
			if ((RD_REG_DWORD(&reg->ctrl_status) &
			    CSRX_DMA_ACTIVE) == 0)
				break;

			udelay(10);
		}

		WRT_REG_DWORD(&reg->ctrl_status,
		    CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1186
		pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1187

1188
		udelay(100);
1189 1190 1191 1192 1193 1194 1195 1196
		/* Wait for firmware to complete NVRAM accesses. */
		mb[0] = (uint32_t) RD_REG_WORD(&reg->mailbox0);
		for (cnt = 10000 ; cnt && mb[0]; cnt--) {
			udelay(5);
			mb[0] = (uint32_t) RD_REG_WORD(&reg->mailbox0);
			barrier();
		}

1197
		/* Wait for soft-reset to complete. */
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
		for (cnt = 0; cnt < 30000; cnt++) {
			if ((RD_REG_DWORD(&reg->ctrl_status) &
			    CSRX_ISP_SOFT_RESET) == 0)
				break;

			udelay(10);
		}
		WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
		RD_REG_DWORD(&reg->hccr);             /* PCI Posting. */
	}

	for (cnt = 30000; RD_REG_WORD(&reg->mailbox0) != 0 &&
	    rval == QLA_SUCCESS; cnt--) {
		if (cnt)
			udelay(100);
		else
			rval = QLA_FUNCTION_TIMEOUT;
	}

	/* Memory. */
	if (rval == QLA_SUCCESS) {
		/* Code RAM. */
		risc_address = 0x20000;
		WRT_REG_WORD(&reg->mailbox0, MBC_READ_RAM_EXTENDED);
		clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
	}
	for (cnt = 0; cnt < sizeof(fw->code_ram) / 4 && rval == QLA_SUCCESS;
	    cnt++, risc_address++) {
		WRT_REG_WORD(&reg->mailbox1, LSW(risc_address));
		WRT_REG_WORD(&reg->mailbox8, MSW(risc_address));
		RD_REG_WORD(&reg->mailbox8);
		WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);

		for (timer = 6000000; timer; timer--) {
			/* Check for pending interrupts. */
			stat = RD_REG_DWORD(&reg->host_status);
			if (stat & HSRX_RISC_INT) {
				stat &= 0xff;

				if (stat == 0x1 || stat == 0x2 ||
				    stat == 0x10 || stat == 0x11) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb[0] = RD_REG_WORD(&reg->mailbox0);
					mb[2] = RD_REG_WORD(&reg->mailbox2);
					mb[3] = RD_REG_WORD(&reg->mailbox3);

					WRT_REG_DWORD(&reg->hccr,
					    HCCRX_CLR_RISC_INT);
					RD_REG_DWORD(&reg->hccr);
					break;
				}

				/* Clear this intr; it wasn't a mailbox intr */
				WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
				RD_REG_DWORD(&reg->hccr);
			}
			udelay(5);
		}

		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
			rval = mb[0] & MBS_MASK;
1261
			fw->code_ram[cnt] = htonl((mb[3] << 16) | mb[2]);
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
		} else {
			rval = QLA_FUNCTION_FAILED;
		}
	}

	if (rval == QLA_SUCCESS) {
		/* External Memory. */
		risc_address = 0x100000;
		ext_mem_cnt = ha->fw_memory_size - 0x100000 + 1;
		WRT_REG_WORD(&reg->mailbox0, MBC_READ_RAM_EXTENDED);
		clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
	}
	for (cnt = 0; cnt < ext_mem_cnt && rval == QLA_SUCCESS;
	    cnt++, risc_address++) {
		WRT_REG_WORD(&reg->mailbox1, LSW(risc_address));
		WRT_REG_WORD(&reg->mailbox8, MSW(risc_address));
		RD_REG_WORD(&reg->mailbox8);
		WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);

		for (timer = 6000000; timer; timer--) {
			/* Check for pending interrupts. */
			stat = RD_REG_DWORD(&reg->host_status);
			if (stat & HSRX_RISC_INT) {
				stat &= 0xff;

				if (stat == 0x1 || stat == 0x2 ||
				    stat == 0x10 || stat == 0x11) {
					set_bit(MBX_INTERRUPT,
					    &ha->mbx_cmd_flags);

					mb[0] = RD_REG_WORD(&reg->mailbox0);
					mb[2] = RD_REG_WORD(&reg->mailbox2);
					mb[3] = RD_REG_WORD(&reg->mailbox3);

					WRT_REG_DWORD(&reg->hccr,
					    HCCRX_CLR_RISC_INT);
					RD_REG_DWORD(&reg->hccr);
					break;
				}

				/* Clear this intr; it wasn't a mailbox intr */
				WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
				RD_REG_DWORD(&reg->hccr);
			}
			udelay(5);
		}

		if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags)) {
			rval = mb[0] & MBS_MASK;
1311
			fw->ext_mem[cnt] = htonl((mb[3] << 16) | mb[2]);
1312 1313 1314 1315 1316
		} else {
			rval = QLA_FUNCTION_FAILED;
		}
	}

1317 1318 1319 1320 1321 1322
	if (rval == QLA_SUCCESS) {
		eft = qla2xxx_copy_queues(ha, &fw->ext_mem[cnt]);
		if (ha->eft)
			memcpy(eft, ha->eft, ntohl(ha->fw_dump->eft_size));
	}

1323 1324 1325 1326 1327 1328 1329 1330
	if (rval != QLA_SUCCESS) {
		qla_printk(KERN_WARNING, ha,
		    "Failed to dump firmware (%x)!!!\n", rval);
		ha->fw_dumped = 0;

	} else {
		qla_printk(KERN_INFO, ha,
		    "Firmware dump saved to temp buffer (%ld/%p).\n",
1331
		    ha->host_no, ha->fw_dump);
1332 1333 1334 1335 1336 1337 1338 1339
		ha->fw_dumped = 1;
	}

qla24xx_fw_dump_failed:
	if (!hardware_locked)
		spin_unlock_irqrestore(&ha->hardware_lock, flags);
}

L
Linus Torvalds 已提交
1340 1341 1342 1343
/****************************************************************************/
/*                         Driver Debug Functions.                          */
/****************************************************************************/

A
Andrew Vasquez 已提交
1344 1345
void
qla2x00_dump_regs(scsi_qla_host_t *ha)
L
Linus Torvalds 已提交
1346
{
1347
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
L
Linus Torvalds 已提交
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365

	printk("Mailbox registers:\n");
	printk("scsi(%ld): mbox 0 0x%04x \n",
	    ha->host_no, RD_MAILBOX_REG(ha, reg, 0));
	printk("scsi(%ld): mbox 1 0x%04x \n",
	    ha->host_no, RD_MAILBOX_REG(ha, reg, 1));
	printk("scsi(%ld): mbox 2 0x%04x \n",
	    ha->host_no, RD_MAILBOX_REG(ha, reg, 2));
	printk("scsi(%ld): mbox 3 0x%04x \n",
	    ha->host_no, RD_MAILBOX_REG(ha, reg, 3));
	printk("scsi(%ld): mbox 4 0x%04x \n",
	    ha->host_no, RD_MAILBOX_REG(ha, reg, 4));
	printk("scsi(%ld): mbox 5 0x%04x \n",
	    ha->host_no, RD_MAILBOX_REG(ha, reg, 5));
}


void
A
Andrew Vasquez 已提交
1366
qla2x00_dump_buffer(uint8_t * b, uint32_t size)
L
Linus Torvalds 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
{
	uint32_t cnt;
	uint8_t c;

	printk(" 0   1   2   3   4   5   6   7   8   9  "
	    "Ah  Bh  Ch  Dh  Eh  Fh\n");
	printk("----------------------------------------"
	    "----------------------\n");

	for (cnt = 0; cnt < size;) {
		c = *b++;
		printk("%02x",(uint32_t) c);
		cnt++;
		if (!(cnt % 16))
			printk("\n");
		else
			printk("  ");
	}
	if (cnt % 16)
		printk("\n");
}

/**************************************************************************
 *   qla2x00_print_scsi_cmd
 *	 Dumps out info about the scsi cmd and srb.
A
Andrew Vasquez 已提交
1392
 *   Input
L
Linus Torvalds 已提交
1393 1394 1395
 *	 cmd : struct scsi_cmnd
 **************************************************************************/
void
A
Andrew Vasquez 已提交
1396
qla2x00_print_scsi_cmd(struct scsi_cmnd * cmd)
L
Linus Torvalds 已提交
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
{
	int i;
	struct scsi_qla_host *ha;
	srb_t *sp;

	ha = (struct scsi_qla_host *)cmd->device->host->hostdata;

	sp = (srb_t *) cmd->SCp.ptr;
	printk("SCSI Command @=0x%p, Handle=0x%p\n", cmd, cmd->host_scribble);
	printk("  chan=0x%02x, target=0x%02x, lun=0x%02x, cmd_len=0x%02x\n",
	    cmd->device->channel, cmd->device->id, cmd->device->lun,
	    cmd->cmd_len);
	printk(" CDB: ");
	for (i = 0; i < cmd->cmd_len; i++) {
		printk("0x%02x ", cmd->cmnd[i]);
	}
1413
	printk("\n  seg_cnt=%d, allowed=%d, retries=%d\n",
1414
	       scsi_sg_count(cmd), cmd->allowed, cmd->retries);
L
Linus Torvalds 已提交
1415
	printk("  request buffer=0x%p, request buffer len=0x%x\n",
1416
	       scsi_sglist(cmd), scsi_bufflen(cmd));
L
Linus Torvalds 已提交
1417 1418
	printk("  tag=%d, transfersize=0x%x\n",
	    cmd->tag, cmd->transfersize);
A
Andrew Vasquez 已提交
1419
	printk("  serial_number=%lx, SP=%p\n", cmd->serial_number, sp);
L
Linus Torvalds 已提交
1420 1421 1422 1423 1424 1425 1426 1427
	printk("  data direction=%d\n", cmd->sc_data_direction);

	if (!sp)
		return;

	printk("  sp flags=0x%x\n", sp->flags);
}

1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442
void
qla2x00_dump_pkt(void *pkt)
{
	uint32_t i;
	uint8_t *data = (uint8_t *) pkt;

	for (i = 0; i < 64; i++) {
		if (!(i % 4))
			printk("\n%02x: ", i);

		printk("%02x ", data[i]);
	}
	printk("\n");
}

L
Linus Torvalds 已提交
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
#if defined(QL_DEBUG_ROUTINES)
/*
 * qla2x00_formatted_dump_buffer
 *       Prints string plus buffer.
 *
 * Input:
 *       string  = Null terminated string (no newline at end).
 *       buffer  = buffer address.
 *       wd_size = word size 8, 16, 32 or 64 bits
 *       count   = number of words.
 */
void
A
Andrew Vasquez 已提交
1455 1456
qla2x00_formatted_dump_buffer(char *string, uint8_t * buffer,
				uint8_t wd_size, uint32_t count)
L
Linus Torvalds 已提交
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
{
	uint32_t cnt;
	uint16_t *buf16;
	uint32_t *buf32;

	if (strcmp(string, "") != 0)
		printk("%s\n",string);

	switch (wd_size) {
		case 8:
			printk(" 0    1    2    3    4    5    6    7    "
				"8    9    Ah   Bh   Ch   Dh   Eh   Fh\n");
			printk("-----------------------------------------"
				"-------------------------------------\n");

			for (cnt = 1; cnt <= count; cnt++, buffer++) {
				printk("%02x",*buffer);
				if (cnt % 16 == 0)
					printk("\n");
				else
					printk("  ");
			}
			if (cnt % 16 != 0)
				printk("\n");
			break;
		case 16:
			printk("   0      2      4      6      8      Ah "
				"	Ch     Eh\n");
			printk("-----------------------------------------"
				"-------------\n");

			buf16 = (uint16_t *) buffer;
			for (cnt = 1; cnt <= count; cnt++, buf16++) {
				printk("%4x",*buf16);

				if (cnt % 8 == 0)
					printk("\n");
				else if (*buf16 < 10)
					printk("   ");
				else
					printk("  ");
			}
			if (cnt % 8 != 0)
				printk("\n");
			break;
		case 32:
			printk("       0          4          8          Ch\n");
			printk("------------------------------------------\n");

			buf32 = (uint32_t *) buffer;
			for (cnt = 1; cnt <= count; cnt++, buf32++) {
				printk("%8x", *buf32);

				if (cnt % 4 == 0)
					printk("\n");
				else if (*buf32 < 10)
					printk("   ");
				else
					printk("  ");
			}
			if (cnt % 4 != 0)
				printk("\n");
			break;
		default:
			break;
	}
}
#endif