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 if (ha
->flags
.disable_serdes
) {
93 /* Mask HBA via NVRAM settings? */
94 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
95 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
96 ha
->port_name
[0], ha
->port_name
[1],
97 ha
->port_name
[2], ha
->port_name
[3],
98 ha
->port_name
[4], ha
->port_name
[5],
99 ha
->port_name
[6], ha
->port_name
[7]);
100 return QLA_FUNCTION_FAILED
;
103 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
107 * Try to configure the loop.
112 /* If firmware needs to be loaded */
113 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
114 if ((rval
= ha
->isp_ops
.chip_diag(ha
)) == QLA_SUCCESS
) {
115 rval
= qla2x00_setup_chip(ha
);
119 if (rval
== QLA_SUCCESS
&&
120 (rval
= qla2x00_init_rings(ha
)) == QLA_SUCCESS
) {
121 check_fw_ready_again
:
123 * Wait for a successful LIP up to a maximum
124 * of (in seconds): RISC login timeout value,
125 * RISC retry count value, and port down retry
126 * value OR a minimum of 4 seconds OR If no
127 * cable, only 5 seconds.
129 rval
= qla2x00_fw_ready(ha
);
130 if (rval
== QLA_SUCCESS
) {
131 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
133 /* Issue a marker after FW becomes ready. */
134 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
137 * Wait at most MAX_TARGET RSCNs for a stable
142 clear_bit(LOOP_RESYNC_NEEDED
,
144 rval
= qla2x00_configure_loop(ha
);
146 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
153 * If loop state change while we were
154 * discoverying devices then wait for
158 if (atomic_read(&ha
->loop_state
) !=
159 LOOP_READY
&& retry
--) {
160 goto check_fw_ready_again
;
163 } while (!atomic_read(&ha
->loop_down_timer
) &&
166 (test_bit(LOOP_RESYNC_NEEDED
,
170 rval
= QLA_FUNCTION_FAILED
;
171 } else if (ha
->device_flags
& DFLG_NO_CABLE
)
172 /* If no cable, then all is good. */
175 } while (restart_risc
&& retry
--);
177 if (rval
== QLA_SUCCESS
) {
178 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
179 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
180 ha
->marker_needed
= 0;
182 ha
->flags
.online
= 1;
184 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
191 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
194 * Returns 0 on success.
197 qla2100_pci_config(scsi_qla_host_t
*ha
)
202 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
204 pci_set_master(ha
->pdev
);
206 if (pci_set_mwi(ha
->pdev
))
207 mwi
= PCI_COMMAND_INVALIDATE
;
209 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
210 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
211 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
213 /* Reset expansion ROM address decode enable */
214 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
215 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
216 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
218 /* Get PCI bus information. */
219 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
220 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
221 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
227 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
230 * Returns 0 on success.
233 qla2300_pci_config(scsi_qla_host_t
*ha
)
237 unsigned long flags
= 0;
239 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
241 pci_set_master(ha
->pdev
);
243 if (pci_set_mwi(ha
->pdev
))
244 mwi
= PCI_COMMAND_INVALIDATE
;
246 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
247 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
249 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
250 w
&= ~PCI_COMMAND_INTX_DISABLE
;
253 * If this is a 2300 card and not 2312, reset the
254 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
255 * the 2310 also reports itself as a 2300 so we need to get the
256 * fb revision level -- a 6 indicates it really is a 2300 and
259 if (IS_QLA2300(ha
)) {
260 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
263 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
264 for (cnt
= 0; cnt
< 30000; cnt
++) {
265 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
271 /* Select FPM registers. */
272 WRT_REG_WORD(®
->ctrl_status
, 0x20);
273 RD_REG_WORD(®
->ctrl_status
);
275 /* Get the fb rev level */
276 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
278 if (ha
->fb_rev
== FPM_2300
)
279 w
&= ~PCI_COMMAND_INVALIDATE
;
281 /* Deselect FPM registers. */
282 WRT_REG_WORD(®
->ctrl_status
, 0x0);
283 RD_REG_WORD(®
->ctrl_status
);
285 /* Release RISC module. */
286 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
287 for (cnt
= 0; cnt
< 30000; cnt
++) {
288 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
294 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
296 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
298 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
300 /* Reset expansion ROM address decode enable */
301 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
302 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
303 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
305 /* Get PCI bus information. */
306 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
307 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
308 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
314 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
317 * Returns 0 on success.
320 qla24xx_pci_config(scsi_qla_host_t
*ha
)
324 unsigned long flags
= 0;
325 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
326 int pcix_cmd_reg
, pcie_dctl_reg
;
328 pci_set_master(ha
->pdev
);
330 if (pci_set_mwi(ha
->pdev
))
331 mwi
= PCI_COMMAND_INVALIDATE
;
333 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
334 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
335 w
&= ~PCI_COMMAND_INTX_DISABLE
;
336 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
338 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
340 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
341 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
345 pcix_cmd_reg
+= PCI_X_CMD
;
346 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
347 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
349 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
352 /* PCIe -- adjust Maximum Read Request Size (2048). */
353 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
357 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
358 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
359 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
361 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
364 /* Reset expansion ROM address decode enable */
365 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
366 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
367 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
369 /* Get PCI bus information. */
370 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
371 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
372 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
378 * qla2x00_isp_firmware() - Choose firmware image.
381 * Returns 0 on success.
384 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
388 /* Assume loading risc code */
389 rval
= QLA_FUNCTION_FAILED
;
391 if (ha
->flags
.disable_risc_code_load
) {
392 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
394 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
396 /* Verify checksum of loaded RISC code. */
397 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
401 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
409 * qla2x00_reset_chip() - Reset ISP chip.
412 * Returns 0 on success.
415 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
417 unsigned long flags
= 0;
418 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
422 ha
->isp_ops
.disable_intrs(ha
);
424 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
426 /* Turn off master enable */
428 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
429 cmd
&= ~PCI_COMMAND_MASTER
;
430 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
432 if (!IS_QLA2100(ha
)) {
434 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
435 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
436 for (cnt
= 0; cnt
< 30000; cnt
++) {
437 if ((RD_REG_WORD(®
->hccr
) &
438 HCCR_RISC_PAUSE
) != 0)
443 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
447 /* Select FPM registers. */
448 WRT_REG_WORD(®
->ctrl_status
, 0x20);
449 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
451 /* FPM Soft Reset. */
452 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
453 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
455 /* Toggle Fpm Reset. */
456 if (!IS_QLA2200(ha
)) {
457 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
458 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
461 /* Select frame buffer registers. */
462 WRT_REG_WORD(®
->ctrl_status
, 0x10);
463 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
465 /* Reset frame buffer FIFOs. */
466 if (IS_QLA2200(ha
)) {
467 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
468 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
470 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
472 /* Read back fb_cmd until zero or 3 seconds max */
473 for (cnt
= 0; cnt
< 3000; cnt
++) {
474 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
480 /* Select RISC module registers. */
481 WRT_REG_WORD(®
->ctrl_status
, 0);
482 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
484 /* Reset RISC processor. */
485 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
486 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
488 /* Release RISC processor. */
489 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
490 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
493 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
494 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
496 /* Reset ISP chip. */
497 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
499 /* Wait for RISC to recover from reset. */
500 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
502 * It is necessary to for a delay here since the card doesn't
503 * respond to PCI reads during a reset. On some architectures
504 * this will result in an MCA.
507 for (cnt
= 30000; cnt
; cnt
--) {
508 if ((RD_REG_WORD(®
->ctrl_status
) &
509 CSR_ISP_SOFT_RESET
) == 0)
516 /* Reset RISC processor. */
517 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
519 WRT_REG_WORD(®
->semaphore
, 0);
521 /* Release RISC processor. */
522 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
523 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
525 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
526 for (cnt
= 0; cnt
< 30000; cnt
++) {
527 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
535 /* Turn on master enable */
536 cmd
|= PCI_COMMAND_MASTER
;
537 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
539 /* Disable RISC pause on FPM parity error. */
540 if (!IS_QLA2100(ha
)) {
541 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
542 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
545 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
549 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
552 * Returns 0 on success.
555 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
557 unsigned long flags
= 0;
558 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
562 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
565 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
566 for (cnt
= 0; cnt
< 30000; cnt
++) {
567 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
573 WRT_REG_DWORD(®
->ctrl_status
,
574 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
575 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
578 /* Wait for firmware to complete NVRAM accesses. */
579 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
580 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
582 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
586 /* Wait for soft-reset to complete. */
587 d2
= RD_REG_DWORD(®
->ctrl_status
);
588 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
590 d2
= RD_REG_DWORD(®
->ctrl_status
);
594 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
595 RD_REG_DWORD(®
->hccr
);
597 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
598 RD_REG_DWORD(®
->hccr
);
600 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
601 RD_REG_DWORD(®
->hccr
);
603 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
604 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
606 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
610 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
614 * qla24xx_reset_chip() - Reset ISP24xx chip.
617 * Returns 0 on success.
620 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
622 ha
->isp_ops
.disable_intrs(ha
);
624 /* Perform RISC reset. */
625 qla24xx_reset_risc(ha
);
629 * qla2x00_chip_diag() - Test chip for proper operation.
632 * Returns 0 on success.
635 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
638 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
639 unsigned long flags
= 0;
644 /* Assume a failed state */
645 rval
= QLA_FUNCTION_FAILED
;
647 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
648 ha
->host_no
, (u_long
)®
->flash_address
));
650 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
652 /* Reset ISP chip. */
653 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
656 * We need to have a delay here since the card will not respond while
657 * in reset causing an MCA on some architectures.
660 data
= qla2x00_debounce_register(®
->ctrl_status
);
661 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
663 data
= RD_REG_WORD(®
->ctrl_status
);
668 goto chip_diag_failed
;
670 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
673 /* Reset RISC processor. */
674 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
675 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
677 /* Workaround for QLA2312 PCI parity error */
678 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
679 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
680 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
682 data
= RD_MAILBOX_REG(ha
, reg
, 0);
689 goto chip_diag_failed
;
691 /* Check product ID of chip */
692 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
694 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
695 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
696 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
697 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
698 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
699 mb
[3] != PROD_ID_3
) {
700 qla_printk(KERN_WARNING
, ha
,
701 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
703 goto chip_diag_failed
;
705 ha
->product_id
[0] = mb
[1];
706 ha
->product_id
[1] = mb
[2];
707 ha
->product_id
[2] = mb
[3];
708 ha
->product_id
[3] = mb
[4];
710 /* Adjust fw RISC transfer size */
711 if (ha
->request_q_length
> 1024)
712 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
714 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
715 ha
->request_q_length
;
717 if (IS_QLA2200(ha
) &&
718 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
719 /* Limit firmware transfer size with a 2200A */
720 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
723 ha
->device_type
|= DT_ISP2200A
;
724 ha
->fw_transfer_size
= 128;
727 /* Wrap Incoming Mailboxes Test. */
728 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
730 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
731 rval
= qla2x00_mbx_reg_test(ha
);
733 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
735 qla_printk(KERN_WARNING
, ha
,
736 "Failed mailbox send register test\n");
739 /* Flag a successful rval */
742 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
746 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
747 "****\n", ha
->host_no
));
749 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
755 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
758 * Returns 0 on success.
761 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
765 /* Perform RISC reset. */
766 qla24xx_reset_risc(ha
);
768 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
770 rval
= qla2x00_mbx_reg_test(ha
);
772 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
774 qla_printk(KERN_WARNING
, ha
,
775 "Failed mailbox send register test\n");
777 /* Flag a successful rval */
785 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
788 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
794 qla_printk(KERN_WARNING
, ha
,
795 "Firmware dump previously allocated.\n");
800 fixed_size
= mem_size
= eft_size
= 0;
801 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
802 fixed_size
= sizeof(struct qla2100_fw_dump
);
803 } else if (IS_QLA23XX(ha
)) {
804 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
805 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
807 } else if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
808 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
809 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
812 /* Allocate memory for Extended Trace Buffer. */
813 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
816 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
817 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
821 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
824 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
825 "EFT (%d).\n", rval
);
826 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
831 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
835 memset(eft
, 0, eft_size
);
836 ha
->eft_dma
= eft_dma
;
840 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
841 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
843 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
844 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
847 ha
->fw_dump
= vmalloc(dump_size
);
849 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
850 "firmware dump!!!\n", dump_size
/ 1024);
853 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
861 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
864 ha
->fw_dump_len
= dump_size
;
865 ha
->fw_dump
->signature
[0] = 'Q';
866 ha
->fw_dump
->signature
[1] = 'L';
867 ha
->fw_dump
->signature
[2] = 'G';
868 ha
->fw_dump
->signature
[3] = 'C';
869 ha
->fw_dump
->version
= __constant_htonl(1);
871 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
872 ha
->fw_dump
->mem_size
= htonl(mem_size
);
873 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
874 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
876 ha
->fw_dump
->eft_size
= htonl(eft_size
);
877 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
878 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
880 ha
->fw_dump
->header_size
=
881 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
885 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
888 * Returns 0 on success.
891 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
894 uint16_t fw_iocb_cnt
= 0;
895 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
896 dma_addr_t request_dma
;
897 request_t
*request_ring
;
899 /* Valid only on recent ISPs. */
900 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
903 /* Retrieve IOCB counts available to the firmware. */
904 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
907 /* No point in continuing if current settings are sufficient. */
908 if (fw_iocb_cnt
< 1024)
910 if (ha
->request_q_length
>= request_q_length
)
913 /* Attempt to claim larger area for request queue. */
914 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
915 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
917 if (request_ring
== NULL
)
920 /* Resize successful, report extensions. */
921 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
922 (ha
->fw_memory_size
+ 1) / 1024);
923 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
924 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
926 /* Clear old allocations. */
927 dma_free_coherent(&ha
->pdev
->dev
,
928 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
931 /* Begin using larger queue. */
932 ha
->request_q_length
= request_q_length
;
933 ha
->request_ring
= request_ring
;
934 ha
->request_dma
= request_dma
;
938 * qla2x00_setup_chip() - Load and start RISC firmware.
941 * Returns 0 on success.
944 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
947 uint32_t srisc_address
= 0;
949 /* Load firmware sequences */
950 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
951 if (rval
== QLA_SUCCESS
) {
952 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
953 "code.\n", ha
->host_no
));
955 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
956 if (rval
== QLA_SUCCESS
) {
957 /* Start firmware execution. */
958 DEBUG(printk("scsi(%ld): Checksum OK, start "
959 "firmware.\n", ha
->host_no
));
961 rval
= qla2x00_execute_fw(ha
, srisc_address
);
962 /* Retrieve firmware information. */
963 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
964 qla2x00_get_fw_version(ha
,
965 &ha
->fw_major_version
,
966 &ha
->fw_minor_version
,
967 &ha
->fw_subminor_version
,
968 &ha
->fw_attributes
, &ha
->fw_memory_size
);
969 qla2x00_resize_request_q(ha
);
972 qla2x00_alloc_fw_dump(ha
);
975 DEBUG2(printk(KERN_INFO
976 "scsi(%ld): ISP Firmware failed checksum.\n",
982 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
990 * qla2x00_init_response_q_entries() - Initializes response queue entries.
993 * Beginning of request ring has initialization control block already built
994 * by nvram config routine.
996 * Returns 0 on success.
999 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
1004 pkt
= ha
->response_ring_ptr
;
1005 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
1006 pkt
->signature
= RESPONSE_PROCESSED
;
1013 * qla2x00_update_fw_options() - Read and process firmware options.
1016 * Returns 0 on success.
1019 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
1021 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1023 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1024 qla2x00_get_fw_options(ha
, ha
->fw_options
);
1026 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1029 /* Serial Link options. */
1030 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1032 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1033 sizeof(ha
->fw_seriallink_options
)));
1035 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1036 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1037 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1040 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1041 emphasis
= (ha
->fw_seriallink_options
[2] &
1042 (BIT_4
| BIT_3
)) >> 3;
1043 tx_sens
= ha
->fw_seriallink_options
[0] &
1044 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1045 rx_sens
= (ha
->fw_seriallink_options
[0] &
1046 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1047 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1048 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1051 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1052 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1053 ha
->fw_options
[10] |= BIT_5
|
1054 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1055 (tx_sens
& (BIT_1
| BIT_0
));
1058 swing
= (ha
->fw_seriallink_options
[2] &
1059 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1060 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1061 tx_sens
= ha
->fw_seriallink_options
[1] &
1062 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1063 rx_sens
= (ha
->fw_seriallink_options
[1] &
1064 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1065 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1066 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1069 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1070 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1071 ha
->fw_options
[11] |= BIT_5
|
1072 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1073 (tx_sens
& (BIT_1
| BIT_0
));
1077 /* Return command IOCBs without waiting for an ABTS to complete. */
1078 ha
->fw_options
[3] |= BIT_13
;
1081 if (ha
->flags
.enable_led_scheme
)
1082 ha
->fw_options
[2] |= BIT_12
;
1084 /* Detect ISP6312. */
1086 ha
->fw_options
[2] |= BIT_13
;
1088 /* Update firmware options. */
1089 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1093 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1097 /* Update Serial Link options. */
1098 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1101 rval
= qla2x00_set_serdes_params(ha
,
1102 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1103 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1104 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1105 if (rval
!= QLA_SUCCESS
) {
1106 qla_printk(KERN_WARNING
, ha
,
1107 "Unable to update Serial Link options (%x).\n", rval
);
1112 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1114 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1116 /* Setup ring parameters in initialization control block. */
1117 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1118 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1119 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1120 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1121 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1122 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1123 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1124 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1126 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1127 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1128 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1129 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1130 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1134 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1136 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1137 struct init_cb_24xx
*icb
;
1139 /* Setup ring parameters in initialization control block. */
1140 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1141 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1142 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1143 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1144 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1145 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1146 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1147 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1148 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1150 WRT_REG_DWORD(®
->req_q_in
, 0);
1151 WRT_REG_DWORD(®
->req_q_out
, 0);
1152 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1153 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1154 RD_REG_DWORD(®
->rsp_q_out
);
1158 * qla2x00_init_rings() - Initializes firmware.
1161 * Beginning of request ring has initialization control block already built
1162 * by nvram config routine.
1164 * Returns 0 on success.
1167 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1170 unsigned long flags
= 0;
1173 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1175 /* Clear outstanding commands array. */
1176 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1177 ha
->outstanding_cmds
[cnt
] = NULL
;
1179 ha
->current_outstanding_cmd
= 0;
1181 /* Clear RSCN queue. */
1182 ha
->rscn_in_ptr
= 0;
1183 ha
->rscn_out_ptr
= 0;
1185 /* Initialize firmware. */
1186 ha
->request_ring_ptr
= ha
->request_ring
;
1187 ha
->req_ring_index
= 0;
1188 ha
->req_q_cnt
= ha
->request_q_length
;
1189 ha
->response_ring_ptr
= ha
->response_ring
;
1190 ha
->rsp_ring_index
= 0;
1192 /* Initialize response queue entries */
1193 qla2x00_init_response_q_entries(ha
);
1195 ha
->isp_ops
.config_rings(ha
);
1197 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1199 /* Update any ISP specific firmware options before initialization. */
1200 ha
->isp_ops
.update_fw_options(ha
);
1202 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1203 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1205 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1208 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1216 * qla2x00_fw_ready() - Waits for firmware ready.
1219 * Returns 0 on success.
1222 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1225 unsigned long wtime
, mtime
;
1226 uint16_t min_wait
; /* Minimum wait time if loop is down */
1227 uint16_t wait_time
; /* Wait time if loop is coming ready */
1232 /* 20 seconds for loop down. */
1236 * Firmware should take at most one RATOV to login, plus 5 seconds for
1237 * our own processing.
1239 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1240 wait_time
= min_wait
;
1243 /* Min wait time if loop down */
1244 mtime
= jiffies
+ (min_wait
* HZ
);
1246 /* wait time before firmware ready */
1247 wtime
= jiffies
+ (wait_time
* HZ
);
1249 /* Wait for ISP to finish LIP */
1250 if (!ha
->flags
.init_done
)
1251 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1253 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1257 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1258 if (rval
== QLA_SUCCESS
) {
1259 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1260 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1262 if (fw_state
== FSTATE_READY
) {
1263 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1266 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1267 &ha
->login_timeout
, &ha
->r_a_tov
);
1273 rval
= QLA_FUNCTION_FAILED
;
1275 if (atomic_read(&ha
->loop_down_timer
) &&
1276 fw_state
!= FSTATE_READY
) {
1277 /* Loop down. Timeout on min_wait for states
1278 * other than Wait for Login.
1280 if (time_after_eq(jiffies
, mtime
)) {
1281 qla_printk(KERN_INFO
, ha
,
1282 "Cable is unplugged...\n");
1284 ha
->device_flags
|= DFLG_NO_CABLE
;
1289 /* Mailbox cmd failed. Timeout on min_wait. */
1290 if (time_after_eq(jiffies
, mtime
))
1294 if (time_after_eq(jiffies
, wtime
))
1297 /* Delay for a while */
1300 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1301 ha
->host_no
, fw_state
, jiffies
));
1304 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1305 ha
->host_no
, fw_state
, jiffies
));
1308 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1316 * qla2x00_configure_hba
1317 * Setup adapter context.
1320 * ha = adapter state pointer.
1329 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1337 char connect_type
[22];
1339 /* Get host addresses. */
1340 rval
= qla2x00_get_adapter_id(ha
,
1341 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1342 if (rval
!= QLA_SUCCESS
) {
1343 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1344 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1345 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1346 __func__
, ha
->host_no
));
1348 qla_printk(KERN_WARNING
, ha
,
1349 "ERROR -- Unable to get host loop ID.\n");
1350 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1356 qla_printk(KERN_INFO
, ha
,
1357 "Cannot get topology - retrying.\n");
1358 return (QLA_FUNCTION_FAILED
);
1361 ha
->loop_id
= loop_id
;
1364 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1365 ha
->operating_mode
= LOOP
;
1369 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1371 ha
->current_topology
= ISP_CFG_NL
;
1372 strcpy(connect_type
, "(Loop)");
1376 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1378 ha
->current_topology
= ISP_CFG_FL
;
1379 strcpy(connect_type
, "(FL_Port)");
1383 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1385 ha
->operating_mode
= P2P
;
1386 ha
->current_topology
= ISP_CFG_N
;
1387 strcpy(connect_type
, "(N_Port-to-N_Port)");
1391 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1393 ha
->operating_mode
= P2P
;
1394 ha
->current_topology
= ISP_CFG_F
;
1395 strcpy(connect_type
, "(F_Port)");
1399 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1401 ha
->host_no
, topo
));
1402 ha
->current_topology
= ISP_CFG_NL
;
1403 strcpy(connect_type
, "(Loop)");
1407 /* Save Host port and loop ID. */
1408 /* byte order - Big Endian */
1409 ha
->d_id
.b
.domain
= domain
;
1410 ha
->d_id
.b
.area
= area
;
1411 ha
->d_id
.b
.al_pa
= al_pa
;
1413 if (!ha
->flags
.init_done
)
1414 qla_printk(KERN_INFO
, ha
,
1415 "Topology - %s, Host Loop address 0x%x\n",
1416 connect_type
, ha
->loop_id
);
1419 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1421 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1428 * NVRAM configuration for ISP 2xxx
1431 * ha = adapter block pointer.
1434 * initialization control block in response_ring
1435 * host adapters parameters in host adapter block
1441 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1446 uint8_t *dptr1
, *dptr2
;
1447 init_cb_t
*icb
= ha
->init_cb
;
1448 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1449 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1450 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1454 /* Determine NVRAM starting address. */
1455 ha
->nvram_size
= sizeof(nvram_t
);
1457 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1458 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1459 ha
->nvram_base
= 0x80;
1461 /* Get NVRAM data and calculate checksum. */
1462 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1463 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1466 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1467 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1470 /* Bad NVRAM data, set defaults parameters. */
1471 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1472 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1473 /* Reset NVRAM data. */
1474 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1475 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1477 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1478 "invalid -- WWPN) defaults.\n");
1481 * Set default initialization control block.
1483 memset(nv
, 0, ha
->nvram_size
);
1484 nv
->parameter_block_version
= ICB_VERSION
;
1486 if (IS_QLA23XX(ha
)) {
1487 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1488 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1489 nv
->add_firmware_options
[0] = BIT_5
;
1490 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1491 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1492 nv
->special_options
[1] = BIT_7
;
1493 } else if (IS_QLA2200(ha
)) {
1494 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1495 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1496 nv
->add_firmware_options
[0] = BIT_5
;
1497 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1498 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1499 } else if (IS_QLA2100(ha
)) {
1500 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1501 nv
->firmware_options
[1] = BIT_5
;
1502 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1505 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1506 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1507 nv
->retry_count
= 8;
1508 nv
->retry_delay
= 1;
1510 nv
->port_name
[0] = 33;
1511 nv
->port_name
[3] = 224;
1512 nv
->port_name
[4] = 139;
1514 nv
->login_timeout
= 4;
1517 * Set default host adapter parameters
1519 nv
->host_p
[1] = BIT_2
;
1520 nv
->reset_delay
= 5;
1521 nv
->port_down_retry_count
= 8;
1522 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1523 nv
->link_down_timeout
= 60;
1528 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1530 * The SN2 does not provide BIOS emulation which means you can't change
1531 * potentially bogus BIOS settings. Force the use of default settings
1532 * for link rate and frame size. Hope that the rest of the settings
1535 if (ia64_platform_is("sn2")) {
1536 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1538 nv
->special_options
[1] = BIT_7
;
1542 /* Reset Initialization control block */
1543 memset(icb
, 0, ha
->init_cb_size
);
1546 * Setup driver NVRAM options.
1548 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1549 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1550 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1551 nv
->firmware_options
[1] &= ~BIT_4
;
1553 if (IS_QLA23XX(ha
)) {
1554 nv
->firmware_options
[0] |= BIT_2
;
1555 nv
->firmware_options
[0] &= ~BIT_3
;
1556 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1558 if (IS_QLA2300(ha
)) {
1559 if (ha
->fb_rev
== FPM_2310
) {
1560 strcpy(ha
->model_number
, "QLA2310");
1562 strcpy(ha
->model_number
, "QLA2300");
1566 memcmp(nv
->model_number
, BINZERO
,
1567 sizeof(nv
->model_number
)) != 0) {
1570 strncpy(ha
->model_number
, nv
->model_number
,
1571 sizeof(nv
->model_number
));
1572 st
= en
= ha
->model_number
;
1573 en
+= sizeof(nv
->model_number
) - 1;
1575 if (*en
!= 0x20 && *en
!= 0x00)
1582 index
= (ha
->pdev
->subsystem_device
& 0xff);
1583 if (index
< QLA_MODEL_NAMES
) {
1584 strcpy(ha
->model_number
,
1585 qla2x00_model_name
[index
* 2]);
1587 qla2x00_model_name
[index
* 2 + 1];
1589 strcpy(ha
->model_number
, "QLA23xx");
1593 } else if (IS_QLA2200(ha
)) {
1594 nv
->firmware_options
[0] |= BIT_2
;
1596 * 'Point-to-point preferred, else loop' is not a safe
1597 * connection mode setting.
1599 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1601 /* Force 'loop preferred, else point-to-point'. */
1602 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1603 nv
->add_firmware_options
[0] |= BIT_5
;
1605 strcpy(ha
->model_number
, "QLA22xx");
1606 } else /*if (IS_QLA2100(ha))*/ {
1607 strcpy(ha
->model_number
, "QLA2100");
1611 * Copy over NVRAM RISC parameter block to initialization control block.
1613 dptr1
= (uint8_t *)icb
;
1614 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1615 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1617 *dptr1
++ = *dptr2
++;
1619 /* Copy 2nd half. */
1620 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1621 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1623 *dptr1
++ = *dptr2
++;
1625 /* Use alternate WWN? */
1626 if (nv
->host_p
[1] & BIT_7
) {
1627 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1628 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1631 /* Prepare nodename */
1632 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1634 * Firmware will apply the following mask if the nodename was
1637 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1638 icb
->node_name
[0] &= 0xF0;
1642 * Set host adapter parameters.
1644 if (nv
->host_p
[0] & BIT_7
)
1645 extended_error_logging
= 1;
1646 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1647 /* Always load RISC code on non ISP2[12]00 chips. */
1648 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1649 ha
->flags
.disable_risc_code_load
= 0;
1650 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1651 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1652 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1653 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1654 ha
->flags
.disable_serdes
= 0;
1656 ha
->operating_mode
=
1657 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1659 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1660 sizeof(ha
->fw_seriallink_options
));
1662 /* save HBA serial number */
1663 ha
->serial0
= icb
->port_name
[5];
1664 ha
->serial1
= icb
->port_name
[6];
1665 ha
->serial2
= icb
->port_name
[7];
1666 ha
->node_name
= icb
->node_name
;
1667 ha
->port_name
= icb
->port_name
;
1669 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1671 ha
->retry_count
= nv
->retry_count
;
1673 /* Set minimum login_timeout to 4 seconds. */
1674 if (nv
->login_timeout
< ql2xlogintimeout
)
1675 nv
->login_timeout
= ql2xlogintimeout
;
1676 if (nv
->login_timeout
< 4)
1677 nv
->login_timeout
= 4;
1678 ha
->login_timeout
= nv
->login_timeout
;
1679 icb
->login_timeout
= nv
->login_timeout
;
1681 /* Set minimum RATOV to 200 tenths of a second. */
1684 ha
->loop_reset_delay
= nv
->reset_delay
;
1686 /* Link Down Timeout = 0:
1688 * When Port Down timer expires we will start returning
1689 * I/O's to OS with "DID_NO_CONNECT".
1691 * Link Down Timeout != 0:
1693 * The driver waits for the link to come up after link down
1694 * before returning I/Os to OS with "DID_NO_CONNECT".
1696 if (nv
->link_down_timeout
== 0) {
1697 ha
->loop_down_abort_time
=
1698 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1700 ha
->link_down_timeout
= nv
->link_down_timeout
;
1701 ha
->loop_down_abort_time
=
1702 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1706 * Need enough time to try and get the port back.
1708 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1709 if (qlport_down_retry
)
1710 ha
->port_down_retry_count
= qlport_down_retry
;
1711 /* Set login_retry_count */
1712 ha
->login_retry_count
= nv
->retry_count
;
1713 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1714 ha
->port_down_retry_count
> 3)
1715 ha
->login_retry_count
= ha
->port_down_retry_count
;
1716 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1717 ha
->login_retry_count
= ha
->port_down_retry_count
;
1718 if (ql2xloginretrycount
)
1719 ha
->login_retry_count
= ql2xloginretrycount
;
1721 icb
->lun_enables
= __constant_cpu_to_le16(0);
1722 icb
->command_resource_count
= 0;
1723 icb
->immediate_notify_resource_count
= 0;
1724 icb
->timeout
= __constant_cpu_to_le16(0);
1726 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1728 icb
->firmware_options
[0] &= ~BIT_3
;
1729 icb
->add_firmware_options
[0] &=
1730 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1731 icb
->add_firmware_options
[0] |= BIT_2
;
1732 icb
->response_accumulation_timer
= 3;
1733 icb
->interrupt_delay_timer
= 5;
1735 ha
->flags
.process_response_queue
= 1;
1738 if (!ha
->flags
.init_done
) {
1739 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1740 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1741 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1742 icb
->interrupt_delay_timer
: 2;
1744 icb
->add_firmware_options
[0] &=
1745 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1746 ha
->flags
.process_response_queue
= 0;
1747 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1748 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1750 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1751 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1752 ha
->zio_timer
* 100));
1753 qla_printk(KERN_INFO
, ha
,
1754 "ZIO mode %d enabled; timer delay (%d us).\n",
1755 ha
->zio_mode
, ha
->zio_timer
* 100);
1757 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1758 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1759 ha
->flags
.process_response_queue
= 1;
1764 DEBUG2_3(printk(KERN_WARNING
1765 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1771 qla2x00_rport_del(void *data
)
1773 fc_port_t
*fcport
= data
;
1774 struct fc_rport
*rport
;
1775 unsigned long flags
;
1777 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1778 rport
= fcport
->drport
;
1779 fcport
->drport
= NULL
;
1780 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1782 fc_remote_port_delete(rport
);
1787 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1789 * @flags: allocation flags
1791 * Returns a pointer to the allocated fcport, or NULL, if none available.
1794 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1798 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1802 /* Setup fcport template structure. */
1803 memset(fcport
, 0, sizeof (fc_port_t
));
1805 fcport
->port_type
= FCT_UNKNOWN
;
1806 fcport
->loop_id
= FC_NO_LOOP_ID
;
1807 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1808 fcport
->flags
= FCF_RLC_SUPPORT
;
1809 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1810 spin_lock_init(&fcport
->rport_lock
);
1816 * qla2x00_configure_loop
1817 * Updates Fibre Channel Device Database with what is actually on loop.
1820 * ha = adapter block pointer.
1825 * 2 = database was full and device was not configured.
1828 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1831 unsigned long flags
, save_flags
;
1835 /* Get Initiator ID */
1836 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1837 rval
= qla2x00_configure_hba(ha
);
1838 if (rval
!= QLA_SUCCESS
) {
1839 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1845 save_flags
= flags
= ha
->dpc_flags
;
1846 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1847 ha
->host_no
, flags
));
1850 * If we have both an RSCN and PORT UPDATE pending then handle them
1851 * both at the same time.
1853 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1854 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1856 /* Determine what we need to do */
1857 if (ha
->current_topology
== ISP_CFG_FL
&&
1858 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1860 ha
->flags
.rscn_queue_overflow
= 1;
1861 set_bit(RSCN_UPDATE
, &flags
);
1863 } else if (ha
->current_topology
== ISP_CFG_F
&&
1864 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1866 ha
->flags
.rscn_queue_overflow
= 1;
1867 set_bit(RSCN_UPDATE
, &flags
);
1868 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1870 } else if (ha
->current_topology
== ISP_CFG_N
) {
1871 clear_bit(RSCN_UPDATE
, &flags
);
1873 } else if (!ha
->flags
.online
||
1874 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1876 ha
->flags
.rscn_queue_overflow
= 1;
1877 set_bit(RSCN_UPDATE
, &flags
);
1878 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1881 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1882 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1883 rval
= QLA_FUNCTION_FAILED
;
1885 rval
= qla2x00_configure_local_loop(ha
);
1889 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1890 if (LOOP_TRANSITION(ha
)) {
1891 rval
= QLA_FUNCTION_FAILED
;
1893 rval
= qla2x00_configure_fabric(ha
);
1897 if (rval
== QLA_SUCCESS
) {
1898 if (atomic_read(&ha
->loop_down_timer
) ||
1899 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1900 rval
= QLA_FUNCTION_FAILED
;
1902 atomic_set(&ha
->loop_state
, LOOP_READY
);
1904 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1909 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1910 __func__
, ha
->host_no
));
1912 DEBUG3(printk("%s: exiting normally\n", __func__
));
1915 /* Restore state if a resync event occured during processing */
1916 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1917 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1918 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1919 if (test_bit(RSCN_UPDATE
, &save_flags
))
1920 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1929 * qla2x00_configure_local_loop
1930 * Updates Fibre Channel Device Database with local loop devices.
1933 * ha = adapter block pointer.
1939 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1944 fc_port_t
*fcport
, *new_fcport
;
1950 uint8_t domain
, area
, al_pa
;
1954 entries
= MAX_FIBRE_DEVICES
;
1956 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1957 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1959 /* Get list of logged in devices. */
1960 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1961 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1963 if (rval
!= QLA_SUCCESS
)
1964 goto cleanup_allocation
;
1966 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1967 ha
->host_no
, entries
));
1968 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1969 entries
* sizeof(struct gid_list_info
)));
1971 /* Allocate temporary fcport for any new fcports discovered. */
1972 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1973 if (new_fcport
== NULL
) {
1974 rval
= QLA_MEMORY_ALLOC_FAILED
;
1975 goto cleanup_allocation
;
1977 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1980 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1982 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1983 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1984 fcport
->port_type
!= FCT_BROADCAST
&&
1985 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1987 DEBUG(printk("scsi(%ld): Marking port lost, "
1989 ha
->host_no
, fcport
->loop_id
));
1991 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1992 fcport
->flags
&= ~FCF_FARP_DONE
;
1996 /* Add devices to port list. */
1997 id_iter
= (char *)ha
->gid_list
;
1998 for (index
= 0; index
< entries
; index
++) {
1999 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2000 area
= ((struct gid_list_info
*)id_iter
)->area
;
2001 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2002 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2003 loop_id
= (uint16_t)
2004 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2006 loop_id
= le16_to_cpu(
2007 ((struct gid_list_info
*)id_iter
)->loop_id
);
2008 id_iter
+= ha
->gid_list_info_size
;
2010 /* Bypass reserved domain fields. */
2011 if ((domain
& 0xf0) == 0xf0)
2014 /* Bypass if not same domain and area of adapter. */
2015 if (area
&& domain
&&
2016 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
2019 /* Bypass invalid local loop ID. */
2020 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2023 /* Fill in member data. */
2024 new_fcport
->d_id
.b
.domain
= domain
;
2025 new_fcport
->d_id
.b
.area
= area
;
2026 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2027 new_fcport
->loop_id
= loop_id
;
2028 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
2029 if (rval2
!= QLA_SUCCESS
) {
2030 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2031 "information -- get_port_database=%x, "
2033 ha
->host_no
, rval2
, new_fcport
->loop_id
));
2034 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2036 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2040 /* Check for matching device in port list. */
2043 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2044 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2048 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2049 FCF_PERSISTENT_BOUND
);
2050 fcport
->loop_id
= new_fcport
->loop_id
;
2051 fcport
->port_type
= new_fcport
->port_type
;
2052 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2053 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2061 /* New device, add to fcports list. */
2062 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2063 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
2065 /* Allocate a new replacement fcport. */
2066 fcport
= new_fcport
;
2067 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2068 if (new_fcport
== NULL
) {
2069 rval
= QLA_MEMORY_ALLOC_FAILED
;
2070 goto cleanup_allocation
;
2072 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2075 qla2x00_update_fcport(ha
, fcport
);
2083 if (rval
!= QLA_SUCCESS
) {
2084 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2085 "rval=%x\n", ha
->host_no
, rval
));
2089 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2090 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2097 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2101 qla2x00_mark_all_devices_lost(ha
, 0);
2102 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2103 if (fcport
->port_type
!= FCT_TARGET
)
2106 qla2x00_update_fcport(ha
, fcport
);
2111 * qla2x00_update_fcport
2112 * Updates device on list.
2115 * ha = adapter block pointer.
2116 * fcport = port structure pointer.
2126 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2129 fcport
->login_retry
= 0;
2130 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2132 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2134 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2136 atomic_set(&fcport
->state
, FCS_ONLINE
);
2138 if (ha
->flags
.init_done
)
2139 qla2x00_reg_remote_port(ha
, fcport
);
2143 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2145 struct fc_rport_identifiers rport_ids
;
2146 struct fc_rport
*rport
;
2147 unsigned long flags
;
2150 qla2x00_rport_del(fcport
);
2154 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2155 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2156 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2157 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2158 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2159 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2161 qla_printk(KERN_WARNING
, ha
,
2162 "Unable to allocate fc remote port!\n");
2165 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2166 fcport
->rport
= rport
;
2167 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2168 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2170 rport
->supported_classes
= fcport
->supported_classes
;
2172 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2173 if (fcport
->port_type
== FCT_INITIATOR
)
2174 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2175 if (fcport
->port_type
== FCT_TARGET
)
2176 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2177 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2179 if (rport
->scsi_target_id
!= -1 &&
2180 rport
->scsi_target_id
< ha
->host
->max_id
)
2181 fcport
->os_target_id
= rport
->scsi_target_id
;
2185 * qla2x00_configure_fabric
2186 * Setup SNS devices with loop ID's.
2189 * ha = adapter block pointer.
2196 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2199 fc_port_t
*fcport
, *fcptemp
;
2200 uint16_t next_loopid
;
2201 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2203 LIST_HEAD(new_fcports
);
2205 /* If FL port exists, then SNS is present */
2206 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2207 loop_id
= NPH_F_PORT
;
2209 loop_id
= SNS_FL_PORT
;
2210 rval
= qla2x00_get_port_name(ha
, loop_id
, NULL
, 0);
2211 if (rval
!= QLA_SUCCESS
) {
2212 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2213 "Port\n", ha
->host_no
));
2215 ha
->device_flags
&= ~SWITCH_FOUND
;
2216 return (QLA_SUCCESS
);
2219 /* Mark devices that need re-synchronization. */
2220 rval2
= qla2x00_device_resync(ha
);
2221 if (rval2
== QLA_RSCNS_HANDLED
) {
2222 /* No point doing the scan, just continue. */
2223 return (QLA_SUCCESS
);
2227 if (ql2xfdmienable
&&
2228 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2229 qla2x00_fdmi_register(ha
);
2231 /* Ensure we are logged into the SNS. */
2232 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2235 loop_id
= SIMPLE_NAME_SERVER
;
2236 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2237 0xfc, mb
, BIT_1
| BIT_0
);
2238 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2239 DEBUG2(qla_printk(KERN_INFO
, ha
,
2240 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2241 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2242 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2243 return (QLA_SUCCESS
);
2246 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2247 if (qla2x00_rft_id(ha
)) {
2249 DEBUG2(printk("scsi(%ld): Register FC-4 "
2250 "TYPE failed.\n", ha
->host_no
));
2252 if (qla2x00_rff_id(ha
)) {
2254 DEBUG2(printk("scsi(%ld): Register FC-4 "
2255 "Features failed.\n", ha
->host_no
));
2257 if (qla2x00_rnn_id(ha
)) {
2259 DEBUG2(printk("scsi(%ld): Register Node Name "
2260 "failed.\n", ha
->host_no
));
2261 } else if (qla2x00_rsnn_nn(ha
)) {
2263 DEBUG2(printk("scsi(%ld): Register Symbolic "
2264 "Node Name failed.\n", ha
->host_no
));
2268 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2269 if (rval
!= QLA_SUCCESS
)
2273 * Logout all previous fabric devices marked lost, except
2276 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2277 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2280 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2283 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2284 qla2x00_mark_device_lost(ha
, fcport
,
2285 ql2xplogiabsentdevice
, 0);
2286 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2287 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2288 fcport
->port_type
!= FCT_INITIATOR
&&
2289 fcport
->port_type
!= FCT_BROADCAST
) {
2290 ha
->isp_ops
.fabric_logout(ha
,
2292 fcport
->d_id
.b
.domain
,
2293 fcport
->d_id
.b
.area
,
2294 fcport
->d_id
.b
.al_pa
);
2295 fcport
->loop_id
= FC_NO_LOOP_ID
;
2300 /* Starting free loop ID. */
2301 next_loopid
= ha
->min_external_loopid
;
2304 * Scan through our port list and login entries that need to be
2307 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2308 if (atomic_read(&ha
->loop_down_timer
) ||
2309 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2312 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2313 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2316 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2317 fcport
->loop_id
= next_loopid
;
2318 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2319 if (rval
!= QLA_SUCCESS
) {
2320 /* Ran out of IDs to use */
2324 /* Login and update database */
2325 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2328 /* Exit if out of loop IDs. */
2329 if (rval
!= QLA_SUCCESS
) {
2334 * Login and add the new devices to our port list.
2336 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2337 if (atomic_read(&ha
->loop_down_timer
) ||
2338 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2341 /* Find a new loop ID to use. */
2342 fcport
->loop_id
= next_loopid
;
2343 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2344 if (rval
!= QLA_SUCCESS
) {
2345 /* Ran out of IDs to use */
2349 /* Remove device from the new list and add it to DB */
2350 list_move_tail(&fcport
->list
, &ha
->fcports
);
2352 /* Login and update database */
2353 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2357 /* Free all new device structures not processed. */
2358 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2359 list_del(&fcport
->list
);
2364 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2365 "rval=%d\n", ha
->host_no
, rval
));
2373 * qla2x00_find_all_fabric_devs
2376 * ha = adapter block pointer.
2377 * dev = database device entry pointer.
2386 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2390 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2395 int first_dev
, last_dev
;
2396 port_id_t wrap
, nxt_d_id
;
2400 /* Try GID_PT to get device list, else GAN. */
2401 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2404 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2405 "on GA_NXT\n", ha
->host_no
));
2407 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2408 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2411 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2414 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2421 /* Allocate temporary fcport for any new fcports discovered. */
2422 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2423 if (new_fcport
== NULL
) {
2425 return (QLA_MEMORY_ALLOC_FAILED
);
2427 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2429 /* Set start port ID scan at adapter ID. */
2433 /* Starting free loop ID. */
2434 loop_id
= ha
->min_external_loopid
;
2435 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2436 if (qla2x00_is_reserved_id(ha
, loop_id
))
2439 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2444 wrap
.b24
= new_fcport
->d_id
.b24
;
2446 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2447 memcpy(new_fcport
->node_name
,
2448 swl
[swl_idx
].node_name
, WWN_SIZE
);
2449 memcpy(new_fcport
->port_name
,
2450 swl
[swl_idx
].port_name
, WWN_SIZE
);
2452 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2458 /* Send GA_NXT to the switch */
2459 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2460 if (rval
!= QLA_SUCCESS
) {
2461 qla_printk(KERN_WARNING
, ha
,
2462 "SNS scan failed -- assuming zero-entry "
2464 list_for_each_entry_safe(fcport
, fcptemp
,
2465 new_fcports
, list
) {
2466 list_del(&fcport
->list
);
2474 /* If wrap on switch device list, exit. */
2476 wrap
.b24
= new_fcport
->d_id
.b24
;
2478 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2479 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2480 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2481 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2485 /* Bypass if host adapter. */
2486 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2489 /* Bypass if same domain and area of adapter. */
2490 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2491 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2495 /* Bypass reserved domain fields. */
2496 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2499 /* Locate matching device in database. */
2501 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2502 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2509 * If address the same and state FCS_ONLINE, nothing
2512 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2513 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2518 * If device was not a fabric device before.
2520 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2521 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2522 fcport
->loop_id
= FC_NO_LOOP_ID
;
2523 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2525 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2530 * Port ID changed or device was marked to be updated;
2531 * Log it out if still logged in and mark it for
2534 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2535 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2536 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2537 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2538 fcport
->port_type
!= FCT_INITIATOR
&&
2539 fcport
->port_type
!= FCT_BROADCAST
) {
2540 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2541 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2542 fcport
->d_id
.b
.al_pa
);
2543 fcport
->loop_id
= FC_NO_LOOP_ID
;
2552 /* If device was not in our fcports list, then add it. */
2553 list_add_tail(&new_fcport
->list
, new_fcports
);
2555 /* Allocate a new replacement fcport. */
2556 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2557 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2558 if (new_fcport
== NULL
) {
2560 return (QLA_MEMORY_ALLOC_FAILED
);
2562 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2563 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2569 if (!list_empty(new_fcports
))
2570 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2576 * qla2x00_find_new_loop_id
2577 * Scan through our port list and find a new usable loop ID.
2580 * ha: adapter state pointer.
2581 * dev: port structure pointer.
2584 * qla2x00 local function return status code.
2590 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2595 uint16_t first_loop_id
;
2599 /* Save starting loop ID. */
2600 first_loop_id
= dev
->loop_id
;
2603 /* Skip loop ID if already used by adapter. */
2604 if (dev
->loop_id
== ha
->loop_id
) {
2608 /* Skip reserved loop IDs. */
2609 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2613 /* Reset loop ID if passed the end. */
2614 if (dev
->loop_id
> ha
->last_loop_id
) {
2615 /* first loop ID. */
2616 dev
->loop_id
= ha
->min_external_loopid
;
2619 /* Check for loop ID being already in use. */
2622 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2623 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2624 /* ID possibly in use */
2630 /* If not in use then it is free to use. */
2635 /* ID in use. Try next value. */
2638 /* If wrap around. No free ID to use. */
2639 if (dev
->loop_id
== first_loop_id
) {
2640 dev
->loop_id
= FC_NO_LOOP_ID
;
2641 rval
= QLA_FUNCTION_FAILED
;
2650 * qla2x00_device_resync
2651 * Marks devices in the database that needs resynchronization.
2654 * ha = adapter block pointer.
2660 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2665 uint32_t rscn_entry
;
2666 uint8_t rscn_out_iter
;
2670 rval
= QLA_RSCNS_HANDLED
;
2672 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2673 ha
->flags
.rscn_queue_overflow
) {
2675 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2676 format
= MSB(MSW(rscn_entry
));
2677 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2678 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2679 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2681 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2682 "[%02x/%02x%02x%02x].\n",
2683 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2684 d_id
.b
.area
, d_id
.b
.al_pa
));
2687 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2688 ha
->rscn_out_ptr
= 0;
2690 /* Skip duplicate entries. */
2691 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2692 !ha
->flags
.rscn_queue_overflow
&&
2693 rscn_out_iter
!= ha
->rscn_in_ptr
;
2694 rscn_out_iter
= (rscn_out_iter
==
2695 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2697 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2700 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2701 "entry found at [%d].\n", ha
->host_no
,
2704 ha
->rscn_out_ptr
= rscn_out_iter
;
2707 /* Queue overflow, set switch default case. */
2708 if (ha
->flags
.rscn_queue_overflow
) {
2709 DEBUG(printk("scsi(%ld): device_resync: rscn "
2710 "overflow.\n", ha
->host_no
));
2713 ha
->flags
.rscn_queue_overflow
= 0;
2729 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2735 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2736 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2737 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2738 fcport
->port_type
== FCT_BROADCAST
)
2741 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2743 fcport
->port_type
!= FCT_INITIATOR
) {
2744 qla2x00_mark_device_lost(ha
, fcport
,
2748 fcport
->flags
&= ~FCF_FARP_DONE
;
2755 * qla2x00_fabric_dev_login
2756 * Login fabric target device and update FC port database.
2759 * ha: adapter state pointer.
2760 * fcport: port structure list pointer.
2761 * next_loopid: contains value of a new loop ID that can be used
2762 * by the next login attempt.
2765 * qla2x00 local function return status code.
2771 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2772 uint16_t *next_loopid
)
2781 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2782 if (rval
== QLA_SUCCESS
) {
2783 /* Send an ADISC to tape devices.*/
2785 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2787 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2788 if (rval
!= QLA_SUCCESS
) {
2789 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2790 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2791 fcport
->d_id
.b
.al_pa
);
2792 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2794 qla2x00_update_fcport(ha
, fcport
);
2802 * qla2x00_fabric_login
2803 * Issue fabric login command.
2806 * ha = adapter block pointer.
2807 * device = pointer to FC device type structure.
2810 * 0 - Login successfully
2812 * 2 - Initiator device
2816 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2817 uint16_t *next_loopid
)
2821 uint16_t tmp_loopid
;
2822 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2828 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2829 "for port %02x%02x%02x.\n",
2830 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2831 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2833 /* Login fcport on switch. */
2834 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2835 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2836 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2837 if (mb
[0] == MBS_PORT_ID_USED
) {
2839 * Device has another loop ID. The firmware team
2840 * recommends the driver perform an implicit login with
2841 * the specified ID again. The ID we just used is save
2842 * here so we return with an ID that can be tried by
2846 tmp_loopid
= fcport
->loop_id
;
2847 fcport
->loop_id
= mb
[1];
2849 DEBUG(printk("Fabric Login: port in use - next "
2850 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2851 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2852 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2854 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2859 /* A retry occurred before. */
2860 *next_loopid
= tmp_loopid
;
2863 * No retry occurred before. Just increment the
2864 * ID value for next login.
2866 *next_loopid
= (fcport
->loop_id
+ 1);
2869 if (mb
[1] & BIT_0
) {
2870 fcport
->port_type
= FCT_INITIATOR
;
2872 fcport
->port_type
= FCT_TARGET
;
2873 if (mb
[1] & BIT_1
) {
2874 fcport
->flags
|= FCF_TAPE_PRESENT
;
2879 fcport
->supported_classes
|= FC_COS_CLASS2
;
2881 fcport
->supported_classes
|= FC_COS_CLASS3
;
2885 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2887 * Loop ID already used, try next loop ID.
2890 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2891 if (rval
!= QLA_SUCCESS
) {
2892 /* Ran out of loop IDs to use */
2895 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2897 * Firmware possibly timed out during login. If NO
2898 * retries are left to do then the device is declared
2901 *next_loopid
= fcport
->loop_id
;
2902 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2903 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2904 fcport
->d_id
.b
.al_pa
);
2905 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2911 * unrecoverable / not handled error
2913 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2914 "loop_id=%x jiffies=%lx.\n",
2915 __func__
, ha
->host_no
, mb
[0],
2916 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2917 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2919 *next_loopid
= fcport
->loop_id
;
2920 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2921 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2922 fcport
->d_id
.b
.al_pa
);
2923 fcport
->loop_id
= FC_NO_LOOP_ID
;
2924 fcport
->login_retry
= 0;
2935 * qla2x00_local_device_login
2936 * Issue local device login command.
2939 * ha = adapter block pointer.
2940 * loop_id = loop id of device to login to.
2942 * Returns (Where's the #define!!!!):
2943 * 0 - Login successfully
2948 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2951 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2953 memset(mb
, 0, sizeof(mb
));
2954 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
2955 if (rval
== QLA_SUCCESS
) {
2956 /* Interrogate mailbox registers for any errors */
2957 if (mb
[0] == MBS_COMMAND_ERROR
)
2959 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2960 /* device not in PCB table */
2968 * qla2x00_loop_resync
2969 * Resync with fibre channel devices.
2972 * ha = adapter block pointer.
2978 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2985 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2986 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2987 if (ha
->flags
.online
) {
2988 if (!(rval
= qla2x00_fw_ready(ha
))) {
2989 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2992 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2994 /* Issue a marker after FW becomes ready. */
2995 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
2996 ha
->marker_needed
= 0;
2998 /* Remap devices on Loop. */
2999 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3001 qla2x00_configure_loop(ha
);
3003 } while (!atomic_read(&ha
->loop_down_timer
) &&
3004 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3006 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3010 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3011 return (QLA_FUNCTION_FAILED
);
3015 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3022 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3028 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3029 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3032 qla2x00_update_fcport(ha
, fcport
);
3033 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3037 qla2x00_probe_for_all_luns(ha
);
3041 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3045 /* Go with deferred removal of rport references. */
3046 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3048 qla2x00_rport_del(fcport
);
3053 * Resets ISP and aborts all outstanding commands.
3056 * ha = adapter block pointer.
3062 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3064 unsigned long flags
= 0;
3069 if (ha
->flags
.online
) {
3070 ha
->flags
.online
= 0;
3071 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3073 qla_printk(KERN_INFO
, ha
,
3074 "Performing ISP error recovery - ha= %p.\n", ha
);
3075 ha
->isp_ops
.reset_chip(ha
);
3077 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3078 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3079 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3080 qla2x00_mark_all_devices_lost(ha
, 0);
3082 if (!atomic_read(&ha
->loop_down_timer
))
3083 atomic_set(&ha
->loop_down_timer
,
3087 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3088 /* Requeue all commands in outstanding command list. */
3089 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3090 sp
= ha
->outstanding_cmds
[cnt
];
3092 ha
->outstanding_cmds
[cnt
] = NULL
;
3094 sp
->cmd
->result
= DID_RESET
<< 16;
3095 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3096 qla2x00_sp_compl(ha
, sp
);
3099 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3101 ha
->isp_ops
.nvram_config(ha
);
3103 if (!qla2x00_restart_isp(ha
)) {
3104 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3106 if (!atomic_read(&ha
->loop_down_timer
)) {
3108 * Issue marker command only when we are going
3109 * to start the I/O .
3111 ha
->marker_needed
= 1;
3114 ha
->flags
.online
= 1;
3116 ha
->isp_ops
.enable_intrs(ha
);
3118 ha
->isp_abort_cnt
= 0;
3119 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3120 } else { /* failed the ISP abort */
3121 ha
->flags
.online
= 1;
3122 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3123 if (ha
->isp_abort_cnt
== 0) {
3124 qla_printk(KERN_WARNING
, ha
,
3125 "ISP error recovery failed - "
3126 "board disabled\n");
3128 * The next call disables the board
3131 ha
->isp_ops
.reset_adapter(ha
);
3132 ha
->flags
.online
= 0;
3133 clear_bit(ISP_ABORT_RETRY
,
3136 } else { /* schedule another ISP abort */
3137 ha
->isp_abort_cnt
--;
3138 DEBUG(printk("qla%ld: ISP abort - "
3139 "retry remaining %d\n",
3140 ha
->host_no
, ha
->isp_abort_cnt
));
3144 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3145 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3146 "- retrying (%d) more times\n",
3147 ha
->host_no
, ha
->isp_abort_cnt
));
3148 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3156 qla_printk(KERN_INFO
, ha
,
3157 "qla2x00_abort_isp: **** FAILED ****\n");
3159 DEBUG(printk(KERN_INFO
3160 "qla2x00_abort_isp(%ld): exiting.\n",
3168 * qla2x00_restart_isp
3169 * restarts the ISP after a reset
3172 * ha = adapter block pointer.
3178 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3181 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3182 unsigned long flags
= 0;
3185 /* If firmware needs to be loaded */
3186 if (qla2x00_isp_firmware(ha
)) {
3187 ha
->flags
.online
= 0;
3188 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3189 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3190 status
= qla2x00_setup_chip(ha
);
3194 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3196 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3198 * Disable SRAM, Instruction RAM and GP RAM
3201 WRT_REG_WORD(®
->hccr
,
3202 (HCCR_ENABLE_PARITY
+ 0x0));
3203 RD_REG_WORD(®
->hccr
);
3206 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3208 status
= qla2x00_setup_chip(ha
);
3210 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3212 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3213 /* Enable proper parity */
3216 WRT_REG_WORD(®
->hccr
,
3217 (HCCR_ENABLE_PARITY
+ 0x1));
3220 * SRAM, Instruction RAM and GP RAM
3223 WRT_REG_WORD(®
->hccr
,
3224 (HCCR_ENABLE_PARITY
+ 0x7));
3225 RD_REG_WORD(®
->hccr
);
3228 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3233 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3234 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3235 if (!(status
= qla2x00_fw_ready(ha
))) {
3236 DEBUG(printk("%s(): Start configure loop, "
3237 "status = %d\n", __func__
, status
));
3239 /* Issue a marker after FW becomes ready. */
3240 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3242 ha
->flags
.online
= 1;
3243 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3246 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3247 qla2x00_configure_loop(ha
);
3249 } while (!atomic_read(&ha
->loop_down_timer
) &&
3250 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3252 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3255 /* if no cable then assume it's good */
3256 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3259 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3267 * qla2x00_reset_adapter
3271 * ha = adapter block pointer.
3274 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3276 unsigned long flags
= 0;
3277 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3279 ha
->flags
.online
= 0;
3280 ha
->isp_ops
.disable_intrs(ha
);
3282 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3283 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3284 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3285 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3286 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3287 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3291 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3293 unsigned long flags
= 0;
3294 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3296 ha
->flags
.online
= 0;
3297 ha
->isp_ops
.disable_intrs(ha
);
3299 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3300 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3301 RD_REG_DWORD(®
->hccr
);
3302 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3303 RD_REG_DWORD(®
->hccr
);
3304 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3308 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3311 struct init_cb_24xx
*icb
;
3312 struct nvram_24xx
*nv
;
3314 uint8_t *dptr1
, *dptr2
;
3319 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3320 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3322 /* Determine NVRAM starting address. */
3323 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3324 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3325 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3326 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3327 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3328 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3329 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3332 /* Get NVRAM data and calculate checksum. */
3333 dptr
= (uint32_t *)nv
;
3334 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3336 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3337 chksum
+= le32_to_cpu(*dptr
++);
3339 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3340 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3343 /* Bad NVRAM data, set defaults parameters. */
3344 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3345 || nv
->id
[3] != ' ' ||
3346 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3347 /* Reset NVRAM data. */
3348 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3349 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3350 le16_to_cpu(nv
->nvram_version
));
3351 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3352 "invalid -- WWPN) defaults.\n");
3355 * Set default initialization control block.
3357 memset(nv
, 0, ha
->nvram_size
);
3358 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3359 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3360 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3361 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3362 nv
->exchange_count
= __constant_cpu_to_le16(0);
3363 nv
->hard_address
= __constant_cpu_to_le16(124);
3364 nv
->port_name
[0] = 0x21;
3365 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3366 nv
->port_name
[2] = 0x00;
3367 nv
->port_name
[3] = 0xe0;
3368 nv
->port_name
[4] = 0x8b;
3369 nv
->port_name
[5] = 0x1c;
3370 nv
->port_name
[6] = 0x55;
3371 nv
->port_name
[7] = 0x86;
3372 nv
->node_name
[0] = 0x20;
3373 nv
->node_name
[1] = 0x00;
3374 nv
->node_name
[2] = 0x00;
3375 nv
->node_name
[3] = 0xe0;
3376 nv
->node_name
[4] = 0x8b;
3377 nv
->node_name
[5] = 0x1c;
3378 nv
->node_name
[6] = 0x55;
3379 nv
->node_name
[7] = 0x86;
3380 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3381 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3382 nv
->login_timeout
= __constant_cpu_to_le16(0);
3383 nv
->firmware_options_1
=
3384 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3385 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3386 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3387 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3388 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3389 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3390 nv
->reset_delay
= 5;
3391 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3392 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3393 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3398 /* Reset Initialization control block */
3399 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3401 /* Copy 1st segment. */
3402 dptr1
= (uint8_t *)icb
;
3403 dptr2
= (uint8_t *)&nv
->version
;
3404 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3406 *dptr1
++ = *dptr2
++;
3408 icb
->login_retry_count
= nv
->login_retry_count
;
3409 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3411 /* Copy 2nd segment. */
3412 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3413 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3414 cnt
= (uint8_t *)&icb
->reserved_3
-
3415 (uint8_t *)&icb
->interrupt_delay_timer
;
3417 *dptr1
++ = *dptr2
++;
3420 * Setup driver NVRAM options.
3422 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3426 strncpy(ha
->model_number
, nv
->model_name
,
3427 sizeof(nv
->model_name
));
3428 st
= en
= ha
->model_number
;
3429 en
+= sizeof(nv
->model_name
) - 1;
3431 if (*en
!= 0x20 && *en
!= 0x00)
3436 index
= (ha
->pdev
->subsystem_device
& 0xff);
3437 if (index
< QLA_MODEL_NAMES
)
3438 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
3440 strcpy(ha
->model_number
, "QLA2462");
3442 /* Use alternate WWN? */
3443 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3444 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3445 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3448 /* Prepare nodename */
3449 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3451 * Firmware will apply the following mask if the nodename was
3454 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3455 icb
->node_name
[0] &= 0xF0;
3458 /* Set host adapter parameters. */
3459 ha
->flags
.disable_risc_code_load
= 0;
3460 ha
->flags
.enable_lip_reset
= 1;
3461 ha
->flags
.enable_lip_full_login
= 1;
3462 ha
->flags
.enable_target_reset
= 1;
3463 ha
->flags
.enable_led_scheme
= 0;
3464 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3466 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3467 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3469 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3470 sizeof(ha
->fw_seriallink_options24
));
3472 /* save HBA serial number */
3473 ha
->serial0
= icb
->port_name
[5];
3474 ha
->serial1
= icb
->port_name
[6];
3475 ha
->serial2
= icb
->port_name
[7];
3476 ha
->node_name
= icb
->node_name
;
3477 ha
->port_name
= icb
->port_name
;
3479 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3481 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3483 /* Set minimum login_timeout to 4 seconds. */
3484 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3485 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3486 if (le16_to_cpu(nv
->login_timeout
) < 4)
3487 nv
->login_timeout
= __constant_cpu_to_le16(4);
3488 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3489 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3491 /* Set minimum RATOV to 200 tenths of a second. */
3494 ha
->loop_reset_delay
= nv
->reset_delay
;
3496 /* Link Down Timeout = 0:
3498 * When Port Down timer expires we will start returning
3499 * I/O's to OS with "DID_NO_CONNECT".
3501 * Link Down Timeout != 0:
3503 * The driver waits for the link to come up after link down
3504 * before returning I/Os to OS with "DID_NO_CONNECT".
3506 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3507 ha
->loop_down_abort_time
=
3508 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3510 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3511 ha
->loop_down_abort_time
=
3512 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3515 /* Need enough time to try and get the port back. */
3516 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3517 if (qlport_down_retry
)
3518 ha
->port_down_retry_count
= qlport_down_retry
;
3520 /* Set login_retry_count */
3521 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3522 if (ha
->port_down_retry_count
==
3523 le16_to_cpu(nv
->port_down_retry_count
) &&
3524 ha
->port_down_retry_count
> 3)
3525 ha
->login_retry_count
= ha
->port_down_retry_count
;
3526 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3527 ha
->login_retry_count
= ha
->port_down_retry_count
;
3528 if (ql2xloginretrycount
)
3529 ha
->login_retry_count
= ql2xloginretrycount
;
3532 if (!ha
->flags
.init_done
) {
3533 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3534 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3535 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3536 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3538 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3539 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3540 ha
->flags
.process_response_queue
= 0;
3541 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3542 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3544 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3545 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3546 ha
->zio_timer
* 100));
3547 qla_printk(KERN_INFO
, ha
,
3548 "ZIO mode %d enabled; timer delay (%d us).\n",
3549 ha
->zio_mode
, ha
->zio_timer
* 100);
3551 icb
->firmware_options_2
|= cpu_to_le32(
3552 (uint32_t)ha
->zio_mode
);
3553 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3554 ha
->flags
.process_response_queue
= 1;
3558 DEBUG2_3(printk(KERN_WARNING
3559 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3565 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3568 int segments
, fragment
;
3570 uint32_t *dcode
, dlen
;
3577 segments
= FA_RISC_CODE_SEGMENTS
;
3578 faddr
= FA_RISC_CODE_ADDR
;
3579 dcode
= (uint32_t *)ha
->request_ring
;
3582 /* Validate firmware image by checking version. */
3583 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3584 for (i
= 0; i
< 4; i
++)
3585 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3586 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3587 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3588 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3590 qla_printk(KERN_WARNING
, ha
,
3591 "Unable to verify integrity of flash firmware image!\n");
3592 qla_printk(KERN_WARNING
, ha
,
3593 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3594 dcode
[1], dcode
[2], dcode
[3]);
3596 return QLA_FUNCTION_FAILED
;
3599 while (segments
&& rval
== QLA_SUCCESS
) {
3600 /* Read segment's load information. */
3601 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3603 risc_addr
= be32_to_cpu(dcode
[2]);
3604 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3605 risc_size
= be32_to_cpu(dcode
[3]);
3608 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3609 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3610 if (dlen
> risc_size
)
3613 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3614 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3615 ha
->host_no
, risc_addr
, dlen
, faddr
));
3617 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3618 for (i
= 0; i
< dlen
; i
++)
3619 dcode
[i
] = swab32(dcode
[i
]);
3621 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3624 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3625 "segment %d of firmware\n", ha
->host_no
,
3627 qla_printk(KERN_WARNING
, ha
,
3628 "[ERROR] Failed to load segment %d of "
3629 "firmware\n", fragment
);
3646 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3649 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3653 uint16_t *wcode
, *fwcode
;
3654 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3655 struct fw_blob
*blob
;
3657 /* Load firmware blob. */
3658 blob
= qla2x00_request_firmware(ha
);
3660 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3661 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3662 "from: " QLA_FW_URL
".\n");
3663 return QLA_FUNCTION_FAILED
;
3668 wcode
= (uint16_t *)ha
->request_ring
;
3670 fwcode
= (uint16_t *)blob
->fw
->data
;
3673 /* Validate firmware image by checking version. */
3674 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3675 qla_printk(KERN_WARNING
, ha
,
3676 "Unable to verify integrity of firmware image (%Zd)!\n",
3678 goto fail_fw_integrity
;
3680 for (i
= 0; i
< 4; i
++)
3681 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3682 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3683 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3684 wcode
[2] == 0 && wcode
[3] == 0)) {
3685 qla_printk(KERN_WARNING
, ha
,
3686 "Unable to verify integrity of firmware image!\n");
3687 qla_printk(KERN_WARNING
, ha
,
3688 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3689 wcode
[1], wcode
[2], wcode
[3]);
3690 goto fail_fw_integrity
;
3694 while (*seg
&& rval
== QLA_SUCCESS
) {
3696 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3697 risc_size
= be16_to_cpu(fwcode
[3]);
3699 /* Validate firmware image size. */
3700 fwclen
+= risc_size
* sizeof(uint16_t);
3701 if (blob
->fw
->size
< fwclen
) {
3702 qla_printk(KERN_WARNING
, ha
,
3703 "Unable to verify integrity of firmware image "
3704 "(%Zd)!\n", blob
->fw
->size
);
3705 goto fail_fw_integrity
;
3709 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3710 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3711 if (wlen
> risc_size
)
3714 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3715 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3718 for (i
= 0; i
< wlen
; i
++)
3719 wcode
[i
] = swab16(fwcode
[i
]);
3721 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3724 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3725 "segment %d of firmware\n", ha
->host_no
,
3727 qla_printk(KERN_WARNING
, ha
,
3728 "[ERROR] Failed to load segment %d of "
3729 "firmware\n", fragment
);
3745 return QLA_FUNCTION_FAILED
;
3749 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3752 int segments
, fragment
;
3753 uint32_t *dcode
, dlen
;
3757 struct fw_blob
*blob
;
3758 uint32_t *fwcode
, fwclen
;
3760 /* Load firmware blob. */
3761 blob
= qla2x00_request_firmware(ha
);
3763 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3764 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3765 "from: " QLA_FW_URL
".\n");
3767 /* Try to load RISC code from flash. */
3768 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3769 "outdated) firmware from flash.\n");
3770 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3775 segments
= FA_RISC_CODE_SEGMENTS
;
3776 dcode
= (uint32_t *)ha
->request_ring
;
3778 fwcode
= (uint32_t *)blob
->fw
->data
;
3781 /* Validate firmware image by checking version. */
3782 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3783 qla_printk(KERN_WARNING
, ha
,
3784 "Unable to verify integrity of firmware image (%Zd)!\n",
3786 goto fail_fw_integrity
;
3788 for (i
= 0; i
< 4; i
++)
3789 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3790 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3791 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3792 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3794 qla_printk(KERN_WARNING
, ha
,
3795 "Unable to verify integrity of firmware image!\n");
3796 qla_printk(KERN_WARNING
, ha
,
3797 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3798 dcode
[1], dcode
[2], dcode
[3]);
3799 goto fail_fw_integrity
;
3802 while (segments
&& rval
== QLA_SUCCESS
) {
3803 risc_addr
= be32_to_cpu(fwcode
[2]);
3804 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3805 risc_size
= be32_to_cpu(fwcode
[3]);
3807 /* Validate firmware image size. */
3808 fwclen
+= risc_size
* sizeof(uint32_t);
3809 if (blob
->fw
->size
< fwclen
) {
3810 qla_printk(KERN_WARNING
, ha
,
3811 "Unable to verify integrity of firmware image "
3812 "(%Zd)!\n", blob
->fw
->size
);
3814 goto fail_fw_integrity
;
3818 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3819 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3820 if (dlen
> risc_size
)
3823 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3824 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3827 for (i
= 0; i
< dlen
; i
++)
3828 dcode
[i
] = swab32(fwcode
[i
]);
3830 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3833 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3834 "segment %d of firmware\n", ha
->host_no
,
3836 qla_printk(KERN_WARNING
, ha
,
3837 "[ERROR] Failed to load segment %d of "
3838 "firmware\n", fragment
);
3854 return QLA_FUNCTION_FAILED
;