2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/delay.h>
22 #include <linux/vmalloc.h>
23 #include <linux/firmware.h>
24 #include <scsi/scsi_transport_fc.h>
26 #include "qla_devtbl.h"
28 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
29 #ifndef EXT_IS_LUN_BIT_SET
30 #define EXT_IS_LUN_BIT_SET(P,L) \
31 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
32 #define EXT_SET_LUN_BIT(P,L) \
33 ((P)->mask[L/8] |= (0x80 >> (L%8)))
37 * QLogic ISP2x00 Hardware Support Function Prototypes.
39 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
40 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
41 static int qla2x00_setup_chip(scsi_qla_host_t
*);
42 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
43 static int qla2x00_init_rings(scsi_qla_host_t
*);
44 static int qla2x00_fw_ready(scsi_qla_host_t
*);
45 static int qla2x00_configure_hba(scsi_qla_host_t
*);
46 static int qla2x00_configure_loop(scsi_qla_host_t
*);
47 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
48 static void qla2x00_update_fcport(scsi_qla_host_t
*, fc_port_t
*);
49 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
50 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
51 static int qla2x00_device_resync(scsi_qla_host_t
*);
52 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
55 static int qla2x00_restart_isp(scsi_qla_host_t
*);
57 /****************************************************************************/
58 /* QLogic ISP2x00 Hardware Support Functions. */
59 /****************************************************************************/
62 * qla2x00_initialize_adapter
66 * ha = adapter block pointer.
72 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
75 uint8_t restart_risc
= 0;
79 /* Clear adapter flags. */
81 ha
->flags
.reset_active
= 0;
82 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
83 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
86 ha
->flags
.management_server_logged_in
= 0;
87 ha
->marker_needed
= 0;
89 ha
->isp_abort_cnt
= 0;
90 ha
->beacon_blink_led
= 0;
92 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
93 rval
= ha
->isp_ops
.pci_config(ha
);
95 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
100 ha
->isp_ops
.reset_chip(ha
);
102 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
104 ha
->isp_ops
.nvram_config(ha
);
106 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
110 * Try to configure the loop.
115 /* If firmware needs to be loaded */
116 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
117 if ((rval
= ha
->isp_ops
.chip_diag(ha
)) == QLA_SUCCESS
) {
118 rval
= qla2x00_setup_chip(ha
);
122 if (rval
== QLA_SUCCESS
&&
123 (rval
= qla2x00_init_rings(ha
)) == QLA_SUCCESS
) {
124 check_fw_ready_again
:
126 * Wait for a successful LIP up to a maximum
127 * of (in seconds): RISC login timeout value,
128 * RISC retry count value, and port down retry
129 * value OR a minimum of 4 seconds OR If no
130 * cable, only 5 seconds.
132 rval
= qla2x00_fw_ready(ha
);
133 if (rval
== QLA_SUCCESS
) {
134 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
136 /* Issue a marker after FW becomes ready. */
137 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
140 * Wait at most MAX_TARGET RSCNs for a stable
145 clear_bit(LOOP_RESYNC_NEEDED
,
147 rval
= qla2x00_configure_loop(ha
);
149 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
156 * If loop state change while we were
157 * discoverying devices then wait for
161 if (atomic_read(&ha
->loop_state
) ==
162 LOOP_DOWN
&& retry
--) {
163 goto check_fw_ready_again
;
166 } while (!atomic_read(&ha
->loop_down_timer
) &&
169 (test_bit(LOOP_RESYNC_NEEDED
,
173 rval
= QLA_FUNCTION_FAILED
;
174 } else if (ha
->device_flags
& DFLG_NO_CABLE
)
175 /* If no cable, then all is good. */
178 } while (restart_risc
&& retry
--);
180 if (rval
== QLA_SUCCESS
) {
181 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
182 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
183 ha
->marker_needed
= 0;
185 ha
->flags
.online
= 1;
187 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
194 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
197 * Returns 0 on success.
200 qla2100_pci_config(scsi_qla_host_t
*ha
)
204 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
206 pci_set_master(ha
->pdev
);
208 if (pci_set_mwi(ha
->pdev
))
209 mwi
= PCI_COMMAND_INVALIDATE
;
210 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
212 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
213 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
214 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
216 /* Reset expansion ROM address decode enable */
217 pci_read_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, &w
);
218 w
&= ~PCI_ROM_ADDRESS_ENABLE
;
219 pci_write_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, w
);
221 /* Get PCI bus information. */
222 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
223 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
224 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
230 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
233 * Returns 0 on success.
236 qla2300_pci_config(scsi_qla_host_t
*ha
)
239 unsigned long flags
= 0;
241 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
243 pci_set_master(ha
->pdev
);
245 if (pci_set_mwi(ha
->pdev
))
246 mwi
= PCI_COMMAND_INVALIDATE
;
247 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
249 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
250 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
252 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
253 w
&= ~PCI_COMMAND_INTX_DISABLE
;
256 * If this is a 2300 card and not 2312, reset the
257 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
258 * the 2310 also reports itself as a 2300 so we need to get the
259 * fb revision level -- a 6 indicates it really is a 2300 and
262 if (IS_QLA2300(ha
)) {
263 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
266 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
267 for (cnt
= 0; cnt
< 30000; cnt
++) {
268 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
274 /* Select FPM registers. */
275 WRT_REG_WORD(®
->ctrl_status
, 0x20);
276 RD_REG_WORD(®
->ctrl_status
);
278 /* Get the fb rev level */
279 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
281 if (ha
->fb_rev
== FPM_2300
)
282 w
&= ~PCI_COMMAND_INVALIDATE
;
284 /* Deselect FPM registers. */
285 WRT_REG_WORD(®
->ctrl_status
, 0x0);
286 RD_REG_WORD(®
->ctrl_status
);
288 /* Release RISC module. */
289 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
290 for (cnt
= 0; cnt
< 30000; cnt
++) {
291 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
297 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
299 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
301 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
303 /* Reset expansion ROM address decode enable */
304 pci_read_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, &w
);
305 w
&= ~PCI_ROM_ADDRESS_ENABLE
;
306 pci_write_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, w
);
308 /* Get PCI bus information. */
309 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
310 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
311 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
317 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
320 * Returns 0 on success.
323 qla24xx_pci_config(scsi_qla_host_t
*ha
)
326 unsigned long flags
= 0;
327 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
328 int pcix_cmd_reg
, pcie_dctl_reg
;
330 pci_set_master(ha
->pdev
);
332 if (pci_set_mwi(ha
->pdev
))
333 mwi
= PCI_COMMAND_INVALIDATE
;
334 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
336 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
337 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
338 w
&= ~PCI_COMMAND_INTX_DISABLE
;
339 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
341 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
343 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
344 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
348 pcix_cmd_reg
+= PCI_X_CMD
;
349 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
350 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
352 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
355 /* PCIe -- adjust Maximum Read Request Size (2048). */
356 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
360 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
361 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
362 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
364 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
367 /* Reset expansion ROM address decode enable */
368 pci_read_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, &w
);
369 w
&= ~PCI_ROM_ADDRESS_ENABLE
;
370 pci_write_config_word(ha
->pdev
, PCI_ROM_ADDRESS
, w
);
372 /* Get PCI bus information. */
373 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
374 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
375 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
381 * qla2x00_isp_firmware() - Choose firmware image.
384 * Returns 0 on success.
387 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
391 /* Assume loading risc code */
392 rval
= QLA_FUNCTION_FAILED
;
394 if (ha
->flags
.disable_risc_code_load
) {
395 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
397 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
399 /* Verify checksum of loaded RISC code. */
400 rval
= qla2x00_verify_checksum(ha
,
401 IS_QLA24XX(ha
) || IS_QLA25XX(ha
) ? RISC_SADDRESS
:
402 *ha
->brd_info
->fw_info
[0].fwstart
);
406 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
414 * qla2x00_reset_chip() - Reset ISP chip.
417 * Returns 0 on success.
420 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
422 unsigned long flags
= 0;
423 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
425 unsigned long mbx_flags
= 0;
428 ha
->isp_ops
.disable_intrs(ha
);
430 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
432 /* Turn off master enable */
434 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
435 cmd
&= ~PCI_COMMAND_MASTER
;
436 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
438 if (!IS_QLA2100(ha
)) {
440 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
441 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
442 for (cnt
= 0; cnt
< 30000; cnt
++) {
443 if ((RD_REG_WORD(®
->hccr
) &
444 HCCR_RISC_PAUSE
) != 0)
449 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
453 /* Select FPM registers. */
454 WRT_REG_WORD(®
->ctrl_status
, 0x20);
455 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
457 /* FPM Soft Reset. */
458 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
459 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
461 /* Toggle Fpm Reset. */
462 if (!IS_QLA2200(ha
)) {
463 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
464 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
467 /* Select frame buffer registers. */
468 WRT_REG_WORD(®
->ctrl_status
, 0x10);
469 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
471 /* Reset frame buffer FIFOs. */
472 if (IS_QLA2200(ha
)) {
473 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
474 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
476 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
478 /* Read back fb_cmd until zero or 3 seconds max */
479 for (cnt
= 0; cnt
< 3000; cnt
++) {
480 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
486 /* Select RISC module registers. */
487 WRT_REG_WORD(®
->ctrl_status
, 0);
488 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
490 /* Reset RISC processor. */
491 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
492 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
494 /* Release RISC processor. */
495 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
496 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
499 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
500 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
502 /* Reset ISP chip. */
503 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
505 /* Wait for RISC to recover from reset. */
506 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
508 * It is necessary to for a delay here since the card doesn't
509 * respond to PCI reads during a reset. On some architectures
510 * this will result in an MCA.
513 for (cnt
= 30000; cnt
; cnt
--) {
514 if ((RD_REG_WORD(®
->ctrl_status
) &
515 CSR_ISP_SOFT_RESET
) == 0)
522 /* Reset RISC processor. */
523 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
525 WRT_REG_WORD(®
->semaphore
, 0);
527 /* Release RISC processor. */
528 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
529 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
531 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
532 for (cnt
= 0; cnt
< 30000; cnt
++) {
533 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
534 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
536 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
) {
537 if (!(test_bit(ABORT_ISP_ACTIVE
,
539 spin_unlock_irqrestore(
540 &ha
->mbx_reg_lock
, mbx_flags
);
544 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
545 spin_unlock_irqrestore(&ha
->mbx_reg_lock
,
553 /* Turn on master enable */
554 cmd
|= PCI_COMMAND_MASTER
;
555 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
557 /* Disable RISC pause on FPM parity error. */
558 if (!IS_QLA2100(ha
)) {
559 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
560 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
563 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
567 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
570 * Returns 0 on success.
573 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
575 unsigned long flags
= 0;
576 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
579 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
582 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
583 for (cnt
= 0; cnt
< 30000; cnt
++) {
584 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
590 WRT_REG_DWORD(®
->ctrl_status
,
591 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
592 RD_REG_DWORD(®
->ctrl_status
);
594 /* Wait for firmware to complete NVRAM accesses. */
596 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
597 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
599 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
604 d2
= RD_REG_DWORD(®
->ctrl_status
);
605 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
607 d2
= RD_REG_DWORD(®
->ctrl_status
);
611 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
612 RD_REG_DWORD(®
->hccr
);
614 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
615 RD_REG_DWORD(®
->hccr
);
617 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
618 RD_REG_DWORD(®
->hccr
);
620 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
621 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
623 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
627 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
631 * qla24xx_reset_chip() - Reset ISP24xx chip.
634 * Returns 0 on success.
637 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
639 ha
->isp_ops
.disable_intrs(ha
);
641 /* Perform RISC reset. */
642 qla24xx_reset_risc(ha
);
646 * qla2x00_chip_diag() - Test chip for proper operation.
649 * Returns 0 on success.
652 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
655 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
656 unsigned long flags
= 0;
661 /* Assume a failed state */
662 rval
= QLA_FUNCTION_FAILED
;
664 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
665 ha
->host_no
, (u_long
)®
->flash_address
));
667 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
669 /* Reset ISP chip. */
670 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
673 * We need to have a delay here since the card will not respond while
674 * in reset causing an MCA on some architectures.
677 data
= qla2x00_debounce_register(®
->ctrl_status
);
678 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
680 data
= RD_REG_WORD(®
->ctrl_status
);
685 goto chip_diag_failed
;
687 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
690 /* Reset RISC processor. */
691 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
692 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
694 /* Workaround for QLA2312 PCI parity error */
695 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
696 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
697 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
699 data
= RD_MAILBOX_REG(ha
, reg
, 0);
706 goto chip_diag_failed
;
708 /* Check product ID of chip */
709 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
711 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
712 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
713 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
714 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
715 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
716 mb
[3] != PROD_ID_3
) {
717 qla_printk(KERN_WARNING
, ha
,
718 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
720 goto chip_diag_failed
;
722 ha
->product_id
[0] = mb
[1];
723 ha
->product_id
[1] = mb
[2];
724 ha
->product_id
[2] = mb
[3];
725 ha
->product_id
[3] = mb
[4];
727 /* Adjust fw RISC transfer size */
728 if (ha
->request_q_length
> 1024)
729 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
731 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
732 ha
->request_q_length
;
734 if (IS_QLA2200(ha
) &&
735 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
736 /* Limit firmware transfer size with a 2200A */
737 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
740 ha
->fw_transfer_size
= 128;
743 /* Wrap Incoming Mailboxes Test. */
744 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
746 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
747 rval
= qla2x00_mbx_reg_test(ha
);
749 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
751 qla_printk(KERN_WARNING
, ha
,
752 "Failed mailbox send register test\n");
755 /* Flag a successful rval */
758 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
762 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
763 "****\n", ha
->host_no
));
765 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
771 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
774 * Returns 0 on success.
777 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
781 /* Perform RISC reset. */
782 qla24xx_reset_risc(ha
);
784 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
786 rval
= qla2x00_mbx_reg_test(ha
);
788 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
790 qla_printk(KERN_WARNING
, ha
,
791 "Failed mailbox send register test\n");
793 /* Flag a successful rval */
801 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
804 ha
->fw_dump24_len
= sizeof(struct qla24xx_fw_dump
);
805 ha
->fw_dump24_len
+= (ha
->fw_memory_size
- 0x100000) * sizeof(uint32_t);
806 ha
->fw_dump24
= vmalloc(ha
->fw_dump24_len
);
808 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware "
809 "dump...\n", ha
->fw_dump24_len
/ 1024);
811 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
812 "firmware dump!!!\n", ha
->fw_dump24_len
/ 1024);
816 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
819 * Returns 0 on success.
822 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
825 uint16_t fw_iocb_cnt
= 0;
826 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
827 dma_addr_t request_dma
;
828 request_t
*request_ring
;
830 /* Valid only on recent ISPs. */
831 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
834 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
835 qla2x00_alloc_fw_dump(ha
);
837 /* Retrieve IOCB counts available to the firmware. */
838 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
841 /* No point in continuing if current settings are sufficient. */
842 if (fw_iocb_cnt
< 1024)
844 if (ha
->request_q_length
>= request_q_length
)
847 /* Attempt to claim larger area for request queue. */
848 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
849 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
851 if (request_ring
== NULL
)
854 /* Resize successful, report extensions. */
855 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
856 (ha
->fw_memory_size
+ 1) / 1024);
857 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
858 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
860 /* Clear old allocations. */
861 dma_free_coherent(&ha
->pdev
->dev
,
862 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
865 /* Begin using larger queue. */
866 ha
->request_q_length
= request_q_length
;
867 ha
->request_ring
= request_ring
;
868 ha
->request_dma
= request_dma
;
872 * qla2x00_setup_chip() - Load and start RISC firmware.
875 * Returns 0 on success.
878 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
881 uint32_t srisc_address
= 0;
883 /* Load firmware sequences */
884 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
885 if (rval
== QLA_SUCCESS
) {
886 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
887 "code.\n", ha
->host_no
));
889 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
890 if (rval
== QLA_SUCCESS
) {
891 /* Start firmware execution. */
892 DEBUG(printk("scsi(%ld): Checksum OK, start "
893 "firmware.\n", ha
->host_no
));
895 rval
= qla2x00_execute_fw(ha
, srisc_address
);
896 /* Retrieve firmware information. */
897 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
898 qla2x00_get_fw_version(ha
,
899 &ha
->fw_major_version
,
900 &ha
->fw_minor_version
,
901 &ha
->fw_subminor_version
,
902 &ha
->fw_attributes
, &ha
->fw_memory_size
);
903 qla2x00_resize_request_q(ha
);
906 DEBUG2(printk(KERN_INFO
907 "scsi(%ld): ISP Firmware failed checksum.\n",
913 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
921 * qla2x00_init_response_q_entries() - Initializes response queue entries.
924 * Beginning of request ring has initialization control block already built
925 * by nvram config routine.
927 * Returns 0 on success.
930 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
935 pkt
= ha
->response_ring_ptr
;
936 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
937 pkt
->signature
= RESPONSE_PROCESSED
;
944 * qla2x00_update_fw_options() - Read and process firmware options.
947 * Returns 0 on success.
950 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
952 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
954 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
955 qla2x00_get_fw_options(ha
, ha
->fw_options
);
957 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
960 /* Serial Link options. */
961 DEBUG3(printk("scsi(%ld): Serial link options:\n",
963 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
964 sizeof(ha
->fw_seriallink_options
)));
966 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
967 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
968 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
971 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
972 emphasis
= (ha
->fw_seriallink_options
[2] &
973 (BIT_4
| BIT_3
)) >> 3;
974 tx_sens
= ha
->fw_seriallink_options
[0] &
975 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
976 rx_sens
= (ha
->fw_seriallink_options
[0] &
977 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
978 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
979 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
982 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
983 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
984 ha
->fw_options
[10] |= BIT_5
|
985 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
986 (tx_sens
& (BIT_1
| BIT_0
));
989 swing
= (ha
->fw_seriallink_options
[2] &
990 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
991 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
992 tx_sens
= ha
->fw_seriallink_options
[1] &
993 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
994 rx_sens
= (ha
->fw_seriallink_options
[1] &
995 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
996 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
997 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1000 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1001 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1002 ha
->fw_options
[11] |= BIT_5
|
1003 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1004 (tx_sens
& (BIT_1
| BIT_0
));
1008 /* Return command IOCBs without waiting for an ABTS to complete. */
1009 ha
->fw_options
[3] |= BIT_13
;
1012 if (ha
->flags
.enable_led_scheme
)
1013 ha
->fw_options
[2] |= BIT_12
;
1015 /* Update firmware options. */
1016 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1020 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1024 /* Update Serial Link options. */
1025 if ((ha
->fw_seriallink_options24
[0] & BIT_0
) == 0)
1028 rval
= qla2x00_set_serdes_params(ha
, ha
->fw_seriallink_options24
[1],
1029 ha
->fw_seriallink_options24
[2], ha
->fw_seriallink_options24
[3]);
1030 if (rval
!= QLA_SUCCESS
) {
1031 qla_printk(KERN_WARNING
, ha
,
1032 "Unable to update Serial Link options (%x).\n", rval
);
1037 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1039 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1041 /* Setup ring parameters in initialization control block. */
1042 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1043 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1044 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1045 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1046 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1047 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1048 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1049 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1051 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1052 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1053 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1054 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1055 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1059 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1061 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1062 struct init_cb_24xx
*icb
;
1064 /* Setup ring parameters in initialization control block. */
1065 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1066 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1067 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1068 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1069 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1070 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1071 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1072 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1073 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1075 WRT_REG_DWORD(®
->req_q_in
, 0);
1076 WRT_REG_DWORD(®
->req_q_out
, 0);
1077 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1078 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1079 RD_REG_DWORD(®
->rsp_q_out
);
1083 * qla2x00_init_rings() - Initializes firmware.
1086 * Beginning of request ring has initialization control block already built
1087 * by nvram config routine.
1089 * Returns 0 on success.
1092 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1095 unsigned long flags
= 0;
1098 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1100 /* Clear outstanding commands array. */
1101 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1102 ha
->outstanding_cmds
[cnt
] = NULL
;
1104 ha
->current_outstanding_cmd
= 0;
1106 /* Clear RSCN queue. */
1107 ha
->rscn_in_ptr
= 0;
1108 ha
->rscn_out_ptr
= 0;
1110 /* Initialize firmware. */
1111 ha
->request_ring_ptr
= ha
->request_ring
;
1112 ha
->req_ring_index
= 0;
1113 ha
->req_q_cnt
= ha
->request_q_length
;
1114 ha
->response_ring_ptr
= ha
->response_ring
;
1115 ha
->rsp_ring_index
= 0;
1117 /* Initialize response queue entries */
1118 qla2x00_init_response_q_entries(ha
);
1120 ha
->isp_ops
.config_rings(ha
);
1122 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1124 /* Update any ISP specific firmware options before initialization. */
1125 ha
->isp_ops
.update_fw_options(ha
);
1127 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1128 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1130 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1133 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1141 * qla2x00_fw_ready() - Waits for firmware ready.
1144 * Returns 0 on success.
1147 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1150 unsigned long wtime
, mtime
;
1151 uint16_t min_wait
; /* Minimum wait time if loop is down */
1152 uint16_t wait_time
; /* Wait time if loop is coming ready */
1157 /* 20 seconds for loop down. */
1161 * Firmware should take at most one RATOV to login, plus 5 seconds for
1162 * our own processing.
1164 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1165 wait_time
= min_wait
;
1168 /* Min wait time if loop down */
1169 mtime
= jiffies
+ (min_wait
* HZ
);
1171 /* wait time before firmware ready */
1172 wtime
= jiffies
+ (wait_time
* HZ
);
1174 /* Wait for ISP to finish LIP */
1175 if (!ha
->flags
.init_done
)
1176 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1178 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1182 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1183 if (rval
== QLA_SUCCESS
) {
1184 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1185 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1187 if (fw_state
== FSTATE_READY
) {
1188 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1191 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1192 &ha
->login_timeout
, &ha
->r_a_tov
);
1198 rval
= QLA_FUNCTION_FAILED
;
1200 if (atomic_read(&ha
->loop_down_timer
) &&
1201 (fw_state
>= FSTATE_LOSS_OF_SYNC
||
1202 fw_state
== FSTATE_WAIT_AL_PA
)) {
1203 /* Loop down. Timeout on min_wait for states
1204 * other than Wait for Login.
1206 if (time_after_eq(jiffies
, mtime
)) {
1207 qla_printk(KERN_INFO
, ha
,
1208 "Cable is unplugged...\n");
1210 ha
->device_flags
|= DFLG_NO_CABLE
;
1215 /* Mailbox cmd failed. Timeout on min_wait. */
1216 if (time_after_eq(jiffies
, mtime
))
1220 if (time_after_eq(jiffies
, wtime
))
1223 /* Delay for a while */
1226 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1227 ha
->host_no
, fw_state
, jiffies
));
1230 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1231 ha
->host_no
, fw_state
, jiffies
));
1234 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1242 * qla2x00_configure_hba
1243 * Setup adapter context.
1246 * ha = adapter state pointer.
1255 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1263 char connect_type
[22];
1265 /* Get host addresses. */
1266 rval
= qla2x00_get_adapter_id(ha
,
1267 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1268 if (rval
!= QLA_SUCCESS
) {
1269 qla_printk(KERN_WARNING
, ha
,
1270 "ERROR -- Unable to get host loop ID.\n");
1271 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1276 qla_printk(KERN_INFO
, ha
,
1277 "Cannot get topology - retrying.\n");
1278 return (QLA_FUNCTION_FAILED
);
1281 ha
->loop_id
= loop_id
;
1284 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1285 ha
->operating_mode
= LOOP
;
1289 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1291 ha
->current_topology
= ISP_CFG_NL
;
1292 strcpy(connect_type
, "(Loop)");
1296 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1298 ha
->current_topology
= ISP_CFG_FL
;
1299 strcpy(connect_type
, "(FL_Port)");
1303 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1305 ha
->operating_mode
= P2P
;
1306 ha
->current_topology
= ISP_CFG_N
;
1307 strcpy(connect_type
, "(N_Port-to-N_Port)");
1311 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1313 ha
->operating_mode
= P2P
;
1314 ha
->current_topology
= ISP_CFG_F
;
1315 strcpy(connect_type
, "(F_Port)");
1319 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1321 ha
->host_no
, topo
));
1322 ha
->current_topology
= ISP_CFG_NL
;
1323 strcpy(connect_type
, "(Loop)");
1327 /* Save Host port and loop ID. */
1328 /* byte order - Big Endian */
1329 ha
->d_id
.b
.domain
= domain
;
1330 ha
->d_id
.b
.area
= area
;
1331 ha
->d_id
.b
.al_pa
= al_pa
;
1333 if (!ha
->flags
.init_done
)
1334 qla_printk(KERN_INFO
, ha
,
1335 "Topology - %s, Host Loop address 0x%x\n",
1336 connect_type
, ha
->loop_id
);
1339 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1341 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1348 * NVRAM configuration for ISP 2xxx
1351 * ha = adapter block pointer.
1354 * initialization control block in response_ring
1355 * host adapters parameters in host adapter block
1361 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1366 uint8_t *dptr1
, *dptr2
;
1367 init_cb_t
*icb
= ha
->init_cb
;
1368 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1369 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1370 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1375 /* Determine NVRAM starting address. */
1376 ha
->nvram_size
= sizeof(nvram_t
);
1378 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1379 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1380 ha
->nvram_base
= 0x80;
1382 /* Get NVRAM data and calculate checksum. */
1383 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1384 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1387 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1388 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1391 /* Bad NVRAM data, set defaults parameters. */
1392 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1393 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1394 /* Reset NVRAM data. */
1395 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1396 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1398 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1399 "invalid -- WWPN) defaults.\n");
1402 * Set default initialization control block.
1404 memset(nv
, 0, ha
->nvram_size
);
1405 nv
->parameter_block_version
= ICB_VERSION
;
1407 if (IS_QLA23XX(ha
)) {
1408 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1409 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1410 nv
->add_firmware_options
[0] = BIT_5
;
1411 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1412 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1413 nv
->special_options
[1] = BIT_7
;
1414 } else if (IS_QLA2200(ha
)) {
1415 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1416 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1417 nv
->add_firmware_options
[0] = BIT_5
;
1418 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1419 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1420 } else if (IS_QLA2100(ha
)) {
1421 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1422 nv
->firmware_options
[1] = BIT_5
;
1423 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1426 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1427 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1428 nv
->retry_count
= 8;
1429 nv
->retry_delay
= 1;
1431 nv
->port_name
[0] = 33;
1432 nv
->port_name
[3] = 224;
1433 nv
->port_name
[4] = 139;
1435 nv
->login_timeout
= 4;
1438 * Set default host adapter parameters
1440 nv
->host_p
[1] = BIT_2
;
1441 nv
->reset_delay
= 5;
1442 nv
->port_down_retry_count
= 8;
1443 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1444 nv
->link_down_timeout
= 60;
1449 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1451 * The SN2 does not provide BIOS emulation which means you can't change
1452 * potentially bogus BIOS settings. Force the use of default settings
1453 * for link rate and frame size. Hope that the rest of the settings
1456 if (ia64_platform_is("sn2")) {
1457 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1459 nv
->special_options
[1] = BIT_7
;
1463 /* Reset Initialization control block */
1464 memset(icb
, 0, ha
->init_cb_size
);
1467 * Setup driver NVRAM options.
1469 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1470 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1471 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1472 nv
->firmware_options
[1] &= ~BIT_4
;
1474 if (IS_QLA23XX(ha
)) {
1475 nv
->firmware_options
[0] |= BIT_2
;
1476 nv
->firmware_options
[0] &= ~BIT_3
;
1477 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1479 if (IS_QLA2300(ha
)) {
1480 if (ha
->fb_rev
== FPM_2310
) {
1481 strcpy(ha
->model_number
, "QLA2310");
1483 strcpy(ha
->model_number
, "QLA2300");
1487 memcmp(nv
->model_number
, BINZERO
,
1488 sizeof(nv
->model_number
)) != 0) {
1491 strncpy(ha
->model_number
, nv
->model_number
,
1492 sizeof(nv
->model_number
));
1493 st
= en
= ha
->model_number
;
1494 en
+= sizeof(nv
->model_number
) - 1;
1496 if (*en
!= 0x20 && *en
!= 0x00)
1503 index
= (ha
->pdev
->subsystem_device
& 0xff);
1504 if (index
< QLA_MODEL_NAMES
) {
1505 strcpy(ha
->model_number
,
1506 qla2x00_model_name
[index
]);
1508 qla2x00_model_desc
[index
];
1510 strcpy(ha
->model_number
, "QLA23xx");
1514 } else if (IS_QLA2200(ha
)) {
1515 nv
->firmware_options
[0] |= BIT_2
;
1517 * 'Point-to-point preferred, else loop' is not a safe
1518 * connection mode setting.
1520 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1522 /* Force 'loop preferred, else point-to-point'. */
1523 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1524 nv
->add_firmware_options
[0] |= BIT_5
;
1526 strcpy(ha
->model_number
, "QLA22xx");
1527 } else /*if (IS_QLA2100(ha))*/ {
1528 strcpy(ha
->model_number
, "QLA2100");
1532 * Copy over NVRAM RISC parameter block to initialization control block.
1534 dptr1
= (uint8_t *)icb
;
1535 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1536 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1538 *dptr1
++ = *dptr2
++;
1540 /* Copy 2nd half. */
1541 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1542 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1544 *dptr1
++ = *dptr2
++;
1546 /* Prepare nodename */
1547 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1549 * Firmware will apply the following mask if the nodename was
1552 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1553 icb
->node_name
[0] &= 0xF0;
1557 * Set host adapter parameters.
1559 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1560 /* Always load RISC code on non ISP2[12]00 chips. */
1561 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1562 ha
->flags
.disable_risc_code_load
= 0;
1563 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1564 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1565 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1566 ha
->flags
.enable_led_scheme
= ((nv
->efi_parameters
& BIT_3
) ? 1 : 0);
1568 ha
->operating_mode
=
1569 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1571 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1572 sizeof(ha
->fw_seriallink_options
));
1574 /* save HBA serial number */
1575 ha
->serial0
= icb
->port_name
[5];
1576 ha
->serial1
= icb
->port_name
[6];
1577 ha
->serial2
= icb
->port_name
[7];
1578 ha
->node_name
= icb
->node_name
;
1579 ha
->port_name
= icb
->port_name
;
1581 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1583 ha
->retry_count
= nv
->retry_count
;
1585 /* Set minimum login_timeout to 4 seconds. */
1586 if (nv
->login_timeout
< ql2xlogintimeout
)
1587 nv
->login_timeout
= ql2xlogintimeout
;
1588 if (nv
->login_timeout
< 4)
1589 nv
->login_timeout
= 4;
1590 ha
->login_timeout
= nv
->login_timeout
;
1591 icb
->login_timeout
= nv
->login_timeout
;
1593 /* Set minimum RATOV to 200 tenths of a second. */
1596 ha
->loop_reset_delay
= nv
->reset_delay
;
1598 /* Link Down Timeout = 0:
1600 * When Port Down timer expires we will start returning
1601 * I/O's to OS with "DID_NO_CONNECT".
1603 * Link Down Timeout != 0:
1605 * The driver waits for the link to come up after link down
1606 * before returning I/Os to OS with "DID_NO_CONNECT".
1608 if (nv
->link_down_timeout
== 0) {
1609 ha
->loop_down_abort_time
=
1610 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1612 ha
->link_down_timeout
= nv
->link_down_timeout
;
1613 ha
->loop_down_abort_time
=
1614 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1618 * Need enough time to try and get the port back.
1620 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1621 if (qlport_down_retry
)
1622 ha
->port_down_retry_count
= qlport_down_retry
;
1623 /* Set login_retry_count */
1624 ha
->login_retry_count
= nv
->retry_count
;
1625 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1626 ha
->port_down_retry_count
> 3)
1627 ha
->login_retry_count
= ha
->port_down_retry_count
;
1628 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1629 ha
->login_retry_count
= ha
->port_down_retry_count
;
1630 if (ql2xloginretrycount
)
1631 ha
->login_retry_count
= ql2xloginretrycount
;
1633 icb
->lun_enables
= __constant_cpu_to_le16(0);
1634 icb
->command_resource_count
= 0;
1635 icb
->immediate_notify_resource_count
= 0;
1636 icb
->timeout
= __constant_cpu_to_le16(0);
1638 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1640 icb
->firmware_options
[0] &= ~BIT_3
;
1641 icb
->add_firmware_options
[0] &=
1642 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1643 icb
->add_firmware_options
[0] |= BIT_2
;
1644 icb
->response_accumulation_timer
= 3;
1645 icb
->interrupt_delay_timer
= 5;
1647 ha
->flags
.process_response_queue
= 1;
1649 /* Enable ZIO -- Support mode 5 only. */
1650 timer_mode
= icb
->add_firmware_options
[0] &
1651 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1652 icb
->add_firmware_options
[0] &=
1653 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1655 timer_mode
= BIT_2
| BIT_0
;
1656 if (timer_mode
== (BIT_2
| BIT_0
)) {
1657 DEBUG2(printk("scsi(%ld): ZIO enabled; timer delay "
1658 "(%d).\n", ha
->host_no
, ql2xintrdelaytimer
));
1659 qla_printk(KERN_INFO
, ha
,
1660 "ZIO enabled; timer delay (%d).\n",
1661 ql2xintrdelaytimer
);
1663 icb
->add_firmware_options
[0] |= timer_mode
;
1664 icb
->interrupt_delay_timer
= ql2xintrdelaytimer
;
1665 ha
->flags
.process_response_queue
= 1;
1670 DEBUG2_3(printk(KERN_WARNING
1671 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1677 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1679 * @flags: allocation flags
1681 * Returns a pointer to the allocated fcport, or NULL, if none available.
1684 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, int flags
)
1688 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1692 /* Setup fcport template structure. */
1693 memset(fcport
, 0, sizeof (fc_port_t
));
1695 fcport
->port_type
= FCT_UNKNOWN
;
1696 fcport
->loop_id
= FC_NO_LOOP_ID
;
1697 fcport
->iodesc_idx_sent
= IODESC_INVALID_INDEX
;
1698 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1699 fcport
->flags
= FCF_RLC_SUPPORT
;
1705 * qla2x00_configure_loop
1706 * Updates Fibre Channel Device Database with what is actually on loop.
1709 * ha = adapter block pointer.
1714 * 2 = database was full and device was not configured.
1717 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1720 unsigned long flags
, save_flags
;
1724 /* Get Initiator ID */
1725 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1726 rval
= qla2x00_configure_hba(ha
);
1727 if (rval
!= QLA_SUCCESS
) {
1728 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1734 save_flags
= flags
= ha
->dpc_flags
;
1735 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1736 ha
->host_no
, flags
));
1739 * If we have both an RSCN and PORT UPDATE pending then handle them
1740 * both at the same time.
1742 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1743 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1745 /* Determine what we need to do */
1746 if (ha
->current_topology
== ISP_CFG_FL
&&
1747 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1749 ha
->flags
.rscn_queue_overflow
= 1;
1750 set_bit(RSCN_UPDATE
, &flags
);
1752 } else if (ha
->current_topology
== ISP_CFG_F
&&
1753 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1755 ha
->flags
.rscn_queue_overflow
= 1;
1756 set_bit(RSCN_UPDATE
, &flags
);
1757 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1759 } else if (!ha
->flags
.online
||
1760 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1762 ha
->flags
.rscn_queue_overflow
= 1;
1763 set_bit(RSCN_UPDATE
, &flags
);
1764 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1767 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1768 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1769 rval
= QLA_FUNCTION_FAILED
;
1771 rval
= qla2x00_configure_local_loop(ha
);
1775 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1776 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1777 rval
= QLA_FUNCTION_FAILED
;
1779 rval
= qla2x00_configure_fabric(ha
);
1783 if (rval
== QLA_SUCCESS
) {
1784 if (atomic_read(&ha
->loop_down_timer
) ||
1785 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1786 rval
= QLA_FUNCTION_FAILED
;
1788 atomic_set(&ha
->loop_state
, LOOP_READY
);
1790 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1795 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1796 __func__
, ha
->host_no
));
1798 DEBUG3(printk("%s: exiting normally\n", __func__
));
1801 /* Restore state if a resync event occured during processing */
1802 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1803 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1804 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1805 if (test_bit(RSCN_UPDATE
, &save_flags
))
1806 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1815 * qla2x00_configure_local_loop
1816 * Updates Fibre Channel Device Database with local loop devices.
1819 * ha = adapter block pointer.
1825 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1830 fc_port_t
*fcport
, *new_fcport
;
1836 uint8_t domain
, area
, al_pa
;
1840 entries
= MAX_FIBRE_DEVICES
;
1842 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1843 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1845 /* Get list of logged in devices. */
1846 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1847 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1849 if (rval
!= QLA_SUCCESS
)
1850 goto cleanup_allocation
;
1852 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1853 ha
->host_no
, entries
));
1854 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1855 entries
* sizeof(struct gid_list_info
)));
1857 /* Allocate temporary fcport for any new fcports discovered. */
1858 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1859 if (new_fcport
== NULL
) {
1860 rval
= QLA_MEMORY_ALLOC_FAILED
;
1861 goto cleanup_allocation
;
1863 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1866 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1868 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1869 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1870 fcport
->port_type
!= FCT_BROADCAST
&&
1871 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1873 DEBUG(printk("scsi(%ld): Marking port lost, "
1875 ha
->host_no
, fcport
->loop_id
));
1877 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1878 fcport
->flags
&= ~FCF_FARP_DONE
;
1882 /* Add devices to port list. */
1883 id_iter
= (char *)ha
->gid_list
;
1884 for (index
= 0; index
< entries
; index
++) {
1885 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1886 area
= ((struct gid_list_info
*)id_iter
)->area
;
1887 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1888 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1889 loop_id
= (uint16_t)
1890 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1892 loop_id
= le16_to_cpu(
1893 ((struct gid_list_info
*)id_iter
)->loop_id
);
1894 id_iter
+= ha
->gid_list_info_size
;
1896 /* Bypass reserved domain fields. */
1897 if ((domain
& 0xf0) == 0xf0)
1900 /* Bypass if not same domain and area of adapter. */
1901 if (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
)
1904 /* Bypass invalid local loop ID. */
1905 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1908 /* Fill in member data. */
1909 new_fcport
->d_id
.b
.domain
= domain
;
1910 new_fcport
->d_id
.b
.area
= area
;
1911 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1912 new_fcport
->loop_id
= loop_id
;
1913 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1914 if (rval2
!= QLA_SUCCESS
) {
1915 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1916 "information -- get_port_database=%x, "
1918 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1922 /* Check for matching device in port list. */
1925 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1926 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
1930 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
1931 FCF_PERSISTENT_BOUND
);
1932 fcport
->loop_id
= new_fcport
->loop_id
;
1933 fcport
->port_type
= new_fcport
->port_type
;
1934 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
1935 memcpy(fcport
->node_name
, new_fcport
->node_name
,
1943 /* New device, add to fcports list. */
1944 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
1945 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
1947 /* Allocate a new replacement fcport. */
1948 fcport
= new_fcport
;
1949 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1950 if (new_fcport
== NULL
) {
1951 rval
= QLA_MEMORY_ALLOC_FAILED
;
1952 goto cleanup_allocation
;
1954 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1957 qla2x00_update_fcport(ha
, fcport
);
1966 if (rval
!= QLA_SUCCESS
) {
1967 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1968 "rval=%x\n", ha
->host_no
, rval
));
1972 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
1973 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
1980 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
1984 qla2x00_mark_all_devices_lost(ha
);
1985 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1986 if (fcport
->port_type
!= FCT_TARGET
)
1989 qla2x00_update_fcport(ha
, fcport
);
1994 * qla2x00_update_fcport
1995 * Updates device on list.
1998 * ha = adapter block pointer.
1999 * fcport = port structure pointer.
2009 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2012 unsigned long flags
;
2016 fcport
->login_retry
= 0;
2017 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2019 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2021 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2024 * Check for outstanding cmd on tape Bypass LUN discovery if active
2027 if (fcport
->flags
& FCF_TAPE_PRESENT
) {
2028 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2029 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
; index
++) {
2032 if ((sp
= ha
->outstanding_cmds
[index
]) != 0) {
2034 if (sfcp
== fcport
) {
2035 atomic_set(&fcport
->state
, FCS_ONLINE
);
2036 spin_unlock_irqrestore(
2037 &ha
->hardware_lock
, flags
);
2042 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2045 if (fcport
->port_type
== FCT_INITIATOR
||
2046 fcport
->port_type
== FCT_BROADCAST
)
2047 fcport
->device_type
= TYPE_PROCESSOR
;
2049 atomic_set(&fcport
->state
, FCS_ONLINE
);
2051 if (ha
->flags
.init_done
)
2052 qla2x00_reg_remote_port(ha
, fcport
);
2056 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2058 struct fc_rport_identifiers rport_ids
;
2059 struct fc_rport
*rport
;
2061 if (fcport
->rport
) {
2062 fc_remote_port_unblock(fcport
->rport
);
2066 rport_ids
.node_name
= be64_to_cpu(*(uint64_t *)fcport
->node_name
);
2067 rport_ids
.port_name
= be64_to_cpu(*(uint64_t *)fcport
->port_name
);
2068 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2069 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2070 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2071 fcport
->rport
= rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2073 qla_printk(KERN_WARNING
, ha
,
2074 "Unable to allocate fc remote port!\n");
2077 rport
->dd_data
= fcport
;
2079 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2080 if (fcport
->port_type
== FCT_INITIATOR
)
2081 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2082 if (fcport
->port_type
== FCT_TARGET
)
2083 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2084 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2086 if (rport
->scsi_target_id
!= -1 &&
2087 rport
->scsi_target_id
< ha
->host
->max_id
)
2088 fcport
->os_target_id
= rport
->scsi_target_id
;
2092 * qla2x00_configure_fabric
2093 * Setup SNS devices with loop ID's.
2096 * ha = adapter block pointer.
2103 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2106 fc_port_t
*fcport
, *fcptemp
;
2107 uint16_t next_loopid
;
2108 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2110 LIST_HEAD(new_fcports
);
2112 /* If FL port exists, then SNS is present */
2113 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
2114 loop_id
= NPH_F_PORT
;
2116 loop_id
= SNS_FL_PORT
;
2117 rval
= qla2x00_get_port_name(ha
, loop_id
, NULL
, 0);
2118 if (rval
!= QLA_SUCCESS
) {
2119 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2120 "Port\n", ha
->host_no
));
2122 ha
->device_flags
&= ~SWITCH_FOUND
;
2123 return (QLA_SUCCESS
);
2126 /* Mark devices that need re-synchronization. */
2127 rval2
= qla2x00_device_resync(ha
);
2128 if (rval2
== QLA_RSCNS_HANDLED
) {
2129 /* No point doing the scan, just continue. */
2130 return (QLA_SUCCESS
);
2133 /* Ensure we are logged into the SNS. */
2134 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
2137 loop_id
= SIMPLE_NAME_SERVER
;
2138 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2139 0xfc, mb
, BIT_1
| BIT_0
);
2140 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2141 DEBUG2(qla_printk(KERN_INFO
, ha
,
2142 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2143 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2144 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2145 return (QLA_SUCCESS
);
2148 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2149 if (qla2x00_rft_id(ha
)) {
2151 DEBUG2(printk("scsi(%ld): Register FC-4 "
2152 "TYPE failed.\n", ha
->host_no
));
2154 if (qla2x00_rff_id(ha
)) {
2156 DEBUG2(printk("scsi(%ld): Register FC-4 "
2157 "Features failed.\n", ha
->host_no
));
2159 if (qla2x00_rnn_id(ha
)) {
2161 DEBUG2(printk("scsi(%ld): Register Node Name "
2162 "failed.\n", ha
->host_no
));
2163 } else if (qla2x00_rsnn_nn(ha
)) {
2165 DEBUG2(printk("scsi(%ld): Register Symbolic "
2166 "Node Name failed.\n", ha
->host_no
));
2170 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2171 if (rval
!= QLA_SUCCESS
)
2175 * Logout all previous fabric devices marked lost, except
2178 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2179 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2182 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2185 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2186 qla2x00_mark_device_lost(ha
, fcport
,
2187 ql2xplogiabsentdevice
);
2188 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2189 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2190 fcport
->port_type
!= FCT_INITIATOR
&&
2191 fcport
->port_type
!= FCT_BROADCAST
) {
2193 ha
->isp_ops
.fabric_logout(ha
,
2195 fcport
->d_id
.b
.domain
,
2196 fcport
->d_id
.b
.area
,
2197 fcport
->d_id
.b
.al_pa
);
2198 fcport
->loop_id
= FC_NO_LOOP_ID
;
2203 /* Starting free loop ID. */
2204 next_loopid
= ha
->min_external_loopid
;
2207 * Scan through our port list and login entries that need to be
2210 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2211 if (atomic_read(&ha
->loop_down_timer
) ||
2212 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2215 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2216 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2219 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2220 fcport
->loop_id
= next_loopid
;
2221 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2222 if (rval
!= QLA_SUCCESS
) {
2223 /* Ran out of IDs to use */
2227 /* Login and update database */
2228 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2231 /* Exit if out of loop IDs. */
2232 if (rval
!= QLA_SUCCESS
) {
2237 * Login and add the new devices to our port list.
2239 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2240 if (atomic_read(&ha
->loop_down_timer
) ||
2241 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2244 /* Find a new loop ID to use. */
2245 fcport
->loop_id
= next_loopid
;
2246 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2247 if (rval
!= QLA_SUCCESS
) {
2248 /* Ran out of IDs to use */
2252 /* Remove device from the new list and add it to DB */
2253 list_del(&fcport
->list
);
2254 list_add_tail(&fcport
->list
, &ha
->fcports
);
2256 /* Login and update database */
2257 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2261 /* Free all new device structures not processed. */
2262 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2263 list_del(&fcport
->list
);
2268 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2269 "rval=%d\n", ha
->host_no
, rval
));
2277 * qla2x00_find_all_fabric_devs
2280 * ha = adapter block pointer.
2281 * dev = database device entry pointer.
2290 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2294 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2299 int first_dev
, last_dev
;
2300 port_id_t wrap
, nxt_d_id
;
2304 /* Try GID_PT to get device list, else GAN. */
2305 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2308 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2309 "on GA_NXT\n", ha
->host_no
));
2311 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2312 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2315 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2318 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2325 /* Allocate temporary fcport for any new fcports discovered. */
2326 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2327 if (new_fcport
== NULL
) {
2330 return (QLA_MEMORY_ALLOC_FAILED
);
2332 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2334 /* Set start port ID scan at adapter ID. */
2338 /* Starting free loop ID. */
2339 loop_id
= ha
->min_external_loopid
;
2340 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2341 if (qla2x00_is_reserved_id(ha
, loop_id
))
2344 if (atomic_read(&ha
->loop_down_timer
) ||
2345 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2350 wrap
.b24
= new_fcport
->d_id
.b24
;
2352 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2353 memcpy(new_fcport
->node_name
,
2354 swl
[swl_idx
].node_name
, WWN_SIZE
);
2355 memcpy(new_fcport
->port_name
,
2356 swl
[swl_idx
].port_name
, WWN_SIZE
);
2358 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2364 /* Send GA_NXT to the switch */
2365 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2366 if (rval
!= QLA_SUCCESS
) {
2367 qla_printk(KERN_WARNING
, ha
,
2368 "SNS scan failed -- assuming zero-entry "
2370 list_for_each_entry_safe(fcport
, fcptemp
,
2371 new_fcports
, list
) {
2372 list_del(&fcport
->list
);
2380 /* If wrap on switch device list, exit. */
2382 wrap
.b24
= new_fcport
->d_id
.b24
;
2384 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2385 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2386 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2387 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2391 /* Bypass if host adapter. */
2392 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2395 /* Bypass reserved domain fields. */
2396 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2399 /* Locate matching device in database. */
2401 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2402 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2409 * If address the same and state FCS_ONLINE, nothing
2412 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2413 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2418 * If device was not a fabric device before.
2420 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2421 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2422 fcport
->loop_id
= FC_NO_LOOP_ID
;
2423 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2425 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2430 * Port ID changed or device was marked to be updated;
2431 * Log it out if still logged in and mark it for
2434 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2435 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2436 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2437 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2438 fcport
->port_type
!= FCT_INITIATOR
&&
2439 fcport
->port_type
!= FCT_BROADCAST
) {
2440 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2441 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2442 fcport
->d_id
.b
.al_pa
);
2443 fcport
->loop_id
= FC_NO_LOOP_ID
;
2452 /* If device was not in our fcports list, then add it. */
2453 list_add_tail(&new_fcport
->list
, new_fcports
);
2455 /* Allocate a new replacement fcport. */
2456 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2457 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2458 if (new_fcport
== NULL
) {
2461 return (QLA_MEMORY_ALLOC_FAILED
);
2463 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2464 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2473 if (!list_empty(new_fcports
))
2474 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2480 * qla2x00_find_new_loop_id
2481 * Scan through our port list and find a new usable loop ID.
2484 * ha: adapter state pointer.
2485 * dev: port structure pointer.
2488 * qla2x00 local function return status code.
2494 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2499 uint16_t first_loop_id
;
2503 /* Save starting loop ID. */
2504 first_loop_id
= dev
->loop_id
;
2507 /* Skip loop ID if already used by adapter. */
2508 if (dev
->loop_id
== ha
->loop_id
) {
2512 /* Skip reserved loop IDs. */
2513 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2517 /* Reset loop ID if passed the end. */
2518 if (dev
->loop_id
> ha
->last_loop_id
) {
2519 /* first loop ID. */
2520 dev
->loop_id
= ha
->min_external_loopid
;
2523 /* Check for loop ID being already in use. */
2526 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2527 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2528 /* ID possibly in use */
2534 /* If not in use then it is free to use. */
2539 /* ID in use. Try next value. */
2542 /* If wrap around. No free ID to use. */
2543 if (dev
->loop_id
== first_loop_id
) {
2544 dev
->loop_id
= FC_NO_LOOP_ID
;
2545 rval
= QLA_FUNCTION_FAILED
;
2554 * qla2x00_device_resync
2555 * Marks devices in the database that needs resynchronization.
2558 * ha = adapter block pointer.
2564 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2570 uint32_t rscn_entry
;
2571 uint8_t rscn_out_iter
;
2575 rval
= QLA_RSCNS_HANDLED
;
2577 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2578 ha
->flags
.rscn_queue_overflow
) {
2580 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2581 format
= MSB(MSW(rscn_entry
));
2582 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2583 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2584 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2586 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2587 "[%02x/%02x%02x%02x].\n",
2588 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2589 d_id
.b
.area
, d_id
.b
.al_pa
));
2592 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2593 ha
->rscn_out_ptr
= 0;
2595 /* Skip duplicate entries. */
2596 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2597 !ha
->flags
.rscn_queue_overflow
&&
2598 rscn_out_iter
!= ha
->rscn_in_ptr
;
2599 rscn_out_iter
= (rscn_out_iter
==
2600 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2602 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2605 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2606 "entry found at [%d].\n", ha
->host_no
,
2609 ha
->rscn_out_ptr
= rscn_out_iter
;
2612 /* Queue overflow, set switch default case. */
2613 if (ha
->flags
.rscn_queue_overflow
) {
2614 DEBUG(printk("scsi(%ld): device_resync: rscn "
2615 "overflow.\n", ha
->host_no
));
2618 ha
->flags
.rscn_queue_overflow
= 0;
2623 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
2624 !IS_QLA6312(ha
) && !IS_QLA6322(ha
) &&
2625 !IS_QLA24XX(ha
) && !IS_QLA25XX(ha
) &&
2626 ha
->flags
.init_done
) {
2627 /* Handle port RSCN via asyncronous IOCBs */
2628 rval2
= qla2x00_handle_port_rscn(ha
, rscn_entry
,
2630 if (rval2
== QLA_SUCCESS
)
2644 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2650 /* Abort any outstanding IO descriptors. */
2651 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2652 qla2x00_cancel_io_descriptors(ha
);
2654 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2655 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2656 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2657 fcport
->port_type
== FCT_BROADCAST
)
2660 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2662 fcport
->port_type
!= FCT_INITIATOR
) {
2663 qla2x00_mark_device_lost(ha
, fcport
, 0);
2666 fcport
->flags
&= ~FCF_FARP_DONE
;
2673 * qla2x00_fabric_dev_login
2674 * Login fabric target device and update FC port database.
2677 * ha: adapter state pointer.
2678 * fcport: port structure list pointer.
2679 * next_loopid: contains value of a new loop ID that can be used
2680 * by the next login attempt.
2683 * qla2x00 local function return status code.
2689 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2690 uint16_t *next_loopid
)
2699 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2700 if (rval
== QLA_SUCCESS
) {
2701 /* Send an ADISC to tape devices.*/
2703 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2705 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2706 if (rval
!= QLA_SUCCESS
) {
2707 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2708 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2709 fcport
->d_id
.b
.al_pa
);
2710 qla2x00_mark_device_lost(ha
, fcport
, 1);
2713 qla2x00_update_fcport(ha
, fcport
);
2721 * qla2x00_fabric_login
2722 * Issue fabric login command.
2725 * ha = adapter block pointer.
2726 * device = pointer to FC device type structure.
2729 * 0 - Login successfully
2731 * 2 - Initiator device
2735 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2736 uint16_t *next_loopid
)
2740 uint16_t tmp_loopid
;
2741 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2747 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2748 "for port %02x%02x%02x.\n",
2749 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2750 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2752 /* Login fcport on switch. */
2753 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2754 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2755 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2756 if (mb
[0] == MBS_PORT_ID_USED
) {
2758 * Device has another loop ID. The firmware team
2759 * recommends the driver perform an implicit login with
2760 * the specified ID again. The ID we just used is save
2761 * here so we return with an ID that can be tried by
2765 tmp_loopid
= fcport
->loop_id
;
2766 fcport
->loop_id
= mb
[1];
2768 DEBUG(printk("Fabric Login: port in use - next "
2769 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2770 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2771 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2773 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2778 /* A retry occurred before. */
2779 *next_loopid
= tmp_loopid
;
2782 * No retry occurred before. Just increment the
2783 * ID value for next login.
2785 *next_loopid
= (fcport
->loop_id
+ 1);
2788 if (mb
[1] & BIT_0
) {
2789 fcport
->port_type
= FCT_INITIATOR
;
2791 fcport
->port_type
= FCT_TARGET
;
2792 if (mb
[1] & BIT_1
) {
2793 fcport
->flags
|= FCF_TAPE_PRESENT
;
2799 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2801 * Loop ID already used, try next loop ID.
2804 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2805 if (rval
!= QLA_SUCCESS
) {
2806 /* Ran out of loop IDs to use */
2809 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2811 * Firmware possibly timed out during login. If NO
2812 * retries are left to do then the device is declared
2815 *next_loopid
= fcport
->loop_id
;
2816 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2817 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2818 fcport
->d_id
.b
.al_pa
);
2819 qla2x00_mark_device_lost(ha
, fcport
, 1);
2825 * unrecoverable / not handled error
2827 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2828 "loop_id=%x jiffies=%lx.\n",
2829 __func__
, ha
->host_no
, mb
[0],
2830 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2831 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2833 *next_loopid
= fcport
->loop_id
;
2834 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2835 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2836 fcport
->d_id
.b
.al_pa
);
2837 fcport
->loop_id
= FC_NO_LOOP_ID
;
2838 atomic_set(&fcport
->state
, FCS_DEVICE_DEAD
);
2849 * qla2x00_local_device_login
2850 * Issue local device login command.
2853 * ha = adapter block pointer.
2854 * loop_id = loop id of device to login to.
2856 * Returns (Where's the #define!!!!):
2857 * 0 - Login successfully
2862 qla2x00_local_device_login(scsi_qla_host_t
*ha
, uint16_t loop_id
)
2865 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2867 memset(mb
, 0, sizeof(mb
));
2868 rval
= qla2x00_login_local_device(ha
, loop_id
, mb
, BIT_0
);
2869 if (rval
== QLA_SUCCESS
) {
2870 /* Interrogate mailbox registers for any errors */
2871 if (mb
[0] == MBS_COMMAND_ERROR
)
2873 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2874 /* device not in PCB table */
2882 * qla2x00_loop_resync
2883 * Resync with fibre channel devices.
2886 * ha = adapter block pointer.
2892 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2899 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2900 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2901 if (ha
->flags
.online
) {
2902 if (!(rval
= qla2x00_fw_ready(ha
))) {
2903 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2906 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2908 /* Issue a marker after FW becomes ready. */
2909 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
2910 ha
->marker_needed
= 0;
2912 /* Remap devices on Loop. */
2913 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2915 qla2x00_configure_loop(ha
);
2917 } while (!atomic_read(&ha
->loop_down_timer
) &&
2918 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
2920 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
2924 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2925 return (QLA_FUNCTION_FAILED
);
2929 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
2936 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
2942 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2943 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
2946 qla2x00_update_fcport(ha
, fcport
);
2947 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
2951 qla2x00_probe_for_all_luns(ha
);
2956 * Resets ISP and aborts all outstanding commands.
2959 * ha = adapter block pointer.
2965 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
2967 unsigned long flags
= 0;
2972 if (ha
->flags
.online
) {
2973 ha
->flags
.online
= 0;
2974 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
2976 qla_printk(KERN_INFO
, ha
,
2977 "Performing ISP error recovery - ha= %p.\n", ha
);
2978 ha
->isp_ops
.reset_chip(ha
);
2980 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
2981 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
2982 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
2983 qla2x00_mark_all_devices_lost(ha
);
2985 if (!atomic_read(&ha
->loop_down_timer
))
2986 atomic_set(&ha
->loop_down_timer
,
2990 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2991 /* Requeue all commands in outstanding command list. */
2992 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
2993 sp
= ha
->outstanding_cmds
[cnt
];
2995 ha
->outstanding_cmds
[cnt
] = NULL
;
2997 sp
->cmd
->result
= DID_RESET
<< 16;
2998 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
2999 qla2x00_sp_compl(ha
, sp
);
3002 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3004 ha
->isp_ops
.nvram_config(ha
);
3006 if (!qla2x00_restart_isp(ha
)) {
3007 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3009 if (!atomic_read(&ha
->loop_down_timer
)) {
3011 * Issue marker command only when we are going
3012 * to start the I/O .
3014 ha
->marker_needed
= 1;
3017 ha
->flags
.online
= 1;
3019 ha
->isp_ops
.enable_intrs(ha
);
3021 ha
->isp_abort_cnt
= 0;
3022 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3023 } else { /* failed the ISP abort */
3024 ha
->flags
.online
= 1;
3025 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3026 if (ha
->isp_abort_cnt
== 0) {
3027 qla_printk(KERN_WARNING
, ha
,
3028 "ISP error recovery failed - "
3029 "board disabled\n");
3031 * The next call disables the board
3034 ha
->isp_ops
.reset_adapter(ha
);
3035 ha
->flags
.online
= 0;
3036 clear_bit(ISP_ABORT_RETRY
,
3039 } else { /* schedule another ISP abort */
3040 ha
->isp_abort_cnt
--;
3041 DEBUG(printk("qla%ld: ISP abort - "
3042 "retry remaining %d\n",
3043 ha
->host_no
, ha
->isp_abort_cnt
);)
3047 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3048 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3049 "- retrying (%d) more times\n",
3050 ha
->host_no
, ha
->isp_abort_cnt
);)
3051 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3059 qla_printk(KERN_INFO
, ha
,
3060 "qla2x00_abort_isp: **** FAILED ****\n");
3062 DEBUG(printk(KERN_INFO
3063 "qla2x00_abort_isp(%ld): exiting.\n",
3071 * qla2x00_restart_isp
3072 * restarts the ISP after a reset
3075 * ha = adapter block pointer.
3081 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3084 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3085 unsigned long flags
= 0;
3088 /* If firmware needs to be loaded */
3089 if (qla2x00_isp_firmware(ha
)) {
3090 ha
->flags
.online
= 0;
3091 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3092 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3093 status
= qla2x00_setup_chip(ha
);
3097 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3099 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
)) {
3101 * Disable SRAM, Instruction RAM and GP RAM
3104 WRT_REG_WORD(®
->hccr
,
3105 (HCCR_ENABLE_PARITY
+ 0x0));
3106 RD_REG_WORD(®
->hccr
);
3109 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3111 status
= qla2x00_setup_chip(ha
);
3113 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3115 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
)) {
3116 /* Enable proper parity */
3119 WRT_REG_WORD(®
->hccr
,
3120 (HCCR_ENABLE_PARITY
+ 0x1));
3123 * SRAM, Instruction RAM and GP RAM
3126 WRT_REG_WORD(®
->hccr
,
3127 (HCCR_ENABLE_PARITY
+ 0x7));
3128 RD_REG_WORD(®
->hccr
);
3131 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3136 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3137 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3138 if (!(status
= qla2x00_fw_ready(ha
))) {
3139 DEBUG(printk("%s(): Start configure loop, "
3140 "status = %d\n", __func__
, status
);)
3142 /* Issue a marker after FW becomes ready. */
3143 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3145 ha
->flags
.online
= 1;
3146 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3149 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3150 qla2x00_configure_loop(ha
);
3152 } while (!atomic_read(&ha
->loop_down_timer
) &&
3153 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3155 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3158 /* if no cable then assume it's good */
3159 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3162 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3170 * qla2x00_reset_adapter
3174 * ha = adapter block pointer.
3177 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3179 unsigned long flags
= 0;
3180 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3182 ha
->flags
.online
= 0;
3183 ha
->isp_ops
.disable_intrs(ha
);
3185 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3186 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3187 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3188 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3189 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3190 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3194 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3196 unsigned long flags
= 0;
3197 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3199 ha
->flags
.online
= 0;
3200 ha
->isp_ops
.disable_intrs(ha
);
3202 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3203 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3204 RD_REG_DWORD(®
->hccr
);
3205 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3206 RD_REG_DWORD(®
->hccr
);
3207 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3211 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3214 struct init_cb_24xx
*icb
;
3215 struct nvram_24xx
*nv
;
3217 uint8_t *dptr1
, *dptr2
;
3222 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3223 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3225 /* Determine NVRAM starting address. */
3226 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3227 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3228 if (PCI_FUNC(ha
->pdev
->devfn
))
3229 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3231 /* Get NVRAM data and calculate checksum. */
3232 dptr
= (uint32_t *)nv
;
3233 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3235 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3236 chksum
+= le32_to_cpu(*dptr
++);
3238 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3239 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3242 /* Bad NVRAM data, set defaults parameters. */
3243 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3244 || nv
->id
[3] != ' ' ||
3245 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3246 /* Reset NVRAM data. */
3247 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3248 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3249 le16_to_cpu(nv
->nvram_version
));
3250 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3251 "invalid -- WWPN) defaults.\n");
3254 * Set default initialization control block.
3256 memset(nv
, 0, ha
->nvram_size
);
3257 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3258 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3259 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3260 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3261 nv
->exchange_count
= __constant_cpu_to_le16(0);
3262 nv
->hard_address
= __constant_cpu_to_le16(124);
3263 nv
->port_name
[0] = 0x21;
3264 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3265 nv
->port_name
[2] = 0x00;
3266 nv
->port_name
[3] = 0xe0;
3267 nv
->port_name
[4] = 0x8b;
3268 nv
->port_name
[5] = 0x1c;
3269 nv
->port_name
[6] = 0x55;
3270 nv
->port_name
[7] = 0x86;
3271 nv
->node_name
[0] = 0x20;
3272 nv
->node_name
[1] = 0x00;
3273 nv
->node_name
[2] = 0x00;
3274 nv
->node_name
[3] = 0xe0;
3275 nv
->node_name
[4] = 0x8b;
3276 nv
->node_name
[5] = 0x1c;
3277 nv
->node_name
[6] = 0x55;
3278 nv
->node_name
[7] = 0x86;
3279 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3280 nv
->link_down_timeout
= __constant_cpu_to_le16(200);
3281 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3282 nv
->login_timeout
= __constant_cpu_to_le16(0);
3283 nv
->firmware_options_1
=
3284 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3285 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3286 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3287 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3288 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3289 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3290 nv
->reset_delay
= 5;
3291 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3292 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3293 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3298 /* Reset Initialization control block */
3299 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3301 /* Copy 1st segment. */
3302 dptr1
= (uint8_t *)icb
;
3303 dptr2
= (uint8_t *)&nv
->version
;
3304 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3306 *dptr1
++ = *dptr2
++;
3308 icb
->login_retry_count
= nv
->login_retry_count
;
3309 icb
->link_down_timeout
= nv
->link_down_timeout
;
3311 /* Copy 2nd segment. */
3312 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3313 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3314 cnt
= (uint8_t *)&icb
->reserved_3
-
3315 (uint8_t *)&icb
->interrupt_delay_timer
;
3317 *dptr1
++ = *dptr2
++;
3320 * Setup driver NVRAM options.
3322 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3326 strncpy(ha
->model_number
, nv
->model_name
,
3327 sizeof(nv
->model_name
));
3328 st
= en
= ha
->model_number
;
3329 en
+= sizeof(nv
->model_name
) - 1;
3331 if (*en
!= 0x20 && *en
!= 0x00)
3336 index
= (ha
->pdev
->subsystem_device
& 0xff);
3337 if (index
< QLA_MODEL_NAMES
)
3338 ha
->model_desc
= qla2x00_model_desc
[index
];
3340 strcpy(ha
->model_number
, "QLA2462");
3342 /* Prepare nodename */
3343 if ((icb
->firmware_options_1
& BIT_14
) == 0) {
3345 * Firmware will apply the following mask if the nodename was
3348 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3349 icb
->node_name
[0] &= 0xF0;
3352 /* Set host adapter parameters. */
3353 ha
->flags
.disable_risc_code_load
= 0;
3354 ha
->flags
.enable_lip_reset
= 1;
3355 ha
->flags
.enable_lip_full_login
= 1;
3356 ha
->flags
.enable_target_reset
= 1;
3357 ha
->flags
.enable_led_scheme
= 0;
3359 ha
->operating_mode
=
3360 (icb
->firmware_options_2
& (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3362 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3363 sizeof(ha
->fw_seriallink_options24
));
3365 /* save HBA serial number */
3366 ha
->serial0
= icb
->port_name
[5];
3367 ha
->serial1
= icb
->port_name
[6];
3368 ha
->serial2
= icb
->port_name
[7];
3369 ha
->node_name
= icb
->node_name
;
3370 ha
->port_name
= icb
->port_name
;
3372 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3374 /* Set minimum login_timeout to 4 seconds. */
3375 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3376 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3377 if (le16_to_cpu(nv
->login_timeout
) < 4)
3378 nv
->login_timeout
= __constant_cpu_to_le16(4);
3379 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3380 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3382 /* Set minimum RATOV to 200 tenths of a second. */
3385 ha
->loop_reset_delay
= nv
->reset_delay
;
3387 /* Link Down Timeout = 0:
3389 * When Port Down timer expires we will start returning
3390 * I/O's to OS with "DID_NO_CONNECT".
3392 * Link Down Timeout != 0:
3394 * The driver waits for the link to come up after link down
3395 * before returning I/Os to OS with "DID_NO_CONNECT".
3397 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3398 ha
->loop_down_abort_time
=
3399 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3401 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3402 ha
->loop_down_abort_time
=
3403 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3406 /* Need enough time to try and get the port back. */
3407 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3408 if (qlport_down_retry
)
3409 ha
->port_down_retry_count
= qlport_down_retry
;
3411 /* Set login_retry_count */
3412 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3413 if (ha
->port_down_retry_count
==
3414 le16_to_cpu(nv
->port_down_retry_count
) &&
3415 ha
->port_down_retry_count
> 3)
3416 ha
->login_retry_count
= ha
->port_down_retry_count
;
3417 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3418 ha
->login_retry_count
= ha
->port_down_retry_count
;
3419 if (ql2xloginretrycount
)
3420 ha
->login_retry_count
= ql2xloginretrycount
;
3423 DEBUG2_3(printk(KERN_WARNING
3424 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3430 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3434 uint16_t *risc_code
;
3435 unsigned long risc_address
;
3436 unsigned long risc_code_size
;
3440 struct qla_fw_info
*fw_iter
;
3444 /* Load firmware sequences */
3445 fw_iter
= ha
->brd_info
->fw_info
;
3446 *srisc_addr
= *ha
->brd_info
->fw_info
->fwstart
;
3447 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3448 risc_code
= fw_iter
->fwcode
;
3449 risc_code_size
= *fw_iter
->fwlen
;
3451 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
) {
3452 risc_address
= *fw_iter
->fwstart
;
3454 /* Extended address */
3455 risc_address
= *fw_iter
->lfwstart
;
3460 while (risc_code_size
> 0 && !rval
) {
3461 cnt
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3462 if (cnt
> risc_code_size
)
3463 cnt
= risc_code_size
;
3465 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3466 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3467 ha
->host_no
, risc_code
, cnt
, risc_address
));
3469 req_ring
= (uint16_t *)ha
->request_ring
;
3470 for (i
= 0; i
< cnt
; i
++)
3471 req_ring
[i
] = cpu_to_le16(risc_code
[i
]);
3473 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
) {
3474 rval
= qla2x00_load_ram(ha
, ha
->request_dma
,
3477 rval
= qla2x00_load_ram_ext(ha
,
3478 ha
->request_dma
, risc_address
, cnt
);
3481 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3482 "load segment %d of firmware\n",
3484 qla_printk(KERN_WARNING
, ha
,
3485 "[ERROR] Failed to load segment %d of "
3488 qla2x00_dump_regs(ha
);
3493 risc_address
+= cnt
;
3494 risc_code_size
-= cnt
;
3498 /* Next firmware sequence */
3506 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3509 int segments
, fragment
;
3511 uint32_t *dcode
, dlen
;
3518 segments
= FA_RISC_CODE_SEGMENTS
;
3519 faddr
= FA_RISC_CODE_ADDR
;
3520 dcode
= (uint32_t *)ha
->request_ring
;
3523 /* Validate firmware image by checking version. */
3524 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3525 for (i
= 0; i
< 4; i
++)
3526 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3527 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3528 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3529 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3531 qla_printk(KERN_WARNING
, ha
,
3532 "Unable to verify integrity of flash firmware image!\n");
3533 qla_printk(KERN_WARNING
, ha
,
3534 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3535 dcode
[1], dcode
[2], dcode
[3]);
3537 return QLA_FUNCTION_FAILED
;
3540 while (segments
&& rval
== QLA_SUCCESS
) {
3541 /* Read segment's load information. */
3542 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3544 risc_addr
= be32_to_cpu(dcode
[2]);
3545 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3546 risc_size
= be32_to_cpu(dcode
[3]);
3549 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3550 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3551 if (dlen
> risc_size
)
3554 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3555 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3556 ha
->host_no
, risc_addr
, dlen
, faddr
));
3558 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3559 for (i
= 0; i
< dlen
; i
++)
3560 dcode
[i
] = swab32(dcode
[i
]);
3562 rval
= qla2x00_load_ram_ext(ha
, ha
->request_dma
,
3565 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3566 "segment %d of firmware\n", ha
->host_no
,
3568 qla_printk(KERN_WARNING
, ha
,
3569 "[ERROR] Failed to load segment %d of "
3570 "firmware\n", fragment
);
3588 qla24xx_load_risc_hotplug(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3591 int segments
, fragment
;
3592 uint32_t *dcode
, dlen
;
3596 const struct firmware
*fw_entry
;
3597 uint32_t *fwcode
, fwclen
;
3599 if (request_firmware(&fw_entry
, ha
->brd_info
->fw_fname
,
3601 qla_printk(KERN_ERR
, ha
,
3602 "Firmware image file not available: '%s'\n",
3603 ha
->brd_info
->fw_fname
);
3604 return QLA_FUNCTION_FAILED
;
3609 segments
= FA_RISC_CODE_SEGMENTS
;
3610 dcode
= (uint32_t *)ha
->request_ring
;
3612 fwcode
= (uint32_t *)fw_entry
->data
;
3615 /* Validate firmware image by checking version. */
3616 if (fw_entry
->size
< 8 * sizeof(uint32_t)) {
3617 qla_printk(KERN_WARNING
, ha
,
3618 "Unable to verify integrity of flash firmware image "
3619 "(%Zd)!\n", fw_entry
->size
);
3620 goto fail_fw_integrity
;
3622 for (i
= 0; i
< 4; i
++)
3623 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3624 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3625 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3626 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3628 qla_printk(KERN_WARNING
, ha
,
3629 "Unable to verify integrity of flash firmware image!\n");
3630 qla_printk(KERN_WARNING
, ha
,
3631 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3632 dcode
[1], dcode
[2], dcode
[3]);
3633 goto fail_fw_integrity
;
3636 while (segments
&& rval
== QLA_SUCCESS
) {
3637 risc_addr
= be32_to_cpu(fwcode
[2]);
3638 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3639 risc_size
= be32_to_cpu(fwcode
[3]);
3641 /* Validate firmware image size. */
3642 fwclen
+= risc_size
* sizeof(uint32_t);
3643 if (fw_entry
->size
< fwclen
) {
3644 qla_printk(KERN_WARNING
, ha
,
3645 "Unable to verify integrity of flash firmware "
3646 "image (%Zd)!\n", fw_entry
->size
);
3647 goto fail_fw_integrity
;
3651 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3652 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3653 if (dlen
> risc_size
)
3656 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3657 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3660 for (i
= 0; i
< dlen
; i
++)
3661 dcode
[i
] = swab32(fwcode
[i
]);
3663 rval
= qla2x00_load_ram_ext(ha
, ha
->request_dma
,
3666 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3667 "segment %d of firmware\n", ha
->host_no
,
3669 qla_printk(KERN_WARNING
, ha
,
3670 "[ERROR] Failed to load segment %d of "
3671 "firmware\n", fragment
);
3685 release_firmware(fw_entry
);
3690 release_firmware(fw_entry
);
3691 return QLA_FUNCTION_FAILED
;