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>
11 #include <scsi/scsi_transport_fc.h>
13 #include "qla_devtbl.h"
15 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
16 #ifndef EXT_IS_LUN_BIT_SET
17 #define EXT_IS_LUN_BIT_SET(P,L) \
18 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
19 #define EXT_SET_LUN_BIT(P,L) \
20 ((P)->mask[L/8] |= (0x80 >> (L%8)))
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
27 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
28 static int qla2x00_setup_chip(scsi_qla_host_t
*);
29 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
30 static int qla2x00_init_rings(scsi_qla_host_t
*);
31 static int qla2x00_fw_ready(scsi_qla_host_t
*);
32 static int qla2x00_configure_hba(scsi_qla_host_t
*);
33 static int qla2x00_configure_loop(scsi_qla_host_t
*);
34 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
35 static void qla2x00_update_fcport(scsi_qla_host_t
*, fc_port_t
*);
36 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
37 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
38 static int qla2x00_device_resync(scsi_qla_host_t
*);
39 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
42 static int qla2x00_restart_isp(scsi_qla_host_t
*);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
62 uint8_t restart_risc
= 0;
66 /* Clear adapter flags. */
68 ha
->flags
.reset_active
= 0;
69 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
70 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
73 ha
->flags
.management_server_logged_in
= 0;
74 ha
->marker_needed
= 0;
76 ha
->isp_abort_cnt
= 0;
77 ha
->beacon_blink_led
= 0;
78 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
80 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
81 rval
= ha
->isp_ops
.pci_config(ha
);
83 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
88 ha
->isp_ops
.reset_chip(ha
);
90 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
92 ha
->isp_ops
.nvram_config(ha
);
94 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
98 * Try to configure the loop.
103 /* If firmware needs to be loaded */
104 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
105 if ((rval
= ha
->isp_ops
.chip_diag(ha
)) == QLA_SUCCESS
) {
106 rval
= qla2x00_setup_chip(ha
);
110 if (rval
== QLA_SUCCESS
&&
111 (rval
= qla2x00_init_rings(ha
)) == QLA_SUCCESS
) {
112 check_fw_ready_again
:
114 * Wait for a successful LIP up to a maximum
115 * of (in seconds): RISC login timeout value,
116 * RISC retry count value, and port down retry
117 * value OR a minimum of 4 seconds OR If no
118 * cable, only 5 seconds.
120 rval
= qla2x00_fw_ready(ha
);
121 if (rval
== QLA_SUCCESS
) {
122 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
124 /* Issue a marker after FW becomes ready. */
125 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
128 * Wait at most MAX_TARGET RSCNs for a stable
133 clear_bit(LOOP_RESYNC_NEEDED
,
135 rval
= qla2x00_configure_loop(ha
);
137 if (test_and_clear_bit(ISP_ABORT_NEEDED
,
144 * If loop state change while we were
145 * discoverying devices then wait for
149 if (atomic_read(&ha
->loop_state
) !=
150 LOOP_READY
&& retry
--) {
151 goto check_fw_ready_again
;
154 } while (!atomic_read(&ha
->loop_down_timer
) &&
157 (test_bit(LOOP_RESYNC_NEEDED
,
161 rval
= QLA_FUNCTION_FAILED
;
162 } else if (ha
->device_flags
& DFLG_NO_CABLE
)
163 /* If no cable, then all is good. */
166 } while (restart_risc
&& retry
--);
168 if (rval
== QLA_SUCCESS
) {
169 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
170 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
171 ha
->marker_needed
= 0;
173 ha
->flags
.online
= 1;
175 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
182 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
185 * Returns 0 on success.
188 qla2100_pci_config(scsi_qla_host_t
*ha
)
193 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
195 pci_set_master(ha
->pdev
);
197 if (pci_set_mwi(ha
->pdev
))
198 mwi
= PCI_COMMAND_INVALIDATE
;
199 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
201 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
202 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
203 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
205 /* Reset expansion ROM address decode enable */
206 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
207 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
208 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
210 /* Get PCI bus information. */
211 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
212 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
213 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
219 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
222 * Returns 0 on success.
225 qla2300_pci_config(scsi_qla_host_t
*ha
)
229 unsigned long flags
= 0;
231 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
233 pci_set_master(ha
->pdev
);
235 if (pci_set_mwi(ha
->pdev
))
236 mwi
= PCI_COMMAND_INVALIDATE
;
237 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
239 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
240 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
242 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
243 w
&= ~PCI_COMMAND_INTX_DISABLE
;
246 * If this is a 2300 card and not 2312, reset the
247 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
248 * the 2310 also reports itself as a 2300 so we need to get the
249 * fb revision level -- a 6 indicates it really is a 2300 and
252 if (IS_QLA2300(ha
)) {
253 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
256 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
257 for (cnt
= 0; cnt
< 30000; cnt
++) {
258 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
264 /* Select FPM registers. */
265 WRT_REG_WORD(®
->ctrl_status
, 0x20);
266 RD_REG_WORD(®
->ctrl_status
);
268 /* Get the fb rev level */
269 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
271 if (ha
->fb_rev
== FPM_2300
)
272 w
&= ~PCI_COMMAND_INVALIDATE
;
274 /* Deselect FPM registers. */
275 WRT_REG_WORD(®
->ctrl_status
, 0x0);
276 RD_REG_WORD(®
->ctrl_status
);
278 /* Release RISC module. */
279 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
280 for (cnt
= 0; cnt
< 30000; cnt
++) {
281 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
287 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
289 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
291 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
293 /* Reset expansion ROM address decode enable */
294 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
295 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
296 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
298 /* Get PCI bus information. */
299 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
300 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
301 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
307 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
310 * Returns 0 on success.
313 qla24xx_pci_config(scsi_qla_host_t
*ha
)
317 unsigned long flags
= 0;
318 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
319 int pcix_cmd_reg
, pcie_dctl_reg
;
321 pci_set_master(ha
->pdev
);
323 if (pci_set_mwi(ha
->pdev
))
324 mwi
= PCI_COMMAND_INVALIDATE
;
325 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->revision
);
327 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
328 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
329 w
&= ~PCI_COMMAND_INTX_DISABLE
;
330 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
332 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
334 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
335 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
339 pcix_cmd_reg
+= PCI_X_CMD
;
340 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
341 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
343 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
346 /* PCIe -- adjust Maximum Read Request Size (2048). */
347 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
351 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
352 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
353 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
355 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
358 /* Reset expansion ROM address decode enable */
359 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
360 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
361 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
363 /* Get PCI bus information. */
364 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
365 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
366 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
372 * qla2x00_isp_firmware() - Choose firmware image.
375 * Returns 0 on success.
378 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
382 /* Assume loading risc code */
383 rval
= QLA_FUNCTION_FAILED
;
385 if (ha
->flags
.disable_risc_code_load
) {
386 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
388 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
390 /* Verify checksum of loaded RISC code. */
391 rval
= qla2x00_verify_checksum(ha
,
392 IS_QLA24XX(ha
) || IS_QLA25XX(ha
) ? RISC_SADDRESS
:
393 *ha
->brd_info
->fw_info
[0].fwstart
);
397 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
405 * qla2x00_reset_chip() - Reset ISP chip.
408 * Returns 0 on success.
411 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
413 unsigned long flags
= 0;
414 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
416 unsigned long mbx_flags
= 0;
419 ha
->isp_ops
.disable_intrs(ha
);
421 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
423 /* Turn off master enable */
425 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
426 cmd
&= ~PCI_COMMAND_MASTER
;
427 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
429 if (!IS_QLA2100(ha
)) {
431 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
432 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
433 for (cnt
= 0; cnt
< 30000; cnt
++) {
434 if ((RD_REG_WORD(®
->hccr
) &
435 HCCR_RISC_PAUSE
) != 0)
440 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
444 /* Select FPM registers. */
445 WRT_REG_WORD(®
->ctrl_status
, 0x20);
446 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
448 /* FPM Soft Reset. */
449 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
450 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
452 /* Toggle Fpm Reset. */
453 if (!IS_QLA2200(ha
)) {
454 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
455 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
458 /* Select frame buffer registers. */
459 WRT_REG_WORD(®
->ctrl_status
, 0x10);
460 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
462 /* Reset frame buffer FIFOs. */
463 if (IS_QLA2200(ha
)) {
464 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
465 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
467 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
469 /* Read back fb_cmd until zero or 3 seconds max */
470 for (cnt
= 0; cnt
< 3000; cnt
++) {
471 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
477 /* Select RISC module registers. */
478 WRT_REG_WORD(®
->ctrl_status
, 0);
479 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
481 /* Reset RISC processor. */
482 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
483 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
485 /* Release RISC processor. */
486 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
487 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
490 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
491 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
493 /* Reset ISP chip. */
494 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
496 /* Wait for RISC to recover from reset. */
497 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
499 * It is necessary to for a delay here since the card doesn't
500 * respond to PCI reads during a reset. On some architectures
501 * this will result in an MCA.
504 for (cnt
= 30000; cnt
; cnt
--) {
505 if ((RD_REG_WORD(®
->ctrl_status
) &
506 CSR_ISP_SOFT_RESET
) == 0)
513 /* Reset RISC processor. */
514 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
516 WRT_REG_WORD(®
->semaphore
, 0);
518 /* Release RISC processor. */
519 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
520 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
522 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
523 for (cnt
= 0; cnt
< 30000; cnt
++) {
524 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
525 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
527 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
) {
528 if (!(test_bit(ABORT_ISP_ACTIVE
,
530 spin_unlock_irqrestore(
531 &ha
->mbx_reg_lock
, mbx_flags
);
535 if (!(test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)))
536 spin_unlock_irqrestore(&ha
->mbx_reg_lock
,
544 /* Turn on master enable */
545 cmd
|= PCI_COMMAND_MASTER
;
546 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
548 /* Disable RISC pause on FPM parity error. */
549 if (!IS_QLA2100(ha
)) {
550 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
551 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
554 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
558 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
561 * Returns 0 on success.
564 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
566 unsigned long flags
= 0;
567 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
571 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
574 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
575 for (cnt
= 0; cnt
< 30000; cnt
++) {
576 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
582 WRT_REG_DWORD(®
->ctrl_status
,
583 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
584 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
587 /* Wait for firmware to complete NVRAM accesses. */
588 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
589 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
591 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
595 /* Wait for soft-reset to complete. */
596 d2
= RD_REG_DWORD(®
->ctrl_status
);
597 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
599 d2
= RD_REG_DWORD(®
->ctrl_status
);
603 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
604 RD_REG_DWORD(®
->hccr
);
606 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
607 RD_REG_DWORD(®
->hccr
);
609 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
610 RD_REG_DWORD(®
->hccr
);
612 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
613 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
615 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
619 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
623 * qla24xx_reset_chip() - Reset ISP24xx chip.
626 * Returns 0 on success.
629 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
631 ha
->isp_ops
.disable_intrs(ha
);
633 /* Perform RISC reset. */
634 qla24xx_reset_risc(ha
);
638 * qla2x00_chip_diag() - Test chip for proper operation.
641 * Returns 0 on success.
644 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
647 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
648 unsigned long flags
= 0;
653 /* Assume a failed state */
654 rval
= QLA_FUNCTION_FAILED
;
656 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
657 ha
->host_no
, (u_long
)®
->flash_address
));
659 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
661 /* Reset ISP chip. */
662 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
665 * We need to have a delay here since the card will not respond while
666 * in reset causing an MCA on some architectures.
669 data
= qla2x00_debounce_register(®
->ctrl_status
);
670 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
672 data
= RD_REG_WORD(®
->ctrl_status
);
677 goto chip_diag_failed
;
679 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
682 /* Reset RISC processor. */
683 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
684 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
686 /* Workaround for QLA2312 PCI parity error */
687 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
688 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
689 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
691 data
= RD_MAILBOX_REG(ha
, reg
, 0);
698 goto chip_diag_failed
;
700 /* Check product ID of chip */
701 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
703 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
704 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
705 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
706 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
707 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
708 mb
[3] != PROD_ID_3
) {
709 qla_printk(KERN_WARNING
, ha
,
710 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
712 goto chip_diag_failed
;
714 ha
->product_id
[0] = mb
[1];
715 ha
->product_id
[1] = mb
[2];
716 ha
->product_id
[2] = mb
[3];
717 ha
->product_id
[3] = mb
[4];
719 /* Adjust fw RISC transfer size */
720 if (ha
->request_q_length
> 1024)
721 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
723 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
724 ha
->request_q_length
;
726 if (IS_QLA2200(ha
) &&
727 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
728 /* Limit firmware transfer size with a 2200A */
729 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
732 ha
->fw_transfer_size
= 128;
735 /* Wrap Incoming Mailboxes Test. */
736 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
738 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
739 rval
= qla2x00_mbx_reg_test(ha
);
741 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
743 qla_printk(KERN_WARNING
, ha
,
744 "Failed mailbox send register test\n");
747 /* Flag a successful rval */
750 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
754 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
755 "****\n", ha
->host_no
));
757 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
763 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
766 * Returns 0 on success.
769 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
773 /* Perform RISC reset. */
774 qla24xx_reset_risc(ha
);
776 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
778 rval
= qla2x00_mbx_reg_test(ha
);
780 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
782 qla_printk(KERN_WARNING
, ha
,
783 "Failed mailbox send register test\n");
785 /* Flag a successful rval */
793 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
796 ha
->fw_dump24_len
= sizeof(struct qla24xx_fw_dump
);
797 ha
->fw_dump24_len
+= (ha
->fw_memory_size
- 0x100000) * sizeof(uint32_t);
798 ha
->fw_dump24
= vmalloc(ha
->fw_dump24_len
);
800 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware "
801 "dump...\n", ha
->fw_dump24_len
/ 1024);
803 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
804 "firmware dump!!!\n", ha
->fw_dump24_len
/ 1024);
808 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
811 * Returns 0 on success.
814 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
817 uint16_t fw_iocb_cnt
= 0;
818 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
819 dma_addr_t request_dma
;
820 request_t
*request_ring
;
822 /* Valid only on recent ISPs. */
823 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
826 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
827 qla2x00_alloc_fw_dump(ha
);
829 /* Retrieve IOCB counts available to the firmware. */
830 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
833 /* No point in continuing if current settings are sufficient. */
834 if (fw_iocb_cnt
< 1024)
836 if (ha
->request_q_length
>= request_q_length
)
839 /* Attempt to claim larger area for request queue. */
840 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
841 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
843 if (request_ring
== NULL
)
846 /* Resize successful, report extensions. */
847 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
848 (ha
->fw_memory_size
+ 1) / 1024);
849 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
850 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
852 /* Clear old allocations. */
853 dma_free_coherent(&ha
->pdev
->dev
,
854 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
857 /* Begin using larger queue. */
858 ha
->request_q_length
= request_q_length
;
859 ha
->request_ring
= request_ring
;
860 ha
->request_dma
= request_dma
;
864 * qla2x00_setup_chip() - Load and start RISC firmware.
867 * Returns 0 on success.
870 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
873 uint32_t srisc_address
= 0;
875 /* Load firmware sequences */
876 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
877 if (rval
== QLA_SUCCESS
) {
878 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
879 "code.\n", ha
->host_no
));
881 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
882 if (rval
== QLA_SUCCESS
) {
883 /* Start firmware execution. */
884 DEBUG(printk("scsi(%ld): Checksum OK, start "
885 "firmware.\n", ha
->host_no
));
887 rval
= qla2x00_execute_fw(ha
, srisc_address
);
888 /* Retrieve firmware information. */
889 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
890 qla2x00_get_fw_version(ha
,
891 &ha
->fw_major_version
,
892 &ha
->fw_minor_version
,
893 &ha
->fw_subminor_version
,
894 &ha
->fw_attributes
, &ha
->fw_memory_size
);
895 qla2x00_resize_request_q(ha
);
898 DEBUG2(printk(KERN_INFO
899 "scsi(%ld): ISP Firmware failed checksum.\n",
905 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
913 * qla2x00_init_response_q_entries() - Initializes response queue entries.
916 * Beginning of request ring has initialization control block already built
917 * by nvram config routine.
919 * Returns 0 on success.
922 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
927 pkt
= ha
->response_ring_ptr
;
928 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
929 pkt
->signature
= RESPONSE_PROCESSED
;
936 * qla2x00_update_fw_options() - Read and process firmware options.
939 * Returns 0 on success.
942 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
944 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
946 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
947 qla2x00_get_fw_options(ha
, ha
->fw_options
);
949 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
952 /* Serial Link options. */
953 DEBUG3(printk("scsi(%ld): Serial link options:\n",
955 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
956 sizeof(ha
->fw_seriallink_options
)));
958 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
959 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
960 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
963 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
964 emphasis
= (ha
->fw_seriallink_options
[2] &
965 (BIT_4
| BIT_3
)) >> 3;
966 tx_sens
= ha
->fw_seriallink_options
[0] &
967 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
968 rx_sens
= (ha
->fw_seriallink_options
[0] &
969 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
970 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
971 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
974 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
975 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
976 ha
->fw_options
[10] |= BIT_5
|
977 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
978 (tx_sens
& (BIT_1
| BIT_0
));
981 swing
= (ha
->fw_seriallink_options
[2] &
982 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
983 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
984 tx_sens
= ha
->fw_seriallink_options
[1] &
985 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
986 rx_sens
= (ha
->fw_seriallink_options
[1] &
987 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
988 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
989 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
992 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
993 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
994 ha
->fw_options
[11] |= BIT_5
|
995 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
996 (tx_sens
& (BIT_1
| BIT_0
));
1000 /* Return command IOCBs without waiting for an ABTS to complete. */
1001 ha
->fw_options
[3] |= BIT_13
;
1004 if (ha
->flags
.enable_led_scheme
)
1005 ha
->fw_options
[2] |= BIT_12
;
1007 /* Update firmware options. */
1008 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1012 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1016 /* Update Serial Link options. */
1017 if ((ha
->fw_seriallink_options24
[0] & BIT_0
) == 0)
1020 rval
= qla2x00_set_serdes_params(ha
, ha
->fw_seriallink_options24
[1],
1021 ha
->fw_seriallink_options24
[2], ha
->fw_seriallink_options24
[3]);
1022 if (rval
!= QLA_SUCCESS
) {
1023 qla_printk(KERN_WARNING
, ha
,
1024 "Unable to update Serial Link options (%x).\n", rval
);
1029 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1031 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1033 /* Setup ring parameters in initialization control block. */
1034 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1035 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1036 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1037 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1038 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1039 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1040 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1041 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1043 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1044 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1045 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1046 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1047 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1051 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1053 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1054 struct init_cb_24xx
*icb
;
1056 /* Setup ring parameters in initialization control block. */
1057 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1058 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1059 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1060 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1061 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1062 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1063 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1064 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1065 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1067 WRT_REG_DWORD(®
->req_q_in
, 0);
1068 WRT_REG_DWORD(®
->req_q_out
, 0);
1069 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1070 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1071 RD_REG_DWORD(®
->rsp_q_out
);
1075 * qla2x00_init_rings() - Initializes firmware.
1078 * Beginning of request ring has initialization control block already built
1079 * by nvram config routine.
1081 * Returns 0 on success.
1084 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1087 unsigned long flags
= 0;
1090 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1092 /* Clear outstanding commands array. */
1093 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1094 ha
->outstanding_cmds
[cnt
] = NULL
;
1096 ha
->current_outstanding_cmd
= 0;
1098 /* Clear RSCN queue. */
1099 ha
->rscn_in_ptr
= 0;
1100 ha
->rscn_out_ptr
= 0;
1102 /* Initialize firmware. */
1103 ha
->request_ring_ptr
= ha
->request_ring
;
1104 ha
->req_ring_index
= 0;
1105 ha
->req_q_cnt
= ha
->request_q_length
;
1106 ha
->response_ring_ptr
= ha
->response_ring
;
1107 ha
->rsp_ring_index
= 0;
1109 /* Initialize response queue entries */
1110 qla2x00_init_response_q_entries(ha
);
1112 ha
->isp_ops
.config_rings(ha
);
1114 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1116 /* Update any ISP specific firmware options before initialization. */
1117 ha
->isp_ops
.update_fw_options(ha
);
1119 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1120 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1122 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1125 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1133 * qla2x00_fw_ready() - Waits for firmware ready.
1136 * Returns 0 on success.
1139 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1142 unsigned long wtime
, mtime
;
1143 uint16_t min_wait
; /* Minimum wait time if loop is down */
1144 uint16_t wait_time
; /* Wait time if loop is coming ready */
1149 /* 20 seconds for loop down. */
1153 * Firmware should take at most one RATOV to login, plus 5 seconds for
1154 * our own processing.
1156 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1157 wait_time
= min_wait
;
1160 /* Min wait time if loop down */
1161 mtime
= jiffies
+ (min_wait
* HZ
);
1163 /* wait time before firmware ready */
1164 wtime
= jiffies
+ (wait_time
* HZ
);
1166 /* Wait for ISP to finish LIP */
1167 if (!ha
->flags
.init_done
)
1168 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1170 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1174 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1175 if (rval
== QLA_SUCCESS
) {
1176 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1177 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1179 if (fw_state
== FSTATE_READY
) {
1180 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1183 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1184 &ha
->login_timeout
, &ha
->r_a_tov
);
1190 rval
= QLA_FUNCTION_FAILED
;
1192 if (atomic_read(&ha
->loop_down_timer
) &&
1193 (fw_state
>= FSTATE_LOSS_OF_SYNC
||
1194 fw_state
== FSTATE_WAIT_AL_PA
)) {
1195 /* Loop down. Timeout on min_wait for states
1196 * other than Wait for Login.
1198 if (time_after_eq(jiffies
, mtime
)) {
1199 qla_printk(KERN_INFO
, ha
,
1200 "Cable is unplugged...\n");
1202 ha
->device_flags
|= DFLG_NO_CABLE
;
1207 /* Mailbox cmd failed. Timeout on min_wait. */
1208 if (time_after_eq(jiffies
, mtime
))
1212 if (time_after_eq(jiffies
, wtime
))
1215 /* Delay for a while */
1218 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1219 ha
->host_no
, fw_state
, jiffies
));
1222 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1223 ha
->host_no
, fw_state
, jiffies
));
1226 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1234 * qla2x00_configure_hba
1235 * Setup adapter context.
1238 * ha = adapter state pointer.
1247 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1255 char connect_type
[22];
1257 /* Get host addresses. */
1258 rval
= qla2x00_get_adapter_id(ha
,
1259 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1260 if (rval
!= QLA_SUCCESS
) {
1261 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1262 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1263 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1264 __func__
, ha
->host_no
));
1266 qla_printk(KERN_WARNING
, ha
,
1267 "ERROR -- Unable to get host loop ID.\n");
1268 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1274 qla_printk(KERN_INFO
, ha
,
1275 "Cannot get topology - retrying.\n");
1276 return (QLA_FUNCTION_FAILED
);
1279 ha
->loop_id
= loop_id
;
1282 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1283 ha
->operating_mode
= LOOP
;
1287 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1289 ha
->current_topology
= ISP_CFG_NL
;
1290 strcpy(connect_type
, "(Loop)");
1294 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1296 ha
->current_topology
= ISP_CFG_FL
;
1297 strcpy(connect_type
, "(FL_Port)");
1301 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1303 ha
->operating_mode
= P2P
;
1304 ha
->current_topology
= ISP_CFG_N
;
1305 strcpy(connect_type
, "(N_Port-to-N_Port)");
1309 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1311 ha
->operating_mode
= P2P
;
1312 ha
->current_topology
= ISP_CFG_F
;
1313 strcpy(connect_type
, "(F_Port)");
1317 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1319 ha
->host_no
, topo
));
1320 ha
->current_topology
= ISP_CFG_NL
;
1321 strcpy(connect_type
, "(Loop)");
1325 /* Save Host port and loop ID. */
1326 /* byte order - Big Endian */
1327 ha
->d_id
.b
.domain
= domain
;
1328 ha
->d_id
.b
.area
= area
;
1329 ha
->d_id
.b
.al_pa
= al_pa
;
1331 if (!ha
->flags
.init_done
)
1332 qla_printk(KERN_INFO
, ha
,
1333 "Topology - %s, Host Loop address 0x%x\n",
1334 connect_type
, ha
->loop_id
);
1337 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1339 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1346 * NVRAM configuration for ISP 2xxx
1349 * ha = adapter block pointer.
1352 * initialization control block in response_ring
1353 * host adapters parameters in host adapter block
1359 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1364 uint8_t *dptr1
, *dptr2
;
1365 init_cb_t
*icb
= ha
->init_cb
;
1366 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1367 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1368 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1372 /* Determine NVRAM starting address. */
1373 ha
->nvram_size
= sizeof(nvram_t
);
1375 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1376 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1377 ha
->nvram_base
= 0x80;
1379 /* Get NVRAM data and calculate checksum. */
1380 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1381 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1384 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1385 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1388 /* Bad NVRAM data, set defaults parameters. */
1389 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1390 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1391 /* Reset NVRAM data. */
1392 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1393 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1395 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1396 "invalid -- WWPN) defaults.\n");
1399 * Set default initialization control block.
1401 memset(nv
, 0, ha
->nvram_size
);
1402 nv
->parameter_block_version
= ICB_VERSION
;
1404 if (IS_QLA23XX(ha
)) {
1405 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1406 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1407 nv
->add_firmware_options
[0] = BIT_5
;
1408 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1409 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1410 nv
->special_options
[1] = BIT_7
;
1411 } else if (IS_QLA2200(ha
)) {
1412 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1413 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1414 nv
->add_firmware_options
[0] = BIT_5
;
1415 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1416 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1417 } else if (IS_QLA2100(ha
)) {
1418 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1419 nv
->firmware_options
[1] = BIT_5
;
1420 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1423 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1424 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1425 nv
->retry_count
= 8;
1426 nv
->retry_delay
= 1;
1428 nv
->port_name
[0] = 33;
1429 nv
->port_name
[3] = 224;
1430 nv
->port_name
[4] = 139;
1432 nv
->login_timeout
= 4;
1435 * Set default host adapter parameters
1437 nv
->host_p
[1] = BIT_2
;
1438 nv
->reset_delay
= 5;
1439 nv
->port_down_retry_count
= 8;
1440 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1441 nv
->link_down_timeout
= 60;
1446 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1448 * The SN2 does not provide BIOS emulation which means you can't change
1449 * potentially bogus BIOS settings. Force the use of default settings
1450 * for link rate and frame size. Hope that the rest of the settings
1453 if (ia64_platform_is("sn2")) {
1454 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1456 nv
->special_options
[1] = BIT_7
;
1460 /* Reset Initialization control block */
1461 memset(icb
, 0, ha
->init_cb_size
);
1464 * Setup driver NVRAM options.
1466 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1467 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1468 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1469 nv
->firmware_options
[1] &= ~BIT_4
;
1471 if (IS_QLA23XX(ha
)) {
1472 nv
->firmware_options
[0] |= BIT_2
;
1473 nv
->firmware_options
[0] &= ~BIT_3
;
1474 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1476 if (IS_QLA2300(ha
)) {
1477 if (ha
->fb_rev
== FPM_2310
) {
1478 strcpy(ha
->model_number
, "QLA2310");
1480 strcpy(ha
->model_number
, "QLA2300");
1484 memcmp(nv
->model_number
, BINZERO
,
1485 sizeof(nv
->model_number
)) != 0) {
1488 strncpy(ha
->model_number
, nv
->model_number
,
1489 sizeof(nv
->model_number
));
1490 st
= en
= ha
->model_number
;
1491 en
+= sizeof(nv
->model_number
) - 1;
1493 if (*en
!= 0x20 && *en
!= 0x00)
1500 index
= (ha
->pdev
->subsystem_device
& 0xff);
1501 if (index
< QLA_MODEL_NAMES
) {
1502 strcpy(ha
->model_number
,
1503 qla2x00_model_name
[index
]);
1505 qla2x00_model_desc
[index
];
1507 strcpy(ha
->model_number
, "QLA23xx");
1511 } else if (IS_QLA2200(ha
)) {
1512 nv
->firmware_options
[0] |= BIT_2
;
1514 * 'Point-to-point preferred, else loop' is not a safe
1515 * connection mode setting.
1517 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1519 /* Force 'loop preferred, else point-to-point'. */
1520 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1521 nv
->add_firmware_options
[0] |= BIT_5
;
1523 strcpy(ha
->model_number
, "QLA22xx");
1524 } else /*if (IS_QLA2100(ha))*/ {
1525 strcpy(ha
->model_number
, "QLA2100");
1529 * Copy over NVRAM RISC parameter block to initialization control block.
1531 dptr1
= (uint8_t *)icb
;
1532 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1533 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1535 *dptr1
++ = *dptr2
++;
1537 /* Copy 2nd half. */
1538 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1539 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1541 *dptr1
++ = *dptr2
++;
1543 /* Prepare nodename */
1544 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1546 * Firmware will apply the following mask if the nodename was
1549 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1550 icb
->node_name
[0] &= 0xF0;
1554 * Set host adapter parameters.
1556 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1557 /* Always load RISC code on non ISP2[12]00 chips. */
1558 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1559 ha
->flags
.disable_risc_code_load
= 0;
1560 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1561 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1562 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1563 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1565 ha
->operating_mode
=
1566 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1568 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1569 sizeof(ha
->fw_seriallink_options
));
1571 /* save HBA serial number */
1572 ha
->serial0
= icb
->port_name
[5];
1573 ha
->serial1
= icb
->port_name
[6];
1574 ha
->serial2
= icb
->port_name
[7];
1575 ha
->node_name
= icb
->node_name
;
1576 ha
->port_name
= icb
->port_name
;
1578 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1580 ha
->retry_count
= nv
->retry_count
;
1582 /* Set minimum login_timeout to 4 seconds. */
1583 if (nv
->login_timeout
< ql2xlogintimeout
)
1584 nv
->login_timeout
= ql2xlogintimeout
;
1585 if (nv
->login_timeout
< 4)
1586 nv
->login_timeout
= 4;
1587 ha
->login_timeout
= nv
->login_timeout
;
1588 icb
->login_timeout
= nv
->login_timeout
;
1590 /* Set minimum RATOV to 200 tenths of a second. */
1593 ha
->loop_reset_delay
= nv
->reset_delay
;
1595 /* Link Down Timeout = 0:
1597 * When Port Down timer expires we will start returning
1598 * I/O's to OS with "DID_NO_CONNECT".
1600 * Link Down Timeout != 0:
1602 * The driver waits for the link to come up after link down
1603 * before returning I/Os to OS with "DID_NO_CONNECT".
1605 if (nv
->link_down_timeout
== 0) {
1606 ha
->loop_down_abort_time
=
1607 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1609 ha
->link_down_timeout
= nv
->link_down_timeout
;
1610 ha
->loop_down_abort_time
=
1611 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1615 * Need enough time to try and get the port back.
1617 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1618 if (qlport_down_retry
)
1619 ha
->port_down_retry_count
= qlport_down_retry
;
1620 /* Set login_retry_count */
1621 ha
->login_retry_count
= nv
->retry_count
;
1622 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1623 ha
->port_down_retry_count
> 3)
1624 ha
->login_retry_count
= ha
->port_down_retry_count
;
1625 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1626 ha
->login_retry_count
= ha
->port_down_retry_count
;
1627 if (ql2xloginretrycount
)
1628 ha
->login_retry_count
= ql2xloginretrycount
;
1630 icb
->lun_enables
= __constant_cpu_to_le16(0);
1631 icb
->command_resource_count
= 0;
1632 icb
->immediate_notify_resource_count
= 0;
1633 icb
->timeout
= __constant_cpu_to_le16(0);
1635 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1637 icb
->firmware_options
[0] &= ~BIT_3
;
1638 icb
->add_firmware_options
[0] &=
1639 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1640 icb
->add_firmware_options
[0] |= BIT_2
;
1641 icb
->response_accumulation_timer
= 3;
1642 icb
->interrupt_delay_timer
= 5;
1644 ha
->flags
.process_response_queue
= 1;
1647 if (!ha
->flags
.init_done
) {
1648 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1649 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1650 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1651 icb
->interrupt_delay_timer
: 2;
1653 icb
->add_firmware_options
[0] &=
1654 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1655 ha
->flags
.process_response_queue
= 0;
1656 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1657 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1658 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1659 ha
->zio_timer
* 100));
1660 qla_printk(KERN_INFO
, ha
,
1661 "ZIO mode %d enabled; timer delay (%d us).\n",
1662 ha
->zio_mode
, ha
->zio_timer
* 100);
1664 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1665 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1666 ha
->flags
.process_response_queue
= 1;
1671 DEBUG2_3(printk(KERN_WARNING
1672 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1678 qla2x00_rport_add(void *data
)
1680 fc_port_t
*fcport
= data
;
1682 qla2x00_reg_remote_port(fcport
->ha
, fcport
);
1686 qla2x00_rport_del(void *data
)
1688 fc_port_t
*fcport
= data
;
1691 fc_remote_port_delete(fcport
->rport
);
1692 fcport
->rport
= NULL
;
1696 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1698 * @flags: allocation flags
1700 * Returns a pointer to the allocated fcport, or NULL, if none available.
1703 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1707 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1711 /* Setup fcport template structure. */
1712 memset(fcport
, 0, sizeof (fc_port_t
));
1714 fcport
->port_type
= FCT_UNKNOWN
;
1715 fcport
->loop_id
= FC_NO_LOOP_ID
;
1716 fcport
->iodesc_idx_sent
= IODESC_INVALID_INDEX
;
1717 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1718 fcport
->flags
= FCF_RLC_SUPPORT
;
1719 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1720 INIT_WORK(&fcport
->rport_add_work
, qla2x00_rport_add
, fcport
);
1721 INIT_WORK(&fcport
->rport_del_work
, qla2x00_rport_del
, fcport
);
1727 * qla2x00_configure_loop
1728 * Updates Fibre Channel Device Database with what is actually on loop.
1731 * ha = adapter block pointer.
1736 * 2 = database was full and device was not configured.
1739 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1742 unsigned long flags
, save_flags
;
1746 /* Get Initiator ID */
1747 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1748 rval
= qla2x00_configure_hba(ha
);
1749 if (rval
!= QLA_SUCCESS
) {
1750 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1756 save_flags
= flags
= ha
->dpc_flags
;
1757 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1758 ha
->host_no
, flags
));
1761 * If we have both an RSCN and PORT UPDATE pending then handle them
1762 * both at the same time.
1764 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1765 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1767 /* Determine what we need to do */
1768 if (ha
->current_topology
== ISP_CFG_FL
&&
1769 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1771 ha
->flags
.rscn_queue_overflow
= 1;
1772 set_bit(RSCN_UPDATE
, &flags
);
1774 } else if (ha
->current_topology
== ISP_CFG_F
&&
1775 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1777 ha
->flags
.rscn_queue_overflow
= 1;
1778 set_bit(RSCN_UPDATE
, &flags
);
1779 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1781 } else if (!ha
->flags
.online
||
1782 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1784 ha
->flags
.rscn_queue_overflow
= 1;
1785 set_bit(RSCN_UPDATE
, &flags
);
1786 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1789 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1790 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1791 rval
= QLA_FUNCTION_FAILED
;
1793 rval
= qla2x00_configure_local_loop(ha
);
1797 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1798 if (LOOP_TRANSITION(ha
)) {
1799 rval
= QLA_FUNCTION_FAILED
;
1801 rval
= qla2x00_configure_fabric(ha
);
1805 if (rval
== QLA_SUCCESS
) {
1806 if (atomic_read(&ha
->loop_down_timer
) ||
1807 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1808 rval
= QLA_FUNCTION_FAILED
;
1810 atomic_set(&ha
->loop_state
, LOOP_READY
);
1812 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1817 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1818 __func__
, ha
->host_no
));
1820 DEBUG3(printk("%s: exiting normally\n", __func__
));
1823 /* Restore state if a resync event occured during processing */
1824 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1825 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1826 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1827 if (test_bit(RSCN_UPDATE
, &save_flags
))
1828 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1837 * qla2x00_configure_local_loop
1838 * Updates Fibre Channel Device Database with local loop devices.
1841 * ha = adapter block pointer.
1847 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1852 fc_port_t
*fcport
, *new_fcport
;
1858 uint8_t domain
, area
, al_pa
;
1862 entries
= MAX_FIBRE_DEVICES
;
1864 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1865 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1867 /* Get list of logged in devices. */
1868 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1869 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1871 if (rval
!= QLA_SUCCESS
)
1872 goto cleanup_allocation
;
1874 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1875 ha
->host_no
, entries
));
1876 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1877 entries
* sizeof(struct gid_list_info
)));
1879 /* Allocate temporary fcport for any new fcports discovered. */
1880 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1881 if (new_fcport
== NULL
) {
1882 rval
= QLA_MEMORY_ALLOC_FAILED
;
1883 goto cleanup_allocation
;
1885 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1888 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1890 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1891 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1892 fcport
->port_type
!= FCT_BROADCAST
&&
1893 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1895 DEBUG(printk("scsi(%ld): Marking port lost, "
1897 ha
->host_no
, fcport
->loop_id
));
1899 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1900 fcport
->flags
&= ~FCF_FARP_DONE
;
1904 /* Add devices to port list. */
1905 id_iter
= (char *)ha
->gid_list
;
1906 for (index
= 0; index
< entries
; index
++) {
1907 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1908 area
= ((struct gid_list_info
*)id_iter
)->area
;
1909 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1910 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1911 loop_id
= (uint16_t)
1912 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1914 loop_id
= le16_to_cpu(
1915 ((struct gid_list_info
*)id_iter
)->loop_id
);
1916 id_iter
+= ha
->gid_list_info_size
;
1918 /* Bypass reserved domain fields. */
1919 if ((domain
& 0xf0) == 0xf0)
1922 /* Bypass if not same domain and area of adapter. */
1923 if (area
&& domain
&&
1924 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
1927 /* Bypass invalid local loop ID. */
1928 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1931 /* Fill in member data. */
1932 new_fcport
->d_id
.b
.domain
= domain
;
1933 new_fcport
->d_id
.b
.area
= area
;
1934 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1935 new_fcport
->loop_id
= loop_id
;
1936 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1937 if (rval2
!= QLA_SUCCESS
) {
1938 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1939 "information -- get_port_database=%x, "
1941 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1945 /* Check for matching device in port list. */
1948 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1949 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
1953 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
1954 FCF_PERSISTENT_BOUND
);
1955 fcport
->loop_id
= new_fcport
->loop_id
;
1956 fcport
->port_type
= new_fcport
->port_type
;
1957 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
1958 memcpy(fcport
->node_name
, new_fcport
->node_name
,
1966 /* New device, add to fcports list. */
1967 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
1968 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
1970 /* Allocate a new replacement fcport. */
1971 fcport
= new_fcport
;
1972 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1973 if (new_fcport
== NULL
) {
1974 rval
= QLA_MEMORY_ALLOC_FAILED
;
1975 goto cleanup_allocation
;
1977 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1980 qla2x00_update_fcport(ha
, fcport
);
1988 if (rval
!= QLA_SUCCESS
) {
1989 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
1990 "rval=%x\n", ha
->host_no
, rval
));
1994 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
1995 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2002 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2006 qla2x00_mark_all_devices_lost(ha
);
2007 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2008 if (fcport
->port_type
!= FCT_TARGET
)
2011 qla2x00_update_fcport(ha
, fcport
);
2016 * qla2x00_update_fcport
2017 * Updates device on list.
2020 * ha = adapter block pointer.
2021 * fcport = port structure pointer.
2031 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2034 unsigned long flags
;
2038 fcport
->login_retry
= 0;
2039 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2041 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2043 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2046 * Check for outstanding cmd on tape Bypass LUN discovery if active
2049 if (fcport
->flags
& FCF_TAPE_PRESENT
) {
2050 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2051 for (index
= 1; index
< MAX_OUTSTANDING_COMMANDS
; index
++) {
2054 if ((sp
= ha
->outstanding_cmds
[index
]) != 0) {
2056 if (sfcp
== fcport
) {
2057 atomic_set(&fcport
->state
, FCS_ONLINE
);
2058 spin_unlock_irqrestore(
2059 &ha
->hardware_lock
, flags
);
2064 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2067 if (fcport
->port_type
== FCT_INITIATOR
||
2068 fcport
->port_type
== FCT_BROADCAST
)
2069 fcport
->device_type
= TYPE_PROCESSOR
;
2071 atomic_set(&fcport
->state
, FCS_ONLINE
);
2073 if (ha
->flags
.init_done
)
2074 qla2x00_reg_remote_port(ha
, fcport
);
2078 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2080 struct fc_rport_identifiers rport_ids
;
2081 struct fc_rport
*rport
;
2083 if (fcport
->rport
) {
2084 fc_remote_port_delete(fcport
->rport
);
2085 fcport
->rport
= NULL
;
2088 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2089 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2090 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2091 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2092 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2093 fcport
->rport
= rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2095 qla_printk(KERN_WARNING
, ha
,
2096 "Unable to allocate fc remote port!\n");
2099 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2100 rport
->supported_classes
= fcport
->supported_classes
;
2102 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2103 if (fcport
->port_type
== FCT_INITIATOR
)
2104 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2105 if (fcport
->port_type
== FCT_TARGET
)
2106 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2107 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2109 if (rport
->scsi_target_id
!= -1 &&
2110 rport
->scsi_target_id
< ha
->host
->max_id
)
2111 fcport
->os_target_id
= rport
->scsi_target_id
;
2115 * qla2x00_configure_fabric
2116 * Setup SNS devices with loop ID's.
2119 * ha = adapter block pointer.
2126 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2129 fc_port_t
*fcport
, *fcptemp
;
2130 uint16_t next_loopid
;
2131 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2133 LIST_HEAD(new_fcports
);
2135 /* If FL port exists, then SNS is present */
2136 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
2137 loop_id
= NPH_F_PORT
;
2139 loop_id
= SNS_FL_PORT
;
2140 rval
= qla2x00_get_port_name(ha
, loop_id
, NULL
, 0);
2141 if (rval
!= QLA_SUCCESS
) {
2142 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2143 "Port\n", ha
->host_no
));
2145 ha
->device_flags
&= ~SWITCH_FOUND
;
2146 return (QLA_SUCCESS
);
2149 /* Mark devices that need re-synchronization. */
2150 rval2
= qla2x00_device_resync(ha
);
2151 if (rval2
== QLA_RSCNS_HANDLED
) {
2152 /* No point doing the scan, just continue. */
2153 return (QLA_SUCCESS
);
2157 if (ql2xfdmienable
&&
2158 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2159 qla2x00_fdmi_register(ha
);
2161 /* Ensure we are logged into the SNS. */
2162 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
2165 loop_id
= SIMPLE_NAME_SERVER
;
2166 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2167 0xfc, mb
, BIT_1
| BIT_0
);
2168 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2169 DEBUG2(qla_printk(KERN_INFO
, ha
,
2170 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2171 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2172 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2173 return (QLA_SUCCESS
);
2176 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2177 if (qla2x00_rft_id(ha
)) {
2179 DEBUG2(printk("scsi(%ld): Register FC-4 "
2180 "TYPE failed.\n", ha
->host_no
));
2182 if (qla2x00_rff_id(ha
)) {
2184 DEBUG2(printk("scsi(%ld): Register FC-4 "
2185 "Features failed.\n", ha
->host_no
));
2187 if (qla2x00_rnn_id(ha
)) {
2189 DEBUG2(printk("scsi(%ld): Register Node Name "
2190 "failed.\n", ha
->host_no
));
2191 } else if (qla2x00_rsnn_nn(ha
)) {
2193 DEBUG2(printk("scsi(%ld): Register Symbolic "
2194 "Node Name failed.\n", ha
->host_no
));
2198 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2199 if (rval
!= QLA_SUCCESS
)
2203 * Logout all previous fabric devices marked lost, except
2206 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2207 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2210 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2213 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2214 qla2x00_mark_device_lost(ha
, fcport
,
2215 ql2xplogiabsentdevice
);
2216 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2217 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2218 fcport
->port_type
!= FCT_INITIATOR
&&
2219 fcport
->port_type
!= FCT_BROADCAST
) {
2221 ha
->isp_ops
.fabric_logout(ha
,
2223 fcport
->d_id
.b
.domain
,
2224 fcport
->d_id
.b
.area
,
2225 fcport
->d_id
.b
.al_pa
);
2226 fcport
->loop_id
= FC_NO_LOOP_ID
;
2231 /* Starting free loop ID. */
2232 next_loopid
= ha
->min_external_loopid
;
2235 * Scan through our port list and login entries that need to be
2238 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2239 if (atomic_read(&ha
->loop_down_timer
) ||
2240 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2243 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2244 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2247 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2248 fcport
->loop_id
= next_loopid
;
2249 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2250 if (rval
!= QLA_SUCCESS
) {
2251 /* Ran out of IDs to use */
2255 /* Login and update database */
2256 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2259 /* Exit if out of loop IDs. */
2260 if (rval
!= QLA_SUCCESS
) {
2265 * Login and add the new devices to our port list.
2267 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2268 if (atomic_read(&ha
->loop_down_timer
) ||
2269 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2272 /* Find a new loop ID to use. */
2273 fcport
->loop_id
= next_loopid
;
2274 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2275 if (rval
!= QLA_SUCCESS
) {
2276 /* Ran out of IDs to use */
2280 /* Remove device from the new list and add it to DB */
2281 list_del(&fcport
->list
);
2282 list_add_tail(&fcport
->list
, &ha
->fcports
);
2284 /* Login and update database */
2285 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2289 /* Free all new device structures not processed. */
2290 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2291 list_del(&fcport
->list
);
2296 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2297 "rval=%d\n", ha
->host_no
, rval
));
2305 * qla2x00_find_all_fabric_devs
2308 * ha = adapter block pointer.
2309 * dev = database device entry pointer.
2318 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2322 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2327 int first_dev
, last_dev
;
2328 port_id_t wrap
, nxt_d_id
;
2332 /* Try GID_PT to get device list, else GAN. */
2333 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2336 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2337 "on GA_NXT\n", ha
->host_no
));
2339 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2340 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2343 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2346 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2353 /* Allocate temporary fcport for any new fcports discovered. */
2354 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2355 if (new_fcport
== NULL
) {
2357 return (QLA_MEMORY_ALLOC_FAILED
);
2359 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2361 /* Set start port ID scan at adapter ID. */
2365 /* Starting free loop ID. */
2366 loop_id
= ha
->min_external_loopid
;
2367 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2368 if (qla2x00_is_reserved_id(ha
, loop_id
))
2371 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2376 wrap
.b24
= new_fcport
->d_id
.b24
;
2378 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2379 memcpy(new_fcport
->node_name
,
2380 swl
[swl_idx
].node_name
, WWN_SIZE
);
2381 memcpy(new_fcport
->port_name
,
2382 swl
[swl_idx
].port_name
, WWN_SIZE
);
2384 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2390 /* Send GA_NXT to the switch */
2391 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2392 if (rval
!= QLA_SUCCESS
) {
2393 qla_printk(KERN_WARNING
, ha
,
2394 "SNS scan failed -- assuming zero-entry "
2396 list_for_each_entry_safe(fcport
, fcptemp
,
2397 new_fcports
, list
) {
2398 list_del(&fcport
->list
);
2406 /* If wrap on switch device list, exit. */
2408 wrap
.b24
= new_fcport
->d_id
.b24
;
2410 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2411 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2412 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2413 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2417 /* Bypass if host adapter. */
2418 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2421 /* Bypass if same domain and area of adapter. */
2422 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2423 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2427 /* Bypass reserved domain fields. */
2428 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2431 /* Locate matching device in database. */
2433 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2434 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2441 * If address the same and state FCS_ONLINE, nothing
2444 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2445 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2450 * If device was not a fabric device before.
2452 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2453 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2454 fcport
->loop_id
= FC_NO_LOOP_ID
;
2455 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2457 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2462 * Port ID changed or device was marked to be updated;
2463 * Log it out if still logged in and mark it for
2466 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2467 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2468 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2469 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2470 fcport
->port_type
!= FCT_INITIATOR
&&
2471 fcport
->port_type
!= FCT_BROADCAST
) {
2472 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2473 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2474 fcport
->d_id
.b
.al_pa
);
2475 fcport
->loop_id
= FC_NO_LOOP_ID
;
2484 /* If device was not in our fcports list, then add it. */
2485 list_add_tail(&new_fcport
->list
, new_fcports
);
2487 /* Allocate a new replacement fcport. */
2488 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2489 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2490 if (new_fcport
== NULL
) {
2492 return (QLA_MEMORY_ALLOC_FAILED
);
2494 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2495 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2501 if (!list_empty(new_fcports
))
2502 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2508 * qla2x00_find_new_loop_id
2509 * Scan through our port list and find a new usable loop ID.
2512 * ha: adapter state pointer.
2513 * dev: port structure pointer.
2516 * qla2x00 local function return status code.
2522 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2527 uint16_t first_loop_id
;
2531 /* Save starting loop ID. */
2532 first_loop_id
= dev
->loop_id
;
2535 /* Skip loop ID if already used by adapter. */
2536 if (dev
->loop_id
== ha
->loop_id
) {
2540 /* Skip reserved loop IDs. */
2541 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2545 /* Reset loop ID if passed the end. */
2546 if (dev
->loop_id
> ha
->last_loop_id
) {
2547 /* first loop ID. */
2548 dev
->loop_id
= ha
->min_external_loopid
;
2551 /* Check for loop ID being already in use. */
2554 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2555 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2556 /* ID possibly in use */
2562 /* If not in use then it is free to use. */
2567 /* ID in use. Try next value. */
2570 /* If wrap around. No free ID to use. */
2571 if (dev
->loop_id
== first_loop_id
) {
2572 dev
->loop_id
= FC_NO_LOOP_ID
;
2573 rval
= QLA_FUNCTION_FAILED
;
2582 * qla2x00_device_resync
2583 * Marks devices in the database that needs resynchronization.
2586 * ha = adapter block pointer.
2592 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2598 uint32_t rscn_entry
;
2599 uint8_t rscn_out_iter
;
2603 rval
= QLA_RSCNS_HANDLED
;
2605 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2606 ha
->flags
.rscn_queue_overflow
) {
2608 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2609 format
= MSB(MSW(rscn_entry
));
2610 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2611 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2612 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2614 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2615 "[%02x/%02x%02x%02x].\n",
2616 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2617 d_id
.b
.area
, d_id
.b
.al_pa
));
2620 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2621 ha
->rscn_out_ptr
= 0;
2623 /* Skip duplicate entries. */
2624 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2625 !ha
->flags
.rscn_queue_overflow
&&
2626 rscn_out_iter
!= ha
->rscn_in_ptr
;
2627 rscn_out_iter
= (rscn_out_iter
==
2628 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2630 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2633 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2634 "entry found at [%d].\n", ha
->host_no
,
2637 ha
->rscn_out_ptr
= rscn_out_iter
;
2640 /* Queue overflow, set switch default case. */
2641 if (ha
->flags
.rscn_queue_overflow
) {
2642 DEBUG(printk("scsi(%ld): device_resync: rscn "
2643 "overflow.\n", ha
->host_no
));
2646 ha
->flags
.rscn_queue_overflow
= 0;
2651 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) &&
2652 !IS_QLA6312(ha
) && !IS_QLA6322(ha
) &&
2653 !IS_QLA24XX(ha
) && !IS_QLA25XX(ha
) &&
2654 ha
->flags
.init_done
) {
2655 /* Handle port RSCN via asyncronous IOCBs */
2656 rval2
= qla2x00_handle_port_rscn(ha
, rscn_entry
,
2658 if (rval2
== QLA_SUCCESS
)
2672 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2678 /* Abort any outstanding IO descriptors. */
2679 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2680 qla2x00_cancel_io_descriptors(ha
);
2682 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2683 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2684 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2685 fcport
->port_type
== FCT_BROADCAST
)
2688 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2690 fcport
->port_type
!= FCT_INITIATOR
) {
2691 qla2x00_mark_device_lost(ha
, fcport
, 0);
2694 fcport
->flags
&= ~FCF_FARP_DONE
;
2701 * qla2x00_fabric_dev_login
2702 * Login fabric target device and update FC port database.
2705 * ha: adapter state pointer.
2706 * fcport: port structure list pointer.
2707 * next_loopid: contains value of a new loop ID that can be used
2708 * by the next login attempt.
2711 * qla2x00 local function return status code.
2717 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2718 uint16_t *next_loopid
)
2727 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2728 if (rval
== QLA_SUCCESS
) {
2729 /* Send an ADISC to tape devices.*/
2731 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2733 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2734 if (rval
!= QLA_SUCCESS
) {
2735 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2736 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2737 fcport
->d_id
.b
.al_pa
);
2738 qla2x00_mark_device_lost(ha
, fcport
, 1);
2741 qla2x00_update_fcport(ha
, fcport
);
2749 * qla2x00_fabric_login
2750 * Issue fabric login command.
2753 * ha = adapter block pointer.
2754 * device = pointer to FC device type structure.
2757 * 0 - Login successfully
2759 * 2 - Initiator device
2763 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2764 uint16_t *next_loopid
)
2768 uint16_t tmp_loopid
;
2769 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2775 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2776 "for port %02x%02x%02x.\n",
2777 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2778 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2780 /* Login fcport on switch. */
2781 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2782 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2783 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2784 if (mb
[0] == MBS_PORT_ID_USED
) {
2786 * Device has another loop ID. The firmware team
2787 * recommends the driver perform an implicit login with
2788 * the specified ID again. The ID we just used is save
2789 * here so we return with an ID that can be tried by
2793 tmp_loopid
= fcport
->loop_id
;
2794 fcport
->loop_id
= mb
[1];
2796 DEBUG(printk("Fabric Login: port in use - next "
2797 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2798 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2799 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2801 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2806 /* A retry occurred before. */
2807 *next_loopid
= tmp_loopid
;
2810 * No retry occurred before. Just increment the
2811 * ID value for next login.
2813 *next_loopid
= (fcport
->loop_id
+ 1);
2816 if (mb
[1] & BIT_0
) {
2817 fcport
->port_type
= FCT_INITIATOR
;
2819 fcport
->port_type
= FCT_TARGET
;
2820 if (mb
[1] & BIT_1
) {
2821 fcport
->flags
|= FCF_TAPE_PRESENT
;
2826 fcport
->supported_classes
|= FC_COS_CLASS2
;
2828 fcport
->supported_classes
|= FC_COS_CLASS3
;
2832 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2834 * Loop ID already used, try next loop ID.
2837 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2838 if (rval
!= QLA_SUCCESS
) {
2839 /* Ran out of loop IDs to use */
2842 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2844 * Firmware possibly timed out during login. If NO
2845 * retries are left to do then the device is declared
2848 *next_loopid
= fcport
->loop_id
;
2849 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2850 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2851 fcport
->d_id
.b
.al_pa
);
2852 qla2x00_mark_device_lost(ha
, fcport
, 1);
2858 * unrecoverable / not handled error
2860 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2861 "loop_id=%x jiffies=%lx.\n",
2862 __func__
, ha
->host_no
, mb
[0],
2863 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2864 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2866 *next_loopid
= fcport
->loop_id
;
2867 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2868 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2869 fcport
->d_id
.b
.al_pa
);
2870 fcport
->loop_id
= FC_NO_LOOP_ID
;
2871 fcport
->login_retry
= 0;
2882 * qla2x00_local_device_login
2883 * Issue local device login command.
2886 * ha = adapter block pointer.
2887 * loop_id = loop id of device to login to.
2889 * Returns (Where's the #define!!!!):
2890 * 0 - Login successfully
2895 qla2x00_local_device_login(scsi_qla_host_t
*ha
, uint16_t loop_id
)
2898 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2900 memset(mb
, 0, sizeof(mb
));
2901 rval
= qla2x00_login_local_device(ha
, loop_id
, mb
, BIT_0
);
2902 if (rval
== QLA_SUCCESS
) {
2903 /* Interrogate mailbox registers for any errors */
2904 if (mb
[0] == MBS_COMMAND_ERROR
)
2906 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2907 /* device not in PCB table */
2915 * qla2x00_loop_resync
2916 * Resync with fibre channel devices.
2919 * ha = adapter block pointer.
2925 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2932 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2933 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2934 if (ha
->flags
.online
) {
2935 if (!(rval
= qla2x00_fw_ready(ha
))) {
2936 /* Wait at most MAX_TARGET RSCNs for a stable link. */
2939 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2941 /* Issue a marker after FW becomes ready. */
2942 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
2943 ha
->marker_needed
= 0;
2945 /* Remap devices on Loop. */
2946 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2948 qla2x00_configure_loop(ha
);
2950 } while (!atomic_read(&ha
->loop_down_timer
) &&
2951 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
2953 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
2957 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
2958 return (QLA_FUNCTION_FAILED
);
2962 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
2969 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
2975 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2976 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
2979 qla2x00_update_fcport(ha
, fcport
);
2980 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
2984 qla2x00_probe_for_all_luns(ha
);
2989 * Resets ISP and aborts all outstanding commands.
2992 * ha = adapter block pointer.
2998 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3000 unsigned long flags
= 0;
3005 if (ha
->flags
.online
) {
3006 ha
->flags
.online
= 0;
3007 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3009 qla_printk(KERN_INFO
, ha
,
3010 "Performing ISP error recovery - ha= %p.\n", ha
);
3011 ha
->isp_ops
.reset_chip(ha
);
3013 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3014 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3015 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3016 qla2x00_mark_all_devices_lost(ha
);
3018 if (!atomic_read(&ha
->loop_down_timer
))
3019 atomic_set(&ha
->loop_down_timer
,
3023 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3024 /* Requeue all commands in outstanding command list. */
3025 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3026 sp
= ha
->outstanding_cmds
[cnt
];
3028 ha
->outstanding_cmds
[cnt
] = NULL
;
3030 sp
->cmd
->result
= DID_RESET
<< 16;
3031 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3032 qla2x00_sp_compl(ha
, sp
);
3035 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3037 ha
->isp_ops
.nvram_config(ha
);
3039 if (!qla2x00_restart_isp(ha
)) {
3040 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3042 if (!atomic_read(&ha
->loop_down_timer
)) {
3044 * Issue marker command only when we are going
3045 * to start the I/O .
3047 ha
->marker_needed
= 1;
3050 ha
->flags
.online
= 1;
3052 ha
->isp_ops
.enable_intrs(ha
);
3054 ha
->isp_abort_cnt
= 0;
3055 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3056 } else { /* failed the ISP abort */
3057 ha
->flags
.online
= 1;
3058 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3059 if (ha
->isp_abort_cnt
== 0) {
3060 qla_printk(KERN_WARNING
, ha
,
3061 "ISP error recovery failed - "
3062 "board disabled\n");
3064 * The next call disables the board
3067 ha
->isp_ops
.reset_adapter(ha
);
3068 ha
->flags
.online
= 0;
3069 clear_bit(ISP_ABORT_RETRY
,
3072 } else { /* schedule another ISP abort */
3073 ha
->isp_abort_cnt
--;
3074 DEBUG(printk("qla%ld: ISP abort - "
3075 "retry remaining %d\n",
3076 ha
->host_no
, ha
->isp_abort_cnt
);)
3080 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3081 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3082 "- retrying (%d) more times\n",
3083 ha
->host_no
, ha
->isp_abort_cnt
);)
3084 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3092 qla_printk(KERN_INFO
, ha
,
3093 "qla2x00_abort_isp: **** FAILED ****\n");
3095 DEBUG(printk(KERN_INFO
3096 "qla2x00_abort_isp(%ld): exiting.\n",
3104 * qla2x00_restart_isp
3105 * restarts the ISP after a reset
3108 * ha = adapter block pointer.
3114 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3117 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3118 unsigned long flags
= 0;
3121 /* If firmware needs to be loaded */
3122 if (qla2x00_isp_firmware(ha
)) {
3123 ha
->flags
.online
= 0;
3124 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3125 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3126 status
= qla2x00_setup_chip(ha
);
3130 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3132 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
)) {
3134 * Disable SRAM, Instruction RAM and GP RAM
3137 WRT_REG_WORD(®
->hccr
,
3138 (HCCR_ENABLE_PARITY
+ 0x0));
3139 RD_REG_WORD(®
->hccr
);
3142 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3144 status
= qla2x00_setup_chip(ha
);
3146 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3148 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
)) {
3149 /* Enable proper parity */
3152 WRT_REG_WORD(®
->hccr
,
3153 (HCCR_ENABLE_PARITY
+ 0x1));
3156 * SRAM, Instruction RAM and GP RAM
3159 WRT_REG_WORD(®
->hccr
,
3160 (HCCR_ENABLE_PARITY
+ 0x7));
3161 RD_REG_WORD(®
->hccr
);
3164 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3169 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3170 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3171 if (!(status
= qla2x00_fw_ready(ha
))) {
3172 DEBUG(printk("%s(): Start configure loop, "
3173 "status = %d\n", __func__
, status
);)
3175 /* Issue a marker after FW becomes ready. */
3176 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3178 ha
->flags
.online
= 1;
3179 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3182 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3183 qla2x00_configure_loop(ha
);
3185 } while (!atomic_read(&ha
->loop_down_timer
) &&
3186 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3188 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3191 /* if no cable then assume it's good */
3192 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3195 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3203 * qla2x00_reset_adapter
3207 * ha = adapter block pointer.
3210 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3212 unsigned long flags
= 0;
3213 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3215 ha
->flags
.online
= 0;
3216 ha
->isp_ops
.disable_intrs(ha
);
3218 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3219 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3220 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3221 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3222 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3223 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3227 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3229 unsigned long flags
= 0;
3230 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3232 ha
->flags
.online
= 0;
3233 ha
->isp_ops
.disable_intrs(ha
);
3235 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3236 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3237 RD_REG_DWORD(®
->hccr
);
3238 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3239 RD_REG_DWORD(®
->hccr
);
3240 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3244 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3247 struct init_cb_24xx
*icb
;
3248 struct nvram_24xx
*nv
;
3250 uint8_t *dptr1
, *dptr2
;
3255 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3256 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3258 /* Determine NVRAM starting address. */
3259 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3260 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3261 if (PCI_FUNC(ha
->pdev
->devfn
))
3262 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3264 /* Get NVRAM data and calculate checksum. */
3265 dptr
= (uint32_t *)nv
;
3266 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3268 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3269 chksum
+= le32_to_cpu(*dptr
++);
3271 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3272 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3275 /* Bad NVRAM data, set defaults parameters. */
3276 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3277 || nv
->id
[3] != ' ' ||
3278 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3279 /* Reset NVRAM data. */
3280 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3281 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3282 le16_to_cpu(nv
->nvram_version
));
3283 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3284 "invalid -- WWPN) defaults.\n");
3287 * Set default initialization control block.
3289 memset(nv
, 0, ha
->nvram_size
);
3290 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3291 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3292 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3293 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3294 nv
->exchange_count
= __constant_cpu_to_le16(0);
3295 nv
->hard_address
= __constant_cpu_to_le16(124);
3296 nv
->port_name
[0] = 0x21;
3297 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3298 nv
->port_name
[2] = 0x00;
3299 nv
->port_name
[3] = 0xe0;
3300 nv
->port_name
[4] = 0x8b;
3301 nv
->port_name
[5] = 0x1c;
3302 nv
->port_name
[6] = 0x55;
3303 nv
->port_name
[7] = 0x86;
3304 nv
->node_name
[0] = 0x20;
3305 nv
->node_name
[1] = 0x00;
3306 nv
->node_name
[2] = 0x00;
3307 nv
->node_name
[3] = 0xe0;
3308 nv
->node_name
[4] = 0x8b;
3309 nv
->node_name
[5] = 0x1c;
3310 nv
->node_name
[6] = 0x55;
3311 nv
->node_name
[7] = 0x86;
3312 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3313 nv
->link_down_timeout
= __constant_cpu_to_le16(200);
3314 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3315 nv
->login_timeout
= __constant_cpu_to_le16(0);
3316 nv
->firmware_options_1
=
3317 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3318 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3319 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3320 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3321 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3322 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3323 nv
->reset_delay
= 5;
3324 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3325 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3326 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3331 /* Reset Initialization control block */
3332 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3334 /* Copy 1st segment. */
3335 dptr1
= (uint8_t *)icb
;
3336 dptr2
= (uint8_t *)&nv
->version
;
3337 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3339 *dptr1
++ = *dptr2
++;
3341 icb
->login_retry_count
= nv
->login_retry_count
;
3342 icb
->link_down_timeout
= nv
->link_down_timeout
;
3344 /* Copy 2nd segment. */
3345 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3346 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3347 cnt
= (uint8_t *)&icb
->reserved_3
-
3348 (uint8_t *)&icb
->interrupt_delay_timer
;
3350 *dptr1
++ = *dptr2
++;
3353 * Setup driver NVRAM options.
3355 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3359 strncpy(ha
->model_number
, nv
->model_name
,
3360 sizeof(nv
->model_name
));
3361 st
= en
= ha
->model_number
;
3362 en
+= sizeof(nv
->model_name
) - 1;
3364 if (*en
!= 0x20 && *en
!= 0x00)
3369 index
= (ha
->pdev
->subsystem_device
& 0xff);
3370 if (index
< QLA_MODEL_NAMES
)
3371 ha
->model_desc
= qla2x00_model_desc
[index
];
3373 strcpy(ha
->model_number
, "QLA2462");
3375 /* Prepare nodename */
3376 if ((icb
->firmware_options_1
& BIT_14
) == 0) {
3378 * Firmware will apply the following mask if the nodename was
3381 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3382 icb
->node_name
[0] &= 0xF0;
3385 /* Set host adapter parameters. */
3386 ha
->flags
.disable_risc_code_load
= 0;
3387 ha
->flags
.enable_lip_reset
= 1;
3388 ha
->flags
.enable_lip_full_login
= 1;
3389 ha
->flags
.enable_target_reset
= 1;
3390 ha
->flags
.enable_led_scheme
= 0;
3392 ha
->operating_mode
=
3393 (icb
->firmware_options_2
& (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3395 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3396 sizeof(ha
->fw_seriallink_options24
));
3398 /* save HBA serial number */
3399 ha
->serial0
= icb
->port_name
[5];
3400 ha
->serial1
= icb
->port_name
[6];
3401 ha
->serial2
= icb
->port_name
[7];
3402 ha
->node_name
= icb
->node_name
;
3403 ha
->port_name
= icb
->port_name
;
3405 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3407 /* Set minimum login_timeout to 4 seconds. */
3408 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3409 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3410 if (le16_to_cpu(nv
->login_timeout
) < 4)
3411 nv
->login_timeout
= __constant_cpu_to_le16(4);
3412 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3413 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3415 /* Set minimum RATOV to 200 tenths of a second. */
3418 ha
->loop_reset_delay
= nv
->reset_delay
;
3420 /* Link Down Timeout = 0:
3422 * When Port Down timer expires we will start returning
3423 * I/O's to OS with "DID_NO_CONNECT".
3425 * Link Down Timeout != 0:
3427 * The driver waits for the link to come up after link down
3428 * before returning I/Os to OS with "DID_NO_CONNECT".
3430 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3431 ha
->loop_down_abort_time
=
3432 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3434 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3435 ha
->loop_down_abort_time
=
3436 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3439 /* Need enough time to try and get the port back. */
3440 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3441 if (qlport_down_retry
)
3442 ha
->port_down_retry_count
= qlport_down_retry
;
3444 /* Set login_retry_count */
3445 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3446 if (ha
->port_down_retry_count
==
3447 le16_to_cpu(nv
->port_down_retry_count
) &&
3448 ha
->port_down_retry_count
> 3)
3449 ha
->login_retry_count
= ha
->port_down_retry_count
;
3450 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3451 ha
->login_retry_count
= ha
->port_down_retry_count
;
3452 if (ql2xloginretrycount
)
3453 ha
->login_retry_count
= ql2xloginretrycount
;
3456 if (!ha
->flags
.init_done
) {
3457 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3458 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3459 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3460 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3462 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3463 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3464 ha
->flags
.process_response_queue
= 0;
3465 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3466 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3467 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3468 ha
->zio_timer
* 100));
3469 qla_printk(KERN_INFO
, ha
,
3470 "ZIO mode %d enabled; timer delay (%d us).\n",
3471 ha
->zio_mode
, ha
->zio_timer
* 100);
3473 icb
->firmware_options_2
|= cpu_to_le32(
3474 (uint32_t)ha
->zio_mode
);
3475 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3476 ha
->flags
.process_response_queue
= 1;
3480 DEBUG2_3(printk(KERN_WARNING
3481 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3486 #if defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE)
3489 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3493 uint16_t *risc_code
;
3494 uint32_t risc_addr
, risc_size
;
3496 struct qla_fw_info
*fw_iter
;
3500 /* Load firmware sequences */
3501 fw_iter
= ha
->brd_info
->fw_info
;
3502 *srisc_addr
= *ha
->brd_info
->fw_info
->fwstart
;
3503 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3504 risc_code
= fw_iter
->fwcode
;
3505 risc_size
= *fw_iter
->fwlen
;
3506 if (fw_iter
->addressing
== FW_INFO_ADDR_NORMAL
)
3507 risc_addr
= *fw_iter
->fwstart
;
3509 risc_addr
= *fw_iter
->lfwstart
;
3513 while (risc_size
> 0 && !rval
) {
3514 cnt
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3515 if (cnt
> risc_size
)
3518 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3519 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3520 ha
->host_no
, risc_code
, cnt
, risc_addr
));
3522 req_ring
= (uint16_t *)ha
->request_ring
;
3523 for (i
= 0; i
< cnt
; i
++)
3524 req_ring
[i
] = cpu_to_le16(risc_code
[i
]);
3526 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3529 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3530 "load segment %d of firmware\n",
3532 qla_printk(KERN_WARNING
, ha
,
3533 "[ERROR] Failed to load segment %d of "
3536 qla2x00_dump_regs(ha
);
3546 /* Next firmware sequence */
3553 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3557 uint32_t *risc_code
;
3558 uint32_t risc_addr
, risc_size
;
3560 struct qla_fw_info
*fw_iter
;
3564 /* Load firmware sequences */
3565 fw_iter
= ha
->brd_info
->fw_info
;
3566 *srisc_addr
= *((uint32_t *)fw_iter
->lfwstart
);
3567 while (fw_iter
->addressing
!= FW_INFO_ADDR_NOMORE
) {
3568 risc_code
= (uint32_t *)fw_iter
->fwcode
;
3569 risc_size
= *((uint32_t *)fw_iter
->fwlen
);
3570 risc_addr
= *((uint32_t *)fw_iter
->lfwstart
);
3574 while (risc_size
> 0 && !rval
) {
3575 cnt
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3576 if (cnt
> risc_size
)
3579 DEBUG7(printk("scsi(%ld): Loading risc segment@ "
3580 "addr %p, number of bytes 0x%x, offset 0x%lx.\n",
3581 ha
->host_no
, risc_code
, cnt
, risc_addr
));
3583 req_ring
= (uint32_t *)ha
->request_ring
;
3584 for (i
= 0; i
< cnt
; i
++)
3585 req_ring
[i
] = cpu_to_le32(risc_code
[i
]);
3587 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3590 DEBUG(printk("scsi(%ld): [ERROR] Failed to "
3591 "load segment %d of firmware\n",
3593 qla_printk(KERN_WARNING
, ha
,
3594 "[ERROR] Failed to load segment %d of "
3597 qla2x00_dump_regs(ha
);
3607 /* Next firmware sequence */
3614 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3617 int segments
, fragment
;
3619 uint32_t *dcode
, dlen
;
3626 segments
= FA_RISC_CODE_SEGMENTS
;
3627 faddr
= FA_RISC_CODE_ADDR
;
3628 dcode
= (uint32_t *)ha
->request_ring
;
3631 /* Validate firmware image by checking version. */
3632 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3633 for (i
= 0; i
< 4; i
++)
3634 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3635 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3636 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3637 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3639 qla_printk(KERN_WARNING
, ha
,
3640 "Unable to verify integrity of flash firmware image!\n");
3641 qla_printk(KERN_WARNING
, ha
,
3642 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3643 dcode
[1], dcode
[2], dcode
[3]);
3645 return QLA_FUNCTION_FAILED
;
3648 while (segments
&& rval
== QLA_SUCCESS
) {
3649 /* Read segment's load information. */
3650 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3652 risc_addr
= be32_to_cpu(dcode
[2]);
3653 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3654 risc_size
= be32_to_cpu(dcode
[3]);
3657 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3658 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3659 if (dlen
> risc_size
)
3662 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3663 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3664 ha
->host_no
, risc_addr
, dlen
, faddr
));
3666 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3667 for (i
= 0; i
< dlen
; i
++)
3668 dcode
[i
] = swab32(dcode
[i
]);
3670 rval
= qla2x00_load_ram_ext(ha
, ha
->request_dma
,
3673 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3674 "segment %d of firmware\n", ha
->host_no
,
3676 qla_printk(KERN_WARNING
, ha
,
3677 "[ERROR] Failed to load segment %d of "
3678 "firmware\n", fragment
);
3695 #else /* !defined(CONFIG_SCSI_QLA2XXX_EMBEDDED_FIRMWARE) */
3698 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3702 uint16_t *wcode
, *fwcode
;
3703 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3704 struct fw_blob
*blob
;
3706 /* Load firmware blob. */
3707 blob
= qla2x00_request_firmware(ha
);
3709 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3710 return QLA_FUNCTION_FAILED
;
3715 wcode
= (uint16_t *)ha
->request_ring
;
3717 fwcode
= (uint16_t *)blob
->fw
->data
;
3720 /* Validate firmware image by checking version. */
3721 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3722 qla_printk(KERN_WARNING
, ha
,
3723 "Unable to verify integrity of firmware image (%Zd)!\n",
3725 goto fail_fw_integrity
;
3727 for (i
= 0; i
< 4; i
++)
3728 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3729 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3730 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3731 wcode
[2] == 0 && wcode
[3] == 0)) {
3732 qla_printk(KERN_WARNING
, ha
,
3733 "Unable to verify integrity of firmware image!\n");
3734 qla_printk(KERN_WARNING
, ha
,
3735 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3736 wcode
[1], wcode
[2], wcode
[3]);
3737 goto fail_fw_integrity
;
3741 while (*seg
&& rval
== QLA_SUCCESS
) {
3743 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3744 risc_size
= be16_to_cpu(fwcode
[3]);
3746 /* Validate firmware image size. */
3747 fwclen
+= risc_size
* sizeof(uint16_t);
3748 if (blob
->fw
->size
< fwclen
) {
3749 qla_printk(KERN_WARNING
, ha
,
3750 "Unable to verify integrity of firmware image "
3751 "(%Zd)!\n", blob
->fw
->size
);
3752 goto fail_fw_integrity
;
3756 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3757 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3758 if (wlen
> risc_size
)
3761 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3762 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3765 for (i
= 0; i
< wlen
; i
++)
3766 wcode
[i
] = swab16(fwcode
[i
]);
3768 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3771 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3772 "segment %d of firmware\n", ha
->host_no
,
3774 qla_printk(KERN_WARNING
, ha
,
3775 "[ERROR] Failed to load segment %d of "
3776 "firmware\n", fragment
);
3792 return QLA_FUNCTION_FAILED
;
3796 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3799 int segments
, fragment
;
3800 uint32_t *dcode
, dlen
;
3804 struct fw_blob
*blob
;
3805 uint32_t *fwcode
, fwclen
;
3807 /* Load firmware blob. */
3808 blob
= qla2x00_request_firmware(ha
);
3810 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3811 return QLA_FUNCTION_FAILED
;
3816 segments
= FA_RISC_CODE_SEGMENTS
;
3817 dcode
= (uint32_t *)ha
->request_ring
;
3819 fwcode
= (uint32_t *)blob
->fw
->data
;
3822 /* Validate firmware image by checking version. */
3823 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3824 qla_printk(KERN_WARNING
, ha
,
3825 "Unable to verify integrity of firmware image (%Zd)!\n",
3827 goto fail_fw_integrity
;
3829 for (i
= 0; i
< 4; i
++)
3830 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3831 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3832 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3833 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3835 qla_printk(KERN_WARNING
, ha
,
3836 "Unable to verify integrity of firmware image!\n");
3837 qla_printk(KERN_WARNING
, ha
,
3838 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3839 dcode
[1], dcode
[2], dcode
[3]);
3840 goto fail_fw_integrity
;
3843 while (segments
&& rval
== QLA_SUCCESS
) {
3844 risc_addr
= be32_to_cpu(fwcode
[2]);
3845 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3846 risc_size
= be32_to_cpu(fwcode
[3]);
3848 /* Validate firmware image size. */
3849 fwclen
+= risc_size
* sizeof(uint32_t);
3850 if (blob
->fw
->size
< fwclen
) {
3851 qla_printk(KERN_WARNING
, ha
,
3852 "Unable to verify integrity of firmware image "
3853 "(%Zd)!\n", blob
->fw
->size
);
3855 goto fail_fw_integrity
;
3859 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3860 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3861 if (dlen
> risc_size
)
3864 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3865 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3868 for (i
= 0; i
< dlen
; i
++)
3869 dcode
[i
] = swab32(fwcode
[i
]);
3871 rval
= qla2x00_load_ram_ext(ha
, ha
->request_dma
,
3874 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3875 "segment %d of firmware\n", ha
->host_no
,
3877 qla_printk(KERN_WARNING
, ha
,
3878 "[ERROR] Failed to load segment %d of "
3879 "firmware\n", fragment
);
3895 return QLA_FUNCTION_FAILED
;