2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
19 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
20 #ifndef EXT_IS_LUN_BIT_SET
21 #define EXT_IS_LUN_BIT_SET(P,L) \
22 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
23 #define EXT_SET_LUN_BIT(P,L) \
24 ((P)->mask[L/8] |= (0x80 >> (L%8)))
28 * QLogic ISP2x00 Hardware Support Function Prototypes.
30 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
31 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
32 static int qla2x00_setup_chip(scsi_qla_host_t
*);
33 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
34 static int qla2x00_init_rings(scsi_qla_host_t
*);
35 static int qla2x00_fw_ready(scsi_qla_host_t
*);
36 static int qla2x00_configure_hba(scsi_qla_host_t
*);
37 static int qla2x00_configure_loop(scsi_qla_host_t
*);
38 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
39 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
40 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
41 static int qla2x00_device_resync(scsi_qla_host_t
*);
42 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
45 static int qla2x00_restart_isp(scsi_qla_host_t
*);
47 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
);
49 /****************************************************************************/
50 /* QLogic ISP2x00 Hardware Support Functions. */
51 /****************************************************************************/
54 * qla2x00_initialize_adapter
58 * ha = adapter block pointer.
64 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
68 /* Clear adapter flags. */
70 ha
->flags
.reset_active
= 0;
71 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
72 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
73 ha
->device_flags
= DFLG_NO_CABLE
;
75 ha
->flags
.management_server_logged_in
= 0;
76 ha
->marker_needed
= 0;
78 ha
->isp_abort_cnt
= 0;
79 ha
->beacon_blink_led
= 0;
80 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
82 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
83 rval
= ha
->isp_ops
.pci_config(ha
);
85 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
90 ha
->isp_ops
.reset_chip(ha
);
92 ha
->isp_ops
.get_flash_version(ha
, ha
->request_ring
);
94 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
96 ha
->isp_ops
.nvram_config(ha
);
98 if (ha
->flags
.disable_serdes
) {
99 /* Mask HBA via NVRAM settings? */
100 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
101 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
102 ha
->port_name
[0], ha
->port_name
[1],
103 ha
->port_name
[2], ha
->port_name
[3],
104 ha
->port_name
[4], ha
->port_name
[5],
105 ha
->port_name
[6], ha
->port_name
[7]);
106 return QLA_FUNCTION_FAILED
;
109 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
111 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
112 rval
= ha
->isp_ops
.chip_diag(ha
);
115 rval
= qla2x00_setup_chip(ha
);
119 rval
= qla2x00_init_rings(ha
);
125 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
128 * Returns 0 on success.
131 qla2100_pci_config(scsi_qla_host_t
*ha
)
137 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
139 pci_set_master(ha
->pdev
);
140 ret
= pci_set_mwi(ha
->pdev
);
142 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
143 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
144 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
146 /* Reset expansion ROM address decode enable */
147 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
148 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
149 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
151 /* Get PCI bus information. */
152 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
153 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
154 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
160 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
163 * Returns 0 on success.
166 qla2300_pci_config(scsi_qla_host_t
*ha
)
171 unsigned long flags
= 0;
173 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
175 pci_set_master(ha
->pdev
);
176 ret
= pci_set_mwi(ha
->pdev
);
178 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
179 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
181 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
182 w
&= ~PCI_COMMAND_INTX_DISABLE
;
183 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
186 * If this is a 2300 card and not 2312, reset the
187 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
188 * the 2310 also reports itself as a 2300 so we need to get the
189 * fb revision level -- a 6 indicates it really is a 2300 and
192 if (IS_QLA2300(ha
)) {
193 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
196 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
197 for (cnt
= 0; cnt
< 30000; cnt
++) {
198 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
204 /* Select FPM registers. */
205 WRT_REG_WORD(®
->ctrl_status
, 0x20);
206 RD_REG_WORD(®
->ctrl_status
);
208 /* Get the fb rev level */
209 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
211 if (ha
->fb_rev
== FPM_2300
)
212 pci_clear_mwi(ha
->pdev
);
214 /* Deselect FPM registers. */
215 WRT_REG_WORD(®
->ctrl_status
, 0x0);
216 RD_REG_WORD(®
->ctrl_status
);
218 /* Release RISC module. */
219 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
220 for (cnt
= 0; cnt
< 30000; cnt
++) {
221 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
227 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
230 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
232 /* Reset expansion ROM address decode enable */
233 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
234 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
235 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
237 /* Get PCI bus information. */
238 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
239 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
240 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
246 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
249 * Returns 0 on success.
252 qla24xx_pci_config(scsi_qla_host_t
*ha
)
257 unsigned long flags
= 0;
258 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
259 int pcix_cmd_reg
, pcie_dctl_reg
;
261 pci_set_master(ha
->pdev
);
262 ret
= pci_set_mwi(ha
->pdev
);
264 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
265 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
266 w
&= ~PCI_COMMAND_INTX_DISABLE
;
267 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
269 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
271 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
272 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
276 pcix_cmd_reg
+= PCI_X_CMD
;
277 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
278 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
280 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
283 /* PCIe -- adjust Maximum Read Request Size (2048). */
284 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
288 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
289 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
290 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
292 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
295 /* Reset expansion ROM address decode enable */
296 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
297 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
298 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
300 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->chip_revision
);
302 /* Get PCI bus information. */
303 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
304 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
305 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
311 * qla2x00_isp_firmware() - Choose firmware image.
314 * Returns 0 on success.
317 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
321 /* Assume loading risc code */
322 rval
= QLA_FUNCTION_FAILED
;
324 if (ha
->flags
.disable_risc_code_load
) {
325 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
327 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
329 /* Verify checksum of loaded RISC code. */
330 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
334 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
342 * qla2x00_reset_chip() - Reset ISP chip.
345 * Returns 0 on success.
348 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
350 unsigned long flags
= 0;
351 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
355 ha
->isp_ops
.disable_intrs(ha
);
357 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
359 /* Turn off master enable */
361 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
362 cmd
&= ~PCI_COMMAND_MASTER
;
363 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
365 if (!IS_QLA2100(ha
)) {
367 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
368 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
369 for (cnt
= 0; cnt
< 30000; cnt
++) {
370 if ((RD_REG_WORD(®
->hccr
) &
371 HCCR_RISC_PAUSE
) != 0)
376 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
380 /* Select FPM registers. */
381 WRT_REG_WORD(®
->ctrl_status
, 0x20);
382 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
384 /* FPM Soft Reset. */
385 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
386 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
388 /* Toggle Fpm Reset. */
389 if (!IS_QLA2200(ha
)) {
390 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
391 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
394 /* Select frame buffer registers. */
395 WRT_REG_WORD(®
->ctrl_status
, 0x10);
396 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
398 /* Reset frame buffer FIFOs. */
399 if (IS_QLA2200(ha
)) {
400 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
401 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
403 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
405 /* Read back fb_cmd until zero or 3 seconds max */
406 for (cnt
= 0; cnt
< 3000; cnt
++) {
407 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
413 /* Select RISC module registers. */
414 WRT_REG_WORD(®
->ctrl_status
, 0);
415 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
417 /* Reset RISC processor. */
418 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
419 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
421 /* Release RISC processor. */
422 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
423 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
426 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
427 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
429 /* Reset ISP chip. */
430 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
432 /* Wait for RISC to recover from reset. */
433 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
435 * It is necessary to for a delay here since the card doesn't
436 * respond to PCI reads during a reset. On some architectures
437 * this will result in an MCA.
440 for (cnt
= 30000; cnt
; cnt
--) {
441 if ((RD_REG_WORD(®
->ctrl_status
) &
442 CSR_ISP_SOFT_RESET
) == 0)
449 /* Reset RISC processor. */
450 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
452 WRT_REG_WORD(®
->semaphore
, 0);
454 /* Release RISC processor. */
455 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
456 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
458 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
459 for (cnt
= 0; cnt
< 30000; cnt
++) {
460 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
468 /* Turn on master enable */
469 cmd
|= PCI_COMMAND_MASTER
;
470 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
472 /* Disable RISC pause on FPM parity error. */
473 if (!IS_QLA2100(ha
)) {
474 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
475 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
478 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
482 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
485 * Returns 0 on success.
488 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
490 unsigned long flags
= 0;
491 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
495 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
498 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
499 for (cnt
= 0; cnt
< 30000; cnt
++) {
500 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
506 WRT_REG_DWORD(®
->ctrl_status
,
507 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
508 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
511 /* Wait for firmware to complete NVRAM accesses. */
512 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
513 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
515 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
519 /* Wait for soft-reset to complete. */
520 d2
= RD_REG_DWORD(®
->ctrl_status
);
521 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
523 d2
= RD_REG_DWORD(®
->ctrl_status
);
527 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
528 RD_REG_DWORD(®
->hccr
);
530 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
531 RD_REG_DWORD(®
->hccr
);
533 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
534 RD_REG_DWORD(®
->hccr
);
536 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
537 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
539 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
543 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
547 * qla24xx_reset_chip() - Reset ISP24xx chip.
550 * Returns 0 on success.
553 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
555 ha
->isp_ops
.disable_intrs(ha
);
557 /* Perform RISC reset. */
558 qla24xx_reset_risc(ha
);
562 * qla2x00_chip_diag() - Test chip for proper operation.
565 * Returns 0 on success.
568 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
571 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
572 unsigned long flags
= 0;
577 /* Assume a failed state */
578 rval
= QLA_FUNCTION_FAILED
;
580 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
581 ha
->host_no
, (u_long
)®
->flash_address
));
583 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
585 /* Reset ISP chip. */
586 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
589 * We need to have a delay here since the card will not respond while
590 * in reset causing an MCA on some architectures.
593 data
= qla2x00_debounce_register(®
->ctrl_status
);
594 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
596 data
= RD_REG_WORD(®
->ctrl_status
);
601 goto chip_diag_failed
;
603 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
606 /* Reset RISC processor. */
607 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
608 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
610 /* Workaround for QLA2312 PCI parity error */
611 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
612 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
613 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
615 data
= RD_MAILBOX_REG(ha
, reg
, 0);
622 goto chip_diag_failed
;
624 /* Check product ID of chip */
625 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
627 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
628 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
629 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
630 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
631 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
632 mb
[3] != PROD_ID_3
) {
633 qla_printk(KERN_WARNING
, ha
,
634 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
636 goto chip_diag_failed
;
638 ha
->product_id
[0] = mb
[1];
639 ha
->product_id
[1] = mb
[2];
640 ha
->product_id
[2] = mb
[3];
641 ha
->product_id
[3] = mb
[4];
643 /* Adjust fw RISC transfer size */
644 if (ha
->request_q_length
> 1024)
645 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
647 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
648 ha
->request_q_length
;
650 if (IS_QLA2200(ha
) &&
651 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
652 /* Limit firmware transfer size with a 2200A */
653 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
656 ha
->device_type
|= DT_ISP2200A
;
657 ha
->fw_transfer_size
= 128;
660 /* Wrap Incoming Mailboxes Test. */
661 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
663 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
664 rval
= qla2x00_mbx_reg_test(ha
);
666 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
668 qla_printk(KERN_WARNING
, ha
,
669 "Failed mailbox send register test\n");
672 /* Flag a successful rval */
675 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
679 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
680 "****\n", ha
->host_no
));
682 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
688 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
691 * Returns 0 on success.
694 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
698 /* Perform RISC reset. */
699 qla24xx_reset_risc(ha
);
701 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
703 rval
= qla2x00_mbx_reg_test(ha
);
705 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
707 qla_printk(KERN_WARNING
, ha
,
708 "Failed mailbox send register test\n");
710 /* Flag a successful rval */
718 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
721 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
727 qla_printk(KERN_WARNING
, ha
,
728 "Firmware dump previously allocated.\n");
733 fixed_size
= mem_size
= eft_size
= 0;
734 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
735 fixed_size
= sizeof(struct qla2100_fw_dump
);
736 } else if (IS_QLA23XX(ha
)) {
737 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
738 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
740 } else if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
741 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
742 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
745 /* Allocate memory for Extended Trace Buffer. */
746 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
749 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
750 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
754 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
757 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
758 "EFT (%d).\n", rval
);
759 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
764 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
768 memset(eft
, 0, eft_size
);
769 ha
->eft_dma
= eft_dma
;
773 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
774 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
776 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
777 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
780 ha
->fw_dump
= vmalloc(dump_size
);
782 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
783 "firmware dump!!!\n", dump_size
/ 1024);
786 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
794 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
797 ha
->fw_dump_len
= dump_size
;
798 ha
->fw_dump
->signature
[0] = 'Q';
799 ha
->fw_dump
->signature
[1] = 'L';
800 ha
->fw_dump
->signature
[2] = 'G';
801 ha
->fw_dump
->signature
[3] = 'C';
802 ha
->fw_dump
->version
= __constant_htonl(1);
804 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
805 ha
->fw_dump
->mem_size
= htonl(mem_size
);
806 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
807 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
809 ha
->fw_dump
->eft_size
= htonl(eft_size
);
810 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
811 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
813 ha
->fw_dump
->header_size
=
814 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
818 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
821 * Returns 0 on success.
824 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
827 uint16_t fw_iocb_cnt
= 0;
828 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
829 dma_addr_t request_dma
;
830 request_t
*request_ring
;
832 /* Valid only on recent ISPs. */
833 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
836 /* Retrieve IOCB counts available to the firmware. */
837 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
840 /* No point in continuing if current settings are sufficient. */
841 if (fw_iocb_cnt
< 1024)
843 if (ha
->request_q_length
>= request_q_length
)
846 /* Attempt to claim larger area for request queue. */
847 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
848 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
850 if (request_ring
== NULL
)
853 /* Resize successful, report extensions. */
854 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
855 (ha
->fw_memory_size
+ 1) / 1024);
856 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
857 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
859 /* Clear old allocations. */
860 dma_free_coherent(&ha
->pdev
->dev
,
861 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
864 /* Begin using larger queue. */
865 ha
->request_q_length
= request_q_length
;
866 ha
->request_ring
= request_ring
;
867 ha
->request_dma
= request_dma
;
871 * qla2x00_setup_chip() - Load and start RISC firmware.
874 * Returns 0 on success.
877 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
880 uint32_t srisc_address
= 0;
882 /* Load firmware sequences */
883 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
884 if (rval
== QLA_SUCCESS
) {
885 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
886 "code.\n", ha
->host_no
));
888 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
889 if (rval
== QLA_SUCCESS
) {
890 /* Start firmware execution. */
891 DEBUG(printk("scsi(%ld): Checksum OK, start "
892 "firmware.\n", ha
->host_no
));
894 rval
= qla2x00_execute_fw(ha
, srisc_address
);
895 /* Retrieve firmware information. */
896 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
897 qla2x00_get_fw_version(ha
,
898 &ha
->fw_major_version
,
899 &ha
->fw_minor_version
,
900 &ha
->fw_subminor_version
,
901 &ha
->fw_attributes
, &ha
->fw_memory_size
);
902 qla2x00_resize_request_q(ha
);
905 qla2x00_alloc_fw_dump(ha
);
908 DEBUG2(printk(KERN_INFO
909 "scsi(%ld): ISP Firmware failed checksum.\n",
915 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
923 * qla2x00_init_response_q_entries() - Initializes response queue entries.
926 * Beginning of request ring has initialization control block already built
927 * by nvram config routine.
929 * Returns 0 on success.
932 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
937 pkt
= ha
->response_ring_ptr
;
938 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
939 pkt
->signature
= RESPONSE_PROCESSED
;
946 * qla2x00_update_fw_options() - Read and process firmware options.
949 * Returns 0 on success.
952 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
954 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
956 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
957 qla2x00_get_fw_options(ha
, ha
->fw_options
);
959 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
962 /* Serial Link options. */
963 DEBUG3(printk("scsi(%ld): Serial link options:\n",
965 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
966 sizeof(ha
->fw_seriallink_options
)));
968 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
969 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
970 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
973 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
974 emphasis
= (ha
->fw_seriallink_options
[2] &
975 (BIT_4
| BIT_3
)) >> 3;
976 tx_sens
= ha
->fw_seriallink_options
[0] &
977 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
978 rx_sens
= (ha
->fw_seriallink_options
[0] &
979 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
980 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
981 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
984 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
985 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
986 ha
->fw_options
[10] |= BIT_5
|
987 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
988 (tx_sens
& (BIT_1
| BIT_0
));
991 swing
= (ha
->fw_seriallink_options
[2] &
992 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
993 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
994 tx_sens
= ha
->fw_seriallink_options
[1] &
995 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
996 rx_sens
= (ha
->fw_seriallink_options
[1] &
997 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
998 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
999 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1002 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1003 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1004 ha
->fw_options
[11] |= BIT_5
|
1005 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1006 (tx_sens
& (BIT_1
| BIT_0
));
1010 /* Return command IOCBs without waiting for an ABTS to complete. */
1011 ha
->fw_options
[3] |= BIT_13
;
1014 if (ha
->flags
.enable_led_scheme
)
1015 ha
->fw_options
[2] |= BIT_12
;
1017 /* Detect ISP6312. */
1019 ha
->fw_options
[2] |= BIT_13
;
1021 /* Update firmware options. */
1022 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1026 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1030 /* Update Serial Link options. */
1031 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1034 rval
= qla2x00_set_serdes_params(ha
,
1035 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1036 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1037 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1038 if (rval
!= QLA_SUCCESS
) {
1039 qla_printk(KERN_WARNING
, ha
,
1040 "Unable to update Serial Link options (%x).\n", rval
);
1045 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1047 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1049 /* Setup ring parameters in initialization control block. */
1050 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1051 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1052 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1053 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1054 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1055 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1056 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1057 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1059 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1060 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1061 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1062 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1063 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1067 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1069 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1070 struct init_cb_24xx
*icb
;
1072 /* Setup ring parameters in initialization control block. */
1073 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1074 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1075 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1076 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1077 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1078 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1079 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1080 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1081 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1083 WRT_REG_DWORD(®
->req_q_in
, 0);
1084 WRT_REG_DWORD(®
->req_q_out
, 0);
1085 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1086 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1087 RD_REG_DWORD(®
->rsp_q_out
);
1091 * qla2x00_init_rings() - Initializes firmware.
1094 * Beginning of request ring has initialization control block already built
1095 * by nvram config routine.
1097 * Returns 0 on success.
1100 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1103 unsigned long flags
= 0;
1106 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1108 /* Clear outstanding commands array. */
1109 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1110 ha
->outstanding_cmds
[cnt
] = NULL
;
1112 ha
->current_outstanding_cmd
= 0;
1114 /* Clear RSCN queue. */
1115 ha
->rscn_in_ptr
= 0;
1116 ha
->rscn_out_ptr
= 0;
1118 /* Initialize firmware. */
1119 ha
->request_ring_ptr
= ha
->request_ring
;
1120 ha
->req_ring_index
= 0;
1121 ha
->req_q_cnt
= ha
->request_q_length
;
1122 ha
->response_ring_ptr
= ha
->response_ring
;
1123 ha
->rsp_ring_index
= 0;
1125 /* Initialize response queue entries */
1126 qla2x00_init_response_q_entries(ha
);
1128 ha
->isp_ops
.config_rings(ha
);
1130 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1132 /* Update any ISP specific firmware options before initialization. */
1133 ha
->isp_ops
.update_fw_options(ha
);
1135 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1136 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1138 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1141 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1149 * qla2x00_fw_ready() - Waits for firmware ready.
1152 * Returns 0 on success.
1155 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1158 unsigned long wtime
, mtime
;
1159 uint16_t min_wait
; /* Minimum wait time if loop is down */
1160 uint16_t wait_time
; /* Wait time if loop is coming ready */
1165 /* 20 seconds for loop down. */
1169 * Firmware should take at most one RATOV to login, plus 5 seconds for
1170 * our own processing.
1172 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1173 wait_time
= min_wait
;
1176 /* Min wait time if loop down */
1177 mtime
= jiffies
+ (min_wait
* HZ
);
1179 /* wait time before firmware ready */
1180 wtime
= jiffies
+ (wait_time
* HZ
);
1182 /* Wait for ISP to finish LIP */
1183 if (!ha
->flags
.init_done
)
1184 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1186 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1190 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1191 if (rval
== QLA_SUCCESS
) {
1192 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1193 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1195 if (fw_state
== FSTATE_READY
) {
1196 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1199 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1200 &ha
->login_timeout
, &ha
->r_a_tov
);
1206 rval
= QLA_FUNCTION_FAILED
;
1208 if (atomic_read(&ha
->loop_down_timer
) &&
1209 fw_state
!= FSTATE_READY
) {
1210 /* Loop down. Timeout on min_wait for states
1211 * other than Wait for Login.
1213 if (time_after_eq(jiffies
, mtime
)) {
1214 qla_printk(KERN_INFO
, ha
,
1215 "Cable is unplugged...\n");
1217 ha
->device_flags
|= DFLG_NO_CABLE
;
1222 /* Mailbox cmd failed. Timeout on min_wait. */
1223 if (time_after_eq(jiffies
, mtime
))
1227 if (time_after_eq(jiffies
, wtime
))
1230 /* Delay for a while */
1233 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1234 ha
->host_no
, fw_state
, jiffies
));
1237 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1238 ha
->host_no
, fw_state
, jiffies
));
1241 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1249 * qla2x00_configure_hba
1250 * Setup adapter context.
1253 * ha = adapter state pointer.
1262 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1270 char connect_type
[22];
1272 /* Get host addresses. */
1273 rval
= qla2x00_get_adapter_id(ha
,
1274 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1275 if (rval
!= QLA_SUCCESS
) {
1276 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1277 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1278 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1279 __func__
, ha
->host_no
));
1281 qla_printk(KERN_WARNING
, ha
,
1282 "ERROR -- Unable to get host loop ID.\n");
1283 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1289 qla_printk(KERN_INFO
, ha
,
1290 "Cannot get topology - retrying.\n");
1291 return (QLA_FUNCTION_FAILED
);
1294 ha
->loop_id
= loop_id
;
1297 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1298 ha
->operating_mode
= LOOP
;
1302 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1304 ha
->current_topology
= ISP_CFG_NL
;
1305 strcpy(connect_type
, "(Loop)");
1309 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1311 ha
->current_topology
= ISP_CFG_FL
;
1312 strcpy(connect_type
, "(FL_Port)");
1316 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1318 ha
->operating_mode
= P2P
;
1319 ha
->current_topology
= ISP_CFG_N
;
1320 strcpy(connect_type
, "(N_Port-to-N_Port)");
1324 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1326 ha
->operating_mode
= P2P
;
1327 ha
->current_topology
= ISP_CFG_F
;
1328 strcpy(connect_type
, "(F_Port)");
1332 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1334 ha
->host_no
, topo
));
1335 ha
->current_topology
= ISP_CFG_NL
;
1336 strcpy(connect_type
, "(Loop)");
1340 /* Save Host port and loop ID. */
1341 /* byte order - Big Endian */
1342 ha
->d_id
.b
.domain
= domain
;
1343 ha
->d_id
.b
.area
= area
;
1344 ha
->d_id
.b
.al_pa
= al_pa
;
1346 if (!ha
->flags
.init_done
)
1347 qla_printk(KERN_INFO
, ha
,
1348 "Topology - %s, Host Loop address 0x%x\n",
1349 connect_type
, ha
->loop_id
);
1352 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1354 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1361 qla2x00_set_model_info(scsi_qla_host_t
*ha
, uint8_t *model
, size_t len
, char *def
)
1366 if (memcmp(model
, BINZERO
, len
) != 0) {
1367 strncpy(ha
->model_number
, model
, len
);
1368 st
= en
= ha
->model_number
;
1371 if (*en
!= 0x20 && *en
!= 0x00)
1376 index
= (ha
->pdev
->subsystem_device
& 0xff);
1377 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1378 index
< QLA_MODEL_NAMES
)
1379 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1381 index
= (ha
->pdev
->subsystem_device
& 0xff);
1382 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1383 index
< QLA_MODEL_NAMES
) {
1384 strcpy(ha
->model_number
,
1385 qla2x00_model_name
[index
* 2]);
1386 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1388 strcpy(ha
->model_number
, def
);
1393 /* On sparc systems, obtain port and node WWN from firmware
1396 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, nvram_t
*nv
)
1399 struct pci_dev
*pdev
= ha
->pdev
;
1400 struct pcidev_cookie
*pcp
= pdev
->sysdata
;
1401 struct device_node
*dp
= pcp
->prom_node
;
1405 val
= of_get_property(dp
, "port-wwn", &len
);
1406 if (val
&& len
>= WWN_SIZE
)
1407 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1409 val
= of_get_property(dp
, "node-wwn", &len
);
1410 if (val
&& len
>= WWN_SIZE
)
1411 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1416 * NVRAM configuration for ISP 2xxx
1419 * ha = adapter block pointer.
1422 * initialization control block in response_ring
1423 * host adapters parameters in host adapter block
1429 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1434 uint8_t *dptr1
, *dptr2
;
1435 init_cb_t
*icb
= ha
->init_cb
;
1436 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1437 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1438 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1442 /* Determine NVRAM starting address. */
1443 ha
->nvram_size
= sizeof(nvram_t
);
1445 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1446 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1447 ha
->nvram_base
= 0x80;
1449 /* Get NVRAM data and calculate checksum. */
1450 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1451 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1454 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1455 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1458 /* Bad NVRAM data, set defaults parameters. */
1459 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1460 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1461 /* Reset NVRAM data. */
1462 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1463 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1465 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1466 "invalid -- WWPN) defaults.\n");
1469 * Set default initialization control block.
1471 memset(nv
, 0, ha
->nvram_size
);
1472 nv
->parameter_block_version
= ICB_VERSION
;
1474 if (IS_QLA23XX(ha
)) {
1475 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1476 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1477 nv
->add_firmware_options
[0] = BIT_5
;
1478 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1479 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1480 nv
->special_options
[1] = BIT_7
;
1481 } else if (IS_QLA2200(ha
)) {
1482 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1483 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1484 nv
->add_firmware_options
[0] = BIT_5
;
1485 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1486 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1487 } else if (IS_QLA2100(ha
)) {
1488 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1489 nv
->firmware_options
[1] = BIT_5
;
1490 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1493 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1494 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1495 nv
->retry_count
= 8;
1496 nv
->retry_delay
= 1;
1498 nv
->port_name
[0] = 33;
1499 nv
->port_name
[3] = 224;
1500 nv
->port_name
[4] = 139;
1502 qla2xxx_nvram_wwn_from_ofw(ha
, nv
);
1504 nv
->login_timeout
= 4;
1507 * Set default host adapter parameters
1509 nv
->host_p
[1] = BIT_2
;
1510 nv
->reset_delay
= 5;
1511 nv
->port_down_retry_count
= 8;
1512 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1513 nv
->link_down_timeout
= 60;
1518 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1520 * The SN2 does not provide BIOS emulation which means you can't change
1521 * potentially bogus BIOS settings. Force the use of default settings
1522 * for link rate and frame size. Hope that the rest of the settings
1525 if (ia64_platform_is("sn2")) {
1526 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1528 nv
->special_options
[1] = BIT_7
;
1532 /* Reset Initialization control block */
1533 memset(icb
, 0, ha
->init_cb_size
);
1536 * Setup driver NVRAM options.
1538 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1539 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1540 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1541 nv
->firmware_options
[1] &= ~BIT_4
;
1543 if (IS_QLA23XX(ha
)) {
1544 nv
->firmware_options
[0] |= BIT_2
;
1545 nv
->firmware_options
[0] &= ~BIT_3
;
1546 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1548 if (IS_QLA2300(ha
)) {
1549 if (ha
->fb_rev
== FPM_2310
) {
1550 strcpy(ha
->model_number
, "QLA2310");
1552 strcpy(ha
->model_number
, "QLA2300");
1555 qla2x00_set_model_info(ha
, nv
->model_number
,
1556 sizeof(nv
->model_number
), "QLA23xx");
1558 } else if (IS_QLA2200(ha
)) {
1559 nv
->firmware_options
[0] |= BIT_2
;
1561 * 'Point-to-point preferred, else loop' is not a safe
1562 * connection mode setting.
1564 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1566 /* Force 'loop preferred, else point-to-point'. */
1567 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1568 nv
->add_firmware_options
[0] |= BIT_5
;
1570 strcpy(ha
->model_number
, "QLA22xx");
1571 } else /*if (IS_QLA2100(ha))*/ {
1572 strcpy(ha
->model_number
, "QLA2100");
1576 * Copy over NVRAM RISC parameter block to initialization control block.
1578 dptr1
= (uint8_t *)icb
;
1579 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1580 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1582 *dptr1
++ = *dptr2
++;
1584 /* Copy 2nd half. */
1585 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1586 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1588 *dptr1
++ = *dptr2
++;
1590 /* Use alternate WWN? */
1591 if (nv
->host_p
[1] & BIT_7
) {
1592 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1593 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1596 /* Prepare nodename */
1597 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1599 * Firmware will apply the following mask if the nodename was
1602 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1603 icb
->node_name
[0] &= 0xF0;
1607 * Set host adapter parameters.
1609 if (nv
->host_p
[0] & BIT_7
)
1610 ql2xextended_error_logging
= 1;
1611 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1612 /* Always load RISC code on non ISP2[12]00 chips. */
1613 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1614 ha
->flags
.disable_risc_code_load
= 0;
1615 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1616 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1617 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1618 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1619 ha
->flags
.disable_serdes
= 0;
1621 ha
->operating_mode
=
1622 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1624 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1625 sizeof(ha
->fw_seriallink_options
));
1627 /* save HBA serial number */
1628 ha
->serial0
= icb
->port_name
[5];
1629 ha
->serial1
= icb
->port_name
[6];
1630 ha
->serial2
= icb
->port_name
[7];
1631 ha
->node_name
= icb
->node_name
;
1632 ha
->port_name
= icb
->port_name
;
1634 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1636 ha
->retry_count
= nv
->retry_count
;
1638 /* Set minimum login_timeout to 4 seconds. */
1639 if (nv
->login_timeout
< ql2xlogintimeout
)
1640 nv
->login_timeout
= ql2xlogintimeout
;
1641 if (nv
->login_timeout
< 4)
1642 nv
->login_timeout
= 4;
1643 ha
->login_timeout
= nv
->login_timeout
;
1644 icb
->login_timeout
= nv
->login_timeout
;
1646 /* Set minimum RATOV to 200 tenths of a second. */
1649 ha
->loop_reset_delay
= nv
->reset_delay
;
1651 /* Link Down Timeout = 0:
1653 * When Port Down timer expires we will start returning
1654 * I/O's to OS with "DID_NO_CONNECT".
1656 * Link Down Timeout != 0:
1658 * The driver waits for the link to come up after link down
1659 * before returning I/Os to OS with "DID_NO_CONNECT".
1661 if (nv
->link_down_timeout
== 0) {
1662 ha
->loop_down_abort_time
=
1663 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1665 ha
->link_down_timeout
= nv
->link_down_timeout
;
1666 ha
->loop_down_abort_time
=
1667 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1671 * Need enough time to try and get the port back.
1673 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1674 if (qlport_down_retry
)
1675 ha
->port_down_retry_count
= qlport_down_retry
;
1676 /* Set login_retry_count */
1677 ha
->login_retry_count
= nv
->retry_count
;
1678 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1679 ha
->port_down_retry_count
> 3)
1680 ha
->login_retry_count
= ha
->port_down_retry_count
;
1681 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1682 ha
->login_retry_count
= ha
->port_down_retry_count
;
1683 if (ql2xloginretrycount
)
1684 ha
->login_retry_count
= ql2xloginretrycount
;
1686 icb
->lun_enables
= __constant_cpu_to_le16(0);
1687 icb
->command_resource_count
= 0;
1688 icb
->immediate_notify_resource_count
= 0;
1689 icb
->timeout
= __constant_cpu_to_le16(0);
1691 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1693 icb
->firmware_options
[0] &= ~BIT_3
;
1694 icb
->add_firmware_options
[0] &=
1695 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1696 icb
->add_firmware_options
[0] |= BIT_2
;
1697 icb
->response_accumulation_timer
= 3;
1698 icb
->interrupt_delay_timer
= 5;
1700 ha
->flags
.process_response_queue
= 1;
1703 if (!ha
->flags
.init_done
) {
1704 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1705 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1706 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1707 icb
->interrupt_delay_timer
: 2;
1709 icb
->add_firmware_options
[0] &=
1710 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1711 ha
->flags
.process_response_queue
= 0;
1712 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1713 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1715 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1716 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1717 ha
->zio_timer
* 100));
1718 qla_printk(KERN_INFO
, ha
,
1719 "ZIO mode %d enabled; timer delay (%d us).\n",
1720 ha
->zio_mode
, ha
->zio_timer
* 100);
1722 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1723 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1724 ha
->flags
.process_response_queue
= 1;
1729 DEBUG2_3(printk(KERN_WARNING
1730 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1736 qla2x00_rport_del(void *data
)
1738 fc_port_t
*fcport
= data
;
1739 struct fc_rport
*rport
;
1740 unsigned long flags
;
1742 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1743 rport
= fcport
->drport
;
1744 fcport
->drport
= NULL
;
1745 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1747 fc_remote_port_delete(rport
);
1752 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1754 * @flags: allocation flags
1756 * Returns a pointer to the allocated fcport, or NULL, if none available.
1759 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1763 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1767 /* Setup fcport template structure. */
1768 memset(fcport
, 0, sizeof (fc_port_t
));
1770 fcport
->port_type
= FCT_UNKNOWN
;
1771 fcport
->loop_id
= FC_NO_LOOP_ID
;
1772 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1773 fcport
->flags
= FCF_RLC_SUPPORT
;
1774 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1775 spin_lock_init(&fcport
->rport_lock
);
1781 * qla2x00_configure_loop
1782 * Updates Fibre Channel Device Database with what is actually on loop.
1785 * ha = adapter block pointer.
1790 * 2 = database was full and device was not configured.
1793 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1796 unsigned long flags
, save_flags
;
1800 /* Get Initiator ID */
1801 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1802 rval
= qla2x00_configure_hba(ha
);
1803 if (rval
!= QLA_SUCCESS
) {
1804 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1810 save_flags
= flags
= ha
->dpc_flags
;
1811 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1812 ha
->host_no
, flags
));
1815 * If we have both an RSCN and PORT UPDATE pending then handle them
1816 * both at the same time.
1818 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1819 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1821 /* Determine what we need to do */
1822 if (ha
->current_topology
== ISP_CFG_FL
&&
1823 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1825 ha
->flags
.rscn_queue_overflow
= 1;
1826 set_bit(RSCN_UPDATE
, &flags
);
1828 } else if (ha
->current_topology
== ISP_CFG_F
&&
1829 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1831 ha
->flags
.rscn_queue_overflow
= 1;
1832 set_bit(RSCN_UPDATE
, &flags
);
1833 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1835 } else if (ha
->current_topology
== ISP_CFG_N
) {
1836 clear_bit(RSCN_UPDATE
, &flags
);
1838 } else if (!ha
->flags
.online
||
1839 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1841 ha
->flags
.rscn_queue_overflow
= 1;
1842 set_bit(RSCN_UPDATE
, &flags
);
1843 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1846 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1847 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1848 rval
= QLA_FUNCTION_FAILED
;
1850 rval
= qla2x00_configure_local_loop(ha
);
1854 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1855 if (LOOP_TRANSITION(ha
)) {
1856 rval
= QLA_FUNCTION_FAILED
;
1858 rval
= qla2x00_configure_fabric(ha
);
1862 if (rval
== QLA_SUCCESS
) {
1863 if (atomic_read(&ha
->loop_down_timer
) ||
1864 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1865 rval
= QLA_FUNCTION_FAILED
;
1867 atomic_set(&ha
->loop_state
, LOOP_READY
);
1869 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1874 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1875 __func__
, ha
->host_no
));
1877 DEBUG3(printk("%s: exiting normally\n", __func__
));
1880 /* Restore state if a resync event occured during processing */
1881 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1882 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1883 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1884 if (test_bit(RSCN_UPDATE
, &save_flags
))
1885 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1894 * qla2x00_configure_local_loop
1895 * Updates Fibre Channel Device Database with local loop devices.
1898 * ha = adapter block pointer.
1904 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1909 fc_port_t
*fcport
, *new_fcport
;
1915 uint8_t domain
, area
, al_pa
;
1919 entries
= MAX_FIBRE_DEVICES
;
1921 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1922 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1924 /* Get list of logged in devices. */
1925 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1926 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1928 if (rval
!= QLA_SUCCESS
)
1929 goto cleanup_allocation
;
1931 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1932 ha
->host_no
, entries
));
1933 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1934 entries
* sizeof(struct gid_list_info
)));
1936 /* Allocate temporary fcport for any new fcports discovered. */
1937 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1938 if (new_fcport
== NULL
) {
1939 rval
= QLA_MEMORY_ALLOC_FAILED
;
1940 goto cleanup_allocation
;
1942 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1945 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1947 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1948 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1949 fcport
->port_type
!= FCT_BROADCAST
&&
1950 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1952 DEBUG(printk("scsi(%ld): Marking port lost, "
1954 ha
->host_no
, fcport
->loop_id
));
1956 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1957 fcport
->flags
&= ~FCF_FARP_DONE
;
1961 /* Add devices to port list. */
1962 id_iter
= (char *)ha
->gid_list
;
1963 for (index
= 0; index
< entries
; index
++) {
1964 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1965 area
= ((struct gid_list_info
*)id_iter
)->area
;
1966 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1967 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1968 loop_id
= (uint16_t)
1969 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1971 loop_id
= le16_to_cpu(
1972 ((struct gid_list_info
*)id_iter
)->loop_id
);
1973 id_iter
+= ha
->gid_list_info_size
;
1975 /* Bypass reserved domain fields. */
1976 if ((domain
& 0xf0) == 0xf0)
1979 /* Bypass if not same domain and area of adapter. */
1980 if (area
&& domain
&&
1981 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
1984 /* Bypass invalid local loop ID. */
1985 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1988 /* Fill in member data. */
1989 new_fcport
->d_id
.b
.domain
= domain
;
1990 new_fcport
->d_id
.b
.area
= area
;
1991 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1992 new_fcport
->loop_id
= loop_id
;
1993 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1994 if (rval2
!= QLA_SUCCESS
) {
1995 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1996 "information -- get_port_database=%x, "
1998 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1999 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2001 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2005 /* Check for matching device in port list. */
2008 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2009 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2013 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2014 FCF_PERSISTENT_BOUND
);
2015 fcport
->loop_id
= new_fcport
->loop_id
;
2016 fcport
->port_type
= new_fcport
->port_type
;
2017 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2018 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2026 /* New device, add to fcports list. */
2027 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2028 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
2030 /* Allocate a new replacement fcport. */
2031 fcport
= new_fcport
;
2032 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2033 if (new_fcport
== NULL
) {
2034 rval
= QLA_MEMORY_ALLOC_FAILED
;
2035 goto cleanup_allocation
;
2037 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2040 /* Base iIDMA settings on HBA port speed. */
2041 switch (ha
->link_data_rate
) {
2042 case PORT_SPEED_1GB
:
2043 fcport
->fp_speed
= cpu_to_be16(BIT_15
);
2045 case PORT_SPEED_2GB
:
2046 fcport
->fp_speed
= cpu_to_be16(BIT_14
);
2048 case PORT_SPEED_4GB
:
2049 fcport
->fp_speed
= cpu_to_be16(BIT_13
);
2053 qla2x00_update_fcport(ha
, fcport
);
2061 if (rval
!= QLA_SUCCESS
) {
2062 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2063 "rval=%x\n", ha
->host_no
, rval
));
2067 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2068 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2075 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2079 qla2x00_mark_all_devices_lost(ha
, 0);
2080 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2081 if (fcport
->port_type
!= FCT_TARGET
)
2084 qla2x00_update_fcport(ha
, fcport
);
2089 qla2x00_iidma_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2091 #define LS_UNKNOWN 2
2092 static char *link_speeds
[5] = { "1", "2", "?", "4" };
2094 uint16_t port_speed
, mb
[6];
2096 if (!IS_QLA24XX(ha
))
2099 switch (be16_to_cpu(fcport
->fp_speed
)) {
2101 port_speed
= PORT_SPEED_1GB
;
2104 port_speed
= PORT_SPEED_2GB
;
2107 port_speed
= PORT_SPEED_4GB
;
2110 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2111 "unsupported FM port operating speed (%04x).\n",
2112 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2113 fcport
->port_name
[2], fcport
->port_name
[3],
2114 fcport
->port_name
[4], fcport
->port_name
[5],
2115 fcport
->port_name
[6], fcport
->port_name
[7],
2116 be16_to_cpu(fcport
->fp_speed
)));
2117 port_speed
= PORT_SPEED_UNKNOWN
;
2120 if (port_speed
== PORT_SPEED_UNKNOWN
)
2123 rval
= qla2x00_set_idma_speed(ha
, fcport
->loop_id
, port_speed
, mb
);
2124 if (rval
!= QLA_SUCCESS
) {
2125 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2126 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2127 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2128 fcport
->port_name
[2], fcport
->port_name
[3],
2129 fcport
->port_name
[4], fcport
->port_name
[5],
2130 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2131 port_speed
, mb
[0], mb
[1]));
2133 DEBUG2(qla_printk(KERN_INFO
, ha
,
2134 "iIDMA adjusted to %s GB/s on "
2135 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2136 link_speeds
[port_speed
], fcport
->port_name
[0],
2137 fcport
->port_name
[1], fcport
->port_name
[2],
2138 fcport
->port_name
[3], fcport
->port_name
[4],
2139 fcport
->port_name
[5], fcport
->port_name
[6],
2140 fcport
->port_name
[7]));
2145 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2147 struct fc_rport_identifiers rport_ids
;
2148 struct fc_rport
*rport
;
2149 unsigned long flags
;
2152 qla2x00_rport_del(fcport
);
2156 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2157 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2158 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2159 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2160 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2161 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2163 qla_printk(KERN_WARNING
, ha
,
2164 "Unable to allocate fc remote port!\n");
2167 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2168 fcport
->rport
= rport
;
2169 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2170 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2172 rport
->supported_classes
= fcport
->supported_classes
;
2174 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2175 if (fcport
->port_type
== FCT_INITIATOR
)
2176 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2177 if (fcport
->port_type
== FCT_TARGET
)
2178 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2179 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2181 if (rport
->scsi_target_id
!= -1 &&
2182 rport
->scsi_target_id
< ha
->host
->max_id
)
2183 fcport
->os_target_id
= rport
->scsi_target_id
;
2187 * qla2x00_update_fcport
2188 * Updates device on list.
2191 * ha = adapter block pointer.
2192 * fcport = port structure pointer.
2202 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2205 fcport
->login_retry
= 0;
2206 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2208 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2210 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2212 qla2x00_iidma_fcport(ha
, fcport
);
2214 atomic_set(&fcport
->state
, FCS_ONLINE
);
2216 qla2x00_reg_remote_port(ha
, fcport
);
2220 * qla2x00_configure_fabric
2221 * Setup SNS devices with loop ID's.
2224 * ha = adapter block pointer.
2231 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2234 fc_port_t
*fcport
, *fcptemp
;
2235 uint16_t next_loopid
;
2236 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2238 LIST_HEAD(new_fcports
);
2240 /* If FL port exists, then SNS is present */
2241 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2242 loop_id
= NPH_F_PORT
;
2244 loop_id
= SNS_FL_PORT
;
2245 rval
= qla2x00_get_port_name(ha
, loop_id
, ha
->fabric_node_name
, 1);
2246 if (rval
!= QLA_SUCCESS
) {
2247 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2248 "Port\n", ha
->host_no
));
2250 ha
->device_flags
&= ~SWITCH_FOUND
;
2251 return (QLA_SUCCESS
);
2253 ha
->device_flags
|= SWITCH_FOUND
;
2255 /* Mark devices that need re-synchronization. */
2256 rval2
= qla2x00_device_resync(ha
);
2257 if (rval2
== QLA_RSCNS_HANDLED
) {
2258 /* No point doing the scan, just continue. */
2259 return (QLA_SUCCESS
);
2263 if (ql2xfdmienable
&&
2264 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2265 qla2x00_fdmi_register(ha
);
2267 /* Ensure we are logged into the SNS. */
2268 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2271 loop_id
= SIMPLE_NAME_SERVER
;
2272 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2273 0xfc, mb
, BIT_1
| BIT_0
);
2274 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2275 DEBUG2(qla_printk(KERN_INFO
, ha
,
2276 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2277 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2278 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2279 return (QLA_SUCCESS
);
2282 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2283 if (qla2x00_rft_id(ha
)) {
2285 DEBUG2(printk("scsi(%ld): Register FC-4 "
2286 "TYPE failed.\n", ha
->host_no
));
2288 if (qla2x00_rff_id(ha
)) {
2290 DEBUG2(printk("scsi(%ld): Register FC-4 "
2291 "Features failed.\n", ha
->host_no
));
2293 if (qla2x00_rnn_id(ha
)) {
2295 DEBUG2(printk("scsi(%ld): Register Node Name "
2296 "failed.\n", ha
->host_no
));
2297 } else if (qla2x00_rsnn_nn(ha
)) {
2299 DEBUG2(printk("scsi(%ld): Register Symbolic "
2300 "Node Name failed.\n", ha
->host_no
));
2304 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2305 if (rval
!= QLA_SUCCESS
)
2309 * Logout all previous fabric devices marked lost, except
2312 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2313 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2316 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2319 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2320 qla2x00_mark_device_lost(ha
, fcport
,
2321 ql2xplogiabsentdevice
, 0);
2322 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2323 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2324 fcport
->port_type
!= FCT_INITIATOR
&&
2325 fcport
->port_type
!= FCT_BROADCAST
) {
2326 ha
->isp_ops
.fabric_logout(ha
,
2328 fcport
->d_id
.b
.domain
,
2329 fcport
->d_id
.b
.area
,
2330 fcport
->d_id
.b
.al_pa
);
2331 fcport
->loop_id
= FC_NO_LOOP_ID
;
2336 /* Starting free loop ID. */
2337 next_loopid
= ha
->min_external_loopid
;
2340 * Scan through our port list and login entries that need to be
2343 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2344 if (atomic_read(&ha
->loop_down_timer
) ||
2345 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2348 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2349 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2352 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2353 fcport
->loop_id
= next_loopid
;
2354 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2355 if (rval
!= QLA_SUCCESS
) {
2356 /* Ran out of IDs to use */
2360 /* Login and update database */
2361 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2364 /* Exit if out of loop IDs. */
2365 if (rval
!= QLA_SUCCESS
) {
2370 * Login and add the new devices to our port list.
2372 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2373 if (atomic_read(&ha
->loop_down_timer
) ||
2374 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2377 /* Find a new loop ID to use. */
2378 fcport
->loop_id
= next_loopid
;
2379 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2380 if (rval
!= QLA_SUCCESS
) {
2381 /* Ran out of IDs to use */
2385 /* Remove device from the new list and add it to DB */
2386 list_move_tail(&fcport
->list
, &ha
->fcports
);
2388 /* Login and update database */
2389 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2393 /* Free all new device structures not processed. */
2394 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2395 list_del(&fcport
->list
);
2400 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2401 "rval=%d\n", ha
->host_no
, rval
));
2409 * qla2x00_find_all_fabric_devs
2412 * ha = adapter block pointer.
2413 * dev = database device entry pointer.
2422 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2426 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2431 int first_dev
, last_dev
;
2432 port_id_t wrap
, nxt_d_id
;
2436 /* Try GID_PT to get device list, else GAN. */
2437 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2440 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2441 "on GA_NXT\n", ha
->host_no
));
2443 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2444 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2447 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2450 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2453 } else if (qla2x00_gfpn_id(ha
, swl
) == QLA_SUCCESS
) {
2454 qla2x00_gpsc(ha
, swl
);
2459 /* Allocate temporary fcport for any new fcports discovered. */
2460 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2461 if (new_fcport
== NULL
) {
2463 return (QLA_MEMORY_ALLOC_FAILED
);
2465 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2467 /* Set start port ID scan at adapter ID. */
2471 /* Starting free loop ID. */
2472 loop_id
= ha
->min_external_loopid
;
2473 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2474 if (qla2x00_is_reserved_id(ha
, loop_id
))
2477 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2482 wrap
.b24
= new_fcport
->d_id
.b24
;
2484 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2485 memcpy(new_fcport
->node_name
,
2486 swl
[swl_idx
].node_name
, WWN_SIZE
);
2487 memcpy(new_fcport
->port_name
,
2488 swl
[swl_idx
].port_name
, WWN_SIZE
);
2489 memcpy(new_fcport
->fabric_port_name
,
2490 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2491 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2493 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2499 /* Send GA_NXT to the switch */
2500 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2501 if (rval
!= QLA_SUCCESS
) {
2502 qla_printk(KERN_WARNING
, ha
,
2503 "SNS scan failed -- assuming zero-entry "
2505 list_for_each_entry_safe(fcport
, fcptemp
,
2506 new_fcports
, list
) {
2507 list_del(&fcport
->list
);
2515 /* If wrap on switch device list, exit. */
2517 wrap
.b24
= new_fcport
->d_id
.b24
;
2519 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2520 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2521 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2522 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2526 /* Bypass if host adapter. */
2527 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2530 /* Bypass if same domain and area of adapter. */
2531 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2532 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2536 /* Bypass reserved domain fields. */
2537 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2540 /* Locate matching device in database. */
2542 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2543 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2549 /* Update port state. */
2550 memcpy(fcport
->fabric_port_name
,
2551 new_fcport
->fabric_port_name
, WWN_SIZE
);
2552 fcport
->fp_speed
= new_fcport
->fp_speed
;
2555 * If address the same and state FCS_ONLINE, nothing
2558 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2559 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2564 * If device was not a fabric device before.
2566 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2567 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2568 fcport
->loop_id
= FC_NO_LOOP_ID
;
2569 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2571 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2576 * Port ID changed or device was marked to be updated;
2577 * Log it out if still logged in and mark it for
2580 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2581 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2582 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2583 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2584 fcport
->port_type
!= FCT_INITIATOR
&&
2585 fcport
->port_type
!= FCT_BROADCAST
) {
2586 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2587 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2588 fcport
->d_id
.b
.al_pa
);
2589 fcport
->loop_id
= FC_NO_LOOP_ID
;
2598 /* If device was not in our fcports list, then add it. */
2599 list_add_tail(&new_fcport
->list
, new_fcports
);
2601 /* Allocate a new replacement fcport. */
2602 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2603 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2604 if (new_fcport
== NULL
) {
2606 return (QLA_MEMORY_ALLOC_FAILED
);
2608 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2609 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2615 if (!list_empty(new_fcports
))
2616 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2622 * qla2x00_find_new_loop_id
2623 * Scan through our port list and find a new usable loop ID.
2626 * ha: adapter state pointer.
2627 * dev: port structure pointer.
2630 * qla2x00 local function return status code.
2636 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2641 uint16_t first_loop_id
;
2645 /* Save starting loop ID. */
2646 first_loop_id
= dev
->loop_id
;
2649 /* Skip loop ID if already used by adapter. */
2650 if (dev
->loop_id
== ha
->loop_id
) {
2654 /* Skip reserved loop IDs. */
2655 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2659 /* Reset loop ID if passed the end. */
2660 if (dev
->loop_id
> ha
->last_loop_id
) {
2661 /* first loop ID. */
2662 dev
->loop_id
= ha
->min_external_loopid
;
2665 /* Check for loop ID being already in use. */
2668 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2669 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2670 /* ID possibly in use */
2676 /* If not in use then it is free to use. */
2681 /* ID in use. Try next value. */
2684 /* If wrap around. No free ID to use. */
2685 if (dev
->loop_id
== first_loop_id
) {
2686 dev
->loop_id
= FC_NO_LOOP_ID
;
2687 rval
= QLA_FUNCTION_FAILED
;
2696 * qla2x00_device_resync
2697 * Marks devices in the database that needs resynchronization.
2700 * ha = adapter block pointer.
2706 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2711 uint32_t rscn_entry
;
2712 uint8_t rscn_out_iter
;
2716 rval
= QLA_RSCNS_HANDLED
;
2718 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2719 ha
->flags
.rscn_queue_overflow
) {
2721 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2722 format
= MSB(MSW(rscn_entry
));
2723 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2724 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2725 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2727 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2728 "[%02x/%02x%02x%02x].\n",
2729 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2730 d_id
.b
.area
, d_id
.b
.al_pa
));
2733 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2734 ha
->rscn_out_ptr
= 0;
2736 /* Skip duplicate entries. */
2737 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2738 !ha
->flags
.rscn_queue_overflow
&&
2739 rscn_out_iter
!= ha
->rscn_in_ptr
;
2740 rscn_out_iter
= (rscn_out_iter
==
2741 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2743 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2746 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2747 "entry found at [%d].\n", ha
->host_no
,
2750 ha
->rscn_out_ptr
= rscn_out_iter
;
2753 /* Queue overflow, set switch default case. */
2754 if (ha
->flags
.rscn_queue_overflow
) {
2755 DEBUG(printk("scsi(%ld): device_resync: rscn "
2756 "overflow.\n", ha
->host_no
));
2759 ha
->flags
.rscn_queue_overflow
= 0;
2775 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2781 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2782 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2783 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2784 fcport
->port_type
== FCT_BROADCAST
)
2787 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2789 fcport
->port_type
!= FCT_INITIATOR
) {
2790 qla2x00_mark_device_lost(ha
, fcport
,
2794 fcport
->flags
&= ~FCF_FARP_DONE
;
2801 * qla2x00_fabric_dev_login
2802 * Login fabric target device and update FC port database.
2805 * ha: adapter state pointer.
2806 * fcport: port structure list pointer.
2807 * next_loopid: contains value of a new loop ID that can be used
2808 * by the next login attempt.
2811 * qla2x00 local function return status code.
2817 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2818 uint16_t *next_loopid
)
2827 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2828 if (rval
== QLA_SUCCESS
) {
2829 /* Send an ADISC to tape devices.*/
2831 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2833 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2834 if (rval
!= QLA_SUCCESS
) {
2835 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2836 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2837 fcport
->d_id
.b
.al_pa
);
2838 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2840 qla2x00_update_fcport(ha
, fcport
);
2848 * qla2x00_fabric_login
2849 * Issue fabric login command.
2852 * ha = adapter block pointer.
2853 * device = pointer to FC device type structure.
2856 * 0 - Login successfully
2858 * 2 - Initiator device
2862 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2863 uint16_t *next_loopid
)
2867 uint16_t tmp_loopid
;
2868 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2874 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2875 "for port %02x%02x%02x.\n",
2876 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2877 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2879 /* Login fcport on switch. */
2880 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2881 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2882 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2883 if (mb
[0] == MBS_PORT_ID_USED
) {
2885 * Device has another loop ID. The firmware team
2886 * recommends the driver perform an implicit login with
2887 * the specified ID again. The ID we just used is save
2888 * here so we return with an ID that can be tried by
2892 tmp_loopid
= fcport
->loop_id
;
2893 fcport
->loop_id
= mb
[1];
2895 DEBUG(printk("Fabric Login: port in use - next "
2896 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2897 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2898 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2900 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2905 /* A retry occurred before. */
2906 *next_loopid
= tmp_loopid
;
2909 * No retry occurred before. Just increment the
2910 * ID value for next login.
2912 *next_loopid
= (fcport
->loop_id
+ 1);
2915 if (mb
[1] & BIT_0
) {
2916 fcport
->port_type
= FCT_INITIATOR
;
2918 fcport
->port_type
= FCT_TARGET
;
2919 if (mb
[1] & BIT_1
) {
2920 fcport
->flags
|= FCF_TAPE_PRESENT
;
2925 fcport
->supported_classes
|= FC_COS_CLASS2
;
2927 fcport
->supported_classes
|= FC_COS_CLASS3
;
2931 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2933 * Loop ID already used, try next loop ID.
2936 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2937 if (rval
!= QLA_SUCCESS
) {
2938 /* Ran out of loop IDs to use */
2941 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2943 * Firmware possibly timed out during login. If NO
2944 * retries are left to do then the device is declared
2947 *next_loopid
= fcport
->loop_id
;
2948 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2949 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2950 fcport
->d_id
.b
.al_pa
);
2951 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2957 * unrecoverable / not handled error
2959 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2960 "loop_id=%x jiffies=%lx.\n",
2961 __func__
, ha
->host_no
, mb
[0],
2962 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2963 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2965 *next_loopid
= fcport
->loop_id
;
2966 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2967 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2968 fcport
->d_id
.b
.al_pa
);
2969 fcport
->loop_id
= FC_NO_LOOP_ID
;
2970 fcport
->login_retry
= 0;
2981 * qla2x00_local_device_login
2982 * Issue local device login command.
2985 * ha = adapter block pointer.
2986 * loop_id = loop id of device to login to.
2988 * Returns (Where's the #define!!!!):
2989 * 0 - Login successfully
2994 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2997 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2999 memset(mb
, 0, sizeof(mb
));
3000 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
3001 if (rval
== QLA_SUCCESS
) {
3002 /* Interrogate mailbox registers for any errors */
3003 if (mb
[0] == MBS_COMMAND_ERROR
)
3005 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3006 /* device not in PCB table */
3014 * qla2x00_loop_resync
3015 * Resync with fibre channel devices.
3018 * ha = adapter block pointer.
3024 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
3031 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3032 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3033 if (ha
->flags
.online
) {
3034 if (!(rval
= qla2x00_fw_ready(ha
))) {
3035 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3038 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3040 /* Issue a marker after FW becomes ready. */
3041 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3042 ha
->marker_needed
= 0;
3044 /* Remap devices on Loop. */
3045 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3047 qla2x00_configure_loop(ha
);
3049 } while (!atomic_read(&ha
->loop_down_timer
) &&
3050 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3052 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3056 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3057 return (QLA_FUNCTION_FAILED
);
3061 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3068 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3074 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3075 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3078 qla2x00_update_fcport(ha
, fcport
);
3079 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3083 qla2x00_probe_for_all_luns(ha
);
3087 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3091 /* Go with deferred removal of rport references. */
3092 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3094 qla2x00_rport_del(fcport
);
3099 * Resets ISP and aborts all outstanding commands.
3102 * ha = adapter block pointer.
3108 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3111 unsigned long flags
= 0;
3116 if (ha
->flags
.online
) {
3117 ha
->flags
.online
= 0;
3118 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3120 qla_printk(KERN_INFO
, ha
,
3121 "Performing ISP error recovery - ha= %p.\n", ha
);
3122 ha
->isp_ops
.reset_chip(ha
);
3124 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3125 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3126 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3127 qla2x00_mark_all_devices_lost(ha
, 0);
3129 if (!atomic_read(&ha
->loop_down_timer
))
3130 atomic_set(&ha
->loop_down_timer
,
3134 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3135 /* Requeue all commands in outstanding command list. */
3136 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3137 sp
= ha
->outstanding_cmds
[cnt
];
3139 ha
->outstanding_cmds
[cnt
] = NULL
;
3141 sp
->cmd
->result
= DID_RESET
<< 16;
3142 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3143 qla2x00_sp_compl(ha
, sp
);
3146 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3148 ha
->isp_ops
.get_flash_version(ha
, ha
->request_ring
);
3150 ha
->isp_ops
.nvram_config(ha
);
3152 if (!qla2x00_restart_isp(ha
)) {
3153 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3155 if (!atomic_read(&ha
->loop_down_timer
)) {
3157 * Issue marker command only when we are going
3158 * to start the I/O .
3160 ha
->marker_needed
= 1;
3163 ha
->flags
.online
= 1;
3165 ha
->isp_ops
.enable_intrs(ha
);
3167 ha
->isp_abort_cnt
= 0;
3168 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3171 rval
= qla2x00_trace_control(ha
, TC_ENABLE
,
3172 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3174 qla_printk(KERN_WARNING
, ha
,
3175 "Unable to reinitialize EFT "
3179 } else { /* failed the ISP abort */
3180 ha
->flags
.online
= 1;
3181 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3182 if (ha
->isp_abort_cnt
== 0) {
3183 qla_printk(KERN_WARNING
, ha
,
3184 "ISP error recovery failed - "
3185 "board disabled\n");
3187 * The next call disables the board
3190 ha
->isp_ops
.reset_adapter(ha
);
3191 ha
->flags
.online
= 0;
3192 clear_bit(ISP_ABORT_RETRY
,
3195 } else { /* schedule another ISP abort */
3196 ha
->isp_abort_cnt
--;
3197 DEBUG(printk("qla%ld: ISP abort - "
3198 "retry remaining %d\n",
3199 ha
->host_no
, ha
->isp_abort_cnt
));
3203 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3204 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3205 "- retrying (%d) more times\n",
3206 ha
->host_no
, ha
->isp_abort_cnt
));
3207 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3215 qla_printk(KERN_INFO
, ha
,
3216 "qla2x00_abort_isp: **** FAILED ****\n");
3218 DEBUG(printk(KERN_INFO
3219 "qla2x00_abort_isp(%ld): exiting.\n",
3227 * qla2x00_restart_isp
3228 * restarts the ISP after a reset
3231 * ha = adapter block pointer.
3237 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3240 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3241 unsigned long flags
= 0;
3244 /* If firmware needs to be loaded */
3245 if (qla2x00_isp_firmware(ha
)) {
3246 ha
->flags
.online
= 0;
3247 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3248 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3249 status
= qla2x00_setup_chip(ha
);
3253 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3255 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3257 * Disable SRAM, Instruction RAM and GP RAM
3260 WRT_REG_WORD(®
->hccr
,
3261 (HCCR_ENABLE_PARITY
+ 0x0));
3262 RD_REG_WORD(®
->hccr
);
3265 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3267 status
= qla2x00_setup_chip(ha
);
3269 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3271 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3272 /* Enable proper parity */
3275 WRT_REG_WORD(®
->hccr
,
3276 (HCCR_ENABLE_PARITY
+ 0x1));
3279 * SRAM, Instruction RAM and GP RAM
3282 WRT_REG_WORD(®
->hccr
,
3283 (HCCR_ENABLE_PARITY
+ 0x7));
3284 RD_REG_WORD(®
->hccr
);
3287 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3292 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3293 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3294 if (!(status
= qla2x00_fw_ready(ha
))) {
3295 DEBUG(printk("%s(): Start configure loop, "
3296 "status = %d\n", __func__
, status
));
3298 /* Issue a marker after FW becomes ready. */
3299 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3301 ha
->flags
.online
= 1;
3302 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3305 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3306 qla2x00_configure_loop(ha
);
3308 } while (!atomic_read(&ha
->loop_down_timer
) &&
3309 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3311 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3314 /* if no cable then assume it's good */
3315 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3318 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3326 * qla2x00_reset_adapter
3330 * ha = adapter block pointer.
3333 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3335 unsigned long flags
= 0;
3336 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3338 ha
->flags
.online
= 0;
3339 ha
->isp_ops
.disable_intrs(ha
);
3341 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3342 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3343 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3344 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3345 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3346 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3350 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3352 unsigned long flags
= 0;
3353 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3355 ha
->flags
.online
= 0;
3356 ha
->isp_ops
.disable_intrs(ha
);
3358 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3359 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3360 RD_REG_DWORD(®
->hccr
);
3361 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3362 RD_REG_DWORD(®
->hccr
);
3363 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3366 /* On sparc systems, obtain port and node WWN from firmware
3369 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, struct nvram_24xx
*nv
)
3372 struct pci_dev
*pdev
= ha
->pdev
;
3373 struct pcidev_cookie
*pcp
= pdev
->sysdata
;
3374 struct device_node
*dp
= pcp
->prom_node
;
3378 val
= of_get_property(dp
, "port-wwn", &len
);
3379 if (val
&& len
>= WWN_SIZE
)
3380 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3382 val
= of_get_property(dp
, "node-wwn", &len
);
3383 if (val
&& len
>= WWN_SIZE
)
3384 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3389 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3392 struct init_cb_24xx
*icb
;
3393 struct nvram_24xx
*nv
;
3395 uint8_t *dptr1
, *dptr2
;
3400 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3401 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3403 /* Determine NVRAM starting address. */
3404 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3405 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3406 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3407 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3408 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3409 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3410 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3413 /* Get NVRAM data and calculate checksum. */
3414 dptr
= (uint32_t *)nv
;
3415 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3417 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3418 chksum
+= le32_to_cpu(*dptr
++);
3420 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3421 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3424 /* Bad NVRAM data, set defaults parameters. */
3425 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3426 || nv
->id
[3] != ' ' ||
3427 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3428 /* Reset NVRAM data. */
3429 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3430 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3431 le16_to_cpu(nv
->nvram_version
));
3432 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3433 "invalid -- WWPN) defaults.\n");
3436 * Set default initialization control block.
3438 memset(nv
, 0, ha
->nvram_size
);
3439 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3440 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3441 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3442 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3443 nv
->exchange_count
= __constant_cpu_to_le16(0);
3444 nv
->hard_address
= __constant_cpu_to_le16(124);
3445 nv
->port_name
[0] = 0x21;
3446 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3447 nv
->port_name
[2] = 0x00;
3448 nv
->port_name
[3] = 0xe0;
3449 nv
->port_name
[4] = 0x8b;
3450 nv
->port_name
[5] = 0x1c;
3451 nv
->port_name
[6] = 0x55;
3452 nv
->port_name
[7] = 0x86;
3453 nv
->node_name
[0] = 0x20;
3454 nv
->node_name
[1] = 0x00;
3455 nv
->node_name
[2] = 0x00;
3456 nv
->node_name
[3] = 0xe0;
3457 nv
->node_name
[4] = 0x8b;
3458 nv
->node_name
[5] = 0x1c;
3459 nv
->node_name
[6] = 0x55;
3460 nv
->node_name
[7] = 0x86;
3461 qla24xx_nvram_wwn_from_ofw(ha
, nv
);
3462 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3463 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3464 nv
->login_timeout
= __constant_cpu_to_le16(0);
3465 nv
->firmware_options_1
=
3466 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3467 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3468 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3469 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3470 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3471 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3472 nv
->reset_delay
= 5;
3473 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3474 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3475 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3480 /* Reset Initialization control block */
3481 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3483 /* Copy 1st segment. */
3484 dptr1
= (uint8_t *)icb
;
3485 dptr2
= (uint8_t *)&nv
->version
;
3486 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3488 *dptr1
++ = *dptr2
++;
3490 icb
->login_retry_count
= nv
->login_retry_count
;
3491 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3493 /* Copy 2nd segment. */
3494 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3495 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3496 cnt
= (uint8_t *)&icb
->reserved_3
-
3497 (uint8_t *)&icb
->interrupt_delay_timer
;
3499 *dptr1
++ = *dptr2
++;
3502 * Setup driver NVRAM options.
3504 qla2x00_set_model_info(ha
, nv
->model_name
, sizeof(nv
->model_name
),
3507 /* Use alternate WWN? */
3508 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3509 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3510 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3513 /* Prepare nodename */
3514 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3516 * Firmware will apply the following mask if the nodename was
3519 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3520 icb
->node_name
[0] &= 0xF0;
3523 /* Set host adapter parameters. */
3524 ha
->flags
.disable_risc_code_load
= 0;
3525 ha
->flags
.enable_lip_reset
= 0;
3526 ha
->flags
.enable_lip_full_login
=
3527 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3528 ha
->flags
.enable_target_reset
=
3529 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3530 ha
->flags
.enable_led_scheme
= 0;
3531 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3533 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3534 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3536 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3537 sizeof(ha
->fw_seriallink_options24
));
3539 /* save HBA serial number */
3540 ha
->serial0
= icb
->port_name
[5];
3541 ha
->serial1
= icb
->port_name
[6];
3542 ha
->serial2
= icb
->port_name
[7];
3543 ha
->node_name
= icb
->node_name
;
3544 ha
->port_name
= icb
->port_name
;
3546 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3548 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3550 /* Set minimum login_timeout to 4 seconds. */
3551 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3552 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3553 if (le16_to_cpu(nv
->login_timeout
) < 4)
3554 nv
->login_timeout
= __constant_cpu_to_le16(4);
3555 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3556 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3558 /* Set minimum RATOV to 200 tenths of a second. */
3561 ha
->loop_reset_delay
= nv
->reset_delay
;
3563 /* Link Down Timeout = 0:
3565 * When Port Down timer expires we will start returning
3566 * I/O's to OS with "DID_NO_CONNECT".
3568 * Link Down Timeout != 0:
3570 * The driver waits for the link to come up after link down
3571 * before returning I/Os to OS with "DID_NO_CONNECT".
3573 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3574 ha
->loop_down_abort_time
=
3575 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3577 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3578 ha
->loop_down_abort_time
=
3579 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3582 /* Need enough time to try and get the port back. */
3583 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3584 if (qlport_down_retry
)
3585 ha
->port_down_retry_count
= qlport_down_retry
;
3587 /* Set login_retry_count */
3588 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3589 if (ha
->port_down_retry_count
==
3590 le16_to_cpu(nv
->port_down_retry_count
) &&
3591 ha
->port_down_retry_count
> 3)
3592 ha
->login_retry_count
= ha
->port_down_retry_count
;
3593 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3594 ha
->login_retry_count
= ha
->port_down_retry_count
;
3595 if (ql2xloginretrycount
)
3596 ha
->login_retry_count
= ql2xloginretrycount
;
3599 if (!ha
->flags
.init_done
) {
3600 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3601 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3602 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3603 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3605 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3606 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3607 ha
->flags
.process_response_queue
= 0;
3608 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3609 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3611 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3612 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3613 ha
->zio_timer
* 100));
3614 qla_printk(KERN_INFO
, ha
,
3615 "ZIO mode %d enabled; timer delay (%d us).\n",
3616 ha
->zio_mode
, ha
->zio_timer
* 100);
3618 icb
->firmware_options_2
|= cpu_to_le32(
3619 (uint32_t)ha
->zio_mode
);
3620 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3621 ha
->flags
.process_response_queue
= 1;
3625 DEBUG2_3(printk(KERN_WARNING
3626 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3632 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3635 int segments
, fragment
;
3637 uint32_t *dcode
, dlen
;
3644 segments
= FA_RISC_CODE_SEGMENTS
;
3645 faddr
= FA_RISC_CODE_ADDR
;
3646 dcode
= (uint32_t *)ha
->request_ring
;
3649 /* Validate firmware image by checking version. */
3650 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3651 for (i
= 0; i
< 4; i
++)
3652 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3653 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3654 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3655 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3657 qla_printk(KERN_WARNING
, ha
,
3658 "Unable to verify integrity of flash firmware image!\n");
3659 qla_printk(KERN_WARNING
, ha
,
3660 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3661 dcode
[1], dcode
[2], dcode
[3]);
3663 return QLA_FUNCTION_FAILED
;
3666 while (segments
&& rval
== QLA_SUCCESS
) {
3667 /* Read segment's load information. */
3668 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3670 risc_addr
= be32_to_cpu(dcode
[2]);
3671 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3672 risc_size
= be32_to_cpu(dcode
[3]);
3675 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3676 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3677 if (dlen
> risc_size
)
3680 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3681 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3682 ha
->host_no
, risc_addr
, dlen
, faddr
));
3684 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3685 for (i
= 0; i
< dlen
; i
++)
3686 dcode
[i
] = swab32(dcode
[i
]);
3688 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3691 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3692 "segment %d of firmware\n", ha
->host_no
,
3694 qla_printk(KERN_WARNING
, ha
,
3695 "[ERROR] Failed to load segment %d of "
3696 "firmware\n", fragment
);
3713 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3716 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3720 uint16_t *wcode
, *fwcode
;
3721 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3722 struct fw_blob
*blob
;
3724 /* Load firmware blob. */
3725 blob
= qla2x00_request_firmware(ha
);
3727 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3728 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3729 "from: " QLA_FW_URL
".\n");
3730 return QLA_FUNCTION_FAILED
;
3735 wcode
= (uint16_t *)ha
->request_ring
;
3737 fwcode
= (uint16_t *)blob
->fw
->data
;
3740 /* Validate firmware image by checking version. */
3741 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3742 qla_printk(KERN_WARNING
, ha
,
3743 "Unable to verify integrity of firmware image (%Zd)!\n",
3745 goto fail_fw_integrity
;
3747 for (i
= 0; i
< 4; i
++)
3748 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3749 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3750 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3751 wcode
[2] == 0 && wcode
[3] == 0)) {
3752 qla_printk(KERN_WARNING
, ha
,
3753 "Unable to verify integrity of firmware image!\n");
3754 qla_printk(KERN_WARNING
, ha
,
3755 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3756 wcode
[1], wcode
[2], wcode
[3]);
3757 goto fail_fw_integrity
;
3761 while (*seg
&& rval
== QLA_SUCCESS
) {
3763 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3764 risc_size
= be16_to_cpu(fwcode
[3]);
3766 /* Validate firmware image size. */
3767 fwclen
+= risc_size
* sizeof(uint16_t);
3768 if (blob
->fw
->size
< fwclen
) {
3769 qla_printk(KERN_WARNING
, ha
,
3770 "Unable to verify integrity of firmware image "
3771 "(%Zd)!\n", blob
->fw
->size
);
3772 goto fail_fw_integrity
;
3776 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3777 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3778 if (wlen
> risc_size
)
3781 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3782 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3785 for (i
= 0; i
< wlen
; i
++)
3786 wcode
[i
] = swab16(fwcode
[i
]);
3788 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3791 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3792 "segment %d of firmware\n", ha
->host_no
,
3794 qla_printk(KERN_WARNING
, ha
,
3795 "[ERROR] Failed to load segment %d of "
3796 "firmware\n", fragment
);
3812 return QLA_FUNCTION_FAILED
;
3816 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3819 int segments
, fragment
;
3820 uint32_t *dcode
, dlen
;
3824 struct fw_blob
*blob
;
3825 uint32_t *fwcode
, fwclen
;
3827 /* Load firmware blob. */
3828 blob
= qla2x00_request_firmware(ha
);
3830 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3831 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3832 "from: " QLA_FW_URL
".\n");
3834 /* Try to load RISC code from flash. */
3835 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3836 "outdated) firmware from flash.\n");
3837 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3842 segments
= FA_RISC_CODE_SEGMENTS
;
3843 dcode
= (uint32_t *)ha
->request_ring
;
3845 fwcode
= (uint32_t *)blob
->fw
->data
;
3848 /* Validate firmware image by checking version. */
3849 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3850 qla_printk(KERN_WARNING
, ha
,
3851 "Unable to verify integrity of firmware image (%Zd)!\n",
3853 goto fail_fw_integrity
;
3855 for (i
= 0; i
< 4; i
++)
3856 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3857 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3858 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3859 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3861 qla_printk(KERN_WARNING
, ha
,
3862 "Unable to verify integrity of firmware image!\n");
3863 qla_printk(KERN_WARNING
, ha
,
3864 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3865 dcode
[1], dcode
[2], dcode
[3]);
3866 goto fail_fw_integrity
;
3869 while (segments
&& rval
== QLA_SUCCESS
) {
3870 risc_addr
= be32_to_cpu(fwcode
[2]);
3871 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3872 risc_size
= be32_to_cpu(fwcode
[3]);
3874 /* Validate firmware image size. */
3875 fwclen
+= risc_size
* sizeof(uint32_t);
3876 if (blob
->fw
->size
< fwclen
) {
3877 qla_printk(KERN_WARNING
, ha
,
3878 "Unable to verify integrity of firmware image "
3879 "(%Zd)!\n", blob
->fw
->size
);
3881 goto fail_fw_integrity
;
3885 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3886 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3887 if (dlen
> risc_size
)
3890 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3891 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3894 for (i
= 0; i
< dlen
; i
++)
3895 dcode
[i
] = swab32(fwcode
[i
]);
3897 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3900 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3901 "segment %d of firmware\n", ha
->host_no
,
3903 qla_printk(KERN_WARNING
, ha
,
3904 "[ERROR] Failed to load segment %d of "
3905 "firmware\n", fragment
);
3921 return QLA_FUNCTION_FAILED
;
3925 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*ha
)
3929 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
))
3931 if (!ha
->fw_major_version
)
3934 ret
= qla2x00_stop_firmware(ha
);
3935 for (retries
= 5; ret
!= QLA_SUCCESS
&& retries
; retries
--) {
3936 qla2x00_reset_chip(ha
);
3937 if (qla2x00_chip_diag(ha
) != QLA_SUCCESS
)
3939 if (qla2x00_setup_chip(ha
) != QLA_SUCCESS
)
3941 qla_printk(KERN_INFO
, ha
,
3942 "Attempting retry of stop-firmware command...\n");
3943 ret
= qla2x00_stop_firmware(ha
);