2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
10 #include <linux/vmalloc.h>
12 #include "qla_devtbl.h"
14 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
15 #ifndef EXT_IS_LUN_BIT_SET
16 #define EXT_IS_LUN_BIT_SET(P,L) \
17 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
18 #define EXT_SET_LUN_BIT(P,L) \
19 ((P)->mask[L/8] |= (0x80 >> (L%8)))
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
26 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
27 static int qla2x00_setup_chip(scsi_qla_host_t
*);
28 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
29 static int qla2x00_init_rings(scsi_qla_host_t
*);
30 static int qla2x00_fw_ready(scsi_qla_host_t
*);
31 static int qla2x00_configure_hba(scsi_qla_host_t
*);
32 static int qla2x00_configure_loop(scsi_qla_host_t
*);
33 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
34 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
35 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
36 static int qla2x00_device_resync(scsi_qla_host_t
*);
37 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
40 static int qla2x00_restart_isp(scsi_qla_host_t
*);
42 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
63 /* Clear adapter flags. */
65 ha
->flags
.reset_active
= 0;
66 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
67 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
70 ha
->flags
.management_server_logged_in
= 0;
71 ha
->marker_needed
= 0;
73 ha
->isp_abort_cnt
= 0;
74 ha
->beacon_blink_led
= 0;
75 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
77 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
78 rval
= ha
->isp_ops
.pci_config(ha
);
80 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n",
85 ha
->isp_ops
.reset_chip(ha
);
87 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
89 ha
->isp_ops
.nvram_config(ha
);
91 if (ha
->flags
.disable_serdes
) {
92 /* Mask HBA via NVRAM settings? */
93 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
94 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
95 ha
->port_name
[0], ha
->port_name
[1],
96 ha
->port_name
[2], ha
->port_name
[3],
97 ha
->port_name
[4], ha
->port_name
[5],
98 ha
->port_name
[6], ha
->port_name
[7]);
99 return QLA_FUNCTION_FAILED
;
102 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
104 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
105 rval
= ha
->isp_ops
.chip_diag(ha
);
108 rval
= qla2x00_setup_chip(ha
);
112 rval
= qla2x00_init_rings(ha
);
118 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
121 * Returns 0 on success.
124 qla2100_pci_config(scsi_qla_host_t
*ha
)
129 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
131 pci_set_master(ha
->pdev
);
133 if (pci_set_mwi(ha
->pdev
))
134 mwi
= PCI_COMMAND_INVALIDATE
;
136 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
137 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
138 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
140 /* Reset expansion ROM address decode enable */
141 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
142 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
143 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
145 /* Get PCI bus information. */
146 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
147 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
148 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
154 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
157 * Returns 0 on success.
160 qla2300_pci_config(scsi_qla_host_t
*ha
)
164 unsigned long flags
= 0;
166 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
168 pci_set_master(ha
->pdev
);
170 if (pci_set_mwi(ha
->pdev
))
171 mwi
= PCI_COMMAND_INVALIDATE
;
173 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
174 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
176 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
177 w
&= ~PCI_COMMAND_INTX_DISABLE
;
180 * If this is a 2300 card and not 2312, reset the
181 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
182 * the 2310 also reports itself as a 2300 so we need to get the
183 * fb revision level -- a 6 indicates it really is a 2300 and
186 if (IS_QLA2300(ha
)) {
187 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
190 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
191 for (cnt
= 0; cnt
< 30000; cnt
++) {
192 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
198 /* Select FPM registers. */
199 WRT_REG_WORD(®
->ctrl_status
, 0x20);
200 RD_REG_WORD(®
->ctrl_status
);
202 /* Get the fb rev level */
203 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
205 if (ha
->fb_rev
== FPM_2300
)
206 w
&= ~PCI_COMMAND_INVALIDATE
;
208 /* Deselect FPM registers. */
209 WRT_REG_WORD(®
->ctrl_status
, 0x0);
210 RD_REG_WORD(®
->ctrl_status
);
212 /* Release RISC module. */
213 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
214 for (cnt
= 0; cnt
< 30000; cnt
++) {
215 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
221 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
223 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
225 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
227 /* Reset expansion ROM address decode enable */
228 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
229 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
230 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
232 /* Get PCI bus information. */
233 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
234 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
235 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
241 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
244 * Returns 0 on success.
247 qla24xx_pci_config(scsi_qla_host_t
*ha
)
251 unsigned long flags
= 0;
252 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
253 int pcix_cmd_reg
, pcie_dctl_reg
;
255 pci_set_master(ha
->pdev
);
257 if (pci_set_mwi(ha
->pdev
))
258 mwi
= PCI_COMMAND_INVALIDATE
;
260 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
261 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
262 w
&= ~PCI_COMMAND_INTX_DISABLE
;
263 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
265 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
267 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
268 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
272 pcix_cmd_reg
+= PCI_X_CMD
;
273 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
274 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
276 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
280 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
284 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
285 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
286 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
288 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
291 /* Reset expansion ROM address decode enable */
292 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
293 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
294 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
296 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->chip_revision
);
298 /* Get PCI bus information. */
299 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
300 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
301 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
307 * qla2x00_isp_firmware() - Choose firmware image.
310 * Returns 0 on success.
313 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
317 /* Assume loading risc code */
318 rval
= QLA_FUNCTION_FAILED
;
320 if (ha
->flags
.disable_risc_code_load
) {
321 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
323 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
325 /* Verify checksum of loaded RISC code. */
326 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
330 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
338 * qla2x00_reset_chip() - Reset ISP chip.
341 * Returns 0 on success.
344 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
346 unsigned long flags
= 0;
347 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
351 ha
->isp_ops
.disable_intrs(ha
);
353 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
355 /* Turn off master enable */
357 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
358 cmd
&= ~PCI_COMMAND_MASTER
;
359 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
361 if (!IS_QLA2100(ha
)) {
363 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
364 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
365 for (cnt
= 0; cnt
< 30000; cnt
++) {
366 if ((RD_REG_WORD(®
->hccr
) &
367 HCCR_RISC_PAUSE
) != 0)
372 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
376 /* Select FPM registers. */
377 WRT_REG_WORD(®
->ctrl_status
, 0x20);
378 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
380 /* FPM Soft Reset. */
381 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
382 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
384 /* Toggle Fpm Reset. */
385 if (!IS_QLA2200(ha
)) {
386 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
387 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
390 /* Select frame buffer registers. */
391 WRT_REG_WORD(®
->ctrl_status
, 0x10);
392 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
394 /* Reset frame buffer FIFOs. */
395 if (IS_QLA2200(ha
)) {
396 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
397 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
399 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
401 /* Read back fb_cmd until zero or 3 seconds max */
402 for (cnt
= 0; cnt
< 3000; cnt
++) {
403 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
409 /* Select RISC module registers. */
410 WRT_REG_WORD(®
->ctrl_status
, 0);
411 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
413 /* Reset RISC processor. */
414 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
415 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
417 /* Release RISC processor. */
418 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
419 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
422 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
423 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
425 /* Reset ISP chip. */
426 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
428 /* Wait for RISC to recover from reset. */
429 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
431 * It is necessary to for a delay here since the card doesn't
432 * respond to PCI reads during a reset. On some architectures
433 * this will result in an MCA.
436 for (cnt
= 30000; cnt
; cnt
--) {
437 if ((RD_REG_WORD(®
->ctrl_status
) &
438 CSR_ISP_SOFT_RESET
) == 0)
445 /* Reset RISC processor. */
446 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
448 WRT_REG_WORD(®
->semaphore
, 0);
450 /* Release RISC processor. */
451 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
452 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
454 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
455 for (cnt
= 0; cnt
< 30000; cnt
++) {
456 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
464 /* Turn on master enable */
465 cmd
|= PCI_COMMAND_MASTER
;
466 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
468 /* Disable RISC pause on FPM parity error. */
469 if (!IS_QLA2100(ha
)) {
470 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
471 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
474 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
478 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
481 * Returns 0 on success.
484 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
486 unsigned long flags
= 0;
487 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
491 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
494 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
495 for (cnt
= 0; cnt
< 30000; cnt
++) {
496 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
502 WRT_REG_DWORD(®
->ctrl_status
,
503 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
504 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
507 /* Wait for firmware to complete NVRAM accesses. */
508 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
509 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
511 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
515 /* Wait for soft-reset to complete. */
516 d2
= RD_REG_DWORD(®
->ctrl_status
);
517 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
519 d2
= RD_REG_DWORD(®
->ctrl_status
);
523 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
524 RD_REG_DWORD(®
->hccr
);
526 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
527 RD_REG_DWORD(®
->hccr
);
529 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
530 RD_REG_DWORD(®
->hccr
);
532 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
533 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
535 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
539 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
543 * qla24xx_reset_chip() - Reset ISP24xx chip.
546 * Returns 0 on success.
549 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
551 ha
->isp_ops
.disable_intrs(ha
);
553 /* Perform RISC reset. */
554 qla24xx_reset_risc(ha
);
558 * qla2x00_chip_diag() - Test chip for proper operation.
561 * Returns 0 on success.
564 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
567 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
568 unsigned long flags
= 0;
573 /* Assume a failed state */
574 rval
= QLA_FUNCTION_FAILED
;
576 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
577 ha
->host_no
, (u_long
)®
->flash_address
));
579 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
581 /* Reset ISP chip. */
582 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
585 * We need to have a delay here since the card will not respond while
586 * in reset causing an MCA on some architectures.
589 data
= qla2x00_debounce_register(®
->ctrl_status
);
590 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
592 data
= RD_REG_WORD(®
->ctrl_status
);
597 goto chip_diag_failed
;
599 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
602 /* Reset RISC processor. */
603 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
604 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
606 /* Workaround for QLA2312 PCI parity error */
607 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
608 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
609 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
611 data
= RD_MAILBOX_REG(ha
, reg
, 0);
618 goto chip_diag_failed
;
620 /* Check product ID of chip */
621 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
623 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
624 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
625 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
626 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
627 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
628 mb
[3] != PROD_ID_3
) {
629 qla_printk(KERN_WARNING
, ha
,
630 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
632 goto chip_diag_failed
;
634 ha
->product_id
[0] = mb
[1];
635 ha
->product_id
[1] = mb
[2];
636 ha
->product_id
[2] = mb
[3];
637 ha
->product_id
[3] = mb
[4];
639 /* Adjust fw RISC transfer size */
640 if (ha
->request_q_length
> 1024)
641 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
643 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
644 ha
->request_q_length
;
646 if (IS_QLA2200(ha
) &&
647 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
648 /* Limit firmware transfer size with a 2200A */
649 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
652 ha
->device_type
|= DT_ISP2200A
;
653 ha
->fw_transfer_size
= 128;
656 /* Wrap Incoming Mailboxes Test. */
657 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
659 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
660 rval
= qla2x00_mbx_reg_test(ha
);
662 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
664 qla_printk(KERN_WARNING
, ha
,
665 "Failed mailbox send register test\n");
668 /* Flag a successful rval */
671 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
675 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
676 "****\n", ha
->host_no
));
678 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
684 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
687 * Returns 0 on success.
690 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
694 /* Perform RISC reset. */
695 qla24xx_reset_risc(ha
);
697 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
699 rval
= qla2x00_mbx_reg_test(ha
);
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
703 qla_printk(KERN_WARNING
, ha
,
704 "Failed mailbox send register test\n");
706 /* Flag a successful rval */
714 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
717 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
723 qla_printk(KERN_WARNING
, ha
,
724 "Firmware dump previously allocated.\n");
729 fixed_size
= mem_size
= eft_size
= 0;
730 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
731 fixed_size
= sizeof(struct qla2100_fw_dump
);
732 } else if (IS_QLA23XX(ha
)) {
733 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
734 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
736 } else if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
737 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
738 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
741 /* Allocate memory for Extended Trace Buffer. */
742 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
745 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
746 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
750 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
753 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
754 "EFT (%d).\n", rval
);
755 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
760 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
764 memset(eft
, 0, eft_size
);
765 ha
->eft_dma
= eft_dma
;
769 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
770 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
772 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
773 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
776 ha
->fw_dump
= vmalloc(dump_size
);
778 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
779 "firmware dump!!!\n", dump_size
/ 1024);
782 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
790 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
793 ha
->fw_dump_len
= dump_size
;
794 ha
->fw_dump
->signature
[0] = 'Q';
795 ha
->fw_dump
->signature
[1] = 'L';
796 ha
->fw_dump
->signature
[2] = 'G';
797 ha
->fw_dump
->signature
[3] = 'C';
798 ha
->fw_dump
->version
= __constant_htonl(1);
800 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
801 ha
->fw_dump
->mem_size
= htonl(mem_size
);
802 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
803 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
805 ha
->fw_dump
->eft_size
= htonl(eft_size
);
806 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
807 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
809 ha
->fw_dump
->header_size
=
810 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
814 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
817 * Returns 0 on success.
820 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
823 uint16_t fw_iocb_cnt
= 0;
824 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
825 dma_addr_t request_dma
;
826 request_t
*request_ring
;
828 /* Valid only on recent ISPs. */
829 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
832 /* Retrieve IOCB counts available to the firmware. */
833 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
836 /* No point in continuing if current settings are sufficient. */
837 if (fw_iocb_cnt
< 1024)
839 if (ha
->request_q_length
>= request_q_length
)
842 /* Attempt to claim larger area for request queue. */
843 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
844 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
846 if (request_ring
== NULL
)
849 /* Resize successful, report extensions. */
850 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
851 (ha
->fw_memory_size
+ 1) / 1024);
852 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
853 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
855 /* Clear old allocations. */
856 dma_free_coherent(&ha
->pdev
->dev
,
857 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
860 /* Begin using larger queue. */
861 ha
->request_q_length
= request_q_length
;
862 ha
->request_ring
= request_ring
;
863 ha
->request_dma
= request_dma
;
867 * qla2x00_setup_chip() - Load and start RISC firmware.
870 * Returns 0 on success.
873 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
876 uint32_t srisc_address
= 0;
878 /* Load firmware sequences */
879 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
880 if (rval
== QLA_SUCCESS
) {
881 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
882 "code.\n", ha
->host_no
));
884 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
885 if (rval
== QLA_SUCCESS
) {
886 /* Start firmware execution. */
887 DEBUG(printk("scsi(%ld): Checksum OK, start "
888 "firmware.\n", ha
->host_no
));
890 rval
= qla2x00_execute_fw(ha
, srisc_address
);
891 /* Retrieve firmware information. */
892 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
893 qla2x00_get_fw_version(ha
,
894 &ha
->fw_major_version
,
895 &ha
->fw_minor_version
,
896 &ha
->fw_subminor_version
,
897 &ha
->fw_attributes
, &ha
->fw_memory_size
);
898 qla2x00_resize_request_q(ha
);
901 qla2x00_alloc_fw_dump(ha
);
904 DEBUG2(printk(KERN_INFO
905 "scsi(%ld): ISP Firmware failed checksum.\n",
911 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
919 * qla2x00_init_response_q_entries() - Initializes response queue entries.
922 * Beginning of request ring has initialization control block already built
923 * by nvram config routine.
925 * Returns 0 on success.
928 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
933 pkt
= ha
->response_ring_ptr
;
934 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
935 pkt
->signature
= RESPONSE_PROCESSED
;
942 * qla2x00_update_fw_options() - Read and process firmware options.
945 * Returns 0 on success.
948 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
950 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
952 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
953 qla2x00_get_fw_options(ha
, ha
->fw_options
);
955 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
958 /* Serial Link options. */
959 DEBUG3(printk("scsi(%ld): Serial link options:\n",
961 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
962 sizeof(ha
->fw_seriallink_options
)));
964 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
965 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
966 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
969 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
970 emphasis
= (ha
->fw_seriallink_options
[2] &
971 (BIT_4
| BIT_3
)) >> 3;
972 tx_sens
= ha
->fw_seriallink_options
[0] &
973 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
974 rx_sens
= (ha
->fw_seriallink_options
[0] &
975 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
976 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
977 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
980 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
981 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
982 ha
->fw_options
[10] |= BIT_5
|
983 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
984 (tx_sens
& (BIT_1
| BIT_0
));
987 swing
= (ha
->fw_seriallink_options
[2] &
988 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
989 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
990 tx_sens
= ha
->fw_seriallink_options
[1] &
991 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
992 rx_sens
= (ha
->fw_seriallink_options
[1] &
993 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
994 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
995 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
998 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
999 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1000 ha
->fw_options
[11] |= BIT_5
|
1001 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1002 (tx_sens
& (BIT_1
| BIT_0
));
1006 /* Return command IOCBs without waiting for an ABTS to complete. */
1007 ha
->fw_options
[3] |= BIT_13
;
1010 if (ha
->flags
.enable_led_scheme
)
1011 ha
->fw_options
[2] |= BIT_12
;
1013 /* Detect ISP6312. */
1015 ha
->fw_options
[2] |= BIT_13
;
1017 /* Update firmware options. */
1018 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1022 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1026 /* Update Serial Link options. */
1027 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1030 rval
= qla2x00_set_serdes_params(ha
,
1031 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1032 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1033 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1034 if (rval
!= QLA_SUCCESS
) {
1035 qla_printk(KERN_WARNING
, ha
,
1036 "Unable to update Serial Link options (%x).\n", rval
);
1041 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1043 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1045 /* Setup ring parameters in initialization control block. */
1046 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1047 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1048 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1049 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1050 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1051 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1052 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1053 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1055 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1056 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1057 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1058 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1059 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1063 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1065 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1066 struct init_cb_24xx
*icb
;
1068 /* Setup ring parameters in initialization control block. */
1069 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1070 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1071 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1072 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1073 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1074 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1075 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1076 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1077 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1079 WRT_REG_DWORD(®
->req_q_in
, 0);
1080 WRT_REG_DWORD(®
->req_q_out
, 0);
1081 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1082 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1083 RD_REG_DWORD(®
->rsp_q_out
);
1087 * qla2x00_init_rings() - Initializes firmware.
1090 * Beginning of request ring has initialization control block already built
1091 * by nvram config routine.
1093 * Returns 0 on success.
1096 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1099 unsigned long flags
= 0;
1102 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1104 /* Clear outstanding commands array. */
1105 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1106 ha
->outstanding_cmds
[cnt
] = NULL
;
1108 ha
->current_outstanding_cmd
= 0;
1110 /* Clear RSCN queue. */
1111 ha
->rscn_in_ptr
= 0;
1112 ha
->rscn_out_ptr
= 0;
1114 /* Initialize firmware. */
1115 ha
->request_ring_ptr
= ha
->request_ring
;
1116 ha
->req_ring_index
= 0;
1117 ha
->req_q_cnt
= ha
->request_q_length
;
1118 ha
->response_ring_ptr
= ha
->response_ring
;
1119 ha
->rsp_ring_index
= 0;
1121 /* Initialize response queue entries */
1122 qla2x00_init_response_q_entries(ha
);
1124 ha
->isp_ops
.config_rings(ha
);
1126 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1128 /* Update any ISP specific firmware options before initialization. */
1129 ha
->isp_ops
.update_fw_options(ha
);
1131 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1132 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1134 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1137 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1145 * qla2x00_fw_ready() - Waits for firmware ready.
1148 * Returns 0 on success.
1151 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1154 unsigned long wtime
, mtime
;
1155 uint16_t min_wait
; /* Minimum wait time if loop is down */
1156 uint16_t wait_time
; /* Wait time if loop is coming ready */
1161 /* 20 seconds for loop down. */
1165 * Firmware should take at most one RATOV to login, plus 5 seconds for
1166 * our own processing.
1168 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1169 wait_time
= min_wait
;
1172 /* Min wait time if loop down */
1173 mtime
= jiffies
+ (min_wait
* HZ
);
1175 /* wait time before firmware ready */
1176 wtime
= jiffies
+ (wait_time
* HZ
);
1178 /* Wait for ISP to finish LIP */
1179 if (!ha
->flags
.init_done
)
1180 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1182 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1186 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1187 if (rval
== QLA_SUCCESS
) {
1188 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1189 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1191 if (fw_state
== FSTATE_READY
) {
1192 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1195 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1196 &ha
->login_timeout
, &ha
->r_a_tov
);
1202 rval
= QLA_FUNCTION_FAILED
;
1204 if (atomic_read(&ha
->loop_down_timer
) &&
1205 fw_state
!= FSTATE_READY
) {
1206 /* Loop down. Timeout on min_wait for states
1207 * other than Wait for Login.
1209 if (time_after_eq(jiffies
, mtime
)) {
1210 qla_printk(KERN_INFO
, ha
,
1211 "Cable is unplugged...\n");
1213 ha
->device_flags
|= DFLG_NO_CABLE
;
1218 /* Mailbox cmd failed. Timeout on min_wait. */
1219 if (time_after_eq(jiffies
, mtime
))
1223 if (time_after_eq(jiffies
, wtime
))
1226 /* Delay for a while */
1229 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1230 ha
->host_no
, fw_state
, jiffies
));
1233 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1234 ha
->host_no
, fw_state
, jiffies
));
1237 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1245 * qla2x00_configure_hba
1246 * Setup adapter context.
1249 * ha = adapter state pointer.
1258 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1266 char connect_type
[22];
1268 /* Get host addresses. */
1269 rval
= qla2x00_get_adapter_id(ha
,
1270 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1271 if (rval
!= QLA_SUCCESS
) {
1272 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1273 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1274 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1275 __func__
, ha
->host_no
));
1277 qla_printk(KERN_WARNING
, ha
,
1278 "ERROR -- Unable to get host loop ID.\n");
1279 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1285 qla_printk(KERN_INFO
, ha
,
1286 "Cannot get topology - retrying.\n");
1287 return (QLA_FUNCTION_FAILED
);
1290 ha
->loop_id
= loop_id
;
1293 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1294 ha
->operating_mode
= LOOP
;
1298 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1300 ha
->current_topology
= ISP_CFG_NL
;
1301 strcpy(connect_type
, "(Loop)");
1305 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1307 ha
->current_topology
= ISP_CFG_FL
;
1308 strcpy(connect_type
, "(FL_Port)");
1312 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1314 ha
->operating_mode
= P2P
;
1315 ha
->current_topology
= ISP_CFG_N
;
1316 strcpy(connect_type
, "(N_Port-to-N_Port)");
1320 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1322 ha
->operating_mode
= P2P
;
1323 ha
->current_topology
= ISP_CFG_F
;
1324 strcpy(connect_type
, "(F_Port)");
1328 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1330 ha
->host_no
, topo
));
1331 ha
->current_topology
= ISP_CFG_NL
;
1332 strcpy(connect_type
, "(Loop)");
1336 /* Save Host port and loop ID. */
1337 /* byte order - Big Endian */
1338 ha
->d_id
.b
.domain
= domain
;
1339 ha
->d_id
.b
.area
= area
;
1340 ha
->d_id
.b
.al_pa
= al_pa
;
1342 if (!ha
->flags
.init_done
)
1343 qla_printk(KERN_INFO
, ha
,
1344 "Topology - %s, Host Loop address 0x%x\n",
1345 connect_type
, ha
->loop_id
);
1348 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1350 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1357 * NVRAM configuration for ISP 2xxx
1360 * ha = adapter block pointer.
1363 * initialization control block in response_ring
1364 * host adapters parameters in host adapter block
1370 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1375 uint8_t *dptr1
, *dptr2
;
1376 init_cb_t
*icb
= ha
->init_cb
;
1377 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1378 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1379 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1383 /* Determine NVRAM starting address. */
1384 ha
->nvram_size
= sizeof(nvram_t
);
1386 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1387 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1388 ha
->nvram_base
= 0x80;
1390 /* Get NVRAM data and calculate checksum. */
1391 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1392 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1395 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1396 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1399 /* Bad NVRAM data, set defaults parameters. */
1400 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1401 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1402 /* Reset NVRAM data. */
1403 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1404 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1406 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1407 "invalid -- WWPN) defaults.\n");
1410 * Set default initialization control block.
1412 memset(nv
, 0, ha
->nvram_size
);
1413 nv
->parameter_block_version
= ICB_VERSION
;
1415 if (IS_QLA23XX(ha
)) {
1416 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1417 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1418 nv
->add_firmware_options
[0] = BIT_5
;
1419 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1420 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1421 nv
->special_options
[1] = BIT_7
;
1422 } else if (IS_QLA2200(ha
)) {
1423 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1424 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1425 nv
->add_firmware_options
[0] = BIT_5
;
1426 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1427 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1428 } else if (IS_QLA2100(ha
)) {
1429 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1430 nv
->firmware_options
[1] = BIT_5
;
1431 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1434 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1435 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1436 nv
->retry_count
= 8;
1437 nv
->retry_delay
= 1;
1439 nv
->port_name
[0] = 33;
1440 nv
->port_name
[3] = 224;
1441 nv
->port_name
[4] = 139;
1443 nv
->login_timeout
= 4;
1446 * Set default host adapter parameters
1448 nv
->host_p
[1] = BIT_2
;
1449 nv
->reset_delay
= 5;
1450 nv
->port_down_retry_count
= 8;
1451 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1452 nv
->link_down_timeout
= 60;
1457 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1459 * The SN2 does not provide BIOS emulation which means you can't change
1460 * potentially bogus BIOS settings. Force the use of default settings
1461 * for link rate and frame size. Hope that the rest of the settings
1464 if (ia64_platform_is("sn2")) {
1465 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1467 nv
->special_options
[1] = BIT_7
;
1471 /* Reset Initialization control block */
1472 memset(icb
, 0, ha
->init_cb_size
);
1475 * Setup driver NVRAM options.
1477 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1478 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1479 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1480 nv
->firmware_options
[1] &= ~BIT_4
;
1482 if (IS_QLA23XX(ha
)) {
1483 nv
->firmware_options
[0] |= BIT_2
;
1484 nv
->firmware_options
[0] &= ~BIT_3
;
1485 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1487 if (IS_QLA2300(ha
)) {
1488 if (ha
->fb_rev
== FPM_2310
) {
1489 strcpy(ha
->model_number
, "QLA2310");
1491 strcpy(ha
->model_number
, "QLA2300");
1495 memcmp(nv
->model_number
, BINZERO
,
1496 sizeof(nv
->model_number
)) != 0) {
1499 strncpy(ha
->model_number
, nv
->model_number
,
1500 sizeof(nv
->model_number
));
1501 st
= en
= ha
->model_number
;
1502 en
+= sizeof(nv
->model_number
) - 1;
1504 if (*en
!= 0x20 && *en
!= 0x00)
1511 index
= (ha
->pdev
->subsystem_device
& 0xff);
1512 if (index
< QLA_MODEL_NAMES
) {
1513 strcpy(ha
->model_number
,
1514 qla2x00_model_name
[index
* 2]);
1516 qla2x00_model_name
[index
* 2 + 1];
1518 strcpy(ha
->model_number
, "QLA23xx");
1522 } else if (IS_QLA2200(ha
)) {
1523 nv
->firmware_options
[0] |= BIT_2
;
1525 * 'Point-to-point preferred, else loop' is not a safe
1526 * connection mode setting.
1528 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1530 /* Force 'loop preferred, else point-to-point'. */
1531 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1532 nv
->add_firmware_options
[0] |= BIT_5
;
1534 strcpy(ha
->model_number
, "QLA22xx");
1535 } else /*if (IS_QLA2100(ha))*/ {
1536 strcpy(ha
->model_number
, "QLA2100");
1540 * Copy over NVRAM RISC parameter block to initialization control block.
1542 dptr1
= (uint8_t *)icb
;
1543 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1544 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1546 *dptr1
++ = *dptr2
++;
1548 /* Copy 2nd half. */
1549 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1550 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1552 *dptr1
++ = *dptr2
++;
1554 /* Use alternate WWN? */
1555 if (nv
->host_p
[1] & BIT_7
) {
1556 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1557 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1560 /* Prepare nodename */
1561 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1563 * Firmware will apply the following mask if the nodename was
1566 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1567 icb
->node_name
[0] &= 0xF0;
1571 * Set host adapter parameters.
1573 if (nv
->host_p
[0] & BIT_7
)
1574 ql2xextended_error_logging
= 1;
1575 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1576 /* Always load RISC code on non ISP2[12]00 chips. */
1577 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1578 ha
->flags
.disable_risc_code_load
= 0;
1579 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1580 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1581 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1582 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1583 ha
->flags
.disable_serdes
= 0;
1585 ha
->operating_mode
=
1586 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1588 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1589 sizeof(ha
->fw_seriallink_options
));
1591 /* save HBA serial number */
1592 ha
->serial0
= icb
->port_name
[5];
1593 ha
->serial1
= icb
->port_name
[6];
1594 ha
->serial2
= icb
->port_name
[7];
1595 ha
->node_name
= icb
->node_name
;
1596 ha
->port_name
= icb
->port_name
;
1598 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1600 ha
->retry_count
= nv
->retry_count
;
1602 /* Set minimum login_timeout to 4 seconds. */
1603 if (nv
->login_timeout
< ql2xlogintimeout
)
1604 nv
->login_timeout
= ql2xlogintimeout
;
1605 if (nv
->login_timeout
< 4)
1606 nv
->login_timeout
= 4;
1607 ha
->login_timeout
= nv
->login_timeout
;
1608 icb
->login_timeout
= nv
->login_timeout
;
1610 /* Set minimum RATOV to 200 tenths of a second. */
1613 ha
->loop_reset_delay
= nv
->reset_delay
;
1615 /* Link Down Timeout = 0:
1617 * When Port Down timer expires we will start returning
1618 * I/O's to OS with "DID_NO_CONNECT".
1620 * Link Down Timeout != 0:
1622 * The driver waits for the link to come up after link down
1623 * before returning I/Os to OS with "DID_NO_CONNECT".
1625 if (nv
->link_down_timeout
== 0) {
1626 ha
->loop_down_abort_time
=
1627 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1629 ha
->link_down_timeout
= nv
->link_down_timeout
;
1630 ha
->loop_down_abort_time
=
1631 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1635 * Need enough time to try and get the port back.
1637 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1638 if (qlport_down_retry
)
1639 ha
->port_down_retry_count
= qlport_down_retry
;
1640 /* Set login_retry_count */
1641 ha
->login_retry_count
= nv
->retry_count
;
1642 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1643 ha
->port_down_retry_count
> 3)
1644 ha
->login_retry_count
= ha
->port_down_retry_count
;
1645 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1646 ha
->login_retry_count
= ha
->port_down_retry_count
;
1647 if (ql2xloginretrycount
)
1648 ha
->login_retry_count
= ql2xloginretrycount
;
1650 icb
->lun_enables
= __constant_cpu_to_le16(0);
1651 icb
->command_resource_count
= 0;
1652 icb
->immediate_notify_resource_count
= 0;
1653 icb
->timeout
= __constant_cpu_to_le16(0);
1655 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1657 icb
->firmware_options
[0] &= ~BIT_3
;
1658 icb
->add_firmware_options
[0] &=
1659 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1660 icb
->add_firmware_options
[0] |= BIT_2
;
1661 icb
->response_accumulation_timer
= 3;
1662 icb
->interrupt_delay_timer
= 5;
1664 ha
->flags
.process_response_queue
= 1;
1667 if (!ha
->flags
.init_done
) {
1668 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1669 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1670 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1671 icb
->interrupt_delay_timer
: 2;
1673 icb
->add_firmware_options
[0] &=
1674 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1675 ha
->flags
.process_response_queue
= 0;
1676 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1677 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1679 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1680 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1681 ha
->zio_timer
* 100));
1682 qla_printk(KERN_INFO
, ha
,
1683 "ZIO mode %d enabled; timer delay (%d us).\n",
1684 ha
->zio_mode
, ha
->zio_timer
* 100);
1686 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1687 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1688 ha
->flags
.process_response_queue
= 1;
1693 DEBUG2_3(printk(KERN_WARNING
1694 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1700 qla2x00_rport_del(void *data
)
1702 fc_port_t
*fcport
= data
;
1703 struct fc_rport
*rport
;
1704 unsigned long flags
;
1706 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1707 rport
= fcport
->drport
;
1708 fcport
->drport
= NULL
;
1709 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1711 fc_remote_port_delete(rport
);
1716 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1718 * @flags: allocation flags
1720 * Returns a pointer to the allocated fcport, or NULL, if none available.
1723 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1727 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1731 /* Setup fcport template structure. */
1732 memset(fcport
, 0, sizeof (fc_port_t
));
1734 fcport
->port_type
= FCT_UNKNOWN
;
1735 fcport
->loop_id
= FC_NO_LOOP_ID
;
1736 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1737 fcport
->flags
= FCF_RLC_SUPPORT
;
1738 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1739 spin_lock_init(&fcport
->rport_lock
);
1745 * qla2x00_configure_loop
1746 * Updates Fibre Channel Device Database with what is actually on loop.
1749 * ha = adapter block pointer.
1754 * 2 = database was full and device was not configured.
1757 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1760 unsigned long flags
, save_flags
;
1764 /* Get Initiator ID */
1765 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1766 rval
= qla2x00_configure_hba(ha
);
1767 if (rval
!= QLA_SUCCESS
) {
1768 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1774 save_flags
= flags
= ha
->dpc_flags
;
1775 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1776 ha
->host_no
, flags
));
1779 * If we have both an RSCN and PORT UPDATE pending then handle them
1780 * both at the same time.
1782 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1783 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1785 /* Determine what we need to do */
1786 if (ha
->current_topology
== ISP_CFG_FL
&&
1787 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1789 ha
->flags
.rscn_queue_overflow
= 1;
1790 set_bit(RSCN_UPDATE
, &flags
);
1792 } else if (ha
->current_topology
== ISP_CFG_F
&&
1793 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1795 ha
->flags
.rscn_queue_overflow
= 1;
1796 set_bit(RSCN_UPDATE
, &flags
);
1797 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1799 } else if (ha
->current_topology
== ISP_CFG_N
) {
1800 clear_bit(RSCN_UPDATE
, &flags
);
1802 } else if (!ha
->flags
.online
||
1803 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1805 ha
->flags
.rscn_queue_overflow
= 1;
1806 set_bit(RSCN_UPDATE
, &flags
);
1807 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1810 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1811 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1812 rval
= QLA_FUNCTION_FAILED
;
1814 rval
= qla2x00_configure_local_loop(ha
);
1818 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1819 if (LOOP_TRANSITION(ha
)) {
1820 rval
= QLA_FUNCTION_FAILED
;
1822 rval
= qla2x00_configure_fabric(ha
);
1826 if (rval
== QLA_SUCCESS
) {
1827 if (atomic_read(&ha
->loop_down_timer
) ||
1828 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1829 rval
= QLA_FUNCTION_FAILED
;
1831 atomic_set(&ha
->loop_state
, LOOP_READY
);
1833 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1838 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1839 __func__
, ha
->host_no
));
1841 DEBUG3(printk("%s: exiting normally\n", __func__
));
1844 /* Restore state if a resync event occured during processing */
1845 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1846 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1847 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1848 if (test_bit(RSCN_UPDATE
, &save_flags
))
1849 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1858 * qla2x00_configure_local_loop
1859 * Updates Fibre Channel Device Database with local loop devices.
1862 * ha = adapter block pointer.
1868 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1873 fc_port_t
*fcport
, *new_fcport
;
1879 uint8_t domain
, area
, al_pa
;
1883 entries
= MAX_FIBRE_DEVICES
;
1885 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1886 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1888 /* Get list of logged in devices. */
1889 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1890 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1892 if (rval
!= QLA_SUCCESS
)
1893 goto cleanup_allocation
;
1895 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1896 ha
->host_no
, entries
));
1897 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1898 entries
* sizeof(struct gid_list_info
)));
1900 /* Allocate temporary fcport for any new fcports discovered. */
1901 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1902 if (new_fcport
== NULL
) {
1903 rval
= QLA_MEMORY_ALLOC_FAILED
;
1904 goto cleanup_allocation
;
1906 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1909 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1911 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1912 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1913 fcport
->port_type
!= FCT_BROADCAST
&&
1914 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1916 DEBUG(printk("scsi(%ld): Marking port lost, "
1918 ha
->host_no
, fcport
->loop_id
));
1920 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1921 fcport
->flags
&= ~FCF_FARP_DONE
;
1925 /* Add devices to port list. */
1926 id_iter
= (char *)ha
->gid_list
;
1927 for (index
= 0; index
< entries
; index
++) {
1928 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1929 area
= ((struct gid_list_info
*)id_iter
)->area
;
1930 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1931 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1932 loop_id
= (uint16_t)
1933 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1935 loop_id
= le16_to_cpu(
1936 ((struct gid_list_info
*)id_iter
)->loop_id
);
1937 id_iter
+= ha
->gid_list_info_size
;
1939 /* Bypass reserved domain fields. */
1940 if ((domain
& 0xf0) == 0xf0)
1943 /* Bypass if not same domain and area of adapter. */
1944 if (area
&& domain
&&
1945 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
1948 /* Bypass invalid local loop ID. */
1949 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1952 /* Fill in member data. */
1953 new_fcport
->d_id
.b
.domain
= domain
;
1954 new_fcport
->d_id
.b
.area
= area
;
1955 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1956 new_fcport
->loop_id
= loop_id
;
1957 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1958 if (rval2
!= QLA_SUCCESS
) {
1959 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1960 "information -- get_port_database=%x, "
1962 ha
->host_no
, rval2
, new_fcport
->loop_id
));
1963 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
1965 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
1969 /* Check for matching device in port list. */
1972 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1973 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
1977 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
1978 FCF_PERSISTENT_BOUND
);
1979 fcport
->loop_id
= new_fcport
->loop_id
;
1980 fcport
->port_type
= new_fcport
->port_type
;
1981 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
1982 memcpy(fcport
->node_name
, new_fcport
->node_name
,
1990 /* New device, add to fcports list. */
1991 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
1992 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
1994 /* Allocate a new replacement fcport. */
1995 fcport
= new_fcport
;
1996 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1997 if (new_fcport
== NULL
) {
1998 rval
= QLA_MEMORY_ALLOC_FAILED
;
1999 goto cleanup_allocation
;
2001 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2004 /* Base iIDMA settings on HBA port speed. */
2005 switch (ha
->link_data_rate
) {
2006 case PORT_SPEED_1GB
:
2007 fcport
->fp_speed
= cpu_to_be16(BIT_15
);
2009 case PORT_SPEED_2GB
:
2010 fcport
->fp_speed
= cpu_to_be16(BIT_14
);
2012 case PORT_SPEED_4GB
:
2013 fcport
->fp_speed
= cpu_to_be16(BIT_13
);
2017 qla2x00_update_fcport(ha
, fcport
);
2025 if (rval
!= QLA_SUCCESS
) {
2026 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2027 "rval=%x\n", ha
->host_no
, rval
));
2031 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2032 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2039 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2043 qla2x00_mark_all_devices_lost(ha
, 0);
2044 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2045 if (fcport
->port_type
!= FCT_TARGET
)
2048 qla2x00_update_fcport(ha
, fcport
);
2053 qla2x00_iidma_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2055 #define LS_UNKNOWN 2
2056 static char *link_speeds
[5] = { "1", "2", "?", "4" };
2058 uint16_t port_speed
, mb
[6];
2060 if (!IS_QLA24XX(ha
))
2063 switch (be16_to_cpu(fcport
->fp_speed
)) {
2065 port_speed
= PORT_SPEED_1GB
;
2068 port_speed
= PORT_SPEED_2GB
;
2071 port_speed
= PORT_SPEED_4GB
;
2074 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2075 "unsupported FM port operating speed (%04x).\n",
2076 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2077 fcport
->port_name
[2], fcport
->port_name
[3],
2078 fcport
->port_name
[4], fcport
->port_name
[5],
2079 fcport
->port_name
[6], fcport
->port_name
[7],
2080 be16_to_cpu(fcport
->fp_speed
)));
2081 port_speed
= PORT_SPEED_UNKNOWN
;
2084 if (port_speed
== PORT_SPEED_UNKNOWN
)
2087 rval
= qla2x00_set_idma_speed(ha
, fcport
->loop_id
, port_speed
, mb
);
2088 if (rval
!= QLA_SUCCESS
) {
2089 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2090 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2091 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2092 fcport
->port_name
[2], fcport
->port_name
[3],
2093 fcport
->port_name
[4], fcport
->port_name
[5],
2094 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2095 port_speed
, mb
[0], mb
[1]));
2097 DEBUG2(qla_printk(KERN_INFO
, ha
,
2098 "iIDMA adjusted to %s GB/s on "
2099 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2100 link_speeds
[port_speed
], fcport
->port_name
[0],
2101 fcport
->port_name
[1], fcport
->port_name
[2],
2102 fcport
->port_name
[3], fcport
->port_name
[4],
2103 fcport
->port_name
[5], fcport
->port_name
[6],
2104 fcport
->port_name
[7]));
2109 * qla2x00_update_fcport
2110 * Updates device on list.
2113 * ha = adapter block pointer.
2114 * fcport = port structure pointer.
2124 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2127 fcport
->login_retry
= 0;
2128 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2130 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2132 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2134 qla2x00_iidma_fcport(ha
, fcport
);
2136 atomic_set(&fcport
->state
, FCS_ONLINE
);
2138 qla2x00_reg_remote_port(ha
, fcport
);
2142 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2144 struct fc_rport_identifiers rport_ids
;
2145 struct fc_rport
*rport
;
2146 unsigned long flags
;
2149 qla2x00_rport_del(fcport
);
2153 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2154 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2155 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2156 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2157 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2158 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2160 qla_printk(KERN_WARNING
, ha
,
2161 "Unable to allocate fc remote port!\n");
2164 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2165 fcport
->rport
= rport
;
2166 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2167 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2169 rport
->supported_classes
= fcport
->supported_classes
;
2171 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2172 if (fcport
->port_type
== FCT_INITIATOR
)
2173 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2174 if (fcport
->port_type
== FCT_TARGET
)
2175 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2176 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2178 if (rport
->scsi_target_id
!= -1 &&
2179 rport
->scsi_target_id
< ha
->host
->max_id
)
2180 fcport
->os_target_id
= rport
->scsi_target_id
;
2184 * qla2x00_configure_fabric
2185 * Setup SNS devices with loop ID's.
2188 * ha = adapter block pointer.
2195 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2198 fc_port_t
*fcport
, *fcptemp
;
2199 uint16_t next_loopid
;
2200 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2202 LIST_HEAD(new_fcports
);
2204 /* If FL port exists, then SNS is present */
2205 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2206 loop_id
= NPH_F_PORT
;
2208 loop_id
= SNS_FL_PORT
;
2209 rval
= qla2x00_get_port_name(ha
, loop_id
, ha
->fabric_node_name
, 1);
2210 if (rval
!= QLA_SUCCESS
) {
2211 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2212 "Port\n", ha
->host_no
));
2214 ha
->device_flags
&= ~SWITCH_FOUND
;
2215 return (QLA_SUCCESS
);
2217 ha
->device_flags
|= SWITCH_FOUND
;
2219 /* Mark devices that need re-synchronization. */
2220 rval2
= qla2x00_device_resync(ha
);
2221 if (rval2
== QLA_RSCNS_HANDLED
) {
2222 /* No point doing the scan, just continue. */
2223 return (QLA_SUCCESS
);
2227 if (ql2xfdmienable
&&
2228 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2229 qla2x00_fdmi_register(ha
);
2231 /* Ensure we are logged into the SNS. */
2232 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2235 loop_id
= SIMPLE_NAME_SERVER
;
2236 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2237 0xfc, mb
, BIT_1
| BIT_0
);
2238 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2239 DEBUG2(qla_printk(KERN_INFO
, ha
,
2240 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2241 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2242 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2243 return (QLA_SUCCESS
);
2246 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2247 if (qla2x00_rft_id(ha
)) {
2249 DEBUG2(printk("scsi(%ld): Register FC-4 "
2250 "TYPE failed.\n", ha
->host_no
));
2252 if (qla2x00_rff_id(ha
)) {
2254 DEBUG2(printk("scsi(%ld): Register FC-4 "
2255 "Features failed.\n", ha
->host_no
));
2257 if (qla2x00_rnn_id(ha
)) {
2259 DEBUG2(printk("scsi(%ld): Register Node Name "
2260 "failed.\n", ha
->host_no
));
2261 } else if (qla2x00_rsnn_nn(ha
)) {
2263 DEBUG2(printk("scsi(%ld): Register Symbolic "
2264 "Node Name failed.\n", ha
->host_no
));
2268 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2269 if (rval
!= QLA_SUCCESS
)
2273 * Logout all previous fabric devices marked lost, except
2276 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2277 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2280 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2283 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2284 qla2x00_mark_device_lost(ha
, fcport
,
2285 ql2xplogiabsentdevice
, 0);
2286 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2287 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2288 fcport
->port_type
!= FCT_INITIATOR
&&
2289 fcport
->port_type
!= FCT_BROADCAST
) {
2290 ha
->isp_ops
.fabric_logout(ha
,
2292 fcport
->d_id
.b
.domain
,
2293 fcport
->d_id
.b
.area
,
2294 fcport
->d_id
.b
.al_pa
);
2295 fcport
->loop_id
= FC_NO_LOOP_ID
;
2300 /* Starting free loop ID. */
2301 next_loopid
= ha
->min_external_loopid
;
2304 * Scan through our port list and login entries that need to be
2307 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2308 if (atomic_read(&ha
->loop_down_timer
) ||
2309 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2312 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2313 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2316 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2317 fcport
->loop_id
= next_loopid
;
2318 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2319 if (rval
!= QLA_SUCCESS
) {
2320 /* Ran out of IDs to use */
2324 /* Login and update database */
2325 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2328 /* Exit if out of loop IDs. */
2329 if (rval
!= QLA_SUCCESS
) {
2334 * Login and add the new devices to our port list.
2336 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2337 if (atomic_read(&ha
->loop_down_timer
) ||
2338 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2341 /* Find a new loop ID to use. */
2342 fcport
->loop_id
= next_loopid
;
2343 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2344 if (rval
!= QLA_SUCCESS
) {
2345 /* Ran out of IDs to use */
2349 /* Remove device from the new list and add it to DB */
2350 list_move_tail(&fcport
->list
, &ha
->fcports
);
2352 /* Login and update database */
2353 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2357 /* Free all new device structures not processed. */
2358 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2359 list_del(&fcport
->list
);
2364 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2365 "rval=%d\n", ha
->host_no
, rval
));
2373 * qla2x00_find_all_fabric_devs
2376 * ha = adapter block pointer.
2377 * dev = database device entry pointer.
2386 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2390 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2395 int first_dev
, last_dev
;
2396 port_id_t wrap
, nxt_d_id
;
2400 /* Try GID_PT to get device list, else GAN. */
2401 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2404 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2405 "on GA_NXT\n", ha
->host_no
));
2407 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2408 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2411 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2414 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2417 } else if (qla2x00_gfpn_id(ha
, swl
) == QLA_SUCCESS
) {
2418 qla2x00_gpsc(ha
, swl
);
2423 /* Allocate temporary fcport for any new fcports discovered. */
2424 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2425 if (new_fcport
== NULL
) {
2427 return (QLA_MEMORY_ALLOC_FAILED
);
2429 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2431 /* Set start port ID scan at adapter ID. */
2435 /* Starting free loop ID. */
2436 loop_id
= ha
->min_external_loopid
;
2437 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2438 if (qla2x00_is_reserved_id(ha
, loop_id
))
2441 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2446 wrap
.b24
= new_fcport
->d_id
.b24
;
2448 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2449 memcpy(new_fcport
->node_name
,
2450 swl
[swl_idx
].node_name
, WWN_SIZE
);
2451 memcpy(new_fcport
->port_name
,
2452 swl
[swl_idx
].port_name
, WWN_SIZE
);
2453 memcpy(new_fcport
->fabric_port_name
,
2454 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2455 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2457 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2463 /* Send GA_NXT to the switch */
2464 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2465 if (rval
!= QLA_SUCCESS
) {
2466 qla_printk(KERN_WARNING
, ha
,
2467 "SNS scan failed -- assuming zero-entry "
2469 list_for_each_entry_safe(fcport
, fcptemp
,
2470 new_fcports
, list
) {
2471 list_del(&fcport
->list
);
2479 /* If wrap on switch device list, exit. */
2481 wrap
.b24
= new_fcport
->d_id
.b24
;
2483 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2484 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2485 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2486 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2490 /* Bypass if host adapter. */
2491 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2494 /* Bypass if same domain and area of adapter. */
2495 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2496 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2500 /* Bypass reserved domain fields. */
2501 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2504 /* Locate matching device in database. */
2506 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2507 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2513 /* Update port state. */
2514 memcpy(fcport
->fabric_port_name
,
2515 new_fcport
->fabric_port_name
, WWN_SIZE
);
2516 fcport
->fp_speed
= new_fcport
->fp_speed
;
2519 * If address the same and state FCS_ONLINE, nothing
2522 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2523 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2528 * If device was not a fabric device before.
2530 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2531 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2532 fcport
->loop_id
= FC_NO_LOOP_ID
;
2533 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2535 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2540 * Port ID changed or device was marked to be updated;
2541 * Log it out if still logged in and mark it for
2544 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2545 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2546 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2547 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2548 fcport
->port_type
!= FCT_INITIATOR
&&
2549 fcport
->port_type
!= FCT_BROADCAST
) {
2550 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2551 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2552 fcport
->d_id
.b
.al_pa
);
2553 fcport
->loop_id
= FC_NO_LOOP_ID
;
2562 /* If device was not in our fcports list, then add it. */
2563 list_add_tail(&new_fcport
->list
, new_fcports
);
2565 /* Allocate a new replacement fcport. */
2566 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2567 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2568 if (new_fcport
== NULL
) {
2570 return (QLA_MEMORY_ALLOC_FAILED
);
2572 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2573 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2579 if (!list_empty(new_fcports
))
2580 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2586 * qla2x00_find_new_loop_id
2587 * Scan through our port list and find a new usable loop ID.
2590 * ha: adapter state pointer.
2591 * dev: port structure pointer.
2594 * qla2x00 local function return status code.
2600 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2605 uint16_t first_loop_id
;
2609 /* Save starting loop ID. */
2610 first_loop_id
= dev
->loop_id
;
2613 /* Skip loop ID if already used by adapter. */
2614 if (dev
->loop_id
== ha
->loop_id
) {
2618 /* Skip reserved loop IDs. */
2619 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2623 /* Reset loop ID if passed the end. */
2624 if (dev
->loop_id
> ha
->last_loop_id
) {
2625 /* first loop ID. */
2626 dev
->loop_id
= ha
->min_external_loopid
;
2629 /* Check for loop ID being already in use. */
2632 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2633 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2634 /* ID possibly in use */
2640 /* If not in use then it is free to use. */
2645 /* ID in use. Try next value. */
2648 /* If wrap around. No free ID to use. */
2649 if (dev
->loop_id
== first_loop_id
) {
2650 dev
->loop_id
= FC_NO_LOOP_ID
;
2651 rval
= QLA_FUNCTION_FAILED
;
2660 * qla2x00_device_resync
2661 * Marks devices in the database that needs resynchronization.
2664 * ha = adapter block pointer.
2670 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2675 uint32_t rscn_entry
;
2676 uint8_t rscn_out_iter
;
2680 rval
= QLA_RSCNS_HANDLED
;
2682 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2683 ha
->flags
.rscn_queue_overflow
) {
2685 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2686 format
= MSB(MSW(rscn_entry
));
2687 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2688 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2689 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2691 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2692 "[%02x/%02x%02x%02x].\n",
2693 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2694 d_id
.b
.area
, d_id
.b
.al_pa
));
2697 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2698 ha
->rscn_out_ptr
= 0;
2700 /* Skip duplicate entries. */
2701 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2702 !ha
->flags
.rscn_queue_overflow
&&
2703 rscn_out_iter
!= ha
->rscn_in_ptr
;
2704 rscn_out_iter
= (rscn_out_iter
==
2705 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2707 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2710 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2711 "entry found at [%d].\n", ha
->host_no
,
2714 ha
->rscn_out_ptr
= rscn_out_iter
;
2717 /* Queue overflow, set switch default case. */
2718 if (ha
->flags
.rscn_queue_overflow
) {
2719 DEBUG(printk("scsi(%ld): device_resync: rscn "
2720 "overflow.\n", ha
->host_no
));
2723 ha
->flags
.rscn_queue_overflow
= 0;
2739 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2745 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2746 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2747 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2748 fcport
->port_type
== FCT_BROADCAST
)
2751 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2753 fcport
->port_type
!= FCT_INITIATOR
) {
2754 qla2x00_mark_device_lost(ha
, fcport
,
2758 fcport
->flags
&= ~FCF_FARP_DONE
;
2765 * qla2x00_fabric_dev_login
2766 * Login fabric target device and update FC port database.
2769 * ha: adapter state pointer.
2770 * fcport: port structure list pointer.
2771 * next_loopid: contains value of a new loop ID that can be used
2772 * by the next login attempt.
2775 * qla2x00 local function return status code.
2781 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2782 uint16_t *next_loopid
)
2791 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2792 if (rval
== QLA_SUCCESS
) {
2793 /* Send an ADISC to tape devices.*/
2795 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2797 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2798 if (rval
!= QLA_SUCCESS
) {
2799 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2800 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2801 fcport
->d_id
.b
.al_pa
);
2802 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2804 qla2x00_update_fcport(ha
, fcport
);
2812 * qla2x00_fabric_login
2813 * Issue fabric login command.
2816 * ha = adapter block pointer.
2817 * device = pointer to FC device type structure.
2820 * 0 - Login successfully
2822 * 2 - Initiator device
2826 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2827 uint16_t *next_loopid
)
2831 uint16_t tmp_loopid
;
2832 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2838 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2839 "for port %02x%02x%02x.\n",
2840 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2841 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2843 /* Login fcport on switch. */
2844 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2845 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2846 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2847 if (mb
[0] == MBS_PORT_ID_USED
) {
2849 * Device has another loop ID. The firmware team
2850 * recommends the driver perform an implicit login with
2851 * the specified ID again. The ID we just used is save
2852 * here so we return with an ID that can be tried by
2856 tmp_loopid
= fcport
->loop_id
;
2857 fcport
->loop_id
= mb
[1];
2859 DEBUG(printk("Fabric Login: port in use - next "
2860 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2861 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2862 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2864 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2869 /* A retry occurred before. */
2870 *next_loopid
= tmp_loopid
;
2873 * No retry occurred before. Just increment the
2874 * ID value for next login.
2876 *next_loopid
= (fcport
->loop_id
+ 1);
2879 if (mb
[1] & BIT_0
) {
2880 fcport
->port_type
= FCT_INITIATOR
;
2882 fcport
->port_type
= FCT_TARGET
;
2883 if (mb
[1] & BIT_1
) {
2884 fcport
->flags
|= FCF_TAPE_PRESENT
;
2889 fcport
->supported_classes
|= FC_COS_CLASS2
;
2891 fcport
->supported_classes
|= FC_COS_CLASS3
;
2895 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2897 * Loop ID already used, try next loop ID.
2900 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2901 if (rval
!= QLA_SUCCESS
) {
2902 /* Ran out of loop IDs to use */
2905 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2907 * Firmware possibly timed out during login. If NO
2908 * retries are left to do then the device is declared
2911 *next_loopid
= fcport
->loop_id
;
2912 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2913 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2914 fcport
->d_id
.b
.al_pa
);
2915 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2921 * unrecoverable / not handled error
2923 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2924 "loop_id=%x jiffies=%lx.\n",
2925 __func__
, ha
->host_no
, mb
[0],
2926 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2927 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2929 *next_loopid
= fcport
->loop_id
;
2930 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2931 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2932 fcport
->d_id
.b
.al_pa
);
2933 fcport
->loop_id
= FC_NO_LOOP_ID
;
2934 fcport
->login_retry
= 0;
2945 * qla2x00_local_device_login
2946 * Issue local device login command.
2949 * ha = adapter block pointer.
2950 * loop_id = loop id of device to login to.
2952 * Returns (Where's the #define!!!!):
2953 * 0 - Login successfully
2958 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2961 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2963 memset(mb
, 0, sizeof(mb
));
2964 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
2965 if (rval
== QLA_SUCCESS
) {
2966 /* Interrogate mailbox registers for any errors */
2967 if (mb
[0] == MBS_COMMAND_ERROR
)
2969 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
2970 /* device not in PCB table */
2978 * qla2x00_loop_resync
2979 * Resync with fibre channel devices.
2982 * ha = adapter block pointer.
2988 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
2995 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
2996 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
2997 if (ha
->flags
.online
) {
2998 if (!(rval
= qla2x00_fw_ready(ha
))) {
2999 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3002 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3004 /* Issue a marker after FW becomes ready. */
3005 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3006 ha
->marker_needed
= 0;
3008 /* Remap devices on Loop. */
3009 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3011 qla2x00_configure_loop(ha
);
3013 } while (!atomic_read(&ha
->loop_down_timer
) &&
3014 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3016 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3020 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3021 return (QLA_FUNCTION_FAILED
);
3025 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3032 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3038 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3039 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3042 qla2x00_update_fcport(ha
, fcport
);
3043 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3047 qla2x00_probe_for_all_luns(ha
);
3051 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3055 /* Go with deferred removal of rport references. */
3056 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3058 qla2x00_rport_del(fcport
);
3063 * Resets ISP and aborts all outstanding commands.
3066 * ha = adapter block pointer.
3072 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3075 unsigned long flags
= 0;
3080 if (ha
->flags
.online
) {
3081 ha
->flags
.online
= 0;
3082 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3084 qla_printk(KERN_INFO
, ha
,
3085 "Performing ISP error recovery - ha= %p.\n", ha
);
3086 ha
->isp_ops
.reset_chip(ha
);
3088 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3089 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3090 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3091 qla2x00_mark_all_devices_lost(ha
, 0);
3093 if (!atomic_read(&ha
->loop_down_timer
))
3094 atomic_set(&ha
->loop_down_timer
,
3098 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3099 /* Requeue all commands in outstanding command list. */
3100 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3101 sp
= ha
->outstanding_cmds
[cnt
];
3103 ha
->outstanding_cmds
[cnt
] = NULL
;
3105 sp
->cmd
->result
= DID_RESET
<< 16;
3106 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3107 qla2x00_sp_compl(ha
, sp
);
3110 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3112 ha
->isp_ops
.nvram_config(ha
);
3114 if (!qla2x00_restart_isp(ha
)) {
3115 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3117 if (!atomic_read(&ha
->loop_down_timer
)) {
3119 * Issue marker command only when we are going
3120 * to start the I/O .
3122 ha
->marker_needed
= 1;
3125 ha
->flags
.online
= 1;
3127 ha
->isp_ops
.enable_intrs(ha
);
3129 ha
->isp_abort_cnt
= 0;
3130 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3133 rval
= qla2x00_trace_control(ha
, TC_ENABLE
,
3134 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3136 qla_printk(KERN_WARNING
, ha
,
3137 "Unable to reinitialize EFT "
3141 } else { /* failed the ISP abort */
3142 ha
->flags
.online
= 1;
3143 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3144 if (ha
->isp_abort_cnt
== 0) {
3145 qla_printk(KERN_WARNING
, ha
,
3146 "ISP error recovery failed - "
3147 "board disabled\n");
3149 * The next call disables the board
3152 ha
->isp_ops
.reset_adapter(ha
);
3153 ha
->flags
.online
= 0;
3154 clear_bit(ISP_ABORT_RETRY
,
3157 } else { /* schedule another ISP abort */
3158 ha
->isp_abort_cnt
--;
3159 DEBUG(printk("qla%ld: ISP abort - "
3160 "retry remaining %d\n",
3161 ha
->host_no
, ha
->isp_abort_cnt
));
3165 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3166 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3167 "- retrying (%d) more times\n",
3168 ha
->host_no
, ha
->isp_abort_cnt
));
3169 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3177 qla_printk(KERN_INFO
, ha
,
3178 "qla2x00_abort_isp: **** FAILED ****\n");
3180 DEBUG(printk(KERN_INFO
3181 "qla2x00_abort_isp(%ld): exiting.\n",
3189 * qla2x00_restart_isp
3190 * restarts the ISP after a reset
3193 * ha = adapter block pointer.
3199 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3202 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3203 unsigned long flags
= 0;
3206 /* If firmware needs to be loaded */
3207 if (qla2x00_isp_firmware(ha
)) {
3208 ha
->flags
.online
= 0;
3209 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3210 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3211 status
= qla2x00_setup_chip(ha
);
3215 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3217 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3219 * Disable SRAM, Instruction RAM and GP RAM
3222 WRT_REG_WORD(®
->hccr
,
3223 (HCCR_ENABLE_PARITY
+ 0x0));
3224 RD_REG_WORD(®
->hccr
);
3227 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3229 status
= qla2x00_setup_chip(ha
);
3231 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3233 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3234 /* Enable proper parity */
3237 WRT_REG_WORD(®
->hccr
,
3238 (HCCR_ENABLE_PARITY
+ 0x1));
3241 * SRAM, Instruction RAM and GP RAM
3244 WRT_REG_WORD(®
->hccr
,
3245 (HCCR_ENABLE_PARITY
+ 0x7));
3246 RD_REG_WORD(®
->hccr
);
3249 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3254 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3255 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3256 if (!(status
= qla2x00_fw_ready(ha
))) {
3257 DEBUG(printk("%s(): Start configure loop, "
3258 "status = %d\n", __func__
, status
));
3260 /* Issue a marker after FW becomes ready. */
3261 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3263 ha
->flags
.online
= 1;
3264 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3267 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3268 qla2x00_configure_loop(ha
);
3270 } while (!atomic_read(&ha
->loop_down_timer
) &&
3271 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3273 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3276 /* if no cable then assume it's good */
3277 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3280 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3288 * qla2x00_reset_adapter
3292 * ha = adapter block pointer.
3295 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3297 unsigned long flags
= 0;
3298 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3300 ha
->flags
.online
= 0;
3301 ha
->isp_ops
.disable_intrs(ha
);
3303 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3304 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3305 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3306 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3307 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3308 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3312 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3314 unsigned long flags
= 0;
3315 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3317 ha
->flags
.online
= 0;
3318 ha
->isp_ops
.disable_intrs(ha
);
3320 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3321 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3322 RD_REG_DWORD(®
->hccr
);
3323 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3324 RD_REG_DWORD(®
->hccr
);
3325 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3329 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3332 struct init_cb_24xx
*icb
;
3333 struct nvram_24xx
*nv
;
3335 uint8_t *dptr1
, *dptr2
;
3340 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3341 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3343 /* Determine NVRAM starting address. */
3344 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3345 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3346 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3347 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3348 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3349 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3350 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3353 /* Get NVRAM data and calculate checksum. */
3354 dptr
= (uint32_t *)nv
;
3355 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3357 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3358 chksum
+= le32_to_cpu(*dptr
++);
3360 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3361 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3364 /* Bad NVRAM data, set defaults parameters. */
3365 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3366 || nv
->id
[3] != ' ' ||
3367 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3368 /* Reset NVRAM data. */
3369 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3370 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3371 le16_to_cpu(nv
->nvram_version
));
3372 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3373 "invalid -- WWPN) defaults.\n");
3376 * Set default initialization control block.
3378 memset(nv
, 0, ha
->nvram_size
);
3379 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3380 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3381 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3382 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3383 nv
->exchange_count
= __constant_cpu_to_le16(0);
3384 nv
->hard_address
= __constant_cpu_to_le16(124);
3385 nv
->port_name
[0] = 0x21;
3386 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3387 nv
->port_name
[2] = 0x00;
3388 nv
->port_name
[3] = 0xe0;
3389 nv
->port_name
[4] = 0x8b;
3390 nv
->port_name
[5] = 0x1c;
3391 nv
->port_name
[6] = 0x55;
3392 nv
->port_name
[7] = 0x86;
3393 nv
->node_name
[0] = 0x20;
3394 nv
->node_name
[1] = 0x00;
3395 nv
->node_name
[2] = 0x00;
3396 nv
->node_name
[3] = 0xe0;
3397 nv
->node_name
[4] = 0x8b;
3398 nv
->node_name
[5] = 0x1c;
3399 nv
->node_name
[6] = 0x55;
3400 nv
->node_name
[7] = 0x86;
3401 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3402 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3403 nv
->login_timeout
= __constant_cpu_to_le16(0);
3404 nv
->firmware_options_1
=
3405 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3406 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3407 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3408 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3409 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3410 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3411 nv
->reset_delay
= 5;
3412 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3413 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3414 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3419 /* Reset Initialization control block */
3420 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3422 /* Copy 1st segment. */
3423 dptr1
= (uint8_t *)icb
;
3424 dptr2
= (uint8_t *)&nv
->version
;
3425 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3427 *dptr1
++ = *dptr2
++;
3429 icb
->login_retry_count
= nv
->login_retry_count
;
3430 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3432 /* Copy 2nd segment. */
3433 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3434 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3435 cnt
= (uint8_t *)&icb
->reserved_3
-
3436 (uint8_t *)&icb
->interrupt_delay_timer
;
3438 *dptr1
++ = *dptr2
++;
3441 * Setup driver NVRAM options.
3443 if (memcmp(nv
->model_name
, BINZERO
, sizeof(nv
->model_name
)) != 0) {
3447 strncpy(ha
->model_number
, nv
->model_name
,
3448 sizeof(nv
->model_name
));
3449 st
= en
= ha
->model_number
;
3450 en
+= sizeof(nv
->model_name
) - 1;
3452 if (*en
!= 0x20 && *en
!= 0x00)
3457 index
= (ha
->pdev
->subsystem_device
& 0xff);
3458 if (index
< QLA_MODEL_NAMES
)
3459 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
3461 strcpy(ha
->model_number
, "QLA2462");
3463 /* Use alternate WWN? */
3464 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3465 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3466 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3469 /* Prepare nodename */
3470 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3472 * Firmware will apply the following mask if the nodename was
3475 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3476 icb
->node_name
[0] &= 0xF0;
3479 /* Set host adapter parameters. */
3480 ha
->flags
.disable_risc_code_load
= 0;
3481 ha
->flags
.enable_lip_reset
= 1;
3482 ha
->flags
.enable_lip_full_login
= 1;
3483 ha
->flags
.enable_target_reset
= 1;
3484 ha
->flags
.enable_led_scheme
= 0;
3485 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3487 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3488 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3490 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3491 sizeof(ha
->fw_seriallink_options24
));
3493 /* save HBA serial number */
3494 ha
->serial0
= icb
->port_name
[5];
3495 ha
->serial1
= icb
->port_name
[6];
3496 ha
->serial2
= icb
->port_name
[7];
3497 ha
->node_name
= icb
->node_name
;
3498 ha
->port_name
= icb
->port_name
;
3500 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3502 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3504 /* Set minimum login_timeout to 4 seconds. */
3505 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3506 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3507 if (le16_to_cpu(nv
->login_timeout
) < 4)
3508 nv
->login_timeout
= __constant_cpu_to_le16(4);
3509 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3510 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3512 /* Set minimum RATOV to 200 tenths of a second. */
3515 ha
->loop_reset_delay
= nv
->reset_delay
;
3517 /* Link Down Timeout = 0:
3519 * When Port Down timer expires we will start returning
3520 * I/O's to OS with "DID_NO_CONNECT".
3522 * Link Down Timeout != 0:
3524 * The driver waits for the link to come up after link down
3525 * before returning I/Os to OS with "DID_NO_CONNECT".
3527 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3528 ha
->loop_down_abort_time
=
3529 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3531 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3532 ha
->loop_down_abort_time
=
3533 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3536 /* Need enough time to try and get the port back. */
3537 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3538 if (qlport_down_retry
)
3539 ha
->port_down_retry_count
= qlport_down_retry
;
3541 /* Set login_retry_count */
3542 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3543 if (ha
->port_down_retry_count
==
3544 le16_to_cpu(nv
->port_down_retry_count
) &&
3545 ha
->port_down_retry_count
> 3)
3546 ha
->login_retry_count
= ha
->port_down_retry_count
;
3547 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3548 ha
->login_retry_count
= ha
->port_down_retry_count
;
3549 if (ql2xloginretrycount
)
3550 ha
->login_retry_count
= ql2xloginretrycount
;
3553 if (!ha
->flags
.init_done
) {
3554 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3555 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3556 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3557 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3559 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3560 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3561 ha
->flags
.process_response_queue
= 0;
3562 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3563 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3565 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3566 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3567 ha
->zio_timer
* 100));
3568 qla_printk(KERN_INFO
, ha
,
3569 "ZIO mode %d enabled; timer delay (%d us).\n",
3570 ha
->zio_mode
, ha
->zio_timer
* 100);
3572 icb
->firmware_options_2
|= cpu_to_le32(
3573 (uint32_t)ha
->zio_mode
);
3574 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3575 ha
->flags
.process_response_queue
= 1;
3579 DEBUG2_3(printk(KERN_WARNING
3580 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3586 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3589 int segments
, fragment
;
3591 uint32_t *dcode
, dlen
;
3598 segments
= FA_RISC_CODE_SEGMENTS
;
3599 faddr
= FA_RISC_CODE_ADDR
;
3600 dcode
= (uint32_t *)ha
->request_ring
;
3603 /* Validate firmware image by checking version. */
3604 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3605 for (i
= 0; i
< 4; i
++)
3606 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3607 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3608 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3609 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3611 qla_printk(KERN_WARNING
, ha
,
3612 "Unable to verify integrity of flash firmware image!\n");
3613 qla_printk(KERN_WARNING
, ha
,
3614 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3615 dcode
[1], dcode
[2], dcode
[3]);
3617 return QLA_FUNCTION_FAILED
;
3620 while (segments
&& rval
== QLA_SUCCESS
) {
3621 /* Read segment's load information. */
3622 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3624 risc_addr
= be32_to_cpu(dcode
[2]);
3625 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3626 risc_size
= be32_to_cpu(dcode
[3]);
3629 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3630 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3631 if (dlen
> risc_size
)
3634 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3635 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3636 ha
->host_no
, risc_addr
, dlen
, faddr
));
3638 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3639 for (i
= 0; i
< dlen
; i
++)
3640 dcode
[i
] = swab32(dcode
[i
]);
3642 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3645 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3646 "segment %d of firmware\n", ha
->host_no
,
3648 qla_printk(KERN_WARNING
, ha
,
3649 "[ERROR] Failed to load segment %d of "
3650 "firmware\n", fragment
);
3667 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3670 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3674 uint16_t *wcode
, *fwcode
;
3675 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3676 struct fw_blob
*blob
;
3678 /* Load firmware blob. */
3679 blob
= qla2x00_request_firmware(ha
);
3681 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3682 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3683 "from: " QLA_FW_URL
".\n");
3684 return QLA_FUNCTION_FAILED
;
3689 wcode
= (uint16_t *)ha
->request_ring
;
3691 fwcode
= (uint16_t *)blob
->fw
->data
;
3694 /* Validate firmware image by checking version. */
3695 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3696 qla_printk(KERN_WARNING
, ha
,
3697 "Unable to verify integrity of firmware image (%Zd)!\n",
3699 goto fail_fw_integrity
;
3701 for (i
= 0; i
< 4; i
++)
3702 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3703 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3704 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3705 wcode
[2] == 0 && wcode
[3] == 0)) {
3706 qla_printk(KERN_WARNING
, ha
,
3707 "Unable to verify integrity of firmware image!\n");
3708 qla_printk(KERN_WARNING
, ha
,
3709 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3710 wcode
[1], wcode
[2], wcode
[3]);
3711 goto fail_fw_integrity
;
3715 while (*seg
&& rval
== QLA_SUCCESS
) {
3717 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3718 risc_size
= be16_to_cpu(fwcode
[3]);
3720 /* Validate firmware image size. */
3721 fwclen
+= risc_size
* sizeof(uint16_t);
3722 if (blob
->fw
->size
< fwclen
) {
3723 qla_printk(KERN_WARNING
, ha
,
3724 "Unable to verify integrity of firmware image "
3725 "(%Zd)!\n", blob
->fw
->size
);
3726 goto fail_fw_integrity
;
3730 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3731 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3732 if (wlen
> risc_size
)
3735 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3736 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3739 for (i
= 0; i
< wlen
; i
++)
3740 wcode
[i
] = swab16(fwcode
[i
]);
3742 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3745 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3746 "segment %d of firmware\n", ha
->host_no
,
3748 qla_printk(KERN_WARNING
, ha
,
3749 "[ERROR] Failed to load segment %d of "
3750 "firmware\n", fragment
);
3766 return QLA_FUNCTION_FAILED
;
3770 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3773 int segments
, fragment
;
3774 uint32_t *dcode
, dlen
;
3778 struct fw_blob
*blob
;
3779 uint32_t *fwcode
, fwclen
;
3781 /* Load firmware blob. */
3782 blob
= qla2x00_request_firmware(ha
);
3784 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3785 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3786 "from: " QLA_FW_URL
".\n");
3788 /* Try to load RISC code from flash. */
3789 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3790 "outdated) firmware from flash.\n");
3791 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3796 segments
= FA_RISC_CODE_SEGMENTS
;
3797 dcode
= (uint32_t *)ha
->request_ring
;
3799 fwcode
= (uint32_t *)blob
->fw
->data
;
3802 /* Validate firmware image by checking version. */
3803 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3804 qla_printk(KERN_WARNING
, ha
,
3805 "Unable to verify integrity of firmware image (%Zd)!\n",
3807 goto fail_fw_integrity
;
3809 for (i
= 0; i
< 4; i
++)
3810 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3811 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3812 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3813 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3815 qla_printk(KERN_WARNING
, ha
,
3816 "Unable to verify integrity of firmware image!\n");
3817 qla_printk(KERN_WARNING
, ha
,
3818 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3819 dcode
[1], dcode
[2], dcode
[3]);
3820 goto fail_fw_integrity
;
3823 while (segments
&& rval
== QLA_SUCCESS
) {
3824 risc_addr
= be32_to_cpu(fwcode
[2]);
3825 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3826 risc_size
= be32_to_cpu(fwcode
[3]);
3828 /* Validate firmware image size. */
3829 fwclen
+= risc_size
* sizeof(uint32_t);
3830 if (blob
->fw
->size
< fwclen
) {
3831 qla_printk(KERN_WARNING
, ha
,
3832 "Unable to verify integrity of firmware image "
3833 "(%Zd)!\n", blob
->fw
->size
);
3835 goto fail_fw_integrity
;
3839 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3840 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3841 if (dlen
> risc_size
)
3844 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3845 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3848 for (i
= 0; i
< dlen
; i
++)
3849 dcode
[i
] = swab32(fwcode
[i
]);
3851 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3854 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3855 "segment %d of firmware\n", ha
->host_no
,
3857 qla_printk(KERN_WARNING
, ha
,
3858 "[ERROR] Failed to load segment %d of "
3859 "firmware\n", fragment
);
3875 return QLA_FUNCTION_FAILED
;
3879 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*ha
)
3883 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
))
3886 ret
= qla2x00_stop_firmware(ha
);
3887 for (retries
= 5; ret
!= QLA_SUCCESS
&& retries
; retries
--) {
3888 qla2x00_reset_chip(ha
);
3889 if (qla2x00_chip_diag(ha
) != QLA_SUCCESS
)
3891 if (qla2x00_setup_chip(ha
) != QLA_SUCCESS
)
3893 qla_printk(KERN_INFO
, ha
,
3894 "Attempting retry of stop-firmware command...\n");
3895 ret
= qla2x00_stop_firmware(ha
);