2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
26 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
27 static int qla2x00_setup_chip(scsi_qla_host_t
*);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
29 static int qla2x00_init_rings(scsi_qla_host_t
*);
30 static int qla2x00_fw_ready(scsi_qla_host_t
*);
31 static int qla2x00_configure_hba(scsi_qla_host_t
*);
32 static int qla2x00_configure_loop(scsi_qla_host_t
*);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
34 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
36 static int qla2x00_device_resync(scsi_qla_host_t
*);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
40 static int qla2x00_restart_isp(scsi_qla_host_t
*);
42 /****************************************************************************/
43 /* QLogic ISP2x00 Hardware Support Functions. */
44 /****************************************************************************/
47 * qla2x00_initialize_adapter
51 * ha = adapter block pointer.
57 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
60 uint8_t restart_risc
= 0;
64 /* Clear adapter flags. */
66 ha
->flags
.reset_active
= 0;
67 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
68 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
71 ha
->flags
.management_server_logged_in
= 0;
72 ha
->marker_needed
= 0;
74 ha
->isp_abort_cnt
= 0;
75 ha
->beacon_blink_led
= 0;
76 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
78 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
79 rval
= ha
->isp_ops
.pci_config(ha
);
81 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
86 ha
->isp_ops
.reset_chip(ha
);
88 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
90 ha
->isp_ops
.nvram_config(ha
);
92 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
96 * Try to configure the loop.
101 /* If firmware needs to be loaded */
102 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
103 if ((rval
= ha
->isp_ops
.chip_diag(ha
)) == QLA_SUCCESS
) {
104 rval
= qla2x00_setup_chip(ha
);
108 if (rval
== QLA_SUCCESS
&&
109 (rval
= qla2x00_init_rings(ha
)) == QLA_SUCCESS
) {
110 check_fw_ready_again
:
112 * Wait for a successful LIP up to a maximum
113 * of (in seconds): RISC login timeout value,
114 * RISC retry count value, and port down retry
115 * value OR a minimum of 4 seconds OR If no
116 * cable, only 5 seconds.
118 rval
= qla2x00_fw_ready(ha
);
119 if (rval
== QLA_SUCCESS
) {
120 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
122 /* Issue a marker after FW becomes ready. */
123 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
126 * Wait at most MAX_TARGET RSCNs for a stable
131 clear_bit(LOOP_RESYNC_NEEDED
,
133 rval
= qla2x00_configure_loop(ha
);
135 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
142 * If loop state change while we were
143 * discoverying devices then wait for
147 if (atomic_read(&ha
->loop_state
) !=
148 LOOP_READY
&& retry
--) {
149 goto check_fw_ready_again
;
152 } while (!atomic_read(&ha
->loop_down_timer
) &&
155 (test_bit(LOOP_RESYNC_NEEDED
,
159 rval
= QLA_FUNCTION_FAILED
;
160 } else if (ha
->device_flags
& DFLG_NO_CABLE
)
161 /* If no cable, then all is good. */
164 } while (restart_risc
&& retry
--);
166 if (rval
== QLA_SUCCESS
) {
167 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
168 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
169 ha
->marker_needed
= 0;
171 ha
->flags
.online
= 1;
173 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
180 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
183 * Returns 0 on success.
186 qla2100_pci_config(scsi_qla_host_t
*ha
)
191 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
193 pci_set_master(ha
->pdev
);
195 if (pci_set_mwi(ha
->pdev
))
196 mwi
= PCI_COMMAND_INVALIDATE
;
197 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
199 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
200 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
201 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
203 /* Reset expansion ROM address decode enable */
204 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
205 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
206 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
208 /* Get PCI bus information. */
209 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
210 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
211 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
217 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
220 * Returns 0 on success.
223 qla2300_pci_config(scsi_qla_host_t
*ha
)
227 unsigned long flags
= 0;
229 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
231 pci_set_master(ha
->pdev
);
233 if (pci_set_mwi(ha
->pdev
))
234 mwi
= PCI_COMMAND_INVALIDATE
;
235 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
237 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
238 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
240 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
241 w
&= ~PCI_COMMAND_INTX_DISABLE
;
244 * If this is a 2300 card and not 2312, reset the
245 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
246 * the 2310 also reports itself as a 2300 so we need to get the
247 * fb revision level -- a 6 indicates it really is a 2300 and
250 if (IS_QLA2300(ha
)) {
251 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
254 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
255 for (cnt
= 0; cnt
< 30000; cnt
++) {
256 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
262 /* Select FPM registers. */
263 WRT_REG_WORD(®
->ctrl_status
, 0x20);
264 RD_REG_WORD(®
->ctrl_status
);
266 /* Get the fb rev level */
267 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
269 if (ha
->fb_rev
== FPM_2300
)
270 w
&= ~PCI_COMMAND_INVALIDATE
;
272 /* Deselect FPM registers. */
273 WRT_REG_WORD(®
->ctrl_status
, 0x0);
274 RD_REG_WORD(®
->ctrl_status
);
276 /* Release RISC module. */
277 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
278 for (cnt
= 0; cnt
< 30000; cnt
++) {
279 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
285 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
287 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
289 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
291 /* Reset expansion ROM address decode enable */
292 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
293 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
294 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
296 /* Get PCI bus information. */
297 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
298 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
299 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
305 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
308 * Returns 0 on success.
311 qla24xx_pci_config(scsi_qla_host_t
*ha
)
315 unsigned long flags
= 0;
316 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
317 int pcix_cmd_reg
, pcie_dctl_reg
;
319 pci_set_master(ha
->pdev
);
321 if (pci_set_mwi(ha
->pdev
))
322 mwi
= PCI_COMMAND_INVALIDATE
;
323 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
325 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
326 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
327 w
&= ~PCI_COMMAND_INTX_DISABLE
;
328 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
330 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
332 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
333 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
337 pcix_cmd_reg
+= PCI_X_CMD
;
338 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
339 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
341 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
344 /* PCIe -- adjust Maximum Read Request Size (2048). */
345 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
349 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
350 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
351 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
353 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
356 /* Reset expansion ROM address decode enable */
357 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
358 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
359 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
361 /* Get PCI bus information. */
362 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
363 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
364 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
370 * qla2x00_isp_firmware() - Choose firmware image.
373 * Returns 0 on success.
376 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
380 /* Assume loading risc code */
381 rval
= QLA_FUNCTION_FAILED
;
383 if (ha
->flags
.disable_risc_code_load
) {
384 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
386 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
388 /* Verify checksum of loaded RISC code. */
389 rval
= qla2x00_verify_checksum(ha
,
390 IS_QLA24XX(ha
) || IS_QLA54XX(ha
) ? RISC_SADDRESS
:
391 *ha
->brd_info
->fw_info
[0].fwstart
);
395 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
403 * qla2x00_reset_chip() - Reset ISP chip.
406 * Returns 0 on success.
409 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
411 unsigned long flags
= 0;
412 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
414 unsigned long mbx_flags
= 0;
417 ha
->isp_ops
.disable_intrs(ha
);
419 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
421 /* Turn off master enable */
423 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
424 cmd
&= ~PCI_COMMAND_MASTER
;
425 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
427 if (!IS_QLA2100(ha
)) {
429 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
430 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
431 for (cnt
= 0; cnt
< 30000; cnt
++) {
432 if ((RD_REG_WORD(®
->hccr
) &
433 HCCR_RISC_PAUSE
) != 0)
438 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
442 /* Select FPM registers. */
443 WRT_REG_WORD(®
->ctrl_status
, 0x20);
444 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
446 /* FPM Soft Reset. */
447 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
448 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
450 /* Toggle Fpm Reset. */
451 if (!IS_QLA2200(ha
)) {
452 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
453 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
456 /* Select frame buffer registers. */
457 WRT_REG_WORD(®
->ctrl_status
, 0x10);
458 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
460 /* Reset frame buffer FIFOs. */
461 if (IS_QLA2200(ha
)) {
462 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
463 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
465 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
467 /* Read back fb_cmd until zero or 3 seconds max */
468 for (cnt
= 0; cnt
< 3000; cnt
++) {
469 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
475 /* Select RISC module registers. */
476 WRT_REG_WORD(®
->ctrl_status
, 0);
477 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
479 /* Reset RISC processor. */
480 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
481 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
483 /* Release RISC processor. */
484 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
485 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
488 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
489 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
491 /* Reset ISP chip. */
492 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
494 /* Wait for RISC to recover from reset. */
495 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
497 * It is necessary to for a delay here since the card doesn't
498 * respond to PCI reads during a reset. On some architectures
499 * this will result in an MCA.
502 for (cnt
= 30000; cnt
; cnt
--) {
503 if ((RD_REG_WORD(®
->ctrl_status
) &
504 CSR_ISP_SOFT_RESET
) == 0)
511 /* Reset RISC processor. */
512 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
514 WRT_REG_WORD(®
->semaphore
, 0);
516 /* Release RISC processor. */
517 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
518 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
520 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
521 for (cnt
= 0; cnt
< 30000; cnt
++) {
522 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
523 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
525 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
) {
526 if (!(test_bit(ABORT_ISP_ACTIVE
,
528 spin_unlock_irqrestore(
529 &ha
->mbx_reg_lock
, mbx_flags
);
533 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
534 spin_unlock_irqrestore(&ha
->mbx_reg_lock
,
542 /* Turn on master enable */
543 cmd
|= PCI_COMMAND_MASTER
;
544 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
546 /* Disable RISC pause on FPM parity error. */
547 if (!IS_QLA2100(ha
)) {
548 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
549 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
552 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
556 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
559 * Returns 0 on success.
562 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
564 unsigned long flags
= 0;
565 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
569 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
572 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
573 for (cnt
= 0; cnt
< 30000; cnt
++) {
574 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
580 WRT_REG_DWORD(®
->ctrl_status
,
581 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
582 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
585 /* Wait for firmware to complete NVRAM accesses. */
586 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
587 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
589 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
593 /* Wait for soft-reset to complete. */
594 d2
= RD_REG_DWORD(®
->ctrl_status
);
595 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
597 d2
= RD_REG_DWORD(®
->ctrl_status
);
601 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
602 RD_REG_DWORD(®
->hccr
);
604 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
605 RD_REG_DWORD(®
->hccr
);
607 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
608 RD_REG_DWORD(®
->hccr
);
610 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
611 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
613 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
617 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
621 * qla24xx_reset_chip() - Reset ISP24xx chip.
624 * Returns 0 on success.
627 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
629 ha
->isp_ops
.disable_intrs(ha
);
631 /* Perform RISC reset. */
632 qla24xx_reset_risc(ha
);
636 * qla2x00_chip_diag() - Test chip for proper operation.
639 * Returns 0 on success.
642 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
645 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
646 unsigned long flags
= 0;
651 /* Assume a failed state */
652 rval
= QLA_FUNCTION_FAILED
;
654 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
655 ha
->host_no
, (u_long
)®
->flash_address
));
657 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
659 /* Reset ISP chip. */
660 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
663 * We need to have a delay here since the card will not respond while
664 * in reset causing an MCA on some architectures.
667 data
= qla2x00_debounce_register(®
->ctrl_status
);
668 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
670 data
= RD_REG_WORD(®
->ctrl_status
);
675 goto chip_diag_failed
;
677 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
680 /* Reset RISC processor. */
681 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
682 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
684 /* Workaround for QLA2312 PCI parity error */
685 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
686 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
687 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
689 data
= RD_MAILBOX_REG(ha
, reg
, 0);
696 goto chip_diag_failed
;
698 /* Check product ID of chip */
699 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
701 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
702 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
703 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
704 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
705 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
706 mb
[3] != PROD_ID_3
) {
707 qla_printk(KERN_WARNING
, ha
,
708 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
710 goto chip_diag_failed
;
712 ha
->product_id
[0] = mb
[1];
713 ha
->product_id
[1] = mb
[2];
714 ha
->product_id
[2] = mb
[3];
715 ha
->product_id
[3] = mb
[4];
717 /* Adjust fw RISC transfer size */
718 if (ha
->request_q_length
> 1024)
719 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
721 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
722 ha
->request_q_length
;
724 if (IS_QLA2200(ha
) &&
725 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
726 /* Limit firmware transfer size with a 2200A */
727 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
730 ha
->device_type
|= DT_ISP2200A
;
731 ha
->fw_transfer_size
= 128;
734 /* Wrap Incoming Mailboxes Test. */
735 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
737 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
738 rval
= qla2x00_mbx_reg_test(ha
);
740 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
742 qla_printk(KERN_WARNING
, ha
,
743 "Failed mailbox send register test\n");
746 /* Flag a successful rval */
749 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
753 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
754 "****\n", ha
->host_no
));
756 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
762 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
765 * Returns 0 on success.
768 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
772 /* Perform RISC reset. */
773 qla24xx_reset_risc(ha
);
775 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
777 rval
= qla2x00_mbx_reg_test(ha
);
779 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
781 qla_printk(KERN_WARNING
, ha
,
782 "Failed mailbox send register test\n");
784 /* Flag a successful rval */
792 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
795 ha
->fw_dump24_len
= sizeof(struct qla24xx_fw_dump
);
796 ha
->fw_dump24_len
+= (ha
->fw_memory_size
- 0x100000) * sizeof(uint32_t);
797 ha
->fw_dump24
= vmalloc(ha
->fw_dump24_len
);
799 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware "
800 "dump...\n", ha
->fw_dump24_len
/ 1024);
802 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
803 "firmware dump!!!\n", ha
->fw_dump24_len
/ 1024);
807 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
810 * Returns 0 on success.
813 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
816 uint16_t fw_iocb_cnt
= 0;
817 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
818 dma_addr_t request_dma
;
819 request_t
*request_ring
;
821 /* Valid only on recent ISPs. */
822 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
825 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
826 qla2x00_alloc_fw_dump(ha
);
828 /* Retrieve IOCB counts available to the firmware. */
829 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
832 /* No point in continuing if current settings are sufficient. */
833 if (fw_iocb_cnt
< 1024)
835 if (ha
->request_q_length
>= request_q_length
)
838 /* Attempt to claim larger area for request queue. */
839 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
840 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
842 if (request_ring
== NULL
)
845 /* Resize successful, report extensions. */
846 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
847 (ha
->fw_memory_size
+ 1) / 1024);
848 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
849 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
851 /* Clear old allocations. */
852 dma_free_coherent(&ha
->pdev
->dev
,
853 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
856 /* Begin using larger queue. */
857 ha
->request_q_length
= request_q_length
;
858 ha
->request_ring
= request_ring
;
859 ha
->request_dma
= request_dma
;
863 * qla2x00_setup_chip() - Load and start RISC firmware.
866 * Returns 0 on success.
869 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
872 uint32_t srisc_address
= 0;
874 /* Load firmware sequences */
875 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
876 if (rval
== QLA_SUCCESS
) {
877 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
878 "code.\n", ha
->host_no
));
880 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
881 if (rval
== QLA_SUCCESS
) {
882 /* Start firmware execution. */
883 DEBUG(printk("scsi(%ld): Checksum OK, start "
884 "firmware.\n", ha
->host_no
));
886 rval
= qla2x00_execute_fw(ha
, srisc_address
);
887 /* Retrieve firmware information. */
888 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
889 qla2x00_get_fw_version(ha
,
890 &ha
->fw_major_version
,
891 &ha
->fw_minor_version
,
892 &ha
->fw_subminor_version
,
893 &ha
->fw_attributes
, &ha
->fw_memory_size
);
894 qla2x00_resize_request_q(ha
);
897 DEBUG2(printk(KERN_INFO
898 "scsi(%ld): ISP Firmware failed checksum.\n",
904 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
912 * qla2x00_init_response_q_entries() - Initializes response queue entries.
915 * Beginning of request ring has initialization control block already built
916 * by nvram config routine.
918 * Returns 0 on success.
921 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
926 pkt
= ha
->response_ring_ptr
;
927 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
928 pkt
->signature
= RESPONSE_PROCESSED
;
935 * qla2x00_update_fw_options() - Read and process firmware options.
938 * Returns 0 on success.
941 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
943 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
945 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
946 qla2x00_get_fw_options(ha
, ha
->fw_options
);
948 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
951 /* Serial Link options. */
952 DEBUG3(printk("scsi(%ld): Serial link options:\n",
954 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
955 sizeof(ha
->fw_seriallink_options
)));
957 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
958 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
959 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
962 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
963 emphasis
= (ha
->fw_seriallink_options
[2] &
964 (BIT_4
| BIT_3
)) >> 3;
965 tx_sens
= ha
->fw_seriallink_options
[0] &
966 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
967 rx_sens
= (ha
->fw_seriallink_options
[0] &
968 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
969 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
970 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
973 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
974 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
975 ha
->fw_options
[10] |= BIT_5
|
976 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
977 (tx_sens
& (BIT_1
| BIT_0
));
980 swing
= (ha
->fw_seriallink_options
[2] &
981 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
982 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
983 tx_sens
= ha
->fw_seriallink_options
[1] &
984 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
985 rx_sens
= (ha
->fw_seriallink_options
[1] &
986 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
987 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
988 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
991 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
992 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
993 ha
->fw_options
[11] |= BIT_5
|
994 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
995 (tx_sens
& (BIT_1
| BIT_0
));
999 /* Return command IOCBs without waiting for an ABTS to complete. */
1000 ha
->fw_options
[3] |= BIT_13
;
1003 if (ha
->flags
.enable_led_scheme
)
1004 ha
->fw_options
[2] |= BIT_12
;
1006 /* Detect ISP6312. */
1008 ha
->fw_options
[2] |= BIT_13
;
1010 /* Update firmware options. */
1011 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1015 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1019 /* Update Serial Link options. */
1020 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1023 rval
= qla2x00_set_serdes_params(ha
,
1024 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1025 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1026 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1027 if (rval
!= QLA_SUCCESS
) {
1028 qla_printk(KERN_WARNING
, ha
,
1029 "Unable to update Serial Link options (%x).\n", rval
);
1034 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1036 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1038 /* Setup ring parameters in initialization control block. */
1039 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1040 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1041 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1042 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1043 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1044 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1045 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1046 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1048 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1049 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1050 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1051 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1052 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1056 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1058 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1059 struct init_cb_24xx
*icb
;
1061 /* Setup ring parameters in initialization control block. */
1062 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1063 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1064 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1065 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1066 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1067 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1068 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1069 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1070 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1072 WRT_REG_DWORD(®
->req_q_in
, 0);
1073 WRT_REG_DWORD(®
->req_q_out
, 0);
1074 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1075 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1076 RD_REG_DWORD(®
->rsp_q_out
);
1080 * qla2x00_init_rings() - Initializes firmware.
1083 * Beginning of request ring has initialization control block already built
1084 * by nvram config routine.
1086 * Returns 0 on success.
1089 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1092 unsigned long flags
= 0;
1095 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1097 /* Clear outstanding commands array. */
1098 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1099 ha
->outstanding_cmds
[cnt
] = NULL
;
1101 ha
->current_outstanding_cmd
= 0;
1103 /* Clear RSCN queue. */
1104 ha
->rscn_in_ptr
= 0;
1105 ha
->rscn_out_ptr
= 0;
1107 /* Initialize firmware. */
1108 ha
->request_ring_ptr
= ha
->request_ring
;
1109 ha
->req_ring_index
= 0;
1110 ha
->req_q_cnt
= ha
->request_q_length
;
1111 ha
->response_ring_ptr
= ha
->response_ring
;
1112 ha
->rsp_ring_index
= 0;
1114 /* Initialize response queue entries */
1115 qla2x00_init_response_q_entries(ha
);
1117 ha
->isp_ops
.config_rings(ha
);
1119 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1121 /* Update any ISP specific firmware options before initialization. */
1122 ha
->isp_ops
.update_fw_options(ha
);
1124 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1125 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1127 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1130 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1138 * qla2x00_fw_ready() - Waits for firmware ready.
1141 * Returns 0 on success.
1144 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1147 unsigned long wtime
, mtime
;
1148 uint16_t min_wait
; /* Minimum wait time if loop is down */
1149 uint16_t wait_time
; /* Wait time if loop is coming ready */
1154 /* 20 seconds for loop down. */
1158 * Firmware should take at most one RATOV to login, plus 5 seconds for
1159 * our own processing.
1161 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1162 wait_time
= min_wait
;
1165 /* Min wait time if loop down */
1166 mtime
= jiffies
+ (min_wait
* HZ
);
1168 /* wait time before firmware ready */
1169 wtime
= jiffies
+ (wait_time
* HZ
);
1171 /* Wait for ISP to finish LIP */
1172 if (!ha
->flags
.init_done
)
1173 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1175 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1179 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1180 if (rval
== QLA_SUCCESS
) {
1181 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1182 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1184 if (fw_state
== FSTATE_READY
) {
1185 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1188 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1189 &ha
->login_timeout
, &ha
->r_a_tov
);
1195 rval
= QLA_FUNCTION_FAILED
;
1197 if (atomic_read(&ha
->loop_down_timer
) &&
1198 (fw_state
>= FSTATE_LOSS_OF_SYNC
||
1199 fw_state
== FSTATE_WAIT_AL_PA
)) {
1200 /* Loop down. Timeout on min_wait for states
1201 * other than Wait for Login.
1203 if (time_after_eq(jiffies
, mtime
)) {
1204 qla_printk(KERN_INFO
, ha
,
1205 "Cable is unplugged...\n");
1207 ha
->device_flags
|= DFLG_NO_CABLE
;
1212 /* Mailbox cmd failed. Timeout on min_wait. */
1213 if (time_after_eq(jiffies
, mtime
))
1217 if (time_after_eq(jiffies
, wtime
))
1220 /* Delay for a while */
1223 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1224 ha
->host_no
, fw_state
, jiffies
));
1227 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1228 ha
->host_no
, fw_state
, jiffies
));
1231 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1239 * qla2x00_configure_hba
1240 * Setup adapter context.
1243 * ha = adapter state pointer.
1252 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1260 char connect_type
[22];
1262 /* Get host addresses. */
1263 rval
= qla2x00_get_adapter_id(ha
,
1264 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1265 if (rval
!= QLA_SUCCESS
) {
1266 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1267 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1268 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1269 __func__
, ha
->host_no
));
1271 qla_printk(KERN_WARNING
, ha
,
1272 "ERROR -- Unable to get host loop ID.\n");
1273 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1279 qla_printk(KERN_INFO
, ha
,
1280 "Cannot get topology - retrying.\n");
1281 return (QLA_FUNCTION_FAILED
);
1284 ha
->loop_id
= loop_id
;
1287 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1288 ha
->operating_mode
= LOOP
;
1292 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1294 ha
->current_topology
= ISP_CFG_NL
;
1295 strcpy(connect_type
, "(Loop)");
1299 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1301 ha
->current_topology
= ISP_CFG_FL
;
1302 strcpy(connect_type
, "(FL_Port)");
1306 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1308 ha
->operating_mode
= P2P
;
1309 ha
->current_topology
= ISP_CFG_N
;
1310 strcpy(connect_type
, "(N_Port-to-N_Port)");
1314 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1316 ha
->operating_mode
= P2P
;
1317 ha
->current_topology
= ISP_CFG_F
;
1318 strcpy(connect_type
, "(F_Port)");
1322 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1324 ha
->host_no
, topo
));
1325 ha
->current_topology
= ISP_CFG_NL
;
1326 strcpy(connect_type
, "(Loop)");
1330 /* Save Host port and loop ID. */
1331 /* byte order - Big Endian */
1332 ha
->d_id
.b
.domain
= domain
;
1333 ha
->d_id
.b
.area
= area
;
1334 ha
->d_id
.b
.al_pa
= al_pa
;
1336 if (!ha
->flags
.init_done
)
1337 qla_printk(KERN_INFO
, ha
,
1338 "Topology - %s, Host Loop address 0x%x\n",
1339 connect_type
, ha
->loop_id
);
1342 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1344 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1351 * NVRAM configuration for ISP 2xxx
1354 * ha = adapter block pointer.
1357 * initialization control block in response_ring
1358 * host adapters parameters in host adapter block
1364 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1369 uint8_t *dptr1
, *dptr2
;
1370 init_cb_t
*icb
= ha
->init_cb
;
1371 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1372 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1373 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1377 /* Determine NVRAM starting address. */
1378 ha
->nvram_size
= sizeof(nvram_t
);
1380 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1381 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1382 ha
->nvram_base
= 0x80;
1384 /* Get NVRAM data and calculate checksum. */
1385 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1386 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1389 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1390 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1393 /* Bad NVRAM data, set defaults parameters. */
1394 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1395 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1396 /* Reset NVRAM data. */
1397 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1398 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1400 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1401 "invalid -- WWPN) defaults.\n");
1404 * Set default initialization control block.
1406 memset(nv
, 0, ha
->nvram_size
);
1407 nv
->parameter_block_version
= ICB_VERSION
;
1409 if (IS_QLA23XX(ha
)) {
1410 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1411 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1412 nv
->add_firmware_options
[0] = BIT_5
;
1413 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1414 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1415 nv
->special_options
[1] = BIT_7
;
1416 } else if (IS_QLA2200(ha
)) {
1417 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1418 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1419 nv
->add_firmware_options
[0] = BIT_5
;
1420 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1421 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1422 } else if (IS_QLA2100(ha
)) {
1423 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1424 nv
->firmware_options
[1] = BIT_5
;
1425 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1428 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1429 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1430 nv
->retry_count
= 8;
1431 nv
->retry_delay
= 1;
1433 nv
->port_name
[0] = 33;
1434 nv
->port_name
[3] = 224;
1435 nv
->port_name
[4] = 139;
1437 nv
->login_timeout
= 4;
1440 * Set default host adapter parameters
1442 nv
->host_p
[1] = BIT_2
;
1443 nv
->reset_delay
= 5;
1444 nv
->port_down_retry_count
= 8;
1445 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1446 nv
->link_down_timeout
= 60;
1451 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1453 * The SN2 does not provide BIOS emulation which means you can't change
1454 * potentially bogus BIOS settings. Force the use of default settings
1455 * for link rate and frame size. Hope that the rest of the settings
1458 if (ia64_platform_is("sn2")) {
1459 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1461 nv
->special_options
[1] = BIT_7
;
1465 /* Reset Initialization control block */
1466 memset(icb
, 0, ha
->init_cb_size
);
1469 * Setup driver NVRAM options.
1471 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1472 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1473 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1474 nv
->firmware_options
[1] &= ~BIT_4
;
1476 if (IS_QLA23XX(ha
)) {
1477 nv
->firmware_options
[0] |= BIT_2
;
1478 nv
->firmware_options
[0] &= ~BIT_3
;
1479 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1481 if (IS_QLA2300(ha
)) {
1482 if (ha
->fb_rev
== FPM_2310
) {
1483 strcpy(ha
->model_number
, "QLA2310");
1485 strcpy(ha
->model_number
, "QLA2300");
1489 memcmp(nv
->model_number
, BINZERO
,
1490 sizeof(nv
->model_number
)) != 0) {
1493 strncpy(ha
->model_number
, nv
->model_number
,
1494 sizeof(nv
->model_number
));
1495 st
= en
= ha
->model_number
;
1496 en
+= sizeof(nv
->model_number
) - 1;
1498 if (*en
!= 0x20 && *en
!= 0x00)
1505 index
= (ha
->pdev
->subsystem_device
& 0xff);
1506 if (index
< QLA_MODEL_NAMES
) {
1507 strcpy(ha
->model_number
,
1508 qla2x00_model_name
[index
* 2]);
1510 qla2x00_model_name
[index
* 2 + 1];
1512 strcpy(ha
->model_number
, "QLA23xx");
1516 } else if (IS_QLA2200(ha
)) {
1517 nv
->firmware_options
[0] |= BIT_2
;
1519 * 'Point-to-point preferred, else loop' is not a safe
1520 * connection mode setting.
1522 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1524 /* Force 'loop preferred, else point-to-point'. */
1525 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1526 nv
->add_firmware_options
[0] |= BIT_5
;
1528 strcpy(ha
->model_number
, "QLA22xx");
1529 } else /*if (IS_QLA2100(ha))*/ {
1530 strcpy(ha
->model_number
, "QLA2100");
1534 * Copy over NVRAM RISC parameter block to initialization control block.
1536 dptr1
= (uint8_t *)icb
;
1537 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1538 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1540 *dptr1
++ = *dptr2
++;
1542 /* Copy 2nd half. */
1543 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1544 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1546 *dptr1
++ = *dptr2
++;
1548 /* Prepare nodename */
1549 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1551 * Firmware will apply the following mask if the nodename was
1554 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1555 icb
->node_name
[0] &= 0xF0;
1559 * Set host adapter parameters.
1561 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1562 /* Always load RISC code on non ISP2[12]00 chips. */
1563 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1564 ha
->flags
.disable_risc_code_load
= 0;
1565 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1566 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1567 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1568 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1570 ha
->operating_mode
=
1571 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1573 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1574 sizeof(ha
->fw_seriallink_options
));
1576 /* save HBA serial number */
1577 ha
->serial0
= icb
->port_name
[5];
1578 ha
->serial1
= icb
->port_name
[6];
1579 ha
->serial2
= icb
->port_name
[7];
1580 ha
->node_name
= icb
->node_name
;
1581 ha
->port_name
= icb
->port_name
;
1583 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1585 ha
->retry_count
= nv
->retry_count
;
1587 /* Set minimum login_timeout to 4 seconds. */
1588 if (nv
->login_timeout
< ql2xlogintimeout
)
1589 nv
->login_timeout
= ql2xlogintimeout
;
1590 if (nv
->login_timeout
< 4)
1591 nv
->login_timeout
= 4;
1592 ha
->login_timeout
= nv
->login_timeout
;
1593 icb
->login_timeout
= nv
->login_timeout
;
1595 /* Set minimum RATOV to 200 tenths of a second. */
1598 ha
->loop_reset_delay
= nv
->reset_delay
;
1600 /* Link Down Timeout = 0:
1602 * When Port Down timer expires we will start returning
1603 * I/O's to OS with "DID_NO_CONNECT".
1605 * Link Down Timeout != 0:
1607 * The driver waits for the link to come up after link down
1608 * before returning I/Os to OS with "DID_NO_CONNECT".
1610 if (nv
->link_down_timeout
== 0) {
1611 ha
->loop_down_abort_time
=
1612 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1614 ha
->link_down_timeout
= nv
->link_down_timeout
;
1615 ha
->loop_down_abort_time
=
1616 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1620 * Need enough time to try and get the port back.
1622 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1623 if (qlport_down_retry
)
1624 ha
->port_down_retry_count
= qlport_down_retry
;
1625 /* Set login_retry_count */
1626 ha
->login_retry_count
= nv
->retry_count
;
1627 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1628 ha
->port_down_retry_count
> 3)
1629 ha
->login_retry_count
= ha
->port_down_retry_count
;
1630 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1631 ha
->login_retry_count
= ha
->port_down_retry_count
;
1632 if (ql2xloginretrycount
)
1633 ha
->login_retry_count
= ql2xloginretrycount
;
1635 icb
->lun_enables
= __constant_cpu_to_le16(0);
1636 icb
->command_resource_count
= 0;
1637 icb
->immediate_notify_resource_count
= 0;
1638 icb
->timeout
= __constant_cpu_to_le16(0);
1640 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1642 icb
->firmware_options
[0] &= ~BIT_3
;
1643 icb
->add_firmware_options
[0] &=
1644 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1645 icb
->add_firmware_options
[0] |= BIT_2
;
1646 icb
->response_accumulation_timer
= 3;
1647 icb
->interrupt_delay_timer
= 5;
1649 ha
->flags
.process_response_queue
= 1;
1652 if (!ha
->flags
.init_done
) {
1653 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1654 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1655 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1656 icb
->interrupt_delay_timer
: 2;
1658 icb
->add_firmware_options
[0] &=
1659 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1660 ha
->flags
.process_response_queue
= 0;
1661 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1662 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1664 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1665 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1666 ha
->zio_timer
* 100));
1667 qla_printk(KERN_INFO
, ha
,
1668 "ZIO mode %d enabled; timer delay (%d us).\n",
1669 ha
->zio_mode
, ha
->zio_timer
* 100);
1671 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1672 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1673 ha
->flags
.process_response_queue
= 1;
1678 DEBUG2_3(printk(KERN_WARNING
1679 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1685 qla2x00_rport_add(void *data
)
1687 fc_port_t
*fcport
= data
;
1689 qla2x00_reg_remote_port(fcport
->ha
, fcport
);
1693 qla2x00_rport_del(void *data
)
1695 fc_port_t
*fcport
= data
;
1696 struct fc_rport
*rport
;
1697 unsigned long flags
;
1699 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1700 rport
= fcport
->drport
;
1701 fcport
->drport
= NULL
;
1702 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1704 fc_remote_port_delete(rport
);
1709 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1711 * @flags: allocation flags
1713 * Returns a pointer to the allocated fcport, or NULL, if none available.
1716 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1720 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1724 /* Setup fcport template structure. */
1725 memset(fcport
, 0, sizeof (fc_port_t
));
1727 fcport
->port_type
= FCT_UNKNOWN
;
1728 fcport
->loop_id
= FC_NO_LOOP_ID
;
1729 fcport
->iodesc_idx_sent
= IODESC_INVALID_INDEX
;
1730 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1731 fcport
->flags
= FCF_RLC_SUPPORT
;
1732 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1733 spin_lock_init(&fcport
->rport_lock
);
1734 INIT_WORK(&fcport
->rport_add_work
, qla2x00_rport_add
, fcport
);
1735 INIT_WORK(&fcport
->rport_del_work
, qla2x00_rport_del
, fcport
);
1741 * qla2x00_configure_loop
1742 * Updates Fibre Channel Device Database with what is actually on loop.
1745 * ha = adapter block pointer.
1750 * 2 = database was full and device was not configured.
1753 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1756 unsigned long flags
, save_flags
;
1760 /* Get Initiator ID */
1761 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1762 rval
= qla2x00_configure_hba(ha
);
1763 if (rval
!= QLA_SUCCESS
) {
1764 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1770 save_flags
= flags
= ha
->dpc_flags
;
1771 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1772 ha
->host_no
, flags
));
1775 * If we have both an RSCN and PORT UPDATE pending then handle them
1776 * both at the same time.
1778 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1779 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1781 /* Determine what we need to do */
1782 if (ha
->current_topology
== ISP_CFG_FL
&&
1783 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1785 ha
->flags
.rscn_queue_overflow
= 1;
1786 set_bit(RSCN_UPDATE
, &flags
);
1788 } else if (ha
->current_topology
== ISP_CFG_F
&&
1789 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1791 ha
->flags
.rscn_queue_overflow
= 1;
1792 set_bit(RSCN_UPDATE
, &flags
);
1793 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1795 } else if (!ha
->flags
.online
||
1796 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1798 ha
->flags
.rscn_queue_overflow
= 1;
1799 set_bit(RSCN_UPDATE
, &flags
);
1800 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1803 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1804 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1805 rval
= QLA_FUNCTION_FAILED
;
1807 rval
= qla2x00_configure_local_loop(ha
);
1811 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1812 if (LOOP_TRANSITION(ha
)) {
1813 rval
= QLA_FUNCTION_FAILED
;
1815 rval
= qla2x00_configure_fabric(ha
);
1819 if (rval
== QLA_SUCCESS
) {
1820 if (atomic_read(&ha
->loop_down_timer
) ||
1821 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1822 rval
= QLA_FUNCTION_FAILED
;
1824 atomic_set(&ha
->loop_state
, LOOP_READY
);
1826 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1831 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1832 __func__
, ha
->host_no
));
1834 DEBUG3(printk("%s: exiting normally\n", __func__
));
1837 /* Restore state if a resync event occured during processing */
1838 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1839 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1840 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1841 if (test_bit(RSCN_UPDATE
, &save_flags
))
1842 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1851 * qla2x00_configure_local_loop
1852 * Updates Fibre Channel Device Database with local loop devices.
1855 * ha = adapter block pointer.
1861 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1866 fc_port_t
*fcport
, *new_fcport
;
1872 uint8_t domain
, area
, al_pa
;
1876 entries
= MAX_FIBRE_DEVICES
;
1878 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1879 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1881 /* Get list of logged in devices. */
1882 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1883 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1885 if (rval
!= QLA_SUCCESS
)
1886 goto cleanup_allocation
;
1888 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1889 ha
->host_no
, entries
));
1890 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1891 entries
* sizeof(struct gid_list_info
)));
1893 /* Allocate temporary fcport for any new fcports discovered. */
1894 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1895 if (new_fcport
== NULL
) {
1896 rval
= QLA_MEMORY_ALLOC_FAILED
;
1897 goto cleanup_allocation
;
1899 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1902 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1904 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1905 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1906 fcport
->port_type
!= FCT_BROADCAST
&&
1907 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1909 DEBUG(printk("scsi(%ld): Marking port lost, "
1911 ha
->host_no
, fcport
->loop_id
));
1913 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1914 fcport
->flags
&= ~FCF_FARP_DONE
;
1918 /* Add devices to port list. */
1919 id_iter
= (char *)ha
->gid_list
;
1920 for (index
= 0; index
< entries
; index
++) {
1921 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1922 area
= ((struct gid_list_info
*)id_iter
)->area
;
1923 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1924 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1925 loop_id
= (uint16_t)
1926 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1928 loop_id
= le16_to_cpu(
1929 ((struct gid_list_info
*)id_iter
)->loop_id
);
1930 id_iter
+= ha
->gid_list_info_size
;
1932 /* Bypass reserved domain fields. */
1933 if ((domain
& 0xf0) == 0xf0)
1936 /* Bypass if not same domain and area of adapter. */
1937 if (area
&& domain
&&
1938 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
1941 /* Bypass invalid local loop ID. */
1942 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1945 /* Fill in member data. */
1946 new_fcport
->d_id
.b
.domain
= domain
;
1947 new_fcport
->d_id
.b
.area
= area
;
1948 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1949 new_fcport
->loop_id
= loop_id
;
1950 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1951 if (rval2
!= QLA_SUCCESS
) {
1952 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1953 "information -- get_port_database=%x, "
1955 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1956 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1958 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
1962 /* Check for matching device in port list. */
1965 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1966 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
1970 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
1971 FCF_PERSISTENT_BOUND
);
1972 fcport
->loop_id
= new_fcport
->loop_id
;
1973 fcport
->port_type
= new_fcport
->port_type
;
1974 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
1975 memcpy(fcport
->node_name
, new_fcport
->node_name
,
1983 /* New device, add to fcports list. */
1984 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
1985 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
1987 /* Allocate a new replacement fcport. */
1988 fcport
= new_fcport
;
1989 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1990 if (new_fcport
== NULL
) {
1991 rval
= QLA_MEMORY_ALLOC_FAILED
;
1992 goto cleanup_allocation
;
1994 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1997 qla2x00_update_fcport(ha
, fcport
);
2005 if (rval
!= QLA_SUCCESS
) {
2006 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2007 "rval=%x\n", ha
->host_no
, rval
));
2011 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2012 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2019 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2023 qla2x00_mark_all_devices_lost(ha
, 0);
2024 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2025 if (fcport
->port_type
!= FCT_TARGET
)
2028 qla2x00_update_fcport(ha
, fcport
);
2033 * qla2x00_update_fcport
2034 * Updates device on list.
2037 * ha = adapter block pointer.
2038 * fcport = port structure pointer.
2048 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2051 fcport
->login_retry
= 0;
2052 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2054 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2056 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2058 if (fcport
->port_type
== FCT_INITIATOR
||
2059 fcport
->port_type
== FCT_BROADCAST
)
2060 fcport
->device_type
= TYPE_PROCESSOR
;
2062 atomic_set(&fcport
->state
, FCS_ONLINE
);
2064 if (ha
->flags
.init_done
)
2065 qla2x00_reg_remote_port(ha
, fcport
);
2069 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2071 struct fc_rport_identifiers rport_ids
;
2072 struct fc_rport
*rport
;
2073 unsigned long flags
;
2076 qla2x00_rport_del(fcport
);
2080 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2081 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2082 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2083 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2084 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2085 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2087 qla_printk(KERN_WARNING
, ha
,
2088 "Unable to allocate fc remote port!\n");
2091 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2092 fcport
->rport
= rport
;
2093 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2094 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2096 rport
->supported_classes
= fcport
->supported_classes
;
2098 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2099 if (fcport
->port_type
== FCT_INITIATOR
)
2100 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2101 if (fcport
->port_type
== FCT_TARGET
)
2102 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2103 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2105 if (rport
->scsi_target_id
!= -1 &&
2106 rport
->scsi_target_id
< ha
->host
->max_id
)
2107 fcport
->os_target_id
= rport
->scsi_target_id
;
2111 * qla2x00_configure_fabric
2112 * Setup SNS devices with loop ID's.
2115 * ha = adapter block pointer.
2122 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2125 fc_port_t
*fcport
, *fcptemp
;
2126 uint16_t next_loopid
;
2127 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2129 LIST_HEAD(new_fcports
);
2131 /* If FL port exists, then SNS is present */
2132 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2133 loop_id
= NPH_F_PORT
;
2135 loop_id
= SNS_FL_PORT
;
2136 rval
= qla2x00_get_port_name(ha
, loop_id
, NULL
, 0);
2137 if (rval
!= QLA_SUCCESS
) {
2138 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2139 "Port\n", ha
->host_no
));
2141 ha
->device_flags
&= ~SWITCH_FOUND
;
2142 return (QLA_SUCCESS
);
2145 /* Mark devices that need re-synchronization. */
2146 rval2
= qla2x00_device_resync(ha
);
2147 if (rval2
== QLA_RSCNS_HANDLED
) {
2148 /* No point doing the scan, just continue. */
2149 return (QLA_SUCCESS
);
2153 if (ql2xfdmienable
&&
2154 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2155 qla2x00_fdmi_register(ha
);
2157 /* Ensure we are logged into the SNS. */
2158 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2161 loop_id
= SIMPLE_NAME_SERVER
;
2162 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2163 0xfc, mb
, BIT_1
| BIT_0
);
2164 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2165 DEBUG2(qla_printk(KERN_INFO
, ha
,
2166 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2167 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2168 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2169 return (QLA_SUCCESS
);
2172 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2173 if (qla2x00_rft_id(ha
)) {
2175 DEBUG2(printk("scsi(%ld): Register FC-4 "
2176 "TYPE failed.\n", ha
->host_no
));
2178 if (qla2x00_rff_id(ha
)) {
2180 DEBUG2(printk("scsi(%ld): Register FC-4 "
2181 "Features failed.\n", ha
->host_no
));
2183 if (qla2x00_rnn_id(ha
)) {
2185 DEBUG2(printk("scsi(%ld): Register Node Name "
2186 "failed.\n", ha
->host_no
));
2187 } else if (qla2x00_rsnn_nn(ha
)) {
2189 DEBUG2(printk("scsi(%ld): Register Symbolic "
2190 "Node Name failed.\n", ha
->host_no
));
2194 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2195 if (rval
!= QLA_SUCCESS
)
2199 * Logout all previous fabric devices marked lost, except
2202 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2203 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2206 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2209 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2210 qla2x00_mark_device_lost(ha
, fcport
,
2211 ql2xplogiabsentdevice
, 0);
2212 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2213 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2214 fcport
->port_type
!= FCT_INITIATOR
&&
2215 fcport
->port_type
!= FCT_BROADCAST
) {
2216 ha
->isp_ops
.fabric_logout(ha
,
2218 fcport
->d_id
.b
.domain
,
2219 fcport
->d_id
.b
.area
,
2220 fcport
->d_id
.b
.al_pa
);
2221 fcport
->loop_id
= FC_NO_LOOP_ID
;
2226 /* Starting free loop ID. */
2227 next_loopid
= ha
->min_external_loopid
;
2230 * Scan through our port list and login entries that need to be
2233 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2234 if (atomic_read(&ha
->loop_down_timer
) ||
2235 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2238 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2239 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2242 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2243 fcport
->loop_id
= next_loopid
;
2244 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2245 if (rval
!= QLA_SUCCESS
) {
2246 /* Ran out of IDs to use */
2250 /* Login and update database */
2251 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2254 /* Exit if out of loop IDs. */
2255 if (rval
!= QLA_SUCCESS
) {
2260 * Login and add the new devices to our port list.
2262 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2263 if (atomic_read(&ha
->loop_down_timer
) ||
2264 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2267 /* Find a new loop ID to use. */
2268 fcport
->loop_id
= next_loopid
;
2269 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2270 if (rval
!= QLA_SUCCESS
) {
2271 /* Ran out of IDs to use */
2275 /* Remove device from the new list and add it to DB */
2276 list_del(&fcport
->list
);
2277 list_add_tail(&fcport
->list
, &ha
->fcports
);
2279 /* Login and update database */
2280 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2284 /* Free all new device structures not processed. */
2285 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2286 list_del(&fcport
->list
);
2291 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2292 "rval=%d\n", ha
->host_no
, rval
));
2300 * qla2x00_find_all_fabric_devs
2303 * ha = adapter block pointer.
2304 * dev = database device entry pointer.
2313 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2317 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2322 int first_dev
, last_dev
;
2323 port_id_t wrap
, nxt_d_id
;
2327 /* Try GID_PT to get device list, else GAN. */
2328 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2331 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2332 "on GA_NXT\n", ha
->host_no
));
2334 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2335 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2338 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2341 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2348 /* Allocate temporary fcport for any new fcports discovered. */
2349 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2350 if (new_fcport
== NULL
) {
2352 return (QLA_MEMORY_ALLOC_FAILED
);
2354 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2356 /* Set start port ID scan at adapter ID. */
2360 /* Starting free loop ID. */
2361 loop_id
= ha
->min_external_loopid
;
2362 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2363 if (qla2x00_is_reserved_id(ha
, loop_id
))
2366 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2371 wrap
.b24
= new_fcport
->d_id
.b24
;
2373 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2374 memcpy(new_fcport
->node_name
,
2375 swl
[swl_idx
].node_name
, WWN_SIZE
);
2376 memcpy(new_fcport
->port_name
,
2377 swl
[swl_idx
].port_name
, WWN_SIZE
);
2379 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2385 /* Send GA_NXT to the switch */
2386 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2387 if (rval
!= QLA_SUCCESS
) {
2388 qla_printk(KERN_WARNING
, ha
,
2389 "SNS scan failed -- assuming zero-entry "
2391 list_for_each_entry_safe(fcport
, fcptemp
,
2392 new_fcports
, list
) {
2393 list_del(&fcport
->list
);
2401 /* If wrap on switch device list, exit. */
2403 wrap
.b24
= new_fcport
->d_id
.b24
;
2405 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2406 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2407 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2408 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2412 /* Bypass if host adapter. */
2413 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2416 /* Bypass if same domain and area of adapter. */
2417 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2418 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2422 /* Bypass reserved domain fields. */
2423 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2426 /* Locate matching device in database. */
2428 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2429 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2436 * If address the same and state FCS_ONLINE, nothing
2439 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2440 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2445 * If device was not a fabric device before.
2447 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2448 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2449 fcport
->loop_id
= FC_NO_LOOP_ID
;
2450 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2452 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2457 * Port ID changed or device was marked to be updated;
2458 * Log it out if still logged in and mark it for
2461 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2462 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2463 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2464 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2465 fcport
->port_type
!= FCT_INITIATOR
&&
2466 fcport
->port_type
!= FCT_BROADCAST
) {
2467 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2468 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2469 fcport
->d_id
.b
.al_pa
);
2470 fcport
->loop_id
= FC_NO_LOOP_ID
;
2479 /* If device was not in our fcports list, then add it. */
2480 list_add_tail(&new_fcport
->list
, new_fcports
);
2482 /* Allocate a new replacement fcport. */
2483 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2484 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2485 if (new_fcport
== NULL
) {
2487 return (QLA_MEMORY_ALLOC_FAILED
);
2489 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2490 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2496 if (!list_empty(new_fcports
))
2497 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2503 * qla2x00_find_new_loop_id
2504 * Scan through our port list and find a new usable loop ID.
2507 * ha: adapter state pointer.
2508 * dev: port structure pointer.
2511 * qla2x00 local function return status code.
2517 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2522 uint16_t first_loop_id
;
2526 /* Save starting loop ID. */
2527 first_loop_id
= dev
->loop_id
;
2530 /* Skip loop ID if already used by adapter. */
2531 if (dev
->loop_id
== ha
->loop_id
) {
2535 /* Skip reserved loop IDs. */
2536 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2540 /* Reset loop ID if passed the end. */
2541 if (dev
->loop_id
> ha
->last_loop_id
) {
2542 /* first loop ID. */
2543 dev
->loop_id
= ha
->min_external_loopid
;
2546 /* Check for loop ID being already in use. */
2549 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2550 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2551 /* ID possibly in use */
2557 /* If not in use then it is free to use. */
2562 /* ID in use. Try next value. */
2565 /* If wrap around. No free ID to use. */
2566 if (dev
->loop_id
== first_loop_id
) {
2567 dev
->loop_id
= FC_NO_LOOP_ID
;
2568 rval
= QLA_FUNCTION_FAILED
;
2577 * qla2x00_device_resync
2578 * Marks devices in the database that needs resynchronization.
2581 * ha = adapter block pointer.
2587 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2593 uint32_t rscn_entry
;
2594 uint8_t rscn_out_iter
;
2598 rval
= QLA_RSCNS_HANDLED
;
2600 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2601 ha
->flags
.rscn_queue_overflow
) {
2603 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2604 format
= MSB(MSW(rscn_entry
));
2605 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2606 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2607 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2609 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2610 "[%02x/%02x%02x%02x].\n",
2611 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2612 d_id
.b
.area
, d_id
.b
.al_pa
));
2615 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2616 ha
->rscn_out_ptr
= 0;
2618 /* Skip duplicate entries. */
2619 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2620 !ha
->flags
.rscn_queue_overflow
&&
2621 rscn_out_iter
!= ha
->rscn_in_ptr
;
2622 rscn_out_iter
= (rscn_out_iter
==
2623 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2625 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2628 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2629 "entry found at [%d].\n", ha
->host_no
,
2632 ha
->rscn_out_ptr
= rscn_out_iter
;
2635 /* Queue overflow, set switch default case. */
2636 if (ha
->flags
.rscn_queue_overflow
) {
2637 DEBUG(printk("scsi(%ld): device_resync: rscn "
2638 "overflow.\n", ha
->host_no
));
2641 ha
->flags
.rscn_queue_overflow
= 0;
2646 if (ql2xprocessrscn
&&
2647 !IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
2648 !IS_QLA6312(ha
) && !IS_QLA6322(ha
) &&
2649 !IS_QLA24XX(ha
) && !IS_QLA54XX(ha
) &&
2650 ha
->flags
.init_done
) {
2651 /* Handle port RSCN via asyncronous IOCBs */
2652 rval2
= qla2x00_handle_port_rscn(ha
, rscn_entry
,
2654 if (rval2
== QLA_SUCCESS
)
2668 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2674 /* Abort any outstanding IO descriptors. */
2675 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2676 qla2x00_cancel_io_descriptors(ha
);
2678 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2679 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2680 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2681 fcport
->port_type
== FCT_BROADCAST
)
2684 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2686 fcport
->port_type
!= FCT_INITIATOR
) {
2687 qla2x00_mark_device_lost(ha
, fcport
,
2691 fcport
->flags
&= ~FCF_FARP_DONE
;
2698 * qla2x00_fabric_dev_login
2699 * Login fabric target device and update FC port database.
2702 * ha: adapter state pointer.
2703 * fcport: port structure list pointer.
2704 * next_loopid: contains value of a new loop ID that can be used
2705 * by the next login attempt.
2708 * qla2x00 local function return status code.
2714 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2715 uint16_t *next_loopid
)
2724 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2725 if (rval
== QLA_SUCCESS
) {
2726 /* Send an ADISC to tape devices.*/
2728 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2730 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2731 if (rval
!= QLA_SUCCESS
) {
2732 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2733 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2734 fcport
->d_id
.b
.al_pa
);
2735 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2737 qla2x00_update_fcport(ha
, fcport
);
2745 * qla2x00_fabric_login
2746 * Issue fabric login command.
2749 * ha = adapter block pointer.
2750 * device = pointer to FC device type structure.
2753 * 0 - Login successfully
2755 * 2 - Initiator device
2759 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2760 uint16_t *next_loopid
)
2764 uint16_t tmp_loopid
;
2765 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2771 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2772 "for port %02x%02x%02x.\n",
2773 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2774 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2776 /* Login fcport on switch. */
2777 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2778 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2779 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2780 if (mb
[0] == MBS_PORT_ID_USED
) {
2782 * Device has another loop ID. The firmware team
2783 * recommends the driver perform an implicit login with
2784 * the specified ID again. The ID we just used is save
2785 * here so we return with an ID that can be tried by
2789 tmp_loopid
= fcport
->loop_id
;
2790 fcport
->loop_id
= mb
[1];
2792 DEBUG(printk("Fabric Login: port in use - next "
2793 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2794 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2795 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2797 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2802 /* A retry occurred before. */
2803 *next_loopid
= tmp_loopid
;
2806 * No retry occurred before. Just increment the
2807 * ID value for next login.
2809 *next_loopid
= (fcport
->loop_id
+ 1);
2812 if (mb
[1] & BIT_0
) {
2813 fcport
->port_type
= FCT_INITIATOR
;
2815 fcport
->port_type
= FCT_TARGET
;
2816 if (mb
[1] & BIT_1
) {
2817 fcport
->flags
|= FCF_TAPE_PRESENT
;
2822 fcport
->supported_classes
|= FC_COS_CLASS2
;
2824 fcport
->supported_classes
|= FC_COS_CLASS3
;
2828 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2830 * Loop ID already used, try next loop ID.
2833 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2834 if (rval
!= QLA_SUCCESS
) {
2835 /* Ran out of loop IDs to use */
2838 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2840 * Firmware possibly timed out during login. If NO
2841 * retries are left to do then the device is declared
2844 *next_loopid
= fcport
->loop_id
;
2845 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2846 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2847 fcport
->d_id
.b
.al_pa
);
2848 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2854 * unrecoverable / not handled error
2856 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2857 "loop_id=%x jiffies=%lx.\n",
2858 __func__
, ha
->host_no
, mb
[0],
2859 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2860 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2862 *next_loopid
= fcport
->loop_id
;
2863 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2864 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2865 fcport
->d_id
.b
.al_pa
);
2866 fcport
->loop_id
= FC_NO_LOOP_ID
;
2867 fcport
->login_retry
= 0;
2878 * qla2x00_local_device_login
2879 * Issue local device login command.
2882 * ha = adapter block pointer.
2883 * loop_id = loop id of device to login to.
2885 * Returns (Where's the #define!!!!):
2886 * 0 - Login successfully
2891 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2894 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2896 memset(mb
, 0, sizeof(mb
));
2897 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
2898 if (rval
== QLA_SUCCESS
) {
2899 /* Interrogate mailbox registers for any errors */
2900 if (mb
[0] == MBS_COMMAND_ERROR
)
2902 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2903 /* device not in PCB table */
2911 * qla2x00_loop_resync
2912 * Resync with fibre channel devices.
2915 * ha = adapter block pointer.
2921 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2928 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2929 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2930 if (ha
->flags
.online
) {
2931 if (!(rval
= qla2x00_fw_ready(ha
))) {
2932 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2935 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2937 /* Issue a marker after FW becomes ready. */
2938 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
2939 ha
->marker_needed
= 0;
2941 /* Remap devices on Loop. */
2942 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2944 qla2x00_configure_loop(ha
);
2946 } while (!atomic_read(&ha
->loop_down_timer
) &&
2947 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
2949 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
2953 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2954 return (QLA_FUNCTION_FAILED
);
2958 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
2965 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
2971 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2972 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
2975 qla2x00_update_fcport(ha
, fcport
);
2976 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
2980 qla2x00_probe_for_all_luns(ha
);
2984 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
2988 /* Go with deferred removal of rport references. */
2989 list_for_each_entry(fcport
, &ha
->fcports
, list
)
2991 qla2x00_rport_del(fcport
);
2996 * Resets ISP and aborts all outstanding commands.
2999 * ha = adapter block pointer.
3005 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3007 unsigned long flags
= 0;
3012 if (ha
->flags
.online
) {
3013 ha
->flags
.online
= 0;
3014 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3016 qla_printk(KERN_INFO
, ha
,
3017 "Performing ISP error recovery - ha= %p.\n", ha
);
3018 ha
->isp_ops
.reset_chip(ha
);
3020 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3021 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3022 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3023 qla2x00_mark_all_devices_lost(ha
, 0);
3025 if (!atomic_read(&ha
->loop_down_timer
))
3026 atomic_set(&ha
->loop_down_timer
,
3030 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3031 /* Requeue all commands in outstanding command list. */
3032 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3033 sp
= ha
->outstanding_cmds
[cnt
];
3035 ha
->outstanding_cmds
[cnt
] = NULL
;
3037 sp
->cmd
->result
= DID_RESET
<< 16;
3038 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3039 qla2x00_sp_compl(ha
, sp
);
3042 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3044 ha
->isp_ops
.nvram_config(ha
);
3046 if (!qla2x00_restart_isp(ha
)) {
3047 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3049 if (!atomic_read(&ha
->loop_down_timer
)) {
3051 * Issue marker command only when we are going
3052 * to start the I/O .
3054 ha
->marker_needed
= 1;
3057 ha
->flags
.online
= 1;
3059 ha
->isp_ops
.enable_intrs(ha
);
3061 ha
->isp_abort_cnt
= 0;
3062 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3063 } else { /* failed the ISP abort */
3064 ha
->flags
.online
= 1;
3065 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3066 if (ha
->isp_abort_cnt
== 0) {
3067 qla_printk(KERN_WARNING
, ha
,
3068 "ISP error recovery failed - "
3069 "board disabled\n");
3071 * The next call disables the board
3074 ha
->isp_ops
.reset_adapter(ha
);
3075 ha
->flags
.online
= 0;
3076 clear_bit(ISP_ABORT_RETRY
,
3079 } else { /* schedule another ISP abort */
3080 ha
->isp_abort_cnt
--;
3081 DEBUG(printk("qla%ld: ISP abort - "
3082 "retry remaining %d\n",
3083 ha
->host_no
, ha
->isp_abort_cnt
);)
3087 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3088 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3089 "- retrying (%d) more times\n",
3090 ha
->host_no
, ha
->isp_abort_cnt
);)
3091 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3099 qla_printk(KERN_INFO
, ha
,
3100 "qla2x00_abort_isp: **** FAILED ****\n");
3102 DEBUG(printk(KERN_INFO
3103 "qla2x00_abort_isp(%ld): exiting.\n",
3111 * qla2x00_restart_isp
3112 * restarts the ISP after a reset
3115 * ha = adapter block pointer.
3121 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3124 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3125 unsigned long flags
= 0;
3128 /* If firmware needs to be loaded */
3129 if (qla2x00_isp_firmware(ha
)) {
3130 ha
->flags
.online
= 0;
3131 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3132 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3133 status
= qla2x00_setup_chip(ha
);
3137 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3139 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3141 * Disable SRAM, Instruction RAM and GP RAM
3144 WRT_REG_WORD(®
->hccr
,
3145 (HCCR_ENABLE_PARITY
+ 0x0));
3146 RD_REG_WORD(®
->hccr
);
3149 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3151 status
= qla2x00_setup_chip(ha
);
3153 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3155 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3156 /* Enable proper parity */
3159 WRT_REG_WORD(®
->hccr
,
3160 (HCCR_ENABLE_PARITY
+ 0x1));
3163 * SRAM, Instruction RAM and GP RAM
3166 WRT_REG_WORD(®
->hccr
,
3167 (HCCR_ENABLE_PARITY
+ 0x7));
3168 RD_REG_WORD(®
->hccr
);
3171 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3176 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3177 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3178 if (!(status
= qla2x00_fw_ready(ha
))) {
3179 DEBUG(printk("%s(): Start configure loop, "
3180 "status = %d\n", __func__
, status
);)
3182 /* Issue a marker after FW becomes ready. */
3183 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3185 ha
->flags
.online
= 1;
3186 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3189 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3190 qla2x00_configure_loop(ha
);
3192 } while (!atomic_read(&ha
->loop_down_timer
) &&
3193 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3195 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3198 /* if no cable then assume it's good */
3199 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3202 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3210 * qla2x00_reset_adapter
3214 * ha = adapter block pointer.
3217 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3219 unsigned long flags
= 0;
3220 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3222 ha
->flags
.online
= 0;
3223 ha
->isp_ops
.disable_intrs(ha
);
3225 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3226 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3227 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3228 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3229 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3230 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3234 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3236 unsigned long flags
= 0;
3237 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3239 ha
->flags
.online
= 0;
3240 ha
->isp_ops
.disable_intrs(ha
);
3242 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3243 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3244 RD_REG_DWORD(®
->hccr
);
3245 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3246 RD_REG_DWORD(®
->hccr
);
3247 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3251 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3254 struct init_cb_24xx
*icb
;
3255 struct nvram_24xx
*nv
;
3257 uint8_t *dptr1
, *dptr2
;
3262 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3263 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3265 /* Determine NVRAM starting address. */
3266 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3267 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3268 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3269 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3270 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3271 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3272 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3275 /* Get NVRAM data and calculate checksum. */
3276 dptr
= (uint32_t *)nv
;
3277 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3279 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3280 chksum
+= le32_to_cpu(*dptr
++);
3282 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3283 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3286 /* Bad NVRAM data, set defaults parameters. */
3287 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3288 || nv
->id
[3] != ' ' ||
3289 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3290 /* Reset NVRAM data. */
3291 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3292 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3293 le16_to_cpu(nv
->nvram_version
));
3294 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3295 "invalid -- WWPN) defaults.\n");
3298 * Set default initialization control block.
3300 memset(nv
, 0, ha
->nvram_size
);
3301 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3302 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3303 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3304 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3305 nv
->exchange_count
= __constant_cpu_to_le16(0);
3306 nv
->hard_address
= __constant_cpu_to_le16(124);
3307 nv
->port_name
[0] = 0x21;
3308 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3309 nv
->port_name
[2] = 0x00;
3310 nv
->port_name
[3] = 0xe0;
3311 nv
->port_name
[4] = 0x8b;
3312 nv
->port_name
[5] = 0x1c;
3313 nv
->port_name
[6] = 0x55;
3314 nv
->port_name
[7] = 0x86;
3315 nv
->node_name
[0] = 0x20;
3316 nv
->node_name
[1] = 0x00;
3317 nv
->node_name
[2] = 0x00;
3318 nv
->node_name
[3] = 0xe0;
3319 nv
->node_name
[4] = 0x8b;
3320 nv
->node_name
[5] = 0x1c;
3321 nv
->node_name
[6] = 0x55;
3322 nv
->node_name
[7] = 0x86;
3323 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3324 nv
->link_down_timeout
= __constant_cpu_to_le16(200);
3325 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3326 nv
->login_timeout
= __constant_cpu_to_le16(0);
3327 nv
->firmware_options_1
=
3328 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3329 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3330 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3331 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3332 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3333 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3334 nv
->reset_delay
= 5;
3335 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3336 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3337 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3342 /* Reset Initialization control block */
3343 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3345 /* Copy 1st segment. */
3346 dptr1
= (uint8_t *)icb
;
3347 dptr2
= (uint8_t *)&nv
->version
;
3348 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3350 *dptr1
++ = *dptr2
++;
3352 icb
->login_retry_count
= nv
->login_retry_count
;
3353 icb
->link_down_timeout
= nv
->link_down_timeout
;
3355 /* Copy 2nd segment. */
3356 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3357 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3358 cnt
= (uint8_t *)&icb
->reserved_3
-
3359 (uint8_t *)&icb
->interrupt_delay_timer
;
3361 *dptr1
++ = *dptr2
++;
3364 * Setup driver NVRAM options.
3366 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3370 strncpy(ha
->model_number
, nv
->model_name
,
3371 sizeof(nv
->model_name
));
3372 st
= en
= ha
->model_number
;
3373 en
+= sizeof(nv
->model_name
) - 1;
3375 if (*en
!= 0x20 && *en
!= 0x00)
3380 index
= (ha
->pdev
->subsystem_device
& 0xff);
3381 if (index
< QLA_MODEL_NAMES
)
3382 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
3384 strcpy(ha
->model_number
, "QLA2462");
3386 /* Prepare nodename */
3387 if ((icb
->firmware_options_1
& BIT_14
) == 0) {
3389 * Firmware will apply the following mask if the nodename was
3392 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3393 icb
->node_name
[0] &= 0xF0;
3396 /* Set host adapter parameters. */
3397 ha
->flags
.disable_risc_code_load
= 0;
3398 ha
->flags
.enable_lip_reset
= 1;
3399 ha
->flags
.enable_lip_full_login
= 1;
3400 ha
->flags
.enable_target_reset
= 1;
3401 ha
->flags
.enable_led_scheme
= 0;
3403 ha
->operating_mode
=
3404 (icb
->firmware_options_2
& (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3406 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3407 sizeof(ha
->fw_seriallink_options24
));
3409 /* save HBA serial number */
3410 ha
->serial0
= icb
->port_name
[5];
3411 ha
->serial1
= icb
->port_name
[6];
3412 ha
->serial2
= icb
->port_name
[7];
3413 ha
->node_name
= icb
->node_name
;
3414 ha
->port_name
= icb
->port_name
;
3416 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3418 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3420 /* Set minimum login_timeout to 4 seconds. */
3421 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3422 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3423 if (le16_to_cpu(nv
->login_timeout
) < 4)
3424 nv
->login_timeout
= __constant_cpu_to_le16(4);
3425 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3426 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3428 /* Set minimum RATOV to 200 tenths of a second. */
3431 ha
->loop_reset_delay
= nv
->reset_delay
;
3433 /* Link Down Timeout = 0:
3435 * When Port Down timer expires we will start returning
3436 * I/O's to OS with "DID_NO_CONNECT".
3438 * Link Down Timeout != 0:
3440 * The driver waits for the link to come up after link down
3441 * before returning I/Os to OS with "DID_NO_CONNECT".
3443 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3444 ha
->loop_down_abort_time
=
3445 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3447 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3448 ha
->loop_down_abort_time
=
3449 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3452 /* Need enough time to try and get the port back. */
3453 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3454 if (qlport_down_retry
)
3455 ha
->port_down_retry_count
= qlport_down_retry
;
3457 /* Set login_retry_count */
3458 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3459 if (ha
->port_down_retry_count
==
3460 le16_to_cpu(nv
->port_down_retry_count
) &&
3461 ha
->port_down_retry_count
> 3)
3462 ha
->login_retry_count
= ha
->port_down_retry_count
;
3463 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3464 ha
->login_retry_count
= ha
->port_down_retry_count
;
3465 if (ql2xloginretrycount
)
3466 ha
->login_retry_count
= ql2xloginretrycount
;
3469 if (!ha
->flags
.init_done
) {
3470 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3471 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3472 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3473 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3475 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3476 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3477 ha
->flags
.process_response_queue
= 0;
3478 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3479 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3481 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3482 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3483 ha
->zio_timer
* 100));
3484 qla_printk(KERN_INFO
, ha
,
3485 "ZIO mode %d enabled; timer delay (%d us).\n",
3486 ha
->zio_mode
, ha
->zio_timer
* 100);
3488 icb
->firmware_options_2
|= cpu_to_le32(
3489 (uint32_t)ha
->zio_mode
);
3490 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3491 ha
->flags
.process_response_queue
= 1;
3495 DEBUG2_3(printk(KERN_WARNING
3496 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3501 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3504 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3508 uint16_t *risc_code
;
3509 uint32_t risc_addr
, risc_size
;
3511 struct qla_fw_info
*fw_iter
;
3515 /* Load firmware sequences */
3516 fw_iter
= ha
->brd_info
->fw_info
;
3517 *srisc_addr
= *ha
->brd_info
->fw_info
->fwstart
;
3518 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3519 risc_code
= fw_iter
->fwcode
;
3520 risc_size
= *fw_iter
->fwlen
;
3521 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
)
3522 risc_addr
= *fw_iter
->fwstart
;
3524 risc_addr
= *fw_iter
->lfwstart
;
3528 while (risc_size
> 0 && !rval
) {
3529 cnt
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3530 if (cnt
> risc_size
)
3533 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3534 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3535 ha
->host_no
, risc_code
, cnt
, risc_addr
));
3537 req_ring
= (uint16_t *)ha
->request_ring
;
3538 for (i
= 0; i
< cnt
; i
++)
3539 req_ring
[i
] = cpu_to_le16(risc_code
[i
]);
3541 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3544 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3545 "load segment %d of firmware\n",
3547 qla_printk(KERN_WARNING
, ha
,
3548 "[ERROR] Failed to load segment %d of "
3551 qla2x00_dump_regs(ha
);
3561 /* Next firmware sequence */
3568 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3572 uint32_t *risc_code
;
3573 uint32_t risc_addr
, risc_size
;
3575 struct qla_fw_info
*fw_iter
;
3579 /* Load firmware sequences */
3580 fw_iter
= ha
->brd_info
->fw_info
;
3581 *srisc_addr
= *((uint32_t *)fw_iter
->lfwstart
);
3582 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3583 risc_code
= (uint32_t *)fw_iter
->fwcode
;
3584 risc_size
= *((uint32_t *)fw_iter
->fwlen
);
3585 risc_addr
= *((uint32_t *)fw_iter
->lfwstart
);
3589 while (risc_size
> 0 && !rval
) {
3590 cnt
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3591 if (cnt
> risc_size
)
3594 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3595 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3596 ha
->host_no
, risc_code
, cnt
, risc_addr
));
3598 req_ring
= (uint32_t *)ha
->request_ring
;
3599 for (i
= 0; i
< cnt
; i
++)
3600 req_ring
[i
] = cpu_to_le32(risc_code
[i
]);
3602 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3605 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3606 "load segment %d of firmware\n",
3608 qla_printk(KERN_WARNING
, ha
,
3609 "[ERROR] Failed to load segment %d of "
3612 qla2x00_dump_regs(ha
);
3622 /* Next firmware sequence */
3629 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3632 int segments
, fragment
;
3634 uint32_t *dcode
, dlen
;
3641 segments
= FA_RISC_CODE_SEGMENTS
;
3642 faddr
= FA_RISC_CODE_ADDR
;
3643 dcode
= (uint32_t *)ha
->request_ring
;
3646 /* Validate firmware image by checking version. */
3647 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3648 for (i
= 0; i
< 4; i
++)
3649 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3650 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3651 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3652 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3654 qla_printk(KERN_WARNING
, ha
,
3655 "Unable to verify integrity of flash firmware image!\n");
3656 qla_printk(KERN_WARNING
, ha
,
3657 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3658 dcode
[1], dcode
[2], dcode
[3]);
3660 return QLA_FUNCTION_FAILED
;
3663 while (segments
&& rval
== QLA_SUCCESS
) {
3664 /* Read segment's load information. */
3665 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3667 risc_addr
= be32_to_cpu(dcode
[2]);
3668 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3669 risc_size
= be32_to_cpu(dcode
[3]);
3672 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3673 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3674 if (dlen
> risc_size
)
3677 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3678 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3679 ha
->host_no
, risc_addr
, dlen
, faddr
));
3681 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3682 for (i
= 0; i
< dlen
; i
++)
3683 dcode
[i
] = swab32(dcode
[i
]);
3685 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3688 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3689 "segment %d of firmware\n", ha
->host_no
,
3691 qla_printk(KERN_WARNING
, ha
,
3692 "[ERROR] Failed to load segment %d of "
3693 "firmware\n", fragment
);
3710 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3713 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3717 uint16_t *wcode
, *fwcode
;
3718 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3719 struct fw_blob
*blob
;
3721 /* Load firmware blob. */
3722 blob
= qla2x00_request_firmware(ha
);
3724 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3725 return QLA_FUNCTION_FAILED
;
3730 wcode
= (uint16_t *)ha
->request_ring
;
3732 fwcode
= (uint16_t *)blob
->fw
->data
;
3735 /* Validate firmware image by checking version. */
3736 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3737 qla_printk(KERN_WARNING
, ha
,
3738 "Unable to verify integrity of firmware image (%Zd)!\n",
3740 goto fail_fw_integrity
;
3742 for (i
= 0; i
< 4; i
++)
3743 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3744 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3745 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3746 wcode
[2] == 0 && wcode
[3] == 0)) {
3747 qla_printk(KERN_WARNING
, ha
,
3748 "Unable to verify integrity of firmware image!\n");
3749 qla_printk(KERN_WARNING
, ha
,
3750 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3751 wcode
[1], wcode
[2], wcode
[3]);
3752 goto fail_fw_integrity
;
3756 while (*seg
&& rval
== QLA_SUCCESS
) {
3758 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3759 risc_size
= be16_to_cpu(fwcode
[3]);
3761 /* Validate firmware image size. */
3762 fwclen
+= risc_size
* sizeof(uint16_t);
3763 if (blob
->fw
->size
< fwclen
) {
3764 qla_printk(KERN_WARNING
, ha
,
3765 "Unable to verify integrity of firmware image "
3766 "(%Zd)!\n", blob
->fw
->size
);
3767 goto fail_fw_integrity
;
3771 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3772 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3773 if (wlen
> risc_size
)
3776 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3777 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3780 for (i
= 0; i
< wlen
; i
++)
3781 wcode
[i
] = swab16(fwcode
[i
]);
3783 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3786 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3787 "segment %d of firmware\n", ha
->host_no
,
3789 qla_printk(KERN_WARNING
, ha
,
3790 "[ERROR] Failed to load segment %d of "
3791 "firmware\n", fragment
);
3807 return QLA_FUNCTION_FAILED
;
3811 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3814 int segments
, fragment
;
3815 uint32_t *dcode
, dlen
;
3819 struct fw_blob
*blob
;
3820 uint32_t *fwcode
, fwclen
;
3822 /* Load firmware blob. */
3823 blob
= qla2x00_request_firmware(ha
);
3825 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3826 return QLA_FUNCTION_FAILED
;
3831 segments
= FA_RISC_CODE_SEGMENTS
;
3832 dcode
= (uint32_t *)ha
->request_ring
;
3834 fwcode
= (uint32_t *)blob
->fw
->data
;
3837 /* Validate firmware image by checking version. */
3838 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3839 qla_printk(KERN_WARNING
, ha
,
3840 "Unable to verify integrity of firmware image (%Zd)!\n",
3842 goto fail_fw_integrity
;
3844 for (i
= 0; i
< 4; i
++)
3845 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3846 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3847 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3848 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3850 qla_printk(KERN_WARNING
, ha
,
3851 "Unable to verify integrity of firmware image!\n");
3852 qla_printk(KERN_WARNING
, ha
,
3853 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3854 dcode
[1], dcode
[2], dcode
[3]);
3855 goto fail_fw_integrity
;
3858 while (segments
&& rval
== QLA_SUCCESS
) {
3859 risc_addr
= be32_to_cpu(fwcode
[2]);
3860 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3861 risc_size
= be32_to_cpu(fwcode
[3]);
3863 /* Validate firmware image size. */
3864 fwclen
+= risc_size
* sizeof(uint32_t);
3865 if (blob
->fw
->size
< fwclen
) {
3866 qla_printk(KERN_WARNING
, ha
,
3867 "Unable to verify integrity of firmware image "
3868 "(%Zd)!\n", blob
->fw
->size
);
3870 goto fail_fw_integrity
;
3874 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3875 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3876 if (dlen
> risc_size
)
3879 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3880 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3883 for (i
= 0; i
< dlen
; i
++)
3884 dcode
[i
] = swab32(fwcode
[i
]);
3886 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3889 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3890 "segment %d of firmware\n", ha
->host_no
,
3892 qla_printk(KERN_WARNING
, ha
,
3893 "[ERROR] Failed to load segment %d of "
3894 "firmware\n", fragment
);
3910 return QLA_FUNCTION_FAILED
;