2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
26 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
27 static int qla2x00_setup_chip(scsi_qla_host_t
*);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
29 static int qla2x00_init_rings(scsi_qla_host_t
*);
30 static int qla2x00_fw_ready(scsi_qla_host_t
*);
31 static int qla2x00_configure_hba(scsi_qla_host_t
*);
32 static int qla2x00_configure_loop(scsi_qla_host_t
*);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
34 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
36 static int qla2x00_device_resync(scsi_qla_host_t
*);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
40 static int qla2x00_restart_isp(scsi_qla_host_t
*);
42 /****************************************************************************/
43 /* QLogic ISP2x00 Hardware Support Functions. */
44 /****************************************************************************/
47 * qla2x00_initialize_adapter
51 * ha = adapter block pointer.
57 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
60 uint8_t restart_risc
= 0;
64 /* Clear adapter flags. */
66 ha
->flags
.reset_active
= 0;
67 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
68 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
71 ha
->flags
.management_server_logged_in
= 0;
72 ha
->marker_needed
= 0;
74 ha
->isp_abort_cnt
= 0;
75 ha
->beacon_blink_led
= 0;
76 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
78 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
79 rval
= ha
->isp_ops
.pci_config(ha
);
81 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
86 ha
->isp_ops
.reset_chip(ha
);
88 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
90 ha
->isp_ops
.nvram_config(ha
);
92 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
96 * Try to configure the loop.
101 /* If firmware needs to be loaded */
102 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
103 if ((rval
= ha
->isp_ops
.chip_diag(ha
)) == QLA_SUCCESS
) {
104 rval
= qla2x00_setup_chip(ha
);
108 if (rval
== QLA_SUCCESS
&&
109 (rval
= qla2x00_init_rings(ha
)) == QLA_SUCCESS
) {
110 check_fw_ready_again
:
112 * Wait for a successful LIP up to a maximum
113 * of (in seconds): RISC login timeout value,
114 * RISC retry count value, and port down retry
115 * value OR a minimum of 4 seconds OR If no
116 * cable, only 5 seconds.
118 rval
= qla2x00_fw_ready(ha
);
119 if (rval
== QLA_SUCCESS
) {
120 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
122 /* Issue a marker after FW becomes ready. */
123 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
126 * Wait at most MAX_TARGET RSCNs for a stable
131 clear_bit(LOOP_RESYNC_NEEDED
,
133 rval
= qla2x00_configure_loop(ha
);
135 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
142 * If loop state change while we were
143 * discoverying devices then wait for
147 if (atomic_read(&ha
->loop_state
) !=
148 LOOP_READY
&& retry
--) {
149 goto check_fw_ready_again
;
152 } while (!atomic_read(&ha
->loop_down_timer
) &&
155 (test_bit(LOOP_RESYNC_NEEDED
,
159 rval
= QLA_FUNCTION_FAILED
;
160 } else if (ha
->device_flags
& DFLG_NO_CABLE
)
161 /* If no cable, then all is good. */
164 } while (restart_risc
&& retry
--);
166 if (rval
== QLA_SUCCESS
) {
167 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
168 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
169 ha
->marker_needed
= 0;
171 ha
->flags
.online
= 1;
173 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
180 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
183 * Returns 0 on success.
186 qla2100_pci_config(scsi_qla_host_t
*ha
)
191 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
193 pci_set_master(ha
->pdev
);
195 if (pci_set_mwi(ha
->pdev
))
196 mwi
= PCI_COMMAND_INVALIDATE
;
198 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
199 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
200 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
202 /* Reset expansion ROM address decode enable */
203 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
204 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
205 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
207 /* Get PCI bus information. */
208 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
209 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
210 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
216 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
219 * Returns 0 on success.
222 qla2300_pci_config(scsi_qla_host_t
*ha
)
226 unsigned long flags
= 0;
228 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
230 pci_set_master(ha
->pdev
);
232 if (pci_set_mwi(ha
->pdev
))
233 mwi
= PCI_COMMAND_INVALIDATE
;
235 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
236 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
238 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
239 w
&= ~PCI_COMMAND_INTX_DISABLE
;
242 * If this is a 2300 card and not 2312, reset the
243 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
244 * the 2310 also reports itself as a 2300 so we need to get the
245 * fb revision level -- a 6 indicates it really is a 2300 and
248 if (IS_QLA2300(ha
)) {
249 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
252 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
253 for (cnt
= 0; cnt
< 30000; cnt
++) {
254 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
260 /* Select FPM registers. */
261 WRT_REG_WORD(®
->ctrl_status
, 0x20);
262 RD_REG_WORD(®
->ctrl_status
);
264 /* Get the fb rev level */
265 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
267 if (ha
->fb_rev
== FPM_2300
)
268 w
&= ~PCI_COMMAND_INVALIDATE
;
270 /* Deselect FPM registers. */
271 WRT_REG_WORD(®
->ctrl_status
, 0x0);
272 RD_REG_WORD(®
->ctrl_status
);
274 /* Release RISC module. */
275 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
276 for (cnt
= 0; cnt
< 30000; cnt
++) {
277 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
283 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
285 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
287 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
289 /* Reset expansion ROM address decode enable */
290 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
291 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
292 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
294 /* Get PCI bus information. */
295 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
296 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
297 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
303 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
306 * Returns 0 on success.
309 qla24xx_pci_config(scsi_qla_host_t
*ha
)
313 unsigned long flags
= 0;
314 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
315 int pcix_cmd_reg
, pcie_dctl_reg
;
317 pci_set_master(ha
->pdev
);
319 if (pci_set_mwi(ha
->pdev
))
320 mwi
= PCI_COMMAND_INVALIDATE
;
322 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
323 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
324 w
&= ~PCI_COMMAND_INTX_DISABLE
;
325 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
327 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
329 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
330 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
334 pcix_cmd_reg
+= PCI_X_CMD
;
335 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
336 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
338 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
341 /* PCIe -- adjust Maximum Read Request Size (2048). */
342 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
346 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
347 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
348 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
350 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
353 /* Reset expansion ROM address decode enable */
354 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
355 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
356 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
358 /* Get PCI bus information. */
359 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
360 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
361 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
367 * qla2x00_isp_firmware() - Choose firmware image.
370 * Returns 0 on success.
373 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
377 /* Assume loading risc code */
378 rval
= QLA_FUNCTION_FAILED
;
380 if (ha
->flags
.disable_risc_code_load
) {
381 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
383 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
385 /* Verify checksum of loaded RISC code. */
386 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
390 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
398 * qla2x00_reset_chip() - Reset ISP chip.
401 * Returns 0 on success.
404 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
406 unsigned long flags
= 0;
407 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
411 ha
->isp_ops
.disable_intrs(ha
);
413 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
415 /* Turn off master enable */
417 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
418 cmd
&= ~PCI_COMMAND_MASTER
;
419 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
421 if (!IS_QLA2100(ha
)) {
423 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
424 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
425 for (cnt
= 0; cnt
< 30000; cnt
++) {
426 if ((RD_REG_WORD(®
->hccr
) &
427 HCCR_RISC_PAUSE
) != 0)
432 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
436 /* Select FPM registers. */
437 WRT_REG_WORD(®
->ctrl_status
, 0x20);
438 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
440 /* FPM Soft Reset. */
441 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
442 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
444 /* Toggle Fpm Reset. */
445 if (!IS_QLA2200(ha
)) {
446 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
447 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
450 /* Select frame buffer registers. */
451 WRT_REG_WORD(®
->ctrl_status
, 0x10);
452 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
454 /* Reset frame buffer FIFOs. */
455 if (IS_QLA2200(ha
)) {
456 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
457 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
459 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
461 /* Read back fb_cmd until zero or 3 seconds max */
462 for (cnt
= 0; cnt
< 3000; cnt
++) {
463 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
469 /* Select RISC module registers. */
470 WRT_REG_WORD(®
->ctrl_status
, 0);
471 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
473 /* Reset RISC processor. */
474 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
475 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
477 /* Release RISC processor. */
478 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
479 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
482 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
483 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
485 /* Reset ISP chip. */
486 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
488 /* Wait for RISC to recover from reset. */
489 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
491 * It is necessary to for a delay here since the card doesn't
492 * respond to PCI reads during a reset. On some architectures
493 * this will result in an MCA.
496 for (cnt
= 30000; cnt
; cnt
--) {
497 if ((RD_REG_WORD(®
->ctrl_status
) &
498 CSR_ISP_SOFT_RESET
) == 0)
505 /* Reset RISC processor. */
506 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
508 WRT_REG_WORD(®
->semaphore
, 0);
510 /* Release RISC processor. */
511 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
512 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
514 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
515 for (cnt
= 0; cnt
< 30000; cnt
++) {
516 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
524 /* Turn on master enable */
525 cmd
|= PCI_COMMAND_MASTER
;
526 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
528 /* Disable RISC pause on FPM parity error. */
529 if (!IS_QLA2100(ha
)) {
530 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
531 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
534 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
538 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
541 * Returns 0 on success.
544 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
546 unsigned long flags
= 0;
547 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
551 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
554 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
555 for (cnt
= 0; cnt
< 30000; cnt
++) {
556 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
562 WRT_REG_DWORD(®
->ctrl_status
,
563 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
564 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
567 /* Wait for firmware to complete NVRAM accesses. */
568 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
569 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
571 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
575 /* Wait for soft-reset to complete. */
576 d2
= RD_REG_DWORD(®
->ctrl_status
);
577 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
579 d2
= RD_REG_DWORD(®
->ctrl_status
);
583 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
584 RD_REG_DWORD(®
->hccr
);
586 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
587 RD_REG_DWORD(®
->hccr
);
589 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
590 RD_REG_DWORD(®
->hccr
);
592 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
593 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
595 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
599 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
603 * qla24xx_reset_chip() - Reset ISP24xx chip.
606 * Returns 0 on success.
609 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
611 ha
->isp_ops
.disable_intrs(ha
);
613 /* Perform RISC reset. */
614 qla24xx_reset_risc(ha
);
618 * qla2x00_chip_diag() - Test chip for proper operation.
621 * Returns 0 on success.
624 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
627 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
628 unsigned long flags
= 0;
633 /* Assume a failed state */
634 rval
= QLA_FUNCTION_FAILED
;
636 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
637 ha
->host_no
, (u_long
)®
->flash_address
));
639 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
641 /* Reset ISP chip. */
642 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
645 * We need to have a delay here since the card will not respond while
646 * in reset causing an MCA on some architectures.
649 data
= qla2x00_debounce_register(®
->ctrl_status
);
650 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
652 data
= RD_REG_WORD(®
->ctrl_status
);
657 goto chip_diag_failed
;
659 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
662 /* Reset RISC processor. */
663 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
664 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
666 /* Workaround for QLA2312 PCI parity error */
667 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
668 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
669 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
671 data
= RD_MAILBOX_REG(ha
, reg
, 0);
678 goto chip_diag_failed
;
680 /* Check product ID of chip */
681 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
683 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
684 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
685 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
686 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
687 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
688 mb
[3] != PROD_ID_3
) {
689 qla_printk(KERN_WARNING
, ha
,
690 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
692 goto chip_diag_failed
;
694 ha
->product_id
[0] = mb
[1];
695 ha
->product_id
[1] = mb
[2];
696 ha
->product_id
[2] = mb
[3];
697 ha
->product_id
[3] = mb
[4];
699 /* Adjust fw RISC transfer size */
700 if (ha
->request_q_length
> 1024)
701 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
703 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
704 ha
->request_q_length
;
706 if (IS_QLA2200(ha
) &&
707 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
708 /* Limit firmware transfer size with a 2200A */
709 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
712 ha
->device_type
|= DT_ISP2200A
;
713 ha
->fw_transfer_size
= 128;
716 /* Wrap Incoming Mailboxes Test. */
717 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
719 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
720 rval
= qla2x00_mbx_reg_test(ha
);
722 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
724 qla_printk(KERN_WARNING
, ha
,
725 "Failed mailbox send register test\n");
728 /* Flag a successful rval */
731 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
735 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
736 "****\n", ha
->host_no
));
738 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
744 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
747 * Returns 0 on success.
750 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
754 /* Perform RISC reset. */
755 qla24xx_reset_risc(ha
);
757 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
759 rval
= qla2x00_mbx_reg_test(ha
);
761 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
763 qla_printk(KERN_WARNING
, ha
,
764 "Failed mailbox send register test\n");
766 /* Flag a successful rval */
774 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
777 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
783 qla_printk(KERN_WARNING
, ha
,
784 "Firmware dump previously allocated.\n");
789 fixed_size
= mem_size
= eft_size
= 0;
790 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
791 fixed_size
= sizeof(struct qla2100_fw_dump
);
792 } else if (IS_QLA23XX(ha
)) {
793 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
794 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
796 } else if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
797 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
798 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
801 /* Allocate memory for Extended Trace Buffer. */
802 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
805 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
806 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
810 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
813 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
814 "EFT (%d).\n", rval
);
815 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
820 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
824 memset(eft
, 0, eft_size
);
825 ha
->eft_dma
= eft_dma
;
829 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
830 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
832 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
833 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
836 ha
->fw_dump
= vmalloc(dump_size
);
838 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
839 "firmware dump!!!\n", dump_size
/ 1024);
842 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
850 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
853 ha
->fw_dump_len
= dump_size
;
854 ha
->fw_dump
->signature
[0] = 'Q';
855 ha
->fw_dump
->signature
[1] = 'L';
856 ha
->fw_dump
->signature
[2] = 'G';
857 ha
->fw_dump
->signature
[3] = 'C';
858 ha
->fw_dump
->version
= __constant_htonl(1);
860 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
861 ha
->fw_dump
->mem_size
= htonl(mem_size
);
862 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
863 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
865 ha
->fw_dump
->eft_size
= htonl(eft_size
);
866 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
867 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
869 ha
->fw_dump
->header_size
=
870 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
874 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
877 * Returns 0 on success.
880 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
883 uint16_t fw_iocb_cnt
= 0;
884 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
885 dma_addr_t request_dma
;
886 request_t
*request_ring
;
888 /* Valid only on recent ISPs. */
889 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
892 /* Retrieve IOCB counts available to the firmware. */
893 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
896 /* No point in continuing if current settings are sufficient. */
897 if (fw_iocb_cnt
< 1024)
899 if (ha
->request_q_length
>= request_q_length
)
902 /* Attempt to claim larger area for request queue. */
903 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
904 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
906 if (request_ring
== NULL
)
909 /* Resize successful, report extensions. */
910 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
911 (ha
->fw_memory_size
+ 1) / 1024);
912 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
913 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
915 /* Clear old allocations. */
916 dma_free_coherent(&ha
->pdev
->dev
,
917 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
920 /* Begin using larger queue. */
921 ha
->request_q_length
= request_q_length
;
922 ha
->request_ring
= request_ring
;
923 ha
->request_dma
= request_dma
;
927 * qla2x00_setup_chip() - Load and start RISC firmware.
930 * Returns 0 on success.
933 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
936 uint32_t srisc_address
= 0;
938 /* Load firmware sequences */
939 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
940 if (rval
== QLA_SUCCESS
) {
941 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
942 "code.\n", ha
->host_no
));
944 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
945 if (rval
== QLA_SUCCESS
) {
946 /* Start firmware execution. */
947 DEBUG(printk("scsi(%ld): Checksum OK, start "
948 "firmware.\n", ha
->host_no
));
950 rval
= qla2x00_execute_fw(ha
, srisc_address
);
951 /* Retrieve firmware information. */
952 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
953 qla2x00_get_fw_version(ha
,
954 &ha
->fw_major_version
,
955 &ha
->fw_minor_version
,
956 &ha
->fw_subminor_version
,
957 &ha
->fw_attributes
, &ha
->fw_memory_size
);
958 qla2x00_resize_request_q(ha
);
961 qla2x00_alloc_fw_dump(ha
);
964 DEBUG2(printk(KERN_INFO
965 "scsi(%ld): ISP Firmware failed checksum.\n",
971 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
979 * qla2x00_init_response_q_entries() - Initializes response queue entries.
982 * Beginning of request ring has initialization control block already built
983 * by nvram config routine.
985 * Returns 0 on success.
988 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
993 pkt
= ha
->response_ring_ptr
;
994 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
995 pkt
->signature
= RESPONSE_PROCESSED
;
1002 * qla2x00_update_fw_options() - Read and process firmware options.
1005 * Returns 0 on success.
1008 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
1010 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1012 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1013 qla2x00_get_fw_options(ha
, ha
->fw_options
);
1015 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1018 /* Serial Link options. */
1019 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1021 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1022 sizeof(ha
->fw_seriallink_options
)));
1024 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1025 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1026 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1029 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1030 emphasis
= (ha
->fw_seriallink_options
[2] &
1031 (BIT_4
| BIT_3
)) >> 3;
1032 tx_sens
= ha
->fw_seriallink_options
[0] &
1033 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1034 rx_sens
= (ha
->fw_seriallink_options
[0] &
1035 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1036 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1037 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1040 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1041 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1042 ha
->fw_options
[10] |= BIT_5
|
1043 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1044 (tx_sens
& (BIT_1
| BIT_0
));
1047 swing
= (ha
->fw_seriallink_options
[2] &
1048 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1049 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1050 tx_sens
= ha
->fw_seriallink_options
[1] &
1051 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1052 rx_sens
= (ha
->fw_seriallink_options
[1] &
1053 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1054 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1055 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1058 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1059 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1060 ha
->fw_options
[11] |= BIT_5
|
1061 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1062 (tx_sens
& (BIT_1
| BIT_0
));
1066 /* Return command IOCBs without waiting for an ABTS to complete. */
1067 ha
->fw_options
[3] |= BIT_13
;
1070 if (ha
->flags
.enable_led_scheme
)
1071 ha
->fw_options
[2] |= BIT_12
;
1073 /* Detect ISP6312. */
1075 ha
->fw_options
[2] |= BIT_13
;
1077 /* Update firmware options. */
1078 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1082 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1086 /* Update Serial Link options. */
1087 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1090 rval
= qla2x00_set_serdes_params(ha
,
1091 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1092 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1093 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1094 if (rval
!= QLA_SUCCESS
) {
1095 qla_printk(KERN_WARNING
, ha
,
1096 "Unable to update Serial Link options (%x).\n", rval
);
1101 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1103 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1105 /* Setup ring parameters in initialization control block. */
1106 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1107 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1108 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1109 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1110 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1111 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1112 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1113 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1115 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1116 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1117 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1118 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1119 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1123 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1125 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1126 struct init_cb_24xx
*icb
;
1128 /* Setup ring parameters in initialization control block. */
1129 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1130 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1131 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1132 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1133 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1134 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1135 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1136 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1137 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1139 WRT_REG_DWORD(®
->req_q_in
, 0);
1140 WRT_REG_DWORD(®
->req_q_out
, 0);
1141 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1142 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1143 RD_REG_DWORD(®
->rsp_q_out
);
1147 * qla2x00_init_rings() - Initializes firmware.
1150 * Beginning of request ring has initialization control block already built
1151 * by nvram config routine.
1153 * Returns 0 on success.
1156 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1159 unsigned long flags
= 0;
1162 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1164 /* Clear outstanding commands array. */
1165 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1166 ha
->outstanding_cmds
[cnt
] = NULL
;
1168 ha
->current_outstanding_cmd
= 0;
1170 /* Clear RSCN queue. */
1171 ha
->rscn_in_ptr
= 0;
1172 ha
->rscn_out_ptr
= 0;
1174 /* Initialize firmware. */
1175 ha
->request_ring_ptr
= ha
->request_ring
;
1176 ha
->req_ring_index
= 0;
1177 ha
->req_q_cnt
= ha
->request_q_length
;
1178 ha
->response_ring_ptr
= ha
->response_ring
;
1179 ha
->rsp_ring_index
= 0;
1181 /* Initialize response queue entries */
1182 qla2x00_init_response_q_entries(ha
);
1184 ha
->isp_ops
.config_rings(ha
);
1186 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1188 /* Update any ISP specific firmware options before initialization. */
1189 ha
->isp_ops
.update_fw_options(ha
);
1191 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1192 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1194 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1197 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1205 * qla2x00_fw_ready() - Waits for firmware ready.
1208 * Returns 0 on success.
1211 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1214 unsigned long wtime
, mtime
;
1215 uint16_t min_wait
; /* Minimum wait time if loop is down */
1216 uint16_t wait_time
; /* Wait time if loop is coming ready */
1221 /* 20 seconds for loop down. */
1225 * Firmware should take at most one RATOV to login, plus 5 seconds for
1226 * our own processing.
1228 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1229 wait_time
= min_wait
;
1232 /* Min wait time if loop down */
1233 mtime
= jiffies
+ (min_wait
* HZ
);
1235 /* wait time before firmware ready */
1236 wtime
= jiffies
+ (wait_time
* HZ
);
1238 /* Wait for ISP to finish LIP */
1239 if (!ha
->flags
.init_done
)
1240 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1242 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1246 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1247 if (rval
== QLA_SUCCESS
) {
1248 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1249 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1251 if (fw_state
== FSTATE_READY
) {
1252 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1255 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1256 &ha
->login_timeout
, &ha
->r_a_tov
);
1262 rval
= QLA_FUNCTION_FAILED
;
1264 if (atomic_read(&ha
->loop_down_timer
) &&
1265 (fw_state
>= FSTATE_LOSS_OF_SYNC
||
1266 fw_state
== FSTATE_WAIT_AL_PA
)) {
1267 /* Loop down. Timeout on min_wait for states
1268 * other than Wait for Login.
1270 if (time_after_eq(jiffies
, mtime
)) {
1271 qla_printk(KERN_INFO
, ha
,
1272 "Cable is unplugged...\n");
1274 ha
->device_flags
|= DFLG_NO_CABLE
;
1279 /* Mailbox cmd failed. Timeout on min_wait. */
1280 if (time_after_eq(jiffies
, mtime
))
1284 if (time_after_eq(jiffies
, wtime
))
1287 /* Delay for a while */
1290 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1291 ha
->host_no
, fw_state
, jiffies
));
1294 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1295 ha
->host_no
, fw_state
, jiffies
));
1298 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1306 * qla2x00_configure_hba
1307 * Setup adapter context.
1310 * ha = adapter state pointer.
1319 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1327 char connect_type
[22];
1329 /* Get host addresses. */
1330 rval
= qla2x00_get_adapter_id(ha
,
1331 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1332 if (rval
!= QLA_SUCCESS
) {
1333 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1334 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1335 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1336 __func__
, ha
->host_no
));
1338 qla_printk(KERN_WARNING
, ha
,
1339 "ERROR -- Unable to get host loop ID.\n");
1340 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1346 qla_printk(KERN_INFO
, ha
,
1347 "Cannot get topology - retrying.\n");
1348 return (QLA_FUNCTION_FAILED
);
1351 ha
->loop_id
= loop_id
;
1354 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1355 ha
->operating_mode
= LOOP
;
1359 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1361 ha
->current_topology
= ISP_CFG_NL
;
1362 strcpy(connect_type
, "(Loop)");
1366 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1368 ha
->current_topology
= ISP_CFG_FL
;
1369 strcpy(connect_type
, "(FL_Port)");
1373 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1375 ha
->operating_mode
= P2P
;
1376 ha
->current_topology
= ISP_CFG_N
;
1377 strcpy(connect_type
, "(N_Port-to-N_Port)");
1381 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1383 ha
->operating_mode
= P2P
;
1384 ha
->current_topology
= ISP_CFG_F
;
1385 strcpy(connect_type
, "(F_Port)");
1389 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1391 ha
->host_no
, topo
));
1392 ha
->current_topology
= ISP_CFG_NL
;
1393 strcpy(connect_type
, "(Loop)");
1397 /* Save Host port and loop ID. */
1398 /* byte order - Big Endian */
1399 ha
->d_id
.b
.domain
= domain
;
1400 ha
->d_id
.b
.area
= area
;
1401 ha
->d_id
.b
.al_pa
= al_pa
;
1403 if (!ha
->flags
.init_done
)
1404 qla_printk(KERN_INFO
, ha
,
1405 "Topology - %s, Host Loop address 0x%x\n",
1406 connect_type
, ha
->loop_id
);
1409 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1411 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1418 * NVRAM configuration for ISP 2xxx
1421 * ha = adapter block pointer.
1424 * initialization control block in response_ring
1425 * host adapters parameters in host adapter block
1431 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1436 uint8_t *dptr1
, *dptr2
;
1437 init_cb_t
*icb
= ha
->init_cb
;
1438 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1439 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1440 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1444 /* Determine NVRAM starting address. */
1445 ha
->nvram_size
= sizeof(nvram_t
);
1447 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1448 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1449 ha
->nvram_base
= 0x80;
1451 /* Get NVRAM data and calculate checksum. */
1452 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1453 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1456 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1457 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1460 /* Bad NVRAM data, set defaults parameters. */
1461 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1462 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1463 /* Reset NVRAM data. */
1464 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1465 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1467 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1468 "invalid -- WWPN) defaults.\n");
1471 * Set default initialization control block.
1473 memset(nv
, 0, ha
->nvram_size
);
1474 nv
->parameter_block_version
= ICB_VERSION
;
1476 if (IS_QLA23XX(ha
)) {
1477 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1478 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1479 nv
->add_firmware_options
[0] = BIT_5
;
1480 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1481 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1482 nv
->special_options
[1] = BIT_7
;
1483 } else if (IS_QLA2200(ha
)) {
1484 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1485 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1486 nv
->add_firmware_options
[0] = BIT_5
;
1487 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1488 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1489 } else if (IS_QLA2100(ha
)) {
1490 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1491 nv
->firmware_options
[1] = BIT_5
;
1492 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1495 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1496 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1497 nv
->retry_count
= 8;
1498 nv
->retry_delay
= 1;
1500 nv
->port_name
[0] = 33;
1501 nv
->port_name
[3] = 224;
1502 nv
->port_name
[4] = 139;
1504 nv
->login_timeout
= 4;
1507 * Set default host adapter parameters
1509 nv
->host_p
[1] = BIT_2
;
1510 nv
->reset_delay
= 5;
1511 nv
->port_down_retry_count
= 8;
1512 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1513 nv
->link_down_timeout
= 60;
1518 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1520 * The SN2 does not provide BIOS emulation which means you can't change
1521 * potentially bogus BIOS settings. Force the use of default settings
1522 * for link rate and frame size. Hope that the rest of the settings
1525 if (ia64_platform_is("sn2")) {
1526 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1528 nv
->special_options
[1] = BIT_7
;
1532 /* Reset Initialization control block */
1533 memset(icb
, 0, ha
->init_cb_size
);
1536 * Setup driver NVRAM options.
1538 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1539 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1540 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1541 nv
->firmware_options
[1] &= ~BIT_4
;
1543 if (IS_QLA23XX(ha
)) {
1544 nv
->firmware_options
[0] |= BIT_2
;
1545 nv
->firmware_options
[0] &= ~BIT_3
;
1546 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1548 if (IS_QLA2300(ha
)) {
1549 if (ha
->fb_rev
== FPM_2310
) {
1550 strcpy(ha
->model_number
, "QLA2310");
1552 strcpy(ha
->model_number
, "QLA2300");
1556 memcmp(nv
->model_number
, BINZERO
,
1557 sizeof(nv
->model_number
)) != 0) {
1560 strncpy(ha
->model_number
, nv
->model_number
,
1561 sizeof(nv
->model_number
));
1562 st
= en
= ha
->model_number
;
1563 en
+= sizeof(nv
->model_number
) - 1;
1565 if (*en
!= 0x20 && *en
!= 0x00)
1572 index
= (ha
->pdev
->subsystem_device
& 0xff);
1573 if (index
< QLA_MODEL_NAMES
) {
1574 strcpy(ha
->model_number
,
1575 qla2x00_model_name
[index
* 2]);
1577 qla2x00_model_name
[index
* 2 + 1];
1579 strcpy(ha
->model_number
, "QLA23xx");
1583 } else if (IS_QLA2200(ha
)) {
1584 nv
->firmware_options
[0] |= BIT_2
;
1586 * 'Point-to-point preferred, else loop' is not a safe
1587 * connection mode setting.
1589 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1591 /* Force 'loop preferred, else point-to-point'. */
1592 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1593 nv
->add_firmware_options
[0] |= BIT_5
;
1595 strcpy(ha
->model_number
, "QLA22xx");
1596 } else /*if (IS_QLA2100(ha))*/ {
1597 strcpy(ha
->model_number
, "QLA2100");
1601 * Copy over NVRAM RISC parameter block to initialization control block.
1603 dptr1
= (uint8_t *)icb
;
1604 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1605 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1607 *dptr1
++ = *dptr2
++;
1609 /* Copy 2nd half. */
1610 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1611 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1613 *dptr1
++ = *dptr2
++;
1615 /* Use alternate WWN? */
1616 if (nv
->host_p
[1] & BIT_7
) {
1617 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1618 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1621 /* Prepare nodename */
1622 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1624 * Firmware will apply the following mask if the nodename was
1627 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1628 icb
->node_name
[0] &= 0xF0;
1632 * Set host adapter parameters.
1634 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1635 /* Always load RISC code on non ISP2[12]00 chips. */
1636 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1637 ha
->flags
.disable_risc_code_load
= 0;
1638 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1639 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1640 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1641 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1643 ha
->operating_mode
=
1644 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1646 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1647 sizeof(ha
->fw_seriallink_options
));
1649 /* save HBA serial number */
1650 ha
->serial0
= icb
->port_name
[5];
1651 ha
->serial1
= icb
->port_name
[6];
1652 ha
->serial2
= icb
->port_name
[7];
1653 ha
->node_name
= icb
->node_name
;
1654 ha
->port_name
= icb
->port_name
;
1656 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1658 ha
->retry_count
= nv
->retry_count
;
1660 /* Set minimum login_timeout to 4 seconds. */
1661 if (nv
->login_timeout
< ql2xlogintimeout
)
1662 nv
->login_timeout
= ql2xlogintimeout
;
1663 if (nv
->login_timeout
< 4)
1664 nv
->login_timeout
= 4;
1665 ha
->login_timeout
= nv
->login_timeout
;
1666 icb
->login_timeout
= nv
->login_timeout
;
1668 /* Set minimum RATOV to 200 tenths of a second. */
1671 ha
->loop_reset_delay
= nv
->reset_delay
;
1673 /* Link Down Timeout = 0:
1675 * When Port Down timer expires we will start returning
1676 * I/O's to OS with "DID_NO_CONNECT".
1678 * Link Down Timeout != 0:
1680 * The driver waits for the link to come up after link down
1681 * before returning I/Os to OS with "DID_NO_CONNECT".
1683 if (nv
->link_down_timeout
== 0) {
1684 ha
->loop_down_abort_time
=
1685 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1687 ha
->link_down_timeout
= nv
->link_down_timeout
;
1688 ha
->loop_down_abort_time
=
1689 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1693 * Need enough time to try and get the port back.
1695 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1696 if (qlport_down_retry
)
1697 ha
->port_down_retry_count
= qlport_down_retry
;
1698 /* Set login_retry_count */
1699 ha
->login_retry_count
= nv
->retry_count
;
1700 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1701 ha
->port_down_retry_count
> 3)
1702 ha
->login_retry_count
= ha
->port_down_retry_count
;
1703 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1704 ha
->login_retry_count
= ha
->port_down_retry_count
;
1705 if (ql2xloginretrycount
)
1706 ha
->login_retry_count
= ql2xloginretrycount
;
1708 icb
->lun_enables
= __constant_cpu_to_le16(0);
1709 icb
->command_resource_count
= 0;
1710 icb
->immediate_notify_resource_count
= 0;
1711 icb
->timeout
= __constant_cpu_to_le16(0);
1713 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1715 icb
->firmware_options
[0] &= ~BIT_3
;
1716 icb
->add_firmware_options
[0] &=
1717 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1718 icb
->add_firmware_options
[0] |= BIT_2
;
1719 icb
->response_accumulation_timer
= 3;
1720 icb
->interrupt_delay_timer
= 5;
1722 ha
->flags
.process_response_queue
= 1;
1725 if (!ha
->flags
.init_done
) {
1726 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1727 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1728 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1729 icb
->interrupt_delay_timer
: 2;
1731 icb
->add_firmware_options
[0] &=
1732 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1733 ha
->flags
.process_response_queue
= 0;
1734 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1735 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1737 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1738 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1739 ha
->zio_timer
* 100));
1740 qla_printk(KERN_INFO
, ha
,
1741 "ZIO mode %d enabled; timer delay (%d us).\n",
1742 ha
->zio_mode
, ha
->zio_timer
* 100);
1744 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1745 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1746 ha
->flags
.process_response_queue
= 1;
1751 DEBUG2_3(printk(KERN_WARNING
1752 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1758 qla2x00_rport_del(void *data
)
1760 fc_port_t
*fcport
= data
;
1761 struct fc_rport
*rport
;
1762 unsigned long flags
;
1764 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1765 rport
= fcport
->drport
;
1766 fcport
->drport
= NULL
;
1767 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1769 fc_remote_port_delete(rport
);
1774 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1776 * @flags: allocation flags
1778 * Returns a pointer to the allocated fcport, or NULL, if none available.
1781 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1785 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1789 /* Setup fcport template structure. */
1790 memset(fcport
, 0, sizeof (fc_port_t
));
1792 fcport
->port_type
= FCT_UNKNOWN
;
1793 fcport
->loop_id
= FC_NO_LOOP_ID
;
1794 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1795 fcport
->flags
= FCF_RLC_SUPPORT
;
1796 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1797 spin_lock_init(&fcport
->rport_lock
);
1803 * qla2x00_configure_loop
1804 * Updates Fibre Channel Device Database with what is actually on loop.
1807 * ha = adapter block pointer.
1812 * 2 = database was full and device was not configured.
1815 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1818 unsigned long flags
, save_flags
;
1822 /* Get Initiator ID */
1823 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1824 rval
= qla2x00_configure_hba(ha
);
1825 if (rval
!= QLA_SUCCESS
) {
1826 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1832 save_flags
= flags
= ha
->dpc_flags
;
1833 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1834 ha
->host_no
, flags
));
1837 * If we have both an RSCN and PORT UPDATE pending then handle them
1838 * both at the same time.
1840 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1841 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1843 /* Determine what we need to do */
1844 if (ha
->current_topology
== ISP_CFG_FL
&&
1845 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1847 ha
->flags
.rscn_queue_overflow
= 1;
1848 set_bit(RSCN_UPDATE
, &flags
);
1850 } else if (ha
->current_topology
== ISP_CFG_F
&&
1851 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1853 ha
->flags
.rscn_queue_overflow
= 1;
1854 set_bit(RSCN_UPDATE
, &flags
);
1855 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1857 } else if (ha
->current_topology
== ISP_CFG_N
) {
1858 clear_bit(RSCN_UPDATE
, &flags
);
1860 } else if (!ha
->flags
.online
||
1861 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1863 ha
->flags
.rscn_queue_overflow
= 1;
1864 set_bit(RSCN_UPDATE
, &flags
);
1865 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1868 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1869 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1870 rval
= QLA_FUNCTION_FAILED
;
1872 rval
= qla2x00_configure_local_loop(ha
);
1876 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1877 if (LOOP_TRANSITION(ha
)) {
1878 rval
= QLA_FUNCTION_FAILED
;
1880 rval
= qla2x00_configure_fabric(ha
);
1884 if (rval
== QLA_SUCCESS
) {
1885 if (atomic_read(&ha
->loop_down_timer
) ||
1886 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1887 rval
= QLA_FUNCTION_FAILED
;
1889 atomic_set(&ha
->loop_state
, LOOP_READY
);
1891 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1896 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1897 __func__
, ha
->host_no
));
1899 DEBUG3(printk("%s: exiting normally\n", __func__
));
1902 /* Restore state if a resync event occured during processing */
1903 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1904 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1905 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1906 if (test_bit(RSCN_UPDATE
, &save_flags
))
1907 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1916 * qla2x00_configure_local_loop
1917 * Updates Fibre Channel Device Database with local loop devices.
1920 * ha = adapter block pointer.
1926 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1931 fc_port_t
*fcport
, *new_fcport
;
1937 uint8_t domain
, area
, al_pa
;
1941 entries
= MAX_FIBRE_DEVICES
;
1943 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1944 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1946 /* Get list of logged in devices. */
1947 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1948 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1950 if (rval
!= QLA_SUCCESS
)
1951 goto cleanup_allocation
;
1953 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1954 ha
->host_no
, entries
));
1955 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1956 entries
* sizeof(struct gid_list_info
)));
1958 /* Allocate temporary fcport for any new fcports discovered. */
1959 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1960 if (new_fcport
== NULL
) {
1961 rval
= QLA_MEMORY_ALLOC_FAILED
;
1962 goto cleanup_allocation
;
1964 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1967 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1969 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1970 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1971 fcport
->port_type
!= FCT_BROADCAST
&&
1972 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1974 DEBUG(printk("scsi(%ld): Marking port lost, "
1976 ha
->host_no
, fcport
->loop_id
));
1978 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1979 fcport
->flags
&= ~FCF_FARP_DONE
;
1983 /* Add devices to port list. */
1984 id_iter
= (char *)ha
->gid_list
;
1985 for (index
= 0; index
< entries
; index
++) {
1986 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1987 area
= ((struct gid_list_info
*)id_iter
)->area
;
1988 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1989 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1990 loop_id
= (uint16_t)
1991 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1993 loop_id
= le16_to_cpu(
1994 ((struct gid_list_info
*)id_iter
)->loop_id
);
1995 id_iter
+= ha
->gid_list_info_size
;
1997 /* Bypass reserved domain fields. */
1998 if ((domain
& 0xf0) == 0xf0)
2001 /* Bypass if not same domain and area of adapter. */
2002 if (area
&& domain
&&
2003 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
2006 /* Bypass invalid local loop ID. */
2007 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2010 /* Fill in member data. */
2011 new_fcport
->d_id
.b
.domain
= domain
;
2012 new_fcport
->d_id
.b
.area
= area
;
2013 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2014 new_fcport
->loop_id
= loop_id
;
2015 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
2016 if (rval2
!= QLA_SUCCESS
) {
2017 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2018 "information -- get_port_database=%x, "
2020 ha
->host_no
, rval2
, new_fcport
->loop_id
));
2021 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2023 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2027 /* Check for matching device in port list. */
2030 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2031 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2035 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2036 FCF_PERSISTENT_BOUND
);
2037 fcport
->loop_id
= new_fcport
->loop_id
;
2038 fcport
->port_type
= new_fcport
->port_type
;
2039 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2040 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2048 /* New device, add to fcports list. */
2049 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2050 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
2052 /* Allocate a new replacement fcport. */
2053 fcport
= new_fcport
;
2054 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2055 if (new_fcport
== NULL
) {
2056 rval
= QLA_MEMORY_ALLOC_FAILED
;
2057 goto cleanup_allocation
;
2059 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2062 qla2x00_update_fcport(ha
, fcport
);
2070 if (rval
!= QLA_SUCCESS
) {
2071 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2072 "rval=%x\n", ha
->host_no
, rval
));
2076 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2077 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2084 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2088 qla2x00_mark_all_devices_lost(ha
, 0);
2089 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2090 if (fcport
->port_type
!= FCT_TARGET
)
2093 qla2x00_update_fcport(ha
, fcport
);
2098 * qla2x00_update_fcport
2099 * Updates device on list.
2102 * ha = adapter block pointer.
2103 * fcport = port structure pointer.
2113 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2116 fcport
->login_retry
= 0;
2117 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2119 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2121 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2123 atomic_set(&fcport
->state
, FCS_ONLINE
);
2125 if (ha
->flags
.init_done
)
2126 qla2x00_reg_remote_port(ha
, fcport
);
2130 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2132 struct fc_rport_identifiers rport_ids
;
2133 struct fc_rport
*rport
;
2134 unsigned long flags
;
2137 qla2x00_rport_del(fcport
);
2141 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2142 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2143 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2144 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2145 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2146 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2148 qla_printk(KERN_WARNING
, ha
,
2149 "Unable to allocate fc remote port!\n");
2152 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2153 fcport
->rport
= rport
;
2154 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2155 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2157 rport
->supported_classes
= fcport
->supported_classes
;
2159 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2160 if (fcport
->port_type
== FCT_INITIATOR
)
2161 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2162 if (fcport
->port_type
== FCT_TARGET
)
2163 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2164 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2166 if (rport
->scsi_target_id
!= -1 &&
2167 rport
->scsi_target_id
< ha
->host
->max_id
)
2168 fcport
->os_target_id
= rport
->scsi_target_id
;
2172 * qla2x00_configure_fabric
2173 * Setup SNS devices with loop ID's.
2176 * ha = adapter block pointer.
2183 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2186 fc_port_t
*fcport
, *fcptemp
;
2187 uint16_t next_loopid
;
2188 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2190 LIST_HEAD(new_fcports
);
2192 /* If FL port exists, then SNS is present */
2193 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2194 loop_id
= NPH_F_PORT
;
2196 loop_id
= SNS_FL_PORT
;
2197 rval
= qla2x00_get_port_name(ha
, loop_id
, NULL
, 0);
2198 if (rval
!= QLA_SUCCESS
) {
2199 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2200 "Port\n", ha
->host_no
));
2202 ha
->device_flags
&= ~SWITCH_FOUND
;
2203 return (QLA_SUCCESS
);
2206 /* Mark devices that need re-synchronization. */
2207 rval2
= qla2x00_device_resync(ha
);
2208 if (rval2
== QLA_RSCNS_HANDLED
) {
2209 /* No point doing the scan, just continue. */
2210 return (QLA_SUCCESS
);
2214 if (ql2xfdmienable
&&
2215 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2216 qla2x00_fdmi_register(ha
);
2218 /* Ensure we are logged into the SNS. */
2219 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2222 loop_id
= SIMPLE_NAME_SERVER
;
2223 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2224 0xfc, mb
, BIT_1
| BIT_0
);
2225 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2226 DEBUG2(qla_printk(KERN_INFO
, ha
,
2227 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2228 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2229 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2230 return (QLA_SUCCESS
);
2233 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2234 if (qla2x00_rft_id(ha
)) {
2236 DEBUG2(printk("scsi(%ld): Register FC-4 "
2237 "TYPE failed.\n", ha
->host_no
));
2239 if (qla2x00_rff_id(ha
)) {
2241 DEBUG2(printk("scsi(%ld): Register FC-4 "
2242 "Features failed.\n", ha
->host_no
));
2244 if (qla2x00_rnn_id(ha
)) {
2246 DEBUG2(printk("scsi(%ld): Register Node Name "
2247 "failed.\n", ha
->host_no
));
2248 } else if (qla2x00_rsnn_nn(ha
)) {
2250 DEBUG2(printk("scsi(%ld): Register Symbolic "
2251 "Node Name failed.\n", ha
->host_no
));
2255 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2256 if (rval
!= QLA_SUCCESS
)
2260 * Logout all previous fabric devices marked lost, except
2263 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2264 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2267 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2270 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2271 qla2x00_mark_device_lost(ha
, fcport
,
2272 ql2xplogiabsentdevice
, 0);
2273 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2274 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2275 fcport
->port_type
!= FCT_INITIATOR
&&
2276 fcport
->port_type
!= FCT_BROADCAST
) {
2277 ha
->isp_ops
.fabric_logout(ha
,
2279 fcport
->d_id
.b
.domain
,
2280 fcport
->d_id
.b
.area
,
2281 fcport
->d_id
.b
.al_pa
);
2282 fcport
->loop_id
= FC_NO_LOOP_ID
;
2287 /* Starting free loop ID. */
2288 next_loopid
= ha
->min_external_loopid
;
2291 * Scan through our port list and login entries that need to be
2294 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2295 if (atomic_read(&ha
->loop_down_timer
) ||
2296 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2299 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2300 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2303 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2304 fcport
->loop_id
= next_loopid
;
2305 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2306 if (rval
!= QLA_SUCCESS
) {
2307 /* Ran out of IDs to use */
2311 /* Login and update database */
2312 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2315 /* Exit if out of loop IDs. */
2316 if (rval
!= QLA_SUCCESS
) {
2321 * Login and add the new devices to our port list.
2323 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2324 if (atomic_read(&ha
->loop_down_timer
) ||
2325 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2328 /* Find a new loop ID to use. */
2329 fcport
->loop_id
= next_loopid
;
2330 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2331 if (rval
!= QLA_SUCCESS
) {
2332 /* Ran out of IDs to use */
2336 /* Remove device from the new list and add it to DB */
2337 list_del(&fcport
->list
);
2338 list_add_tail(&fcport
->list
, &ha
->fcports
);
2340 /* Login and update database */
2341 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2345 /* Free all new device structures not processed. */
2346 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2347 list_del(&fcport
->list
);
2352 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2353 "rval=%d\n", ha
->host_no
, rval
));
2361 * qla2x00_find_all_fabric_devs
2364 * ha = adapter block pointer.
2365 * dev = database device entry pointer.
2374 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2378 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2383 int first_dev
, last_dev
;
2384 port_id_t wrap
, nxt_d_id
;
2388 /* Try GID_PT to get device list, else GAN. */
2389 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2392 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2393 "on GA_NXT\n", ha
->host_no
));
2395 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2396 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2399 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2402 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2409 /* Allocate temporary fcport for any new fcports discovered. */
2410 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2411 if (new_fcport
== NULL
) {
2413 return (QLA_MEMORY_ALLOC_FAILED
);
2415 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2417 /* Set start port ID scan at adapter ID. */
2421 /* Starting free loop ID. */
2422 loop_id
= ha
->min_external_loopid
;
2423 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2424 if (qla2x00_is_reserved_id(ha
, loop_id
))
2427 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2432 wrap
.b24
= new_fcport
->d_id
.b24
;
2434 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2435 memcpy(new_fcport
->node_name
,
2436 swl
[swl_idx
].node_name
, WWN_SIZE
);
2437 memcpy(new_fcport
->port_name
,
2438 swl
[swl_idx
].port_name
, WWN_SIZE
);
2440 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2446 /* Send GA_NXT to the switch */
2447 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2448 if (rval
!= QLA_SUCCESS
) {
2449 qla_printk(KERN_WARNING
, ha
,
2450 "SNS scan failed -- assuming zero-entry "
2452 list_for_each_entry_safe(fcport
, fcptemp
,
2453 new_fcports
, list
) {
2454 list_del(&fcport
->list
);
2462 /* If wrap on switch device list, exit. */
2464 wrap
.b24
= new_fcport
->d_id
.b24
;
2466 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2467 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2468 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2469 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2473 /* Bypass if host adapter. */
2474 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2477 /* Bypass if same domain and area of adapter. */
2478 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2479 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2483 /* Bypass reserved domain fields. */
2484 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2487 /* Locate matching device in database. */
2489 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2490 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2497 * If address the same and state FCS_ONLINE, nothing
2500 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2501 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2506 * If device was not a fabric device before.
2508 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2509 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2510 fcport
->loop_id
= FC_NO_LOOP_ID
;
2511 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2513 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2518 * Port ID changed or device was marked to be updated;
2519 * Log it out if still logged in and mark it for
2522 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2523 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2524 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2525 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2526 fcport
->port_type
!= FCT_INITIATOR
&&
2527 fcport
->port_type
!= FCT_BROADCAST
) {
2528 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2529 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2530 fcport
->d_id
.b
.al_pa
);
2531 fcport
->loop_id
= FC_NO_LOOP_ID
;
2540 /* If device was not in our fcports list, then add it. */
2541 list_add_tail(&new_fcport
->list
, new_fcports
);
2543 /* Allocate a new replacement fcport. */
2544 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2545 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2546 if (new_fcport
== NULL
) {
2548 return (QLA_MEMORY_ALLOC_FAILED
);
2550 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2551 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2557 if (!list_empty(new_fcports
))
2558 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2564 * qla2x00_find_new_loop_id
2565 * Scan through our port list and find a new usable loop ID.
2568 * ha: adapter state pointer.
2569 * dev: port structure pointer.
2572 * qla2x00 local function return status code.
2578 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2583 uint16_t first_loop_id
;
2587 /* Save starting loop ID. */
2588 first_loop_id
= dev
->loop_id
;
2591 /* Skip loop ID if already used by adapter. */
2592 if (dev
->loop_id
== ha
->loop_id
) {
2596 /* Skip reserved loop IDs. */
2597 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2601 /* Reset loop ID if passed the end. */
2602 if (dev
->loop_id
> ha
->last_loop_id
) {
2603 /* first loop ID. */
2604 dev
->loop_id
= ha
->min_external_loopid
;
2607 /* Check for loop ID being already in use. */
2610 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2611 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2612 /* ID possibly in use */
2618 /* If not in use then it is free to use. */
2623 /* ID in use. Try next value. */
2626 /* If wrap around. No free ID to use. */
2627 if (dev
->loop_id
== first_loop_id
) {
2628 dev
->loop_id
= FC_NO_LOOP_ID
;
2629 rval
= QLA_FUNCTION_FAILED
;
2638 * qla2x00_device_resync
2639 * Marks devices in the database that needs resynchronization.
2642 * ha = adapter block pointer.
2648 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2653 uint32_t rscn_entry
;
2654 uint8_t rscn_out_iter
;
2658 rval
= QLA_RSCNS_HANDLED
;
2660 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2661 ha
->flags
.rscn_queue_overflow
) {
2663 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2664 format
= MSB(MSW(rscn_entry
));
2665 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2666 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2667 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2669 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2670 "[%02x/%02x%02x%02x].\n",
2671 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2672 d_id
.b
.area
, d_id
.b
.al_pa
));
2675 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2676 ha
->rscn_out_ptr
= 0;
2678 /* Skip duplicate entries. */
2679 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2680 !ha
->flags
.rscn_queue_overflow
&&
2681 rscn_out_iter
!= ha
->rscn_in_ptr
;
2682 rscn_out_iter
= (rscn_out_iter
==
2683 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2685 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2688 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2689 "entry found at [%d].\n", ha
->host_no
,
2692 ha
->rscn_out_ptr
= rscn_out_iter
;
2695 /* Queue overflow, set switch default case. */
2696 if (ha
->flags
.rscn_queue_overflow
) {
2697 DEBUG(printk("scsi(%ld): device_resync: rscn "
2698 "overflow.\n", ha
->host_no
));
2701 ha
->flags
.rscn_queue_overflow
= 0;
2717 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2723 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2724 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2725 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2726 fcport
->port_type
== FCT_BROADCAST
)
2729 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2731 fcport
->port_type
!= FCT_INITIATOR
) {
2732 qla2x00_mark_device_lost(ha
, fcport
,
2736 fcport
->flags
&= ~FCF_FARP_DONE
;
2743 * qla2x00_fabric_dev_login
2744 * Login fabric target device and update FC port database.
2747 * ha: adapter state pointer.
2748 * fcport: port structure list pointer.
2749 * next_loopid: contains value of a new loop ID that can be used
2750 * by the next login attempt.
2753 * qla2x00 local function return status code.
2759 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2760 uint16_t *next_loopid
)
2769 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2770 if (rval
== QLA_SUCCESS
) {
2771 /* Send an ADISC to tape devices.*/
2773 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2775 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2776 if (rval
!= QLA_SUCCESS
) {
2777 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2778 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2779 fcport
->d_id
.b
.al_pa
);
2780 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2782 qla2x00_update_fcport(ha
, fcport
);
2790 * qla2x00_fabric_login
2791 * Issue fabric login command.
2794 * ha = adapter block pointer.
2795 * device = pointer to FC device type structure.
2798 * 0 - Login successfully
2800 * 2 - Initiator device
2804 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2805 uint16_t *next_loopid
)
2809 uint16_t tmp_loopid
;
2810 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2816 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2817 "for port %02x%02x%02x.\n",
2818 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2819 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2821 /* Login fcport on switch. */
2822 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2823 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2824 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2825 if (mb
[0] == MBS_PORT_ID_USED
) {
2827 * Device has another loop ID. The firmware team
2828 * recommends the driver perform an implicit login with
2829 * the specified ID again. The ID we just used is save
2830 * here so we return with an ID that can be tried by
2834 tmp_loopid
= fcport
->loop_id
;
2835 fcport
->loop_id
= mb
[1];
2837 DEBUG(printk("Fabric Login: port in use - next "
2838 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2839 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2840 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2842 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2847 /* A retry occurred before. */
2848 *next_loopid
= tmp_loopid
;
2851 * No retry occurred before. Just increment the
2852 * ID value for next login.
2854 *next_loopid
= (fcport
->loop_id
+ 1);
2857 if (mb
[1] & BIT_0
) {
2858 fcport
->port_type
= FCT_INITIATOR
;
2860 fcport
->port_type
= FCT_TARGET
;
2861 if (mb
[1] & BIT_1
) {
2862 fcport
->flags
|= FCF_TAPE_PRESENT
;
2867 fcport
->supported_classes
|= FC_COS_CLASS2
;
2869 fcport
->supported_classes
|= FC_COS_CLASS3
;
2873 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2875 * Loop ID already used, try next loop ID.
2878 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2879 if (rval
!= QLA_SUCCESS
) {
2880 /* Ran out of loop IDs to use */
2883 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2885 * Firmware possibly timed out during login. If NO
2886 * retries are left to do then the device is declared
2889 *next_loopid
= fcport
->loop_id
;
2890 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2891 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2892 fcport
->d_id
.b
.al_pa
);
2893 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2899 * unrecoverable / not handled error
2901 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2902 "loop_id=%x jiffies=%lx.\n",
2903 __func__
, ha
->host_no
, mb
[0],
2904 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2905 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2907 *next_loopid
= fcport
->loop_id
;
2908 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2909 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2910 fcport
->d_id
.b
.al_pa
);
2911 fcport
->loop_id
= FC_NO_LOOP_ID
;
2912 fcport
->login_retry
= 0;
2923 * qla2x00_local_device_login
2924 * Issue local device login command.
2927 * ha = adapter block pointer.
2928 * loop_id = loop id of device to login to.
2930 * Returns (Where's the #define!!!!):
2931 * 0 - Login successfully
2936 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2939 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2941 memset(mb
, 0, sizeof(mb
));
2942 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
2943 if (rval
== QLA_SUCCESS
) {
2944 /* Interrogate mailbox registers for any errors */
2945 if (mb
[0] == MBS_COMMAND_ERROR
)
2947 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2948 /* device not in PCB table */
2956 * qla2x00_loop_resync
2957 * Resync with fibre channel devices.
2960 * ha = adapter block pointer.
2966 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2973 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2974 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2975 if (ha
->flags
.online
) {
2976 if (!(rval
= qla2x00_fw_ready(ha
))) {
2977 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2980 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2982 /* Issue a marker after FW becomes ready. */
2983 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
2984 ha
->marker_needed
= 0;
2986 /* Remap devices on Loop. */
2987 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2989 qla2x00_configure_loop(ha
);
2991 } while (!atomic_read(&ha
->loop_down_timer
) &&
2992 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
2994 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
2998 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2999 return (QLA_FUNCTION_FAILED
);
3003 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3010 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3016 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3017 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3020 qla2x00_update_fcport(ha
, fcport
);
3021 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3025 qla2x00_probe_for_all_luns(ha
);
3029 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3033 /* Go with deferred removal of rport references. */
3034 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3036 qla2x00_rport_del(fcport
);
3041 * Resets ISP and aborts all outstanding commands.
3044 * ha = adapter block pointer.
3050 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3052 unsigned long flags
= 0;
3057 if (ha
->flags
.online
) {
3058 ha
->flags
.online
= 0;
3059 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3061 qla_printk(KERN_INFO
, ha
,
3062 "Performing ISP error recovery - ha= %p.\n", ha
);
3063 ha
->isp_ops
.reset_chip(ha
);
3065 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3066 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3067 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3068 qla2x00_mark_all_devices_lost(ha
, 0);
3070 if (!atomic_read(&ha
->loop_down_timer
))
3071 atomic_set(&ha
->loop_down_timer
,
3075 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3076 /* Requeue all commands in outstanding command list. */
3077 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3078 sp
= ha
->outstanding_cmds
[cnt
];
3080 ha
->outstanding_cmds
[cnt
] = NULL
;
3082 sp
->cmd
->result
= DID_RESET
<< 16;
3083 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3084 qla2x00_sp_compl(ha
, sp
);
3087 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3089 ha
->isp_ops
.nvram_config(ha
);
3091 if (!qla2x00_restart_isp(ha
)) {
3092 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3094 if (!atomic_read(&ha
->loop_down_timer
)) {
3096 * Issue marker command only when we are going
3097 * to start the I/O .
3099 ha
->marker_needed
= 1;
3102 ha
->flags
.online
= 1;
3104 ha
->isp_ops
.enable_intrs(ha
);
3106 ha
->isp_abort_cnt
= 0;
3107 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3108 } else { /* failed the ISP abort */
3109 ha
->flags
.online
= 1;
3110 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3111 if (ha
->isp_abort_cnt
== 0) {
3112 qla_printk(KERN_WARNING
, ha
,
3113 "ISP error recovery failed - "
3114 "board disabled\n");
3116 * The next call disables the board
3119 ha
->isp_ops
.reset_adapter(ha
);
3120 ha
->flags
.online
= 0;
3121 clear_bit(ISP_ABORT_RETRY
,
3124 } else { /* schedule another ISP abort */
3125 ha
->isp_abort_cnt
--;
3126 DEBUG(printk("qla%ld: ISP abort - "
3127 "retry remaining %d\n",
3128 ha
->host_no
, ha
->isp_abort_cnt
);)
3132 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3133 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3134 "- retrying (%d) more times\n",
3135 ha
->host_no
, ha
->isp_abort_cnt
);)
3136 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3144 qla_printk(KERN_INFO
, ha
,
3145 "qla2x00_abort_isp: **** FAILED ****\n");
3147 DEBUG(printk(KERN_INFO
3148 "qla2x00_abort_isp(%ld): exiting.\n",
3156 * qla2x00_restart_isp
3157 * restarts the ISP after a reset
3160 * ha = adapter block pointer.
3166 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3169 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3170 unsigned long flags
= 0;
3173 /* If firmware needs to be loaded */
3174 if (qla2x00_isp_firmware(ha
)) {
3175 ha
->flags
.online
= 0;
3176 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3177 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3178 status
= qla2x00_setup_chip(ha
);
3182 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3184 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3186 * Disable SRAM, Instruction RAM and GP RAM
3189 WRT_REG_WORD(®
->hccr
,
3190 (HCCR_ENABLE_PARITY
+ 0x0));
3191 RD_REG_WORD(®
->hccr
);
3194 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3196 status
= qla2x00_setup_chip(ha
);
3198 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3200 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3201 /* Enable proper parity */
3204 WRT_REG_WORD(®
->hccr
,
3205 (HCCR_ENABLE_PARITY
+ 0x1));
3208 * SRAM, Instruction RAM and GP RAM
3211 WRT_REG_WORD(®
->hccr
,
3212 (HCCR_ENABLE_PARITY
+ 0x7));
3213 RD_REG_WORD(®
->hccr
);
3216 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3221 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3222 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3223 if (!(status
= qla2x00_fw_ready(ha
))) {
3224 DEBUG(printk("%s(): Start configure loop, "
3225 "status = %d\n", __func__
, status
);)
3227 /* Issue a marker after FW becomes ready. */
3228 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3230 ha
->flags
.online
= 1;
3231 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3234 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3235 qla2x00_configure_loop(ha
);
3237 } while (!atomic_read(&ha
->loop_down_timer
) &&
3238 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3240 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3243 /* if no cable then assume it's good */
3244 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3247 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3255 * qla2x00_reset_adapter
3259 * ha = adapter block pointer.
3262 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3264 unsigned long flags
= 0;
3265 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3267 ha
->flags
.online
= 0;
3268 ha
->isp_ops
.disable_intrs(ha
);
3270 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3271 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3272 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3273 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3274 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3275 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3279 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3281 unsigned long flags
= 0;
3282 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3284 ha
->flags
.online
= 0;
3285 ha
->isp_ops
.disable_intrs(ha
);
3287 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3288 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3289 RD_REG_DWORD(®
->hccr
);
3290 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3291 RD_REG_DWORD(®
->hccr
);
3292 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3296 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3299 struct init_cb_24xx
*icb
;
3300 struct nvram_24xx
*nv
;
3302 uint8_t *dptr1
, *dptr2
;
3307 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3308 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3310 /* Determine NVRAM starting address. */
3311 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3312 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3313 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3314 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3315 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3316 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3317 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3320 /* Get NVRAM data and calculate checksum. */
3321 dptr
= (uint32_t *)nv
;
3322 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3324 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3325 chksum
+= le32_to_cpu(*dptr
++);
3327 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3328 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3331 /* Bad NVRAM data, set defaults parameters. */
3332 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3333 || nv
->id
[3] != ' ' ||
3334 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3335 /* Reset NVRAM data. */
3336 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3337 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3338 le16_to_cpu(nv
->nvram_version
));
3339 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3340 "invalid -- WWPN) defaults.\n");
3343 * Set default initialization control block.
3345 memset(nv
, 0, ha
->nvram_size
);
3346 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3347 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3348 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3349 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3350 nv
->exchange_count
= __constant_cpu_to_le16(0);
3351 nv
->hard_address
= __constant_cpu_to_le16(124);
3352 nv
->port_name
[0] = 0x21;
3353 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3354 nv
->port_name
[2] = 0x00;
3355 nv
->port_name
[3] = 0xe0;
3356 nv
->port_name
[4] = 0x8b;
3357 nv
->port_name
[5] = 0x1c;
3358 nv
->port_name
[6] = 0x55;
3359 nv
->port_name
[7] = 0x86;
3360 nv
->node_name
[0] = 0x20;
3361 nv
->node_name
[1] = 0x00;
3362 nv
->node_name
[2] = 0x00;
3363 nv
->node_name
[3] = 0xe0;
3364 nv
->node_name
[4] = 0x8b;
3365 nv
->node_name
[5] = 0x1c;
3366 nv
->node_name
[6] = 0x55;
3367 nv
->node_name
[7] = 0x86;
3368 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3369 nv
->link_down_timeout
= __constant_cpu_to_le16(200);
3370 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3371 nv
->login_timeout
= __constant_cpu_to_le16(0);
3372 nv
->firmware_options_1
=
3373 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3374 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3375 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3376 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3377 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3378 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3379 nv
->reset_delay
= 5;
3380 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3381 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3382 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3387 /* Reset Initialization control block */
3388 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3390 /* Copy 1st segment. */
3391 dptr1
= (uint8_t *)icb
;
3392 dptr2
= (uint8_t *)&nv
->version
;
3393 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3395 *dptr1
++ = *dptr2
++;
3397 icb
->login_retry_count
= nv
->login_retry_count
;
3398 icb
->link_down_timeout
= nv
->link_down_timeout
;
3400 /* Copy 2nd segment. */
3401 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3402 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3403 cnt
= (uint8_t *)&icb
->reserved_3
-
3404 (uint8_t *)&icb
->interrupt_delay_timer
;
3406 *dptr1
++ = *dptr2
++;
3409 * Setup driver NVRAM options.
3411 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3415 strncpy(ha
->model_number
, nv
->model_name
,
3416 sizeof(nv
->model_name
));
3417 st
= en
= ha
->model_number
;
3418 en
+= sizeof(nv
->model_name
) - 1;
3420 if (*en
!= 0x20 && *en
!= 0x00)
3425 index
= (ha
->pdev
->subsystem_device
& 0xff);
3426 if (index
< QLA_MODEL_NAMES
)
3427 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
3429 strcpy(ha
->model_number
, "QLA2462");
3431 /* Use alternate WWN? */
3432 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3433 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3434 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3437 /* Prepare nodename */
3438 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3440 * Firmware will apply the following mask if the nodename was
3443 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3444 icb
->node_name
[0] &= 0xF0;
3447 /* Set host adapter parameters. */
3448 ha
->flags
.disable_risc_code_load
= 0;
3449 ha
->flags
.enable_lip_reset
= 1;
3450 ha
->flags
.enable_lip_full_login
= 1;
3451 ha
->flags
.enable_target_reset
= 1;
3452 ha
->flags
.enable_led_scheme
= 0;
3454 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3455 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3457 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3458 sizeof(ha
->fw_seriallink_options24
));
3460 /* save HBA serial number */
3461 ha
->serial0
= icb
->port_name
[5];
3462 ha
->serial1
= icb
->port_name
[6];
3463 ha
->serial2
= icb
->port_name
[7];
3464 ha
->node_name
= icb
->node_name
;
3465 ha
->port_name
= icb
->port_name
;
3467 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3469 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3471 /* Set minimum login_timeout to 4 seconds. */
3472 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3473 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3474 if (le16_to_cpu(nv
->login_timeout
) < 4)
3475 nv
->login_timeout
= __constant_cpu_to_le16(4);
3476 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3477 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3479 /* Set minimum RATOV to 200 tenths of a second. */
3482 ha
->loop_reset_delay
= nv
->reset_delay
;
3484 /* Link Down Timeout = 0:
3486 * When Port Down timer expires we will start returning
3487 * I/O's to OS with "DID_NO_CONNECT".
3489 * Link Down Timeout != 0:
3491 * The driver waits for the link to come up after link down
3492 * before returning I/Os to OS with "DID_NO_CONNECT".
3494 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3495 ha
->loop_down_abort_time
=
3496 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3498 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3499 ha
->loop_down_abort_time
=
3500 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3503 /* Need enough time to try and get the port back. */
3504 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3505 if (qlport_down_retry
)
3506 ha
->port_down_retry_count
= qlport_down_retry
;
3508 /* Set login_retry_count */
3509 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3510 if (ha
->port_down_retry_count
==
3511 le16_to_cpu(nv
->port_down_retry_count
) &&
3512 ha
->port_down_retry_count
> 3)
3513 ha
->login_retry_count
= ha
->port_down_retry_count
;
3514 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3515 ha
->login_retry_count
= ha
->port_down_retry_count
;
3516 if (ql2xloginretrycount
)
3517 ha
->login_retry_count
= ql2xloginretrycount
;
3520 if (!ha
->flags
.init_done
) {
3521 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3522 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3523 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3524 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3526 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3527 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3528 ha
->flags
.process_response_queue
= 0;
3529 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3530 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3532 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3533 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3534 ha
->zio_timer
* 100));
3535 qla_printk(KERN_INFO
, ha
,
3536 "ZIO mode %d enabled; timer delay (%d us).\n",
3537 ha
->zio_mode
, ha
->zio_timer
* 100);
3539 icb
->firmware_options_2
|= cpu_to_le32(
3540 (uint32_t)ha
->zio_mode
);
3541 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3542 ha
->flags
.process_response_queue
= 1;
3546 DEBUG2_3(printk(KERN_WARNING
3547 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3553 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3556 int segments
, fragment
;
3558 uint32_t *dcode
, dlen
;
3565 segments
= FA_RISC_CODE_SEGMENTS
;
3566 faddr
= FA_RISC_CODE_ADDR
;
3567 dcode
= (uint32_t *)ha
->request_ring
;
3570 /* Validate firmware image by checking version. */
3571 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3572 for (i
= 0; i
< 4; i
++)
3573 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3574 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3575 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3576 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3578 qla_printk(KERN_WARNING
, ha
,
3579 "Unable to verify integrity of flash firmware image!\n");
3580 qla_printk(KERN_WARNING
, ha
,
3581 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3582 dcode
[1], dcode
[2], dcode
[3]);
3584 return QLA_FUNCTION_FAILED
;
3587 while (segments
&& rval
== QLA_SUCCESS
) {
3588 /* Read segment's load information. */
3589 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3591 risc_addr
= be32_to_cpu(dcode
[2]);
3592 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3593 risc_size
= be32_to_cpu(dcode
[3]);
3596 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3597 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3598 if (dlen
> risc_size
)
3601 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3602 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3603 ha
->host_no
, risc_addr
, dlen
, faddr
));
3605 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3606 for (i
= 0; i
< dlen
; i
++)
3607 dcode
[i
] = swab32(dcode
[i
]);
3609 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3612 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3613 "segment %d of firmware\n", ha
->host_no
,
3615 qla_printk(KERN_WARNING
, ha
,
3616 "[ERROR] Failed to load segment %d of "
3617 "firmware\n", fragment
);
3634 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3637 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3641 uint16_t *wcode
, *fwcode
;
3642 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3643 struct fw_blob
*blob
;
3645 /* Load firmware blob. */
3646 blob
= qla2x00_request_firmware(ha
);
3648 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3649 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3650 "from: " QLA_FW_URL
".\n");
3651 return QLA_FUNCTION_FAILED
;
3656 wcode
= (uint16_t *)ha
->request_ring
;
3658 fwcode
= (uint16_t *)blob
->fw
->data
;
3661 /* Validate firmware image by checking version. */
3662 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3663 qla_printk(KERN_WARNING
, ha
,
3664 "Unable to verify integrity of firmware image (%Zd)!\n",
3666 goto fail_fw_integrity
;
3668 for (i
= 0; i
< 4; i
++)
3669 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3670 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3671 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3672 wcode
[2] == 0 && wcode
[3] == 0)) {
3673 qla_printk(KERN_WARNING
, ha
,
3674 "Unable to verify integrity of firmware image!\n");
3675 qla_printk(KERN_WARNING
, ha
,
3676 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3677 wcode
[1], wcode
[2], wcode
[3]);
3678 goto fail_fw_integrity
;
3682 while (*seg
&& rval
== QLA_SUCCESS
) {
3684 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3685 risc_size
= be16_to_cpu(fwcode
[3]);
3687 /* Validate firmware image size. */
3688 fwclen
+= risc_size
* sizeof(uint16_t);
3689 if (blob
->fw
->size
< fwclen
) {
3690 qla_printk(KERN_WARNING
, ha
,
3691 "Unable to verify integrity of firmware image "
3692 "(%Zd)!\n", blob
->fw
->size
);
3693 goto fail_fw_integrity
;
3697 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3698 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3699 if (wlen
> risc_size
)
3702 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3703 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3706 for (i
= 0; i
< wlen
; i
++)
3707 wcode
[i
] = swab16(fwcode
[i
]);
3709 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3712 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3713 "segment %d of firmware\n", ha
->host_no
,
3715 qla_printk(KERN_WARNING
, ha
,
3716 "[ERROR] Failed to load segment %d of "
3717 "firmware\n", fragment
);
3733 return QLA_FUNCTION_FAILED
;
3737 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3740 int segments
, fragment
;
3741 uint32_t *dcode
, dlen
;
3745 struct fw_blob
*blob
;
3746 uint32_t *fwcode
, fwclen
;
3748 /* Load firmware blob. */
3749 blob
= qla2x00_request_firmware(ha
);
3751 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3752 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3753 "from: " QLA_FW_URL
".\n");
3755 /* Try to load RISC code from flash. */
3756 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3757 "outdated) firmware from flash.\n");
3758 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3763 segments
= FA_RISC_CODE_SEGMENTS
;
3764 dcode
= (uint32_t *)ha
->request_ring
;
3766 fwcode
= (uint32_t *)blob
->fw
->data
;
3769 /* Validate firmware image by checking version. */
3770 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3771 qla_printk(KERN_WARNING
, ha
,
3772 "Unable to verify integrity of firmware image (%Zd)!\n",
3774 goto fail_fw_integrity
;
3776 for (i
= 0; i
< 4; i
++)
3777 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3778 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3779 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3780 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3782 qla_printk(KERN_WARNING
, ha
,
3783 "Unable to verify integrity of firmware image!\n");
3784 qla_printk(KERN_WARNING
, ha
,
3785 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3786 dcode
[1], dcode
[2], dcode
[3]);
3787 goto fail_fw_integrity
;
3790 while (segments
&& rval
== QLA_SUCCESS
) {
3791 risc_addr
= be32_to_cpu(fwcode
[2]);
3792 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3793 risc_size
= be32_to_cpu(fwcode
[3]);
3795 /* Validate firmware image size. */
3796 fwclen
+= risc_size
* sizeof(uint32_t);
3797 if (blob
->fw
->size
< fwclen
) {
3798 qla_printk(KERN_WARNING
, ha
,
3799 "Unable to verify integrity of firmware image "
3800 "(%Zd)!\n", blob
->fw
->size
);
3802 goto fail_fw_integrity
;
3806 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3807 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3808 if (dlen
> risc_size
)
3811 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3812 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3815 for (i
= 0; i
< dlen
; i
++)
3816 dcode
[i
] = swab32(fwcode
[i
]);
3818 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3821 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3822 "segment %d of firmware\n", ha
->host_no
,
3824 qla_printk(KERN_WARNING
, ha
,
3825 "[ERROR] Failed to load segment %d of "
3826 "firmware\n", fragment
);
3842 return QLA_FUNCTION_FAILED
;