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_QLA25XX(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
->fw_transfer_size
= 128;
733 /* Wrap Incoming Mailboxes Test. */
734 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
736 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
737 rval
= qla2x00_mbx_reg_test(ha
);
739 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
741 qla_printk(KERN_WARNING
, ha
,
742 "Failed mailbox send register test\n");
745 /* Flag a successful rval */
748 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
752 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
753 "****\n", ha
->host_no
));
755 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
761 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
764 * Returns 0 on success.
767 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
771 /* Perform RISC reset. */
772 qla24xx_reset_risc(ha
);
774 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
776 rval
= qla2x00_mbx_reg_test(ha
);
778 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
780 qla_printk(KERN_WARNING
, ha
,
781 "Failed mailbox send register test\n");
783 /* Flag a successful rval */
791 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
794 ha
->fw_dump24_len
= sizeof(struct qla24xx_fw_dump
);
795 ha
->fw_dump24_len
+= (ha
->fw_memory_size
- 0x100000) * sizeof(uint32_t);
796 ha
->fw_dump24
= vmalloc(ha
->fw_dump24_len
);
798 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware "
799 "dump...\n", ha
->fw_dump24_len
/ 1024);
801 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
802 "firmware dump!!!\n", ha
->fw_dump24_len
/ 1024);
806 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
809 * Returns 0 on success.
812 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
815 uint16_t fw_iocb_cnt
= 0;
816 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
817 dma_addr_t request_dma
;
818 request_t
*request_ring
;
820 /* Valid only on recent ISPs. */
821 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
824 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
825 qla2x00_alloc_fw_dump(ha
);
827 /* Retrieve IOCB counts available to the firmware. */
828 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
831 /* No point in continuing if current settings are sufficient. */
832 if (fw_iocb_cnt
< 1024)
834 if (ha
->request_q_length
>= request_q_length
)
837 /* Attempt to claim larger area for request queue. */
838 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
839 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
841 if (request_ring
== NULL
)
844 /* Resize successful, report extensions. */
845 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
846 (ha
->fw_memory_size
+ 1) / 1024);
847 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
848 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
850 /* Clear old allocations. */
851 dma_free_coherent(&ha
->pdev
->dev
,
852 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
855 /* Begin using larger queue. */
856 ha
->request_q_length
= request_q_length
;
857 ha
->request_ring
= request_ring
;
858 ha
->request_dma
= request_dma
;
862 * qla2x00_setup_chip() - Load and start RISC firmware.
865 * Returns 0 on success.
868 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
871 uint32_t srisc_address
= 0;
873 /* Load firmware sequences */
874 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
875 if (rval
== QLA_SUCCESS
) {
876 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
877 "code.\n", ha
->host_no
));
879 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
880 if (rval
== QLA_SUCCESS
) {
881 /* Start firmware execution. */
882 DEBUG(printk("scsi(%ld): Checksum OK, start "
883 "firmware.\n", ha
->host_no
));
885 rval
= qla2x00_execute_fw(ha
, srisc_address
);
886 /* Retrieve firmware information. */
887 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
888 qla2x00_get_fw_version(ha
,
889 &ha
->fw_major_version
,
890 &ha
->fw_minor_version
,
891 &ha
->fw_subminor_version
,
892 &ha
->fw_attributes
, &ha
->fw_memory_size
);
893 qla2x00_resize_request_q(ha
);
896 DEBUG2(printk(KERN_INFO
897 "scsi(%ld): ISP Firmware failed checksum.\n",
903 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
911 * qla2x00_init_response_q_entries() - Initializes response queue entries.
914 * Beginning of request ring has initialization control block already built
915 * by nvram config routine.
917 * Returns 0 on success.
920 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
925 pkt
= ha
->response_ring_ptr
;
926 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
927 pkt
->signature
= RESPONSE_PROCESSED
;
934 * qla2x00_update_fw_options() - Read and process firmware options.
937 * Returns 0 on success.
940 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
942 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
944 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
945 qla2x00_get_fw_options(ha
, ha
->fw_options
);
947 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
950 /* Serial Link options. */
951 DEBUG3(printk("scsi(%ld): Serial link options:\n",
953 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
954 sizeof(ha
->fw_seriallink_options
)));
956 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
957 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
958 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
961 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
962 emphasis
= (ha
->fw_seriallink_options
[2] &
963 (BIT_4
| BIT_3
)) >> 3;
964 tx_sens
= ha
->fw_seriallink_options
[0] &
965 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
966 rx_sens
= (ha
->fw_seriallink_options
[0] &
967 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
968 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
969 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
972 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
973 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
974 ha
->fw_options
[10] |= BIT_5
|
975 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
976 (tx_sens
& (BIT_1
| BIT_0
));
979 swing
= (ha
->fw_seriallink_options
[2] &
980 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
981 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
982 tx_sens
= ha
->fw_seriallink_options
[1] &
983 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
984 rx_sens
= (ha
->fw_seriallink_options
[1] &
985 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
986 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
987 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
990 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
991 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
992 ha
->fw_options
[11] |= BIT_5
|
993 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
994 (tx_sens
& (BIT_1
| BIT_0
));
998 /* Return command IOCBs without waiting for an ABTS to complete. */
999 ha
->fw_options
[3] |= BIT_13
;
1002 if (ha
->flags
.enable_led_scheme
)
1003 ha
->fw_options
[2] |= BIT_12
;
1005 /* Update firmware options. */
1006 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1010 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1014 /* Update Serial Link options. */
1015 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1018 rval
= qla2x00_set_serdes_params(ha
,
1019 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1020 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1021 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1022 if (rval
!= QLA_SUCCESS
) {
1023 qla_printk(KERN_WARNING
, ha
,
1024 "Unable to update Serial Link options (%x).\n", rval
);
1029 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1031 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1033 /* Setup ring parameters in initialization control block. */
1034 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1035 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1036 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1037 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1038 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1039 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1040 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1041 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1043 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1044 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1045 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1046 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1047 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1051 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1053 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1054 struct init_cb_24xx
*icb
;
1056 /* Setup ring parameters in initialization control block. */
1057 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1058 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1059 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1060 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1061 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1062 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1063 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1064 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1065 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1067 WRT_REG_DWORD(®
->req_q_in
, 0);
1068 WRT_REG_DWORD(®
->req_q_out
, 0);
1069 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1070 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1071 RD_REG_DWORD(®
->rsp_q_out
);
1075 * qla2x00_init_rings() - Initializes firmware.
1078 * Beginning of request ring has initialization control block already built
1079 * by nvram config routine.
1081 * Returns 0 on success.
1084 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1087 unsigned long flags
= 0;
1090 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1092 /* Clear outstanding commands array. */
1093 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1094 ha
->outstanding_cmds
[cnt
] = NULL
;
1096 ha
->current_outstanding_cmd
= 0;
1098 /* Clear RSCN queue. */
1099 ha
->rscn_in_ptr
= 0;
1100 ha
->rscn_out_ptr
= 0;
1102 /* Initialize firmware. */
1103 ha
->request_ring_ptr
= ha
->request_ring
;
1104 ha
->req_ring_index
= 0;
1105 ha
->req_q_cnt
= ha
->request_q_length
;
1106 ha
->response_ring_ptr
= ha
->response_ring
;
1107 ha
->rsp_ring_index
= 0;
1109 /* Initialize response queue entries */
1110 qla2x00_init_response_q_entries(ha
);
1112 ha
->isp_ops
.config_rings(ha
);
1114 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1116 /* Update any ISP specific firmware options before initialization. */
1117 ha
->isp_ops
.update_fw_options(ha
);
1119 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1120 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1122 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1125 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1133 * qla2x00_fw_ready() - Waits for firmware ready.
1136 * Returns 0 on success.
1139 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1142 unsigned long wtime
, mtime
;
1143 uint16_t min_wait
; /* Minimum wait time if loop is down */
1144 uint16_t wait_time
; /* Wait time if loop is coming ready */
1149 /* 20 seconds for loop down. */
1153 * Firmware should take at most one RATOV to login, plus 5 seconds for
1154 * our own processing.
1156 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1157 wait_time
= min_wait
;
1160 /* Min wait time if loop down */
1161 mtime
= jiffies
+ (min_wait
* HZ
);
1163 /* wait time before firmware ready */
1164 wtime
= jiffies
+ (wait_time
* HZ
);
1166 /* Wait for ISP to finish LIP */
1167 if (!ha
->flags
.init_done
)
1168 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1170 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1174 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1175 if (rval
== QLA_SUCCESS
) {
1176 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1177 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1179 if (fw_state
== FSTATE_READY
) {
1180 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1183 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1184 &ha
->login_timeout
, &ha
->r_a_tov
);
1190 rval
= QLA_FUNCTION_FAILED
;
1192 if (atomic_read(&ha
->loop_down_timer
) &&
1193 (fw_state
>= FSTATE_LOSS_OF_SYNC
||
1194 fw_state
== FSTATE_WAIT_AL_PA
)) {
1195 /* Loop down. Timeout on min_wait for states
1196 * other than Wait for Login.
1198 if (time_after_eq(jiffies
, mtime
)) {
1199 qla_printk(KERN_INFO
, ha
,
1200 "Cable is unplugged...\n");
1202 ha
->device_flags
|= DFLG_NO_CABLE
;
1207 /* Mailbox cmd failed. Timeout on min_wait. */
1208 if (time_after_eq(jiffies
, mtime
))
1212 if (time_after_eq(jiffies
, wtime
))
1215 /* Delay for a while */
1218 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1219 ha
->host_no
, fw_state
, jiffies
));
1222 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1223 ha
->host_no
, fw_state
, jiffies
));
1226 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1234 * qla2x00_configure_hba
1235 * Setup adapter context.
1238 * ha = adapter state pointer.
1247 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1255 char connect_type
[22];
1257 /* Get host addresses. */
1258 rval
= qla2x00_get_adapter_id(ha
,
1259 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1260 if (rval
!= QLA_SUCCESS
) {
1261 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1262 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1263 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1264 __func__
, ha
->host_no
));
1266 qla_printk(KERN_WARNING
, ha
,
1267 "ERROR -- Unable to get host loop ID.\n");
1268 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1274 qla_printk(KERN_INFO
, ha
,
1275 "Cannot get topology - retrying.\n");
1276 return (QLA_FUNCTION_FAILED
);
1279 ha
->loop_id
= loop_id
;
1282 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1283 ha
->operating_mode
= LOOP
;
1287 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1289 ha
->current_topology
= ISP_CFG_NL
;
1290 strcpy(connect_type
, "(Loop)");
1294 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1296 ha
->current_topology
= ISP_CFG_FL
;
1297 strcpy(connect_type
, "(FL_Port)");
1301 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1303 ha
->operating_mode
= P2P
;
1304 ha
->current_topology
= ISP_CFG_N
;
1305 strcpy(connect_type
, "(N_Port-to-N_Port)");
1309 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1311 ha
->operating_mode
= P2P
;
1312 ha
->current_topology
= ISP_CFG_F
;
1313 strcpy(connect_type
, "(F_Port)");
1317 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1319 ha
->host_no
, topo
));
1320 ha
->current_topology
= ISP_CFG_NL
;
1321 strcpy(connect_type
, "(Loop)");
1325 /* Save Host port and loop ID. */
1326 /* byte order - Big Endian */
1327 ha
->d_id
.b
.domain
= domain
;
1328 ha
->d_id
.b
.area
= area
;
1329 ha
->d_id
.b
.al_pa
= al_pa
;
1331 if (!ha
->flags
.init_done
)
1332 qla_printk(KERN_INFO
, ha
,
1333 "Topology - %s, Host Loop address 0x%x\n",
1334 connect_type
, ha
->loop_id
);
1337 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1339 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1346 * NVRAM configuration for ISP 2xxx
1349 * ha = adapter block pointer.
1352 * initialization control block in response_ring
1353 * host adapters parameters in host adapter block
1359 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1364 uint8_t *dptr1
, *dptr2
;
1365 init_cb_t
*icb
= ha
->init_cb
;
1366 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1367 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1368 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1372 /* Determine NVRAM starting address. */
1373 ha
->nvram_size
= sizeof(nvram_t
);
1375 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1376 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1377 ha
->nvram_base
= 0x80;
1379 /* Get NVRAM data and calculate checksum. */
1380 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1381 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1384 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1385 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1388 /* Bad NVRAM data, set defaults parameters. */
1389 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1390 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1391 /* Reset NVRAM data. */
1392 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1393 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1395 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1396 "invalid -- WWPN) defaults.\n");
1399 * Set default initialization control block.
1401 memset(nv
, 0, ha
->nvram_size
);
1402 nv
->parameter_block_version
= ICB_VERSION
;
1404 if (IS_QLA23XX(ha
)) {
1405 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1406 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1407 nv
->add_firmware_options
[0] = BIT_5
;
1408 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1409 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1410 nv
->special_options
[1] = BIT_7
;
1411 } else if (IS_QLA2200(ha
)) {
1412 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1413 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1414 nv
->add_firmware_options
[0] = BIT_5
;
1415 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1416 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1417 } else if (IS_QLA2100(ha
)) {
1418 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1419 nv
->firmware_options
[1] = BIT_5
;
1420 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1423 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1424 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1425 nv
->retry_count
= 8;
1426 nv
->retry_delay
= 1;
1428 nv
->port_name
[0] = 33;
1429 nv
->port_name
[3] = 224;
1430 nv
->port_name
[4] = 139;
1432 nv
->login_timeout
= 4;
1435 * Set default host adapter parameters
1437 nv
->host_p
[1] = BIT_2
;
1438 nv
->reset_delay
= 5;
1439 nv
->port_down_retry_count
= 8;
1440 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1441 nv
->link_down_timeout
= 60;
1446 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1448 * The SN2 does not provide BIOS emulation which means you can't change
1449 * potentially bogus BIOS settings. Force the use of default settings
1450 * for link rate and frame size. Hope that the rest of the settings
1453 if (ia64_platform_is("sn2")) {
1454 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1456 nv
->special_options
[1] = BIT_7
;
1460 /* Reset Initialization control block */
1461 memset(icb
, 0, ha
->init_cb_size
);
1464 * Setup driver NVRAM options.
1466 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1467 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1468 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1469 nv
->firmware_options
[1] &= ~BIT_4
;
1471 if (IS_QLA23XX(ha
)) {
1472 nv
->firmware_options
[0] |= BIT_2
;
1473 nv
->firmware_options
[0] &= ~BIT_3
;
1474 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1476 if (IS_QLA2300(ha
)) {
1477 if (ha
->fb_rev
== FPM_2310
) {
1478 strcpy(ha
->model_number
, "QLA2310");
1480 strcpy(ha
->model_number
, "QLA2300");
1484 memcmp(nv
->model_number
, BINZERO
,
1485 sizeof(nv
->model_number
)) != 0) {
1488 strncpy(ha
->model_number
, nv
->model_number
,
1489 sizeof(nv
->model_number
));
1490 st
= en
= ha
->model_number
;
1491 en
+= sizeof(nv
->model_number
) - 1;
1493 if (*en
!= 0x20 && *en
!= 0x00)
1500 index
= (ha
->pdev
->subsystem_device
& 0xff);
1501 if (index
< QLA_MODEL_NAMES
) {
1502 strcpy(ha
->model_number
,
1503 qla2x00_model_name
[index
]);
1505 qla2x00_model_desc
[index
];
1507 strcpy(ha
->model_number
, "QLA23xx");
1511 } else if (IS_QLA2200(ha
)) {
1512 nv
->firmware_options
[0] |= BIT_2
;
1514 * 'Point-to-point preferred, else loop' is not a safe
1515 * connection mode setting.
1517 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1519 /* Force 'loop preferred, else point-to-point'. */
1520 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1521 nv
->add_firmware_options
[0] |= BIT_5
;
1523 strcpy(ha
->model_number
, "QLA22xx");
1524 } else /*if (IS_QLA2100(ha))*/ {
1525 strcpy(ha
->model_number
, "QLA2100");
1529 * Copy over NVRAM RISC parameter block to initialization control block.
1531 dptr1
= (uint8_t *)icb
;
1532 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1533 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1535 *dptr1
++ = *dptr2
++;
1537 /* Copy 2nd half. */
1538 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1539 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1541 *dptr1
++ = *dptr2
++;
1543 /* Prepare nodename */
1544 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1546 * Firmware will apply the following mask if the nodename was
1549 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1550 icb
->node_name
[0] &= 0xF0;
1554 * Set host adapter parameters.
1556 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1557 /* Always load RISC code on non ISP2[12]00 chips. */
1558 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1559 ha
->flags
.disable_risc_code_load
= 0;
1560 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1561 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1562 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1563 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1565 ha
->operating_mode
=
1566 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1568 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1569 sizeof(ha
->fw_seriallink_options
));
1571 /* save HBA serial number */
1572 ha
->serial0
= icb
->port_name
[5];
1573 ha
->serial1
= icb
->port_name
[6];
1574 ha
->serial2
= icb
->port_name
[7];
1575 ha
->node_name
= icb
->node_name
;
1576 ha
->port_name
= icb
->port_name
;
1578 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1580 ha
->retry_count
= nv
->retry_count
;
1582 /* Set minimum login_timeout to 4 seconds. */
1583 if (nv
->login_timeout
< ql2xlogintimeout
)
1584 nv
->login_timeout
= ql2xlogintimeout
;
1585 if (nv
->login_timeout
< 4)
1586 nv
->login_timeout
= 4;
1587 ha
->login_timeout
= nv
->login_timeout
;
1588 icb
->login_timeout
= nv
->login_timeout
;
1590 /* Set minimum RATOV to 200 tenths of a second. */
1593 ha
->loop_reset_delay
= nv
->reset_delay
;
1595 /* Link Down Timeout = 0:
1597 * When Port Down timer expires we will start returning
1598 * I/O's to OS with "DID_NO_CONNECT".
1600 * Link Down Timeout != 0:
1602 * The driver waits for the link to come up after link down
1603 * before returning I/Os to OS with "DID_NO_CONNECT".
1605 if (nv
->link_down_timeout
== 0) {
1606 ha
->loop_down_abort_time
=
1607 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1609 ha
->link_down_timeout
= nv
->link_down_timeout
;
1610 ha
->loop_down_abort_time
=
1611 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1615 * Need enough time to try and get the port back.
1617 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1618 if (qlport_down_retry
)
1619 ha
->port_down_retry_count
= qlport_down_retry
;
1620 /* Set login_retry_count */
1621 ha
->login_retry_count
= nv
->retry_count
;
1622 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1623 ha
->port_down_retry_count
> 3)
1624 ha
->login_retry_count
= ha
->port_down_retry_count
;
1625 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1626 ha
->login_retry_count
= ha
->port_down_retry_count
;
1627 if (ql2xloginretrycount
)
1628 ha
->login_retry_count
= ql2xloginretrycount
;
1630 icb
->lun_enables
= __constant_cpu_to_le16(0);
1631 icb
->command_resource_count
= 0;
1632 icb
->immediate_notify_resource_count
= 0;
1633 icb
->timeout
= __constant_cpu_to_le16(0);
1635 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1637 icb
->firmware_options
[0] &= ~BIT_3
;
1638 icb
->add_firmware_options
[0] &=
1639 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1640 icb
->add_firmware_options
[0] |= BIT_2
;
1641 icb
->response_accumulation_timer
= 3;
1642 icb
->interrupt_delay_timer
= 5;
1644 ha
->flags
.process_response_queue
= 1;
1647 if (!ha
->flags
.init_done
) {
1648 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1649 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1650 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1651 icb
->interrupt_delay_timer
: 2;
1653 icb
->add_firmware_options
[0] &=
1654 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1655 ha
->flags
.process_response_queue
= 0;
1656 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1657 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1658 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1659 ha
->zio_timer
* 100));
1660 qla_printk(KERN_INFO
, ha
,
1661 "ZIO mode %d enabled; timer delay (%d us).\n",
1662 ha
->zio_mode
, ha
->zio_timer
* 100);
1664 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1665 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1666 ha
->flags
.process_response_queue
= 1;
1671 DEBUG2_3(printk(KERN_WARNING
1672 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1678 qla2x00_rport_add(void *data
)
1680 fc_port_t
*fcport
= data
;
1682 qla2x00_reg_remote_port(fcport
->ha
, fcport
);
1686 qla2x00_rport_del(void *data
)
1688 fc_port_t
*fcport
= data
;
1689 struct fc_rport
*rport
;
1690 unsigned long flags
;
1692 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1693 rport
= fcport
->drport
;
1694 fcport
->drport
= NULL
;
1695 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1697 fc_remote_port_delete(rport
);
1702 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1704 * @flags: allocation flags
1706 * Returns a pointer to the allocated fcport, or NULL, if none available.
1709 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1713 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1717 /* Setup fcport template structure. */
1718 memset(fcport
, 0, sizeof (fc_port_t
));
1720 fcport
->port_type
= FCT_UNKNOWN
;
1721 fcport
->loop_id
= FC_NO_LOOP_ID
;
1722 fcport
->iodesc_idx_sent
= IODESC_INVALID_INDEX
;
1723 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1724 fcport
->flags
= FCF_RLC_SUPPORT
;
1725 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1726 spin_lock_init(&fcport
->rport_lock
);
1727 INIT_WORK(&fcport
->rport_add_work
, qla2x00_rport_add
, fcport
);
1728 INIT_WORK(&fcport
->rport_del_work
, qla2x00_rport_del
, fcport
);
1734 * qla2x00_configure_loop
1735 * Updates Fibre Channel Device Database with what is actually on loop.
1738 * ha = adapter block pointer.
1743 * 2 = database was full and device was not configured.
1746 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1749 unsigned long flags
, save_flags
;
1753 /* Get Initiator ID */
1754 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1755 rval
= qla2x00_configure_hba(ha
);
1756 if (rval
!= QLA_SUCCESS
) {
1757 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1763 save_flags
= flags
= ha
->dpc_flags
;
1764 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1765 ha
->host_no
, flags
));
1768 * If we have both an RSCN and PORT UPDATE pending then handle them
1769 * both at the same time.
1771 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1772 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1774 /* Determine what we need to do */
1775 if (ha
->current_topology
== ISP_CFG_FL
&&
1776 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1778 ha
->flags
.rscn_queue_overflow
= 1;
1779 set_bit(RSCN_UPDATE
, &flags
);
1781 } else if (ha
->current_topology
== ISP_CFG_F
&&
1782 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1784 ha
->flags
.rscn_queue_overflow
= 1;
1785 set_bit(RSCN_UPDATE
, &flags
);
1786 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1788 } else if (!ha
->flags
.online
||
1789 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1791 ha
->flags
.rscn_queue_overflow
= 1;
1792 set_bit(RSCN_UPDATE
, &flags
);
1793 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1796 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1797 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1798 rval
= QLA_FUNCTION_FAILED
;
1800 rval
= qla2x00_configure_local_loop(ha
);
1804 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1805 if (LOOP_TRANSITION(ha
)) {
1806 rval
= QLA_FUNCTION_FAILED
;
1808 rval
= qla2x00_configure_fabric(ha
);
1812 if (rval
== QLA_SUCCESS
) {
1813 if (atomic_read(&ha
->loop_down_timer
) ||
1814 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1815 rval
= QLA_FUNCTION_FAILED
;
1817 atomic_set(&ha
->loop_state
, LOOP_READY
);
1819 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1824 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1825 __func__
, ha
->host_no
));
1827 DEBUG3(printk("%s: exiting normally\n", __func__
));
1830 /* Restore state if a resync event occured during processing */
1831 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1832 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1833 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1834 if (test_bit(RSCN_UPDATE
, &save_flags
))
1835 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1844 * qla2x00_configure_local_loop
1845 * Updates Fibre Channel Device Database with local loop devices.
1848 * ha = adapter block pointer.
1854 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1859 fc_port_t
*fcport
, *new_fcport
;
1865 uint8_t domain
, area
, al_pa
;
1869 entries
= MAX_FIBRE_DEVICES
;
1871 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1872 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1874 /* Get list of logged in devices. */
1875 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1876 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1878 if (rval
!= QLA_SUCCESS
)
1879 goto cleanup_allocation
;
1881 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1882 ha
->host_no
, entries
));
1883 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1884 entries
* sizeof(struct gid_list_info
)));
1886 /* Allocate temporary fcport for any new fcports discovered. */
1887 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1888 if (new_fcport
== NULL
) {
1889 rval
= QLA_MEMORY_ALLOC_FAILED
;
1890 goto cleanup_allocation
;
1892 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1895 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1897 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1898 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1899 fcport
->port_type
!= FCT_BROADCAST
&&
1900 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1902 DEBUG(printk("scsi(%ld): Marking port lost, "
1904 ha
->host_no
, fcport
->loop_id
));
1906 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1907 fcport
->flags
&= ~FCF_FARP_DONE
;
1911 /* Add devices to port list. */
1912 id_iter
= (char *)ha
->gid_list
;
1913 for (index
= 0; index
< entries
; index
++) {
1914 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1915 area
= ((struct gid_list_info
*)id_iter
)->area
;
1916 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1917 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1918 loop_id
= (uint16_t)
1919 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1921 loop_id
= le16_to_cpu(
1922 ((struct gid_list_info
*)id_iter
)->loop_id
);
1923 id_iter
+= ha
->gid_list_info_size
;
1925 /* Bypass reserved domain fields. */
1926 if ((domain
& 0xf0) == 0xf0)
1929 /* Bypass if not same domain and area of adapter. */
1930 if (area
&& domain
&&
1931 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
1934 /* Bypass invalid local loop ID. */
1935 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1938 /* Fill in member data. */
1939 new_fcport
->d_id
.b
.domain
= domain
;
1940 new_fcport
->d_id
.b
.area
= area
;
1941 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1942 new_fcport
->loop_id
= loop_id
;
1943 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1944 if (rval2
!= QLA_SUCCESS
) {
1945 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1946 "information -- get_port_database=%x, "
1948 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1949 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1951 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
1955 /* Check for matching device in port list. */
1958 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1959 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
1963 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
1964 FCF_PERSISTENT_BOUND
);
1965 fcport
->loop_id
= new_fcport
->loop_id
;
1966 fcport
->port_type
= new_fcport
->port_type
;
1967 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
1968 memcpy(fcport
->node_name
, new_fcport
->node_name
,
1976 /* New device, add to fcports list. */
1977 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
1978 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
1980 /* Allocate a new replacement fcport. */
1981 fcport
= new_fcport
;
1982 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1983 if (new_fcport
== NULL
) {
1984 rval
= QLA_MEMORY_ALLOC_FAILED
;
1985 goto cleanup_allocation
;
1987 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1990 qla2x00_update_fcport(ha
, fcport
);
1998 if (rval
!= QLA_SUCCESS
) {
1999 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2000 "rval=%x\n", ha
->host_no
, rval
));
2004 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2005 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2012 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2016 qla2x00_mark_all_devices_lost(ha
, 0);
2017 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2018 if (fcport
->port_type
!= FCT_TARGET
)
2021 qla2x00_update_fcport(ha
, fcport
);
2026 * qla2x00_update_fcport
2027 * Updates device on list.
2030 * ha = adapter block pointer.
2031 * fcport = port structure pointer.
2041 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2044 fcport
->login_retry
= 0;
2045 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2047 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2049 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2051 if (fcport
->port_type
== FCT_INITIATOR
||
2052 fcport
->port_type
== FCT_BROADCAST
)
2053 fcport
->device_type
= TYPE_PROCESSOR
;
2055 atomic_set(&fcport
->state
, FCS_ONLINE
);
2057 if (ha
->flags
.init_done
)
2058 qla2x00_reg_remote_port(ha
, fcport
);
2062 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2064 struct fc_rport_identifiers rport_ids
;
2065 struct fc_rport
*rport
;
2066 unsigned long flags
;
2069 qla2x00_rport_del(fcport
);
2073 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2074 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2075 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2076 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2077 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2078 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2080 qla_printk(KERN_WARNING
, ha
,
2081 "Unable to allocate fc remote port!\n");
2084 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2085 fcport
->rport
= rport
;
2086 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2087 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2089 rport
->supported_classes
= fcport
->supported_classes
;
2091 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2092 if (fcport
->port_type
== FCT_INITIATOR
)
2093 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2094 if (fcport
->port_type
== FCT_TARGET
)
2095 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2096 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2098 if (rport
->scsi_target_id
!= -1 &&
2099 rport
->scsi_target_id
< ha
->host
->max_id
)
2100 fcport
->os_target_id
= rport
->scsi_target_id
;
2104 * qla2x00_configure_fabric
2105 * Setup SNS devices with loop ID's.
2108 * ha = adapter block pointer.
2115 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2118 fc_port_t
*fcport
, *fcptemp
;
2119 uint16_t next_loopid
;
2120 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2122 LIST_HEAD(new_fcports
);
2124 /* If FL port exists, then SNS is present */
2125 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
2126 loop_id
= NPH_F_PORT
;
2128 loop_id
= SNS_FL_PORT
;
2129 rval
= qla2x00_get_port_name(ha
, loop_id
, NULL
, 0);
2130 if (rval
!= QLA_SUCCESS
) {
2131 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2132 "Port\n", ha
->host_no
));
2134 ha
->device_flags
&= ~SWITCH_FOUND
;
2135 return (QLA_SUCCESS
);
2138 /* Mark devices that need re-synchronization. */
2139 rval2
= qla2x00_device_resync(ha
);
2140 if (rval2
== QLA_RSCNS_HANDLED
) {
2141 /* No point doing the scan, just continue. */
2142 return (QLA_SUCCESS
);
2146 if (ql2xfdmienable
&&
2147 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2148 qla2x00_fdmi_register(ha
);
2150 /* Ensure we are logged into the SNS. */
2151 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
2154 loop_id
= SIMPLE_NAME_SERVER
;
2155 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2156 0xfc, mb
, BIT_1
| BIT_0
);
2157 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2158 DEBUG2(qla_printk(KERN_INFO
, ha
,
2159 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2160 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2161 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2162 return (QLA_SUCCESS
);
2165 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2166 if (qla2x00_rft_id(ha
)) {
2168 DEBUG2(printk("scsi(%ld): Register FC-4 "
2169 "TYPE failed.\n", ha
->host_no
));
2171 if (qla2x00_rff_id(ha
)) {
2173 DEBUG2(printk("scsi(%ld): Register FC-4 "
2174 "Features failed.\n", ha
->host_no
));
2176 if (qla2x00_rnn_id(ha
)) {
2178 DEBUG2(printk("scsi(%ld): Register Node Name "
2179 "failed.\n", ha
->host_no
));
2180 } else if (qla2x00_rsnn_nn(ha
)) {
2182 DEBUG2(printk("scsi(%ld): Register Symbolic "
2183 "Node Name failed.\n", ha
->host_no
));
2187 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2188 if (rval
!= QLA_SUCCESS
)
2192 * Logout all previous fabric devices marked lost, except
2195 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2196 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2199 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2202 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2203 qla2x00_mark_device_lost(ha
, fcport
,
2204 ql2xplogiabsentdevice
, 0);
2205 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2206 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2207 fcport
->port_type
!= FCT_INITIATOR
&&
2208 fcport
->port_type
!= FCT_BROADCAST
) {
2209 ha
->isp_ops
.fabric_logout(ha
,
2211 fcport
->d_id
.b
.domain
,
2212 fcport
->d_id
.b
.area
,
2213 fcport
->d_id
.b
.al_pa
);
2214 fcport
->loop_id
= FC_NO_LOOP_ID
;
2219 /* Starting free loop ID. */
2220 next_loopid
= ha
->min_external_loopid
;
2223 * Scan through our port list and login entries that need to be
2226 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2227 if (atomic_read(&ha
->loop_down_timer
) ||
2228 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2231 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2232 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2235 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2236 fcport
->loop_id
= next_loopid
;
2237 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2238 if (rval
!= QLA_SUCCESS
) {
2239 /* Ran out of IDs to use */
2243 /* Login and update database */
2244 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2247 /* Exit if out of loop IDs. */
2248 if (rval
!= QLA_SUCCESS
) {
2253 * Login and add the new devices to our port list.
2255 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2256 if (atomic_read(&ha
->loop_down_timer
) ||
2257 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2260 /* Find a new loop ID to use. */
2261 fcport
->loop_id
= next_loopid
;
2262 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2263 if (rval
!= QLA_SUCCESS
) {
2264 /* Ran out of IDs to use */
2268 /* Remove device from the new list and add it to DB */
2269 list_del(&fcport
->list
);
2270 list_add_tail(&fcport
->list
, &ha
->fcports
);
2272 /* Login and update database */
2273 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2277 /* Free all new device structures not processed. */
2278 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2279 list_del(&fcport
->list
);
2284 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2285 "rval=%d\n", ha
->host_no
, rval
));
2293 * qla2x00_find_all_fabric_devs
2296 * ha = adapter block pointer.
2297 * dev = database device entry pointer.
2306 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2310 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2315 int first_dev
, last_dev
;
2316 port_id_t wrap
, nxt_d_id
;
2320 /* Try GID_PT to get device list, else GAN. */
2321 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2324 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2325 "on GA_NXT\n", ha
->host_no
));
2327 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2328 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2331 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2334 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2341 /* Allocate temporary fcport for any new fcports discovered. */
2342 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2343 if (new_fcport
== NULL
) {
2345 return (QLA_MEMORY_ALLOC_FAILED
);
2347 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2349 /* Set start port ID scan at adapter ID. */
2353 /* Starting free loop ID. */
2354 loop_id
= ha
->min_external_loopid
;
2355 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2356 if (qla2x00_is_reserved_id(ha
, loop_id
))
2359 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2364 wrap
.b24
= new_fcport
->d_id
.b24
;
2366 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2367 memcpy(new_fcport
->node_name
,
2368 swl
[swl_idx
].node_name
, WWN_SIZE
);
2369 memcpy(new_fcport
->port_name
,
2370 swl
[swl_idx
].port_name
, WWN_SIZE
);
2372 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2378 /* Send GA_NXT to the switch */
2379 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2380 if (rval
!= QLA_SUCCESS
) {
2381 qla_printk(KERN_WARNING
, ha
,
2382 "SNS scan failed -- assuming zero-entry "
2384 list_for_each_entry_safe(fcport
, fcptemp
,
2385 new_fcports
, list
) {
2386 list_del(&fcport
->list
);
2394 /* If wrap on switch device list, exit. */
2396 wrap
.b24
= new_fcport
->d_id
.b24
;
2398 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2399 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2400 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2401 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2405 /* Bypass if host adapter. */
2406 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2409 /* Bypass if same domain and area of adapter. */
2410 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2411 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2415 /* Bypass reserved domain fields. */
2416 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2419 /* Locate matching device in database. */
2421 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2422 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2429 * If address the same and state FCS_ONLINE, nothing
2432 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2433 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2438 * If device was not a fabric device before.
2440 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2441 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2442 fcport
->loop_id
= FC_NO_LOOP_ID
;
2443 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2445 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2450 * Port ID changed or device was marked to be updated;
2451 * Log it out if still logged in and mark it for
2454 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2455 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2456 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2457 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2458 fcport
->port_type
!= FCT_INITIATOR
&&
2459 fcport
->port_type
!= FCT_BROADCAST
) {
2460 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2461 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2462 fcport
->d_id
.b
.al_pa
);
2463 fcport
->loop_id
= FC_NO_LOOP_ID
;
2472 /* If device was not in our fcports list, then add it. */
2473 list_add_tail(&new_fcport
->list
, new_fcports
);
2475 /* Allocate a new replacement fcport. */
2476 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2477 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2478 if (new_fcport
== NULL
) {
2480 return (QLA_MEMORY_ALLOC_FAILED
);
2482 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2483 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2489 if (!list_empty(new_fcports
))
2490 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2496 * qla2x00_find_new_loop_id
2497 * Scan through our port list and find a new usable loop ID.
2500 * ha: adapter state pointer.
2501 * dev: port structure pointer.
2504 * qla2x00 local function return status code.
2510 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2515 uint16_t first_loop_id
;
2519 /* Save starting loop ID. */
2520 first_loop_id
= dev
->loop_id
;
2523 /* Skip loop ID if already used by adapter. */
2524 if (dev
->loop_id
== ha
->loop_id
) {
2528 /* Skip reserved loop IDs. */
2529 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2533 /* Reset loop ID if passed the end. */
2534 if (dev
->loop_id
> ha
->last_loop_id
) {
2535 /* first loop ID. */
2536 dev
->loop_id
= ha
->min_external_loopid
;
2539 /* Check for loop ID being already in use. */
2542 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2543 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2544 /* ID possibly in use */
2550 /* If not in use then it is free to use. */
2555 /* ID in use. Try next value. */
2558 /* If wrap around. No free ID to use. */
2559 if (dev
->loop_id
== first_loop_id
) {
2560 dev
->loop_id
= FC_NO_LOOP_ID
;
2561 rval
= QLA_FUNCTION_FAILED
;
2570 * qla2x00_device_resync
2571 * Marks devices in the database that needs resynchronization.
2574 * ha = adapter block pointer.
2580 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2586 uint32_t rscn_entry
;
2587 uint8_t rscn_out_iter
;
2591 rval
= QLA_RSCNS_HANDLED
;
2593 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2594 ha
->flags
.rscn_queue_overflow
) {
2596 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2597 format
= MSB(MSW(rscn_entry
));
2598 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2599 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2600 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2602 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2603 "[%02x/%02x%02x%02x].\n",
2604 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2605 d_id
.b
.area
, d_id
.b
.al_pa
));
2608 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2609 ha
->rscn_out_ptr
= 0;
2611 /* Skip duplicate entries. */
2612 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2613 !ha
->flags
.rscn_queue_overflow
&&
2614 rscn_out_iter
!= ha
->rscn_in_ptr
;
2615 rscn_out_iter
= (rscn_out_iter
==
2616 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2618 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2621 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2622 "entry found at [%d].\n", ha
->host_no
,
2625 ha
->rscn_out_ptr
= rscn_out_iter
;
2628 /* Queue overflow, set switch default case. */
2629 if (ha
->flags
.rscn_queue_overflow
) {
2630 DEBUG(printk("scsi(%ld): device_resync: rscn "
2631 "overflow.\n", ha
->host_no
));
2634 ha
->flags
.rscn_queue_overflow
= 0;
2639 if (ql2xprocessrscn
&&
2640 !IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
2641 !IS_QLA6312(ha
) && !IS_QLA6322(ha
) &&
2642 !IS_QLA24XX(ha
) && !IS_QLA25XX(ha
) &&
2643 ha
->flags
.init_done
) {
2644 /* Handle port RSCN via asyncronous IOCBs */
2645 rval2
= qla2x00_handle_port_rscn(ha
, rscn_entry
,
2647 if (rval2
== QLA_SUCCESS
)
2661 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2667 /* Abort any outstanding IO descriptors. */
2668 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2669 qla2x00_cancel_io_descriptors(ha
);
2671 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2672 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2673 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2674 fcport
->port_type
== FCT_BROADCAST
)
2677 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2679 fcport
->port_type
!= FCT_INITIATOR
) {
2680 qla2x00_mark_device_lost(ha
, fcport
,
2684 fcport
->flags
&= ~FCF_FARP_DONE
;
2691 * qla2x00_fabric_dev_login
2692 * Login fabric target device and update FC port database.
2695 * ha: adapter state pointer.
2696 * fcport: port structure list pointer.
2697 * next_loopid: contains value of a new loop ID that can be used
2698 * by the next login attempt.
2701 * qla2x00 local function return status code.
2707 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2708 uint16_t *next_loopid
)
2717 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2718 if (rval
== QLA_SUCCESS
) {
2719 /* Send an ADISC to tape devices.*/
2721 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2723 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2724 if (rval
!= QLA_SUCCESS
) {
2725 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2726 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2727 fcport
->d_id
.b
.al_pa
);
2728 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2730 qla2x00_update_fcport(ha
, fcport
);
2738 * qla2x00_fabric_login
2739 * Issue fabric login command.
2742 * ha = adapter block pointer.
2743 * device = pointer to FC device type structure.
2746 * 0 - Login successfully
2748 * 2 - Initiator device
2752 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2753 uint16_t *next_loopid
)
2757 uint16_t tmp_loopid
;
2758 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2764 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2765 "for port %02x%02x%02x.\n",
2766 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2767 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2769 /* Login fcport on switch. */
2770 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2771 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2772 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2773 if (mb
[0] == MBS_PORT_ID_USED
) {
2775 * Device has another loop ID. The firmware team
2776 * recommends the driver perform an implicit login with
2777 * the specified ID again. The ID we just used is save
2778 * here so we return with an ID that can be tried by
2782 tmp_loopid
= fcport
->loop_id
;
2783 fcport
->loop_id
= mb
[1];
2785 DEBUG(printk("Fabric Login: port in use - next "
2786 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2787 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2788 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2790 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2795 /* A retry occurred before. */
2796 *next_loopid
= tmp_loopid
;
2799 * No retry occurred before. Just increment the
2800 * ID value for next login.
2802 *next_loopid
= (fcport
->loop_id
+ 1);
2805 if (mb
[1] & BIT_0
) {
2806 fcport
->port_type
= FCT_INITIATOR
;
2808 fcport
->port_type
= FCT_TARGET
;
2809 if (mb
[1] & BIT_1
) {
2810 fcport
->flags
|= FCF_TAPE_PRESENT
;
2815 fcport
->supported_classes
|= FC_COS_CLASS2
;
2817 fcport
->supported_classes
|= FC_COS_CLASS3
;
2821 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2823 * Loop ID already used, try next loop ID.
2826 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2827 if (rval
!= QLA_SUCCESS
) {
2828 /* Ran out of loop IDs to use */
2831 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2833 * Firmware possibly timed out during login. If NO
2834 * retries are left to do then the device is declared
2837 *next_loopid
= fcport
->loop_id
;
2838 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2839 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2840 fcport
->d_id
.b
.al_pa
);
2841 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2847 * unrecoverable / not handled error
2849 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2850 "loop_id=%x jiffies=%lx.\n",
2851 __func__
, ha
->host_no
, mb
[0],
2852 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2853 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2855 *next_loopid
= fcport
->loop_id
;
2856 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2857 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2858 fcport
->d_id
.b
.al_pa
);
2859 fcport
->loop_id
= FC_NO_LOOP_ID
;
2860 fcport
->login_retry
= 0;
2871 * qla2x00_local_device_login
2872 * Issue local device login command.
2875 * ha = adapter block pointer.
2876 * loop_id = loop id of device to login to.
2878 * Returns (Where's the #define!!!!):
2879 * 0 - Login successfully
2884 qla2x00_local_device_login(scsi_qla_host_t
*ha
, uint16_t loop_id
)
2887 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2889 memset(mb
, 0, sizeof(mb
));
2890 rval
= qla2x00_login_local_device(ha
, loop_id
, mb
, BIT_0
);
2891 if (rval
== QLA_SUCCESS
) {
2892 /* Interrogate mailbox registers for any errors */
2893 if (mb
[0] == MBS_COMMAND_ERROR
)
2895 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2896 /* device not in PCB table */
2904 * qla2x00_loop_resync
2905 * Resync with fibre channel devices.
2908 * ha = adapter block pointer.
2914 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2921 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2922 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2923 if (ha
->flags
.online
) {
2924 if (!(rval
= qla2x00_fw_ready(ha
))) {
2925 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2928 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2930 /* Issue a marker after FW becomes ready. */
2931 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
2932 ha
->marker_needed
= 0;
2934 /* Remap devices on Loop. */
2935 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2937 qla2x00_configure_loop(ha
);
2939 } while (!atomic_read(&ha
->loop_down_timer
) &&
2940 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
2942 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
2946 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2947 return (QLA_FUNCTION_FAILED
);
2951 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
2958 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
2964 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2965 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
2968 qla2x00_update_fcport(ha
, fcport
);
2969 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
2973 qla2x00_probe_for_all_luns(ha
);
2977 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
2981 /* Go with deferred removal of rport references. */
2982 list_for_each_entry(fcport
, &ha
->fcports
, list
)
2984 qla2x00_rport_del(fcport
);
2989 * Resets ISP and aborts all outstanding commands.
2992 * ha = adapter block pointer.
2998 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3000 unsigned long flags
= 0;
3005 if (ha
->flags
.online
) {
3006 ha
->flags
.online
= 0;
3007 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3009 qla_printk(KERN_INFO
, ha
,
3010 "Performing ISP error recovery - ha= %p.\n", ha
);
3011 ha
->isp_ops
.reset_chip(ha
);
3013 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3014 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3015 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3016 qla2x00_mark_all_devices_lost(ha
, 0);
3018 if (!atomic_read(&ha
->loop_down_timer
))
3019 atomic_set(&ha
->loop_down_timer
,
3023 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3024 /* Requeue all commands in outstanding command list. */
3025 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3026 sp
= ha
->outstanding_cmds
[cnt
];
3028 ha
->outstanding_cmds
[cnt
] = NULL
;
3030 sp
->cmd
->result
= DID_RESET
<< 16;
3031 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3032 qla2x00_sp_compl(ha
, sp
);
3035 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3037 ha
->isp_ops
.nvram_config(ha
);
3039 if (!qla2x00_restart_isp(ha
)) {
3040 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3042 if (!atomic_read(&ha
->loop_down_timer
)) {
3044 * Issue marker command only when we are going
3045 * to start the I/O .
3047 ha
->marker_needed
= 1;
3050 ha
->flags
.online
= 1;
3052 ha
->isp_ops
.enable_intrs(ha
);
3054 ha
->isp_abort_cnt
= 0;
3055 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3056 } else { /* failed the ISP abort */
3057 ha
->flags
.online
= 1;
3058 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3059 if (ha
->isp_abort_cnt
== 0) {
3060 qla_printk(KERN_WARNING
, ha
,
3061 "ISP error recovery failed - "
3062 "board disabled\n");
3064 * The next call disables the board
3067 ha
->isp_ops
.reset_adapter(ha
);
3068 ha
->flags
.online
= 0;
3069 clear_bit(ISP_ABORT_RETRY
,
3072 } else { /* schedule another ISP abort */
3073 ha
->isp_abort_cnt
--;
3074 DEBUG(printk("qla%ld: ISP abort - "
3075 "retry remaining %d\n",
3076 ha
->host_no
, ha
->isp_abort_cnt
);)
3080 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3081 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3082 "- retrying (%d) more times\n",
3083 ha
->host_no
, ha
->isp_abort_cnt
);)
3084 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3092 qla_printk(KERN_INFO
, ha
,
3093 "qla2x00_abort_isp: **** FAILED ****\n");
3095 DEBUG(printk(KERN_INFO
3096 "qla2x00_abort_isp(%ld): exiting.\n",
3104 * qla2x00_restart_isp
3105 * restarts the ISP after a reset
3108 * ha = adapter block pointer.
3114 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3117 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3118 unsigned long flags
= 0;
3121 /* If firmware needs to be loaded */
3122 if (qla2x00_isp_firmware(ha
)) {
3123 ha
->flags
.online
= 0;
3124 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3125 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3126 status
= qla2x00_setup_chip(ha
);
3130 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3132 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
)) {
3134 * Disable SRAM, Instruction RAM and GP RAM
3137 WRT_REG_WORD(®
->hccr
,
3138 (HCCR_ENABLE_PARITY
+ 0x0));
3139 RD_REG_WORD(®
->hccr
);
3142 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3144 status
= qla2x00_setup_chip(ha
);
3146 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3148 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
)) {
3149 /* Enable proper parity */
3152 WRT_REG_WORD(®
->hccr
,
3153 (HCCR_ENABLE_PARITY
+ 0x1));
3156 * SRAM, Instruction RAM and GP RAM
3159 WRT_REG_WORD(®
->hccr
,
3160 (HCCR_ENABLE_PARITY
+ 0x7));
3161 RD_REG_WORD(®
->hccr
);
3164 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3169 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3170 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3171 if (!(status
= qla2x00_fw_ready(ha
))) {
3172 DEBUG(printk("%s(): Start configure loop, "
3173 "status = %d\n", __func__
, status
);)
3175 /* Issue a marker after FW becomes ready. */
3176 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3178 ha
->flags
.online
= 1;
3179 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3182 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3183 qla2x00_configure_loop(ha
);
3185 } while (!atomic_read(&ha
->loop_down_timer
) &&
3186 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3188 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3191 /* if no cable then assume it's good */
3192 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3195 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3203 * qla2x00_reset_adapter
3207 * ha = adapter block pointer.
3210 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3212 unsigned long flags
= 0;
3213 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3215 ha
->flags
.online
= 0;
3216 ha
->isp_ops
.disable_intrs(ha
);
3218 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3219 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3220 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3221 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3222 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3223 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3227 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3229 unsigned long flags
= 0;
3230 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3232 ha
->flags
.online
= 0;
3233 ha
->isp_ops
.disable_intrs(ha
);
3235 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3236 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3237 RD_REG_DWORD(®
->hccr
);
3238 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3239 RD_REG_DWORD(®
->hccr
);
3240 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3244 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3247 struct init_cb_24xx
*icb
;
3248 struct nvram_24xx
*nv
;
3250 uint8_t *dptr1
, *dptr2
;
3255 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3256 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3258 /* Determine NVRAM starting address. */
3259 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3260 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3261 if (PCI_FUNC(ha
->pdev
->devfn
))
3262 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3264 /* Get NVRAM data and calculate checksum. */
3265 dptr
= (uint32_t *)nv
;
3266 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3268 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3269 chksum
+= le32_to_cpu(*dptr
++);
3271 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3272 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3275 /* Bad NVRAM data, set defaults parameters. */
3276 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3277 || nv
->id
[3] != ' ' ||
3278 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3279 /* Reset NVRAM data. */
3280 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3281 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3282 le16_to_cpu(nv
->nvram_version
));
3283 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3284 "invalid -- WWPN) defaults.\n");
3287 * Set default initialization control block.
3289 memset(nv
, 0, ha
->nvram_size
);
3290 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3291 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3292 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3293 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3294 nv
->exchange_count
= __constant_cpu_to_le16(0);
3295 nv
->hard_address
= __constant_cpu_to_le16(124);
3296 nv
->port_name
[0] = 0x21;
3297 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3298 nv
->port_name
[2] = 0x00;
3299 nv
->port_name
[3] = 0xe0;
3300 nv
->port_name
[4] = 0x8b;
3301 nv
->port_name
[5] = 0x1c;
3302 nv
->port_name
[6] = 0x55;
3303 nv
->port_name
[7] = 0x86;
3304 nv
->node_name
[0] = 0x20;
3305 nv
->node_name
[1] = 0x00;
3306 nv
->node_name
[2] = 0x00;
3307 nv
->node_name
[3] = 0xe0;
3308 nv
->node_name
[4] = 0x8b;
3309 nv
->node_name
[5] = 0x1c;
3310 nv
->node_name
[6] = 0x55;
3311 nv
->node_name
[7] = 0x86;
3312 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3313 nv
->link_down_timeout
= __constant_cpu_to_le16(200);
3314 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3315 nv
->login_timeout
= __constant_cpu_to_le16(0);
3316 nv
->firmware_options_1
=
3317 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3318 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3319 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3320 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3321 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3322 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3323 nv
->reset_delay
= 5;
3324 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3325 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3326 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3331 /* Reset Initialization control block */
3332 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3334 /* Copy 1st segment. */
3335 dptr1
= (uint8_t *)icb
;
3336 dptr2
= (uint8_t *)&nv
->version
;
3337 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3339 *dptr1
++ = *dptr2
++;
3341 icb
->login_retry_count
= nv
->login_retry_count
;
3342 icb
->link_down_timeout
= nv
->link_down_timeout
;
3344 /* Copy 2nd segment. */
3345 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3346 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3347 cnt
= (uint8_t *)&icb
->reserved_3
-
3348 (uint8_t *)&icb
->interrupt_delay_timer
;
3350 *dptr1
++ = *dptr2
++;
3353 * Setup driver NVRAM options.
3355 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3359 strncpy(ha
->model_number
, nv
->model_name
,
3360 sizeof(nv
->model_name
));
3361 st
= en
= ha
->model_number
;
3362 en
+= sizeof(nv
->model_name
) - 1;
3364 if (*en
!= 0x20 && *en
!= 0x00)
3369 index
= (ha
->pdev
->subsystem_device
& 0xff);
3370 if (index
< QLA_MODEL_NAMES
)
3371 ha
->model_desc
= qla2x00_model_desc
[index
];
3373 strcpy(ha
->model_number
, "QLA2462");
3375 /* Prepare nodename */
3376 if ((icb
->firmware_options_1
& BIT_14
) == 0) {
3378 * Firmware will apply the following mask if the nodename was
3381 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3382 icb
->node_name
[0] &= 0xF0;
3385 /* Set host adapter parameters. */
3386 ha
->flags
.disable_risc_code_load
= 0;
3387 ha
->flags
.enable_lip_reset
= 1;
3388 ha
->flags
.enable_lip_full_login
= 1;
3389 ha
->flags
.enable_target_reset
= 1;
3390 ha
->flags
.enable_led_scheme
= 0;
3392 ha
->operating_mode
=
3393 (icb
->firmware_options_2
& (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3395 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3396 sizeof(ha
->fw_seriallink_options24
));
3398 /* save HBA serial number */
3399 ha
->serial0
= icb
->port_name
[5];
3400 ha
->serial1
= icb
->port_name
[6];
3401 ha
->serial2
= icb
->port_name
[7];
3402 ha
->node_name
= icb
->node_name
;
3403 ha
->port_name
= icb
->port_name
;
3405 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3407 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3409 /* Set minimum login_timeout to 4 seconds. */
3410 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3411 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3412 if (le16_to_cpu(nv
->login_timeout
) < 4)
3413 nv
->login_timeout
= __constant_cpu_to_le16(4);
3414 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3415 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3417 /* Set minimum RATOV to 200 tenths of a second. */
3420 ha
->loop_reset_delay
= nv
->reset_delay
;
3422 /* Link Down Timeout = 0:
3424 * When Port Down timer expires we will start returning
3425 * I/O's to OS with "DID_NO_CONNECT".
3427 * Link Down Timeout != 0:
3429 * The driver waits for the link to come up after link down
3430 * before returning I/Os to OS with "DID_NO_CONNECT".
3432 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3433 ha
->loop_down_abort_time
=
3434 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3436 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3437 ha
->loop_down_abort_time
=
3438 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3441 /* Need enough time to try and get the port back. */
3442 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3443 if (qlport_down_retry
)
3444 ha
->port_down_retry_count
= qlport_down_retry
;
3446 /* Set login_retry_count */
3447 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3448 if (ha
->port_down_retry_count
==
3449 le16_to_cpu(nv
->port_down_retry_count
) &&
3450 ha
->port_down_retry_count
> 3)
3451 ha
->login_retry_count
= ha
->port_down_retry_count
;
3452 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3453 ha
->login_retry_count
= ha
->port_down_retry_count
;
3454 if (ql2xloginretrycount
)
3455 ha
->login_retry_count
= ql2xloginretrycount
;
3458 if (!ha
->flags
.init_done
) {
3459 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3460 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3461 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3462 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3464 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3465 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3466 ha
->flags
.process_response_queue
= 0;
3467 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3468 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3469 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3470 ha
->zio_timer
* 100));
3471 qla_printk(KERN_INFO
, ha
,
3472 "ZIO mode %d enabled; timer delay (%d us).\n",
3473 ha
->zio_mode
, ha
->zio_timer
* 100);
3475 icb
->firmware_options_2
|= cpu_to_le32(
3476 (uint32_t)ha
->zio_mode
);
3477 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3478 ha
->flags
.process_response_queue
= 1;
3482 DEBUG2_3(printk(KERN_WARNING
3483 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3488 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3491 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3495 uint16_t *risc_code
;
3496 uint32_t risc_addr
, risc_size
;
3498 struct qla_fw_info
*fw_iter
;
3502 /* Load firmware sequences */
3503 fw_iter
= ha
->brd_info
->fw_info
;
3504 *srisc_addr
= *ha
->brd_info
->fw_info
->fwstart
;
3505 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3506 risc_code
= fw_iter
->fwcode
;
3507 risc_size
= *fw_iter
->fwlen
;
3508 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
)
3509 risc_addr
= *fw_iter
->fwstart
;
3511 risc_addr
= *fw_iter
->lfwstart
;
3515 while (risc_size
> 0 && !rval
) {
3516 cnt
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3517 if (cnt
> risc_size
)
3520 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3521 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3522 ha
->host_no
, risc_code
, cnt
, risc_addr
));
3524 req_ring
= (uint16_t *)ha
->request_ring
;
3525 for (i
= 0; i
< cnt
; i
++)
3526 req_ring
[i
] = cpu_to_le16(risc_code
[i
]);
3528 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3531 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3532 "load segment %d of firmware\n",
3534 qla_printk(KERN_WARNING
, ha
,
3535 "[ERROR] Failed to load segment %d of "
3538 qla2x00_dump_regs(ha
);
3548 /* Next firmware sequence */
3555 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3559 uint32_t *risc_code
;
3560 uint32_t risc_addr
, risc_size
;
3562 struct qla_fw_info
*fw_iter
;
3566 /* Load firmware sequences */
3567 fw_iter
= ha
->brd_info
->fw_info
;
3568 *srisc_addr
= *((uint32_t *)fw_iter
->lfwstart
);
3569 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3570 risc_code
= (uint32_t *)fw_iter
->fwcode
;
3571 risc_size
= *((uint32_t *)fw_iter
->fwlen
);
3572 risc_addr
= *((uint32_t *)fw_iter
->lfwstart
);
3576 while (risc_size
> 0 && !rval
) {
3577 cnt
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3578 if (cnt
> risc_size
)
3581 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3582 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3583 ha
->host_no
, risc_code
, cnt
, risc_addr
));
3585 req_ring
= (uint32_t *)ha
->request_ring
;
3586 for (i
= 0; i
< cnt
; i
++)
3587 req_ring
[i
] = cpu_to_le32(risc_code
[i
]);
3589 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3592 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3593 "load segment %d of firmware\n",
3595 qla_printk(KERN_WARNING
, ha
,
3596 "[ERROR] Failed to load segment %d of "
3599 qla2x00_dump_regs(ha
);
3609 /* Next firmware sequence */
3616 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3619 int segments
, fragment
;
3621 uint32_t *dcode
, dlen
;
3628 segments
= FA_RISC_CODE_SEGMENTS
;
3629 faddr
= FA_RISC_CODE_ADDR
;
3630 dcode
= (uint32_t *)ha
->request_ring
;
3633 /* Validate firmware image by checking version. */
3634 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3635 for (i
= 0; i
< 4; i
++)
3636 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3637 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3638 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3639 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3641 qla_printk(KERN_WARNING
, ha
,
3642 "Unable to verify integrity of flash firmware image!\n");
3643 qla_printk(KERN_WARNING
, ha
,
3644 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3645 dcode
[1], dcode
[2], dcode
[3]);
3647 return QLA_FUNCTION_FAILED
;
3650 while (segments
&& rval
== QLA_SUCCESS
) {
3651 /* Read segment's load information. */
3652 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3654 risc_addr
= be32_to_cpu(dcode
[2]);
3655 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3656 risc_size
= be32_to_cpu(dcode
[3]);
3659 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3660 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3661 if (dlen
> risc_size
)
3664 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3665 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3666 ha
->host_no
, risc_addr
, dlen
, faddr
));
3668 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3669 for (i
= 0; i
< dlen
; i
++)
3670 dcode
[i
] = swab32(dcode
[i
]);
3672 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3675 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3676 "segment %d of firmware\n", ha
->host_no
,
3678 qla_printk(KERN_WARNING
, ha
,
3679 "[ERROR] Failed to load segment %d of "
3680 "firmware\n", fragment
);
3697 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3700 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3704 uint16_t *wcode
, *fwcode
;
3705 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3706 struct fw_blob
*blob
;
3708 /* Load firmware blob. */
3709 blob
= qla2x00_request_firmware(ha
);
3711 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3712 return QLA_FUNCTION_FAILED
;
3717 wcode
= (uint16_t *)ha
->request_ring
;
3719 fwcode
= (uint16_t *)blob
->fw
->data
;
3722 /* Validate firmware image by checking version. */
3723 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3724 qla_printk(KERN_WARNING
, ha
,
3725 "Unable to verify integrity of firmware image (%Zd)!\n",
3727 goto fail_fw_integrity
;
3729 for (i
= 0; i
< 4; i
++)
3730 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3731 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3732 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3733 wcode
[2] == 0 && wcode
[3] == 0)) {
3734 qla_printk(KERN_WARNING
, ha
,
3735 "Unable to verify integrity of firmware image!\n");
3736 qla_printk(KERN_WARNING
, ha
,
3737 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3738 wcode
[1], wcode
[2], wcode
[3]);
3739 goto fail_fw_integrity
;
3743 while (*seg
&& rval
== QLA_SUCCESS
) {
3745 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3746 risc_size
= be16_to_cpu(fwcode
[3]);
3748 /* Validate firmware image size. */
3749 fwclen
+= risc_size
* sizeof(uint16_t);
3750 if (blob
->fw
->size
< fwclen
) {
3751 qla_printk(KERN_WARNING
, ha
,
3752 "Unable to verify integrity of firmware image "
3753 "(%Zd)!\n", blob
->fw
->size
);
3754 goto fail_fw_integrity
;
3758 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3759 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3760 if (wlen
> risc_size
)
3763 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3764 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3767 for (i
= 0; i
< wlen
; i
++)
3768 wcode
[i
] = swab16(fwcode
[i
]);
3770 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3773 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3774 "segment %d of firmware\n", ha
->host_no
,
3776 qla_printk(KERN_WARNING
, ha
,
3777 "[ERROR] Failed to load segment %d of "
3778 "firmware\n", fragment
);
3794 return QLA_FUNCTION_FAILED
;
3798 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3801 int segments
, fragment
;
3802 uint32_t *dcode
, dlen
;
3806 struct fw_blob
*blob
;
3807 uint32_t *fwcode
, fwclen
;
3809 /* Load firmware blob. */
3810 blob
= qla2x00_request_firmware(ha
);
3812 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3813 return QLA_FUNCTION_FAILED
;
3818 segments
= FA_RISC_CODE_SEGMENTS
;
3819 dcode
= (uint32_t *)ha
->request_ring
;
3821 fwcode
= (uint32_t *)blob
->fw
->data
;
3824 /* Validate firmware image by checking version. */
3825 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3826 qla_printk(KERN_WARNING
, ha
,
3827 "Unable to verify integrity of firmware image (%Zd)!\n",
3829 goto fail_fw_integrity
;
3831 for (i
= 0; i
< 4; i
++)
3832 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3833 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3834 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3835 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3837 qla_printk(KERN_WARNING
, ha
,
3838 "Unable to verify integrity of firmware image!\n");
3839 qla_printk(KERN_WARNING
, ha
,
3840 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3841 dcode
[1], dcode
[2], dcode
[3]);
3842 goto fail_fw_integrity
;
3845 while (segments
&& rval
== QLA_SUCCESS
) {
3846 risc_addr
= be32_to_cpu(fwcode
[2]);
3847 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3848 risc_size
= be32_to_cpu(fwcode
[3]);
3850 /* Validate firmware image size. */
3851 fwclen
+= risc_size
* sizeof(uint32_t);
3852 if (blob
->fw
->size
< fwclen
) {
3853 qla_printk(KERN_WARNING
, ha
,
3854 "Unable to verify integrity of firmware image "
3855 "(%Zd)!\n", blob
->fw
->size
);
3857 goto fail_fw_integrity
;
3861 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3862 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3863 if (dlen
> risc_size
)
3866 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3867 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3870 for (i
= 0; i
< dlen
; i
++)
3871 dcode
[i
] = swab32(fwcode
[i
]);
3873 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3876 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3877 "segment %d of firmware\n", ha
->host_no
,
3879 qla_printk(KERN_WARNING
, ha
,
3880 "[ERROR] Failed to load segment %d of "
3881 "firmware\n", fragment
);
3897 return QLA_FUNCTION_FAILED
;