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"
18 /* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
19 #ifndef EXT_IS_LUN_BIT_SET
20 #define EXT_IS_LUN_BIT_SET(P,L) \
21 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
22 #define EXT_SET_LUN_BIT(P,L) \
23 ((P)->mask[L/8] |= (0x80 >> (L%8)))
27 * QLogic ISP2x00 Hardware Support Function Prototypes.
29 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
30 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
31 static int qla2x00_setup_chip(scsi_qla_host_t
*);
32 static void qla2x00_init_response_q_entries(scsi_qla_host_t
*);
33 static int qla2x00_init_rings(scsi_qla_host_t
*);
34 static int qla2x00_fw_ready(scsi_qla_host_t
*);
35 static int qla2x00_configure_hba(scsi_qla_host_t
*);
36 static int qla2x00_configure_loop(scsi_qla_host_t
*);
37 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
38 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
39 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
40 static int qla2x00_device_resync(scsi_qla_host_t
*);
41 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
44 static int qla2x00_restart_isp(scsi_qla_host_t
*);
46 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
);
48 /****************************************************************************/
49 /* QLogic ISP2x00 Hardware Support Functions. */
50 /****************************************************************************/
53 * qla2x00_initialize_adapter
57 * ha = adapter block pointer.
63 qla2x00_initialize_adapter(scsi_qla_host_t
*ha
)
67 /* Clear adapter flags. */
69 ha
->flags
.reset_active
= 0;
70 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
71 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
72 ha
->device_flags
= DFLG_NO_CABLE
;
74 ha
->flags
.management_server_logged_in
= 0;
75 ha
->marker_needed
= 0;
77 ha
->isp_abort_cnt
= 0;
78 ha
->beacon_blink_led
= 0;
79 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
81 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
82 rval
= ha
->isp_ops
.pci_config(ha
);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha
->isp_ops
.reset_chip(ha
);
91 ha
->isp_ops
.get_flash_version(ha
, ha
->request_ring
);
93 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
95 ha
->isp_ops
.nvram_config(ha
);
97 if (ha
->flags
.disable_serdes
) {
98 /* Mask HBA via NVRAM settings? */
99 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
100 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
101 ha
->port_name
[0], ha
->port_name
[1],
102 ha
->port_name
[2], ha
->port_name
[3],
103 ha
->port_name
[4], ha
->port_name
[5],
104 ha
->port_name
[6], ha
->port_name
[7]);
105 return QLA_FUNCTION_FAILED
;
108 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
110 if (qla2x00_isp_firmware(ha
) != QLA_SUCCESS
) {
111 rval
= ha
->isp_ops
.chip_diag(ha
);
114 rval
= qla2x00_setup_chip(ha
);
118 rval
= qla2x00_init_rings(ha
);
124 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
127 * Returns 0 on success.
130 qla2100_pci_config(scsi_qla_host_t
*ha
)
135 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
137 pci_set_master(ha
->pdev
);
139 if (pci_set_mwi(ha
->pdev
))
140 mwi
= PCI_COMMAND_INVALIDATE
;
142 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
143 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
144 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
146 /* Reset expansion ROM address decode enable */
147 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
148 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
149 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
151 /* Get PCI bus information. */
152 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
153 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
154 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
160 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
163 * Returns 0 on success.
166 qla2300_pci_config(scsi_qla_host_t
*ha
)
170 unsigned long flags
= 0;
172 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
174 pci_set_master(ha
->pdev
);
176 if (pci_set_mwi(ha
->pdev
))
177 mwi
= PCI_COMMAND_INVALIDATE
;
179 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
180 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
182 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
183 w
&= ~PCI_COMMAND_INTX_DISABLE
;
186 * If this is a 2300 card and not 2312, reset the
187 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
188 * the 2310 also reports itself as a 2300 so we need to get the
189 * fb revision level -- a 6 indicates it really is a 2300 and
192 if (IS_QLA2300(ha
)) {
193 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
196 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
197 for (cnt
= 0; cnt
< 30000; cnt
++) {
198 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
204 /* Select FPM registers. */
205 WRT_REG_WORD(®
->ctrl_status
, 0x20);
206 RD_REG_WORD(®
->ctrl_status
);
208 /* Get the fb rev level */
209 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
211 if (ha
->fb_rev
== FPM_2300
)
212 w
&= ~PCI_COMMAND_INVALIDATE
;
214 /* Deselect FPM registers. */
215 WRT_REG_WORD(®
->ctrl_status
, 0x0);
216 RD_REG_WORD(®
->ctrl_status
);
218 /* Release RISC module. */
219 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
220 for (cnt
= 0; cnt
< 30000; cnt
++) {
221 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
227 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
229 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
231 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
233 /* Reset expansion ROM address decode enable */
234 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
235 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
236 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
238 /* Get PCI bus information. */
239 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
240 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
241 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
247 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
250 * Returns 0 on success.
253 qla24xx_pci_config(scsi_qla_host_t
*ha
)
257 unsigned long flags
= 0;
258 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
259 int pcix_cmd_reg
, pcie_dctl_reg
;
261 pci_set_master(ha
->pdev
);
263 if (pci_set_mwi(ha
->pdev
))
264 mwi
= PCI_COMMAND_INVALIDATE
;
266 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
267 w
|= mwi
| (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
268 w
&= ~PCI_COMMAND_INTX_DISABLE
;
269 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
271 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
273 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
274 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
278 pcix_cmd_reg
+= PCI_X_CMD
;
279 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
280 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
282 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
285 /* PCIe -- adjust Maximum Read Request Size (2048). */
286 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
290 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
291 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
292 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
294 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
297 /* Reset expansion ROM address decode enable */
298 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
299 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
300 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
302 pci_read_config_word(ha
->pdev
, PCI_REVISION_ID
, &ha
->chip_revision
);
304 /* Get PCI bus information. */
305 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
306 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
307 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
313 * qla2x00_isp_firmware() - Choose firmware image.
316 * Returns 0 on success.
319 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
323 /* Assume loading risc code */
324 rval
= QLA_FUNCTION_FAILED
;
326 if (ha
->flags
.disable_risc_code_load
) {
327 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
329 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
331 /* Verify checksum of loaded RISC code. */
332 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
336 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
344 * qla2x00_reset_chip() - Reset ISP chip.
347 * Returns 0 on success.
350 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
352 unsigned long flags
= 0;
353 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
357 ha
->isp_ops
.disable_intrs(ha
);
359 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
361 /* Turn off master enable */
363 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
364 cmd
&= ~PCI_COMMAND_MASTER
;
365 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
367 if (!IS_QLA2100(ha
)) {
369 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
370 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
371 for (cnt
= 0; cnt
< 30000; cnt
++) {
372 if ((RD_REG_WORD(®
->hccr
) &
373 HCCR_RISC_PAUSE
) != 0)
378 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
382 /* Select FPM registers. */
383 WRT_REG_WORD(®
->ctrl_status
, 0x20);
384 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
386 /* FPM Soft Reset. */
387 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
388 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
390 /* Toggle Fpm Reset. */
391 if (!IS_QLA2200(ha
)) {
392 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
393 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
396 /* Select frame buffer registers. */
397 WRT_REG_WORD(®
->ctrl_status
, 0x10);
398 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
400 /* Reset frame buffer FIFOs. */
401 if (IS_QLA2200(ha
)) {
402 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
403 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
405 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
407 /* Read back fb_cmd until zero or 3 seconds max */
408 for (cnt
= 0; cnt
< 3000; cnt
++) {
409 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
415 /* Select RISC module registers. */
416 WRT_REG_WORD(®
->ctrl_status
, 0);
417 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
419 /* Reset RISC processor. */
420 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
421 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
423 /* Release RISC processor. */
424 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
425 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
428 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
429 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
431 /* Reset ISP chip. */
432 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
434 /* Wait for RISC to recover from reset. */
435 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
437 * It is necessary to for a delay here since the card doesn't
438 * respond to PCI reads during a reset. On some architectures
439 * this will result in an MCA.
442 for (cnt
= 30000; cnt
; cnt
--) {
443 if ((RD_REG_WORD(®
->ctrl_status
) &
444 CSR_ISP_SOFT_RESET
) == 0)
451 /* Reset RISC processor. */
452 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
454 WRT_REG_WORD(®
->semaphore
, 0);
456 /* Release RISC processor. */
457 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
458 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
460 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
461 for (cnt
= 0; cnt
< 30000; cnt
++) {
462 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
470 /* Turn on master enable */
471 cmd
|= PCI_COMMAND_MASTER
;
472 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
474 /* Disable RISC pause on FPM parity error. */
475 if (!IS_QLA2100(ha
)) {
476 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
477 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
480 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
484 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
487 * Returns 0 on success.
490 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
492 unsigned long flags
= 0;
493 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
497 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
500 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
501 for (cnt
= 0; cnt
< 30000; cnt
++) {
502 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
508 WRT_REG_DWORD(®
->ctrl_status
,
509 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
510 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
513 /* Wait for firmware to complete NVRAM accesses. */
514 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
515 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
517 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
521 /* Wait for soft-reset to complete. */
522 d2
= RD_REG_DWORD(®
->ctrl_status
);
523 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
525 d2
= RD_REG_DWORD(®
->ctrl_status
);
529 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
530 RD_REG_DWORD(®
->hccr
);
532 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
533 RD_REG_DWORD(®
->hccr
);
535 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
536 RD_REG_DWORD(®
->hccr
);
538 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
539 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
541 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
545 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
549 * qla24xx_reset_chip() - Reset ISP24xx chip.
552 * Returns 0 on success.
555 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
557 ha
->isp_ops
.disable_intrs(ha
);
559 /* Perform RISC reset. */
560 qla24xx_reset_risc(ha
);
564 * qla2x00_chip_diag() - Test chip for proper operation.
567 * Returns 0 on success.
570 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
573 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
574 unsigned long flags
= 0;
579 /* Assume a failed state */
580 rval
= QLA_FUNCTION_FAILED
;
582 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
583 ha
->host_no
, (u_long
)®
->flash_address
));
585 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
587 /* Reset ISP chip. */
588 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
591 * We need to have a delay here since the card will not respond while
592 * in reset causing an MCA on some architectures.
595 data
= qla2x00_debounce_register(®
->ctrl_status
);
596 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
598 data
= RD_REG_WORD(®
->ctrl_status
);
603 goto chip_diag_failed
;
605 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
608 /* Reset RISC processor. */
609 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
610 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
612 /* Workaround for QLA2312 PCI parity error */
613 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
614 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
615 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
617 data
= RD_MAILBOX_REG(ha
, reg
, 0);
624 goto chip_diag_failed
;
626 /* Check product ID of chip */
627 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
629 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
630 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
631 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
632 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
633 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
634 mb
[3] != PROD_ID_3
) {
635 qla_printk(KERN_WARNING
, ha
,
636 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
638 goto chip_diag_failed
;
640 ha
->product_id
[0] = mb
[1];
641 ha
->product_id
[1] = mb
[2];
642 ha
->product_id
[2] = mb
[3];
643 ha
->product_id
[3] = mb
[4];
645 /* Adjust fw RISC transfer size */
646 if (ha
->request_q_length
> 1024)
647 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
649 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
650 ha
->request_q_length
;
652 if (IS_QLA2200(ha
) &&
653 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
654 /* Limit firmware transfer size with a 2200A */
655 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
658 ha
->device_type
|= DT_ISP2200A
;
659 ha
->fw_transfer_size
= 128;
662 /* Wrap Incoming Mailboxes Test. */
663 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
665 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
666 rval
= qla2x00_mbx_reg_test(ha
);
668 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
670 qla_printk(KERN_WARNING
, ha
,
671 "Failed mailbox send register test\n");
674 /* Flag a successful rval */
677 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
681 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
682 "****\n", ha
->host_no
));
684 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
690 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
693 * Returns 0 on success.
696 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
700 /* Perform RISC reset. */
701 qla24xx_reset_risc(ha
);
703 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
705 rval
= qla2x00_mbx_reg_test(ha
);
707 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
709 qla_printk(KERN_WARNING
, ha
,
710 "Failed mailbox send register test\n");
712 /* Flag a successful rval */
720 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
723 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
729 qla_printk(KERN_WARNING
, ha
,
730 "Firmware dump previously allocated.\n");
735 fixed_size
= mem_size
= eft_size
= 0;
736 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
737 fixed_size
= sizeof(struct qla2100_fw_dump
);
738 } else if (IS_QLA23XX(ha
)) {
739 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
740 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
742 } else if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
743 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
744 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
747 /* Allocate memory for Extended Trace Buffer. */
748 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
751 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
752 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
756 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
759 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
760 "EFT (%d).\n", rval
);
761 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
766 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
770 memset(eft
, 0, eft_size
);
771 ha
->eft_dma
= eft_dma
;
775 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
776 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
778 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
779 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
782 ha
->fw_dump
= vmalloc(dump_size
);
784 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
785 "firmware dump!!!\n", dump_size
/ 1024);
788 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
796 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
799 ha
->fw_dump_len
= dump_size
;
800 ha
->fw_dump
->signature
[0] = 'Q';
801 ha
->fw_dump
->signature
[1] = 'L';
802 ha
->fw_dump
->signature
[2] = 'G';
803 ha
->fw_dump
->signature
[3] = 'C';
804 ha
->fw_dump
->version
= __constant_htonl(1);
806 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
807 ha
->fw_dump
->mem_size
= htonl(mem_size
);
808 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
809 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
811 ha
->fw_dump
->eft_size
= htonl(eft_size
);
812 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
813 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
815 ha
->fw_dump
->header_size
=
816 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
820 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
823 * Returns 0 on success.
826 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
829 uint16_t fw_iocb_cnt
= 0;
830 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
831 dma_addr_t request_dma
;
832 request_t
*request_ring
;
834 /* Valid only on recent ISPs. */
835 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
838 /* Retrieve IOCB counts available to the firmware. */
839 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
842 /* No point in continuing if current settings are sufficient. */
843 if (fw_iocb_cnt
< 1024)
845 if (ha
->request_q_length
>= request_q_length
)
848 /* Attempt to claim larger area for request queue. */
849 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
850 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
852 if (request_ring
== NULL
)
855 /* Resize successful, report extensions. */
856 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
857 (ha
->fw_memory_size
+ 1) / 1024);
858 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
859 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
861 /* Clear old allocations. */
862 dma_free_coherent(&ha
->pdev
->dev
,
863 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
866 /* Begin using larger queue. */
867 ha
->request_q_length
= request_q_length
;
868 ha
->request_ring
= request_ring
;
869 ha
->request_dma
= request_dma
;
873 * qla2x00_setup_chip() - Load and start RISC firmware.
876 * Returns 0 on success.
879 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
882 uint32_t srisc_address
= 0;
884 /* Load firmware sequences */
885 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
886 if (rval
== QLA_SUCCESS
) {
887 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
888 "code.\n", ha
->host_no
));
890 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
891 if (rval
== QLA_SUCCESS
) {
892 /* Start firmware execution. */
893 DEBUG(printk("scsi(%ld): Checksum OK, start "
894 "firmware.\n", ha
->host_no
));
896 rval
= qla2x00_execute_fw(ha
, srisc_address
);
897 /* Retrieve firmware information. */
898 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
899 qla2x00_get_fw_version(ha
,
900 &ha
->fw_major_version
,
901 &ha
->fw_minor_version
,
902 &ha
->fw_subminor_version
,
903 &ha
->fw_attributes
, &ha
->fw_memory_size
);
904 qla2x00_resize_request_q(ha
);
907 qla2x00_alloc_fw_dump(ha
);
910 DEBUG2(printk(KERN_INFO
911 "scsi(%ld): ISP Firmware failed checksum.\n",
917 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
925 * qla2x00_init_response_q_entries() - Initializes response queue entries.
928 * Beginning of request ring has initialization control block already built
929 * by nvram config routine.
931 * Returns 0 on success.
934 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
939 pkt
= ha
->response_ring_ptr
;
940 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
941 pkt
->signature
= RESPONSE_PROCESSED
;
948 * qla2x00_update_fw_options() - Read and process firmware options.
951 * Returns 0 on success.
954 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
956 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
958 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
959 qla2x00_get_fw_options(ha
, ha
->fw_options
);
961 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
964 /* Serial Link options. */
965 DEBUG3(printk("scsi(%ld): Serial link options:\n",
967 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
968 sizeof(ha
->fw_seriallink_options
)));
970 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
971 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
972 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
975 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
976 emphasis
= (ha
->fw_seriallink_options
[2] &
977 (BIT_4
| BIT_3
)) >> 3;
978 tx_sens
= ha
->fw_seriallink_options
[0] &
979 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
980 rx_sens
= (ha
->fw_seriallink_options
[0] &
981 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
982 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
983 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
986 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
987 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
988 ha
->fw_options
[10] |= BIT_5
|
989 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
990 (tx_sens
& (BIT_1
| BIT_0
));
993 swing
= (ha
->fw_seriallink_options
[2] &
994 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
995 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
996 tx_sens
= ha
->fw_seriallink_options
[1] &
997 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
998 rx_sens
= (ha
->fw_seriallink_options
[1] &
999 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1000 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1001 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1004 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1005 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1006 ha
->fw_options
[11] |= BIT_5
|
1007 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1008 (tx_sens
& (BIT_1
| BIT_0
));
1012 /* Return command IOCBs without waiting for an ABTS to complete. */
1013 ha
->fw_options
[3] |= BIT_13
;
1016 if (ha
->flags
.enable_led_scheme
)
1017 ha
->fw_options
[2] |= BIT_12
;
1019 /* Detect ISP6312. */
1021 ha
->fw_options
[2] |= BIT_13
;
1023 /* Update firmware options. */
1024 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1028 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1032 /* Update Serial Link options. */
1033 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1036 rval
= qla2x00_set_serdes_params(ha
,
1037 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1038 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1039 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1040 if (rval
!= QLA_SUCCESS
) {
1041 qla_printk(KERN_WARNING
, ha
,
1042 "Unable to update Serial Link options (%x).\n", rval
);
1047 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1049 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1051 /* Setup ring parameters in initialization control block. */
1052 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1053 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1054 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1055 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1056 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1057 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1058 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1059 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1061 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1062 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1063 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1064 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1065 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1069 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1071 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1072 struct init_cb_24xx
*icb
;
1074 /* Setup ring parameters in initialization control block. */
1075 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1076 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1077 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1078 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1079 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1080 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1081 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1082 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1083 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1085 WRT_REG_DWORD(®
->req_q_in
, 0);
1086 WRT_REG_DWORD(®
->req_q_out
, 0);
1087 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1088 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1089 RD_REG_DWORD(®
->rsp_q_out
);
1093 * qla2x00_init_rings() - Initializes firmware.
1096 * Beginning of request ring has initialization control block already built
1097 * by nvram config routine.
1099 * Returns 0 on success.
1102 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1105 unsigned long flags
= 0;
1108 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1110 /* Clear outstanding commands array. */
1111 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1112 ha
->outstanding_cmds
[cnt
] = NULL
;
1114 ha
->current_outstanding_cmd
= 0;
1116 /* Clear RSCN queue. */
1117 ha
->rscn_in_ptr
= 0;
1118 ha
->rscn_out_ptr
= 0;
1120 /* Initialize firmware. */
1121 ha
->request_ring_ptr
= ha
->request_ring
;
1122 ha
->req_ring_index
= 0;
1123 ha
->req_q_cnt
= ha
->request_q_length
;
1124 ha
->response_ring_ptr
= ha
->response_ring
;
1125 ha
->rsp_ring_index
= 0;
1127 /* Initialize response queue entries */
1128 qla2x00_init_response_q_entries(ha
);
1130 ha
->isp_ops
.config_rings(ha
);
1132 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1134 /* Update any ISP specific firmware options before initialization. */
1135 ha
->isp_ops
.update_fw_options(ha
);
1137 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1138 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1140 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1143 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1151 * qla2x00_fw_ready() - Waits for firmware ready.
1154 * Returns 0 on success.
1157 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1160 unsigned long wtime
, mtime
;
1161 uint16_t min_wait
; /* Minimum wait time if loop is down */
1162 uint16_t wait_time
; /* Wait time if loop is coming ready */
1167 /* 20 seconds for loop down. */
1171 * Firmware should take at most one RATOV to login, plus 5 seconds for
1172 * our own processing.
1174 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1175 wait_time
= min_wait
;
1178 /* Min wait time if loop down */
1179 mtime
= jiffies
+ (min_wait
* HZ
);
1181 /* wait time before firmware ready */
1182 wtime
= jiffies
+ (wait_time
* HZ
);
1184 /* Wait for ISP to finish LIP */
1185 if (!ha
->flags
.init_done
)
1186 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1188 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1192 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1193 if (rval
== QLA_SUCCESS
) {
1194 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1195 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1197 if (fw_state
== FSTATE_READY
) {
1198 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1201 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1202 &ha
->login_timeout
, &ha
->r_a_tov
);
1208 rval
= QLA_FUNCTION_FAILED
;
1210 if (atomic_read(&ha
->loop_down_timer
) &&
1211 fw_state
!= FSTATE_READY
) {
1212 /* Loop down. Timeout on min_wait for states
1213 * other than Wait for Login.
1215 if (time_after_eq(jiffies
, mtime
)) {
1216 qla_printk(KERN_INFO
, ha
,
1217 "Cable is unplugged...\n");
1219 ha
->device_flags
|= DFLG_NO_CABLE
;
1224 /* Mailbox cmd failed. Timeout on min_wait. */
1225 if (time_after_eq(jiffies
, mtime
))
1229 if (time_after_eq(jiffies
, wtime
))
1232 /* Delay for a while */
1235 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1236 ha
->host_no
, fw_state
, jiffies
));
1239 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1240 ha
->host_no
, fw_state
, jiffies
));
1243 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1251 * qla2x00_configure_hba
1252 * Setup adapter context.
1255 * ha = adapter state pointer.
1264 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1272 char connect_type
[22];
1274 /* Get host addresses. */
1275 rval
= qla2x00_get_adapter_id(ha
,
1276 &loop_id
, &al_pa
, &area
, &domain
, &topo
);
1277 if (rval
!= QLA_SUCCESS
) {
1278 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1279 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1280 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1281 __func__
, ha
->host_no
));
1283 qla_printk(KERN_WARNING
, ha
,
1284 "ERROR -- Unable to get host loop ID.\n");
1285 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1291 qla_printk(KERN_INFO
, ha
,
1292 "Cannot get topology - retrying.\n");
1293 return (QLA_FUNCTION_FAILED
);
1296 ha
->loop_id
= loop_id
;
1299 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1300 ha
->operating_mode
= LOOP
;
1304 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1306 ha
->current_topology
= ISP_CFG_NL
;
1307 strcpy(connect_type
, "(Loop)");
1311 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1313 ha
->current_topology
= ISP_CFG_FL
;
1314 strcpy(connect_type
, "(FL_Port)");
1318 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1320 ha
->operating_mode
= P2P
;
1321 ha
->current_topology
= ISP_CFG_N
;
1322 strcpy(connect_type
, "(N_Port-to-N_Port)");
1326 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1328 ha
->operating_mode
= P2P
;
1329 ha
->current_topology
= ISP_CFG_F
;
1330 strcpy(connect_type
, "(F_Port)");
1334 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1336 ha
->host_no
, topo
));
1337 ha
->current_topology
= ISP_CFG_NL
;
1338 strcpy(connect_type
, "(Loop)");
1342 /* Save Host port and loop ID. */
1343 /* byte order - Big Endian */
1344 ha
->d_id
.b
.domain
= domain
;
1345 ha
->d_id
.b
.area
= area
;
1346 ha
->d_id
.b
.al_pa
= al_pa
;
1348 if (!ha
->flags
.init_done
)
1349 qla_printk(KERN_INFO
, ha
,
1350 "Topology - %s, Host Loop address 0x%x\n",
1351 connect_type
, ha
->loop_id
);
1354 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1356 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1363 qla2x00_set_model_info(scsi_qla_host_t
*ha
, uint8_t *model
, size_t len
, char *def
)
1368 if (memcmp(model
, BINZERO
, len
) != 0) {
1369 strncpy(ha
->model_number
, model
, len
);
1370 st
= en
= ha
->model_number
;
1373 if (*en
!= 0x20 && *en
!= 0x00)
1378 index
= (ha
->pdev
->subsystem_device
& 0xff);
1379 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1380 index
< QLA_MODEL_NAMES
)
1381 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1383 index
= (ha
->pdev
->subsystem_device
& 0xff);
1384 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1385 index
< QLA_MODEL_NAMES
) {
1386 strcpy(ha
->model_number
,
1387 qla2x00_model_name
[index
* 2]);
1388 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1390 strcpy(ha
->model_number
, def
);
1395 /* On sparc systems, obtain port and node WWN from firmware
1398 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, nvram_t
*nv
)
1401 struct pci_dev
*pdev
= ha
->pdev
;
1402 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1406 val
= of_get_property(dp
, "port-wwn", &len
);
1407 if (val
&& len
>= WWN_SIZE
)
1408 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1410 val
= of_get_property(dp
, "node-wwn", &len
);
1411 if (val
&& len
>= WWN_SIZE
)
1412 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1417 * NVRAM configuration for ISP 2xxx
1420 * ha = adapter block pointer.
1423 * initialization control block in response_ring
1424 * host adapters parameters in host adapter block
1430 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1435 uint8_t *dptr1
, *dptr2
;
1436 init_cb_t
*icb
= ha
->init_cb
;
1437 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1438 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1439 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1443 /* Determine NVRAM starting address. */
1444 ha
->nvram_size
= sizeof(nvram_t
);
1446 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1447 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1448 ha
->nvram_base
= 0x80;
1450 /* Get NVRAM data and calculate checksum. */
1451 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1452 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1455 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1456 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1459 /* Bad NVRAM data, set defaults parameters. */
1460 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1461 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1462 /* Reset NVRAM data. */
1463 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1464 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1466 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1467 "invalid -- WWPN) defaults.\n");
1470 * Set default initialization control block.
1472 memset(nv
, 0, ha
->nvram_size
);
1473 nv
->parameter_block_version
= ICB_VERSION
;
1475 if (IS_QLA23XX(ha
)) {
1476 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1477 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1478 nv
->add_firmware_options
[0] = BIT_5
;
1479 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1480 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1481 nv
->special_options
[1] = BIT_7
;
1482 } else if (IS_QLA2200(ha
)) {
1483 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1484 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1485 nv
->add_firmware_options
[0] = BIT_5
;
1486 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1487 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1488 } else if (IS_QLA2100(ha
)) {
1489 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1490 nv
->firmware_options
[1] = BIT_5
;
1491 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1494 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1495 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1496 nv
->retry_count
= 8;
1497 nv
->retry_delay
= 1;
1499 nv
->port_name
[0] = 33;
1500 nv
->port_name
[3] = 224;
1501 nv
->port_name
[4] = 139;
1503 qla2xxx_nvram_wwn_from_ofw(ha
, nv
);
1505 nv
->login_timeout
= 4;
1508 * Set default host adapter parameters
1510 nv
->host_p
[1] = BIT_2
;
1511 nv
->reset_delay
= 5;
1512 nv
->port_down_retry_count
= 8;
1513 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1514 nv
->link_down_timeout
= 60;
1519 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1521 * The SN2 does not provide BIOS emulation which means you can't change
1522 * potentially bogus BIOS settings. Force the use of default settings
1523 * for link rate and frame size. Hope that the rest of the settings
1526 if (ia64_platform_is("sn2")) {
1527 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1529 nv
->special_options
[1] = BIT_7
;
1533 /* Reset Initialization control block */
1534 memset(icb
, 0, ha
->init_cb_size
);
1537 * Setup driver NVRAM options.
1539 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1540 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1541 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1542 nv
->firmware_options
[1] &= ~BIT_4
;
1544 if (IS_QLA23XX(ha
)) {
1545 nv
->firmware_options
[0] |= BIT_2
;
1546 nv
->firmware_options
[0] &= ~BIT_3
;
1547 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1549 if (IS_QLA2300(ha
)) {
1550 if (ha
->fb_rev
== FPM_2310
) {
1551 strcpy(ha
->model_number
, "QLA2310");
1553 strcpy(ha
->model_number
, "QLA2300");
1556 qla2x00_set_model_info(ha
, nv
->model_number
,
1557 sizeof(nv
->model_number
), "QLA23xx");
1559 } else if (IS_QLA2200(ha
)) {
1560 nv
->firmware_options
[0] |= BIT_2
;
1562 * 'Point-to-point preferred, else loop' is not a safe
1563 * connection mode setting.
1565 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1567 /* Force 'loop preferred, else point-to-point'. */
1568 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1569 nv
->add_firmware_options
[0] |= BIT_5
;
1571 strcpy(ha
->model_number
, "QLA22xx");
1572 } else /*if (IS_QLA2100(ha))*/ {
1573 strcpy(ha
->model_number
, "QLA2100");
1577 * Copy over NVRAM RISC parameter block to initialization control block.
1579 dptr1
= (uint8_t *)icb
;
1580 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1581 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1583 *dptr1
++ = *dptr2
++;
1585 /* Copy 2nd half. */
1586 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1587 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1589 *dptr1
++ = *dptr2
++;
1591 /* Use alternate WWN? */
1592 if (nv
->host_p
[1] & BIT_7
) {
1593 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1594 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1597 /* Prepare nodename */
1598 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1600 * Firmware will apply the following mask if the nodename was
1603 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1604 icb
->node_name
[0] &= 0xF0;
1608 * Set host adapter parameters.
1610 if (nv
->host_p
[0] & BIT_7
)
1611 ql2xextended_error_logging
= 1;
1612 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1613 /* Always load RISC code on non ISP2[12]00 chips. */
1614 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1615 ha
->flags
.disable_risc_code_load
= 0;
1616 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1617 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1618 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1619 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1620 ha
->flags
.disable_serdes
= 0;
1622 ha
->operating_mode
=
1623 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1625 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1626 sizeof(ha
->fw_seriallink_options
));
1628 /* save HBA serial number */
1629 ha
->serial0
= icb
->port_name
[5];
1630 ha
->serial1
= icb
->port_name
[6];
1631 ha
->serial2
= icb
->port_name
[7];
1632 ha
->node_name
= icb
->node_name
;
1633 ha
->port_name
= icb
->port_name
;
1635 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1637 ha
->retry_count
= nv
->retry_count
;
1639 /* Set minimum login_timeout to 4 seconds. */
1640 if (nv
->login_timeout
< ql2xlogintimeout
)
1641 nv
->login_timeout
= ql2xlogintimeout
;
1642 if (nv
->login_timeout
< 4)
1643 nv
->login_timeout
= 4;
1644 ha
->login_timeout
= nv
->login_timeout
;
1645 icb
->login_timeout
= nv
->login_timeout
;
1647 /* Set minimum RATOV to 200 tenths of a second. */
1650 ha
->loop_reset_delay
= nv
->reset_delay
;
1652 /* Link Down Timeout = 0:
1654 * When Port Down timer expires we will start returning
1655 * I/O's to OS with "DID_NO_CONNECT".
1657 * Link Down Timeout != 0:
1659 * The driver waits for the link to come up after link down
1660 * before returning I/Os to OS with "DID_NO_CONNECT".
1662 if (nv
->link_down_timeout
== 0) {
1663 ha
->loop_down_abort_time
=
1664 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1666 ha
->link_down_timeout
= nv
->link_down_timeout
;
1667 ha
->loop_down_abort_time
=
1668 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1672 * Need enough time to try and get the port back.
1674 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1675 if (qlport_down_retry
)
1676 ha
->port_down_retry_count
= qlport_down_retry
;
1677 /* Set login_retry_count */
1678 ha
->login_retry_count
= nv
->retry_count
;
1679 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1680 ha
->port_down_retry_count
> 3)
1681 ha
->login_retry_count
= ha
->port_down_retry_count
;
1682 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1683 ha
->login_retry_count
= ha
->port_down_retry_count
;
1684 if (ql2xloginretrycount
)
1685 ha
->login_retry_count
= ql2xloginretrycount
;
1687 icb
->lun_enables
= __constant_cpu_to_le16(0);
1688 icb
->command_resource_count
= 0;
1689 icb
->immediate_notify_resource_count
= 0;
1690 icb
->timeout
= __constant_cpu_to_le16(0);
1692 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1694 icb
->firmware_options
[0] &= ~BIT_3
;
1695 icb
->add_firmware_options
[0] &=
1696 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1697 icb
->add_firmware_options
[0] |= BIT_2
;
1698 icb
->response_accumulation_timer
= 3;
1699 icb
->interrupt_delay_timer
= 5;
1701 ha
->flags
.process_response_queue
= 1;
1704 if (!ha
->flags
.init_done
) {
1705 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1706 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1707 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1708 icb
->interrupt_delay_timer
: 2;
1710 icb
->add_firmware_options
[0] &=
1711 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1712 ha
->flags
.process_response_queue
= 0;
1713 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1714 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1716 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1717 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1718 ha
->zio_timer
* 100));
1719 qla_printk(KERN_INFO
, ha
,
1720 "ZIO mode %d enabled; timer delay (%d us).\n",
1721 ha
->zio_mode
, ha
->zio_timer
* 100);
1723 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1724 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1725 ha
->flags
.process_response_queue
= 1;
1730 DEBUG2_3(printk(KERN_WARNING
1731 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1737 qla2x00_rport_del(void *data
)
1739 fc_port_t
*fcport
= data
;
1740 struct fc_rport
*rport
;
1741 unsigned long flags
;
1743 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1744 rport
= fcport
->drport
;
1745 fcport
->drport
= NULL
;
1746 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1748 fc_remote_port_delete(rport
);
1753 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1755 * @flags: allocation flags
1757 * Returns a pointer to the allocated fcport, or NULL, if none available.
1760 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1764 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1768 /* Setup fcport template structure. */
1769 memset(fcport
, 0, sizeof (fc_port_t
));
1771 fcport
->port_type
= FCT_UNKNOWN
;
1772 fcport
->loop_id
= FC_NO_LOOP_ID
;
1773 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1774 fcport
->flags
= FCF_RLC_SUPPORT
;
1775 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1776 spin_lock_init(&fcport
->rport_lock
);
1782 * qla2x00_configure_loop
1783 * Updates Fibre Channel Device Database with what is actually on loop.
1786 * ha = adapter block pointer.
1791 * 2 = database was full and device was not configured.
1794 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1797 unsigned long flags
, save_flags
;
1801 /* Get Initiator ID */
1802 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1803 rval
= qla2x00_configure_hba(ha
);
1804 if (rval
!= QLA_SUCCESS
) {
1805 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1811 save_flags
= flags
= ha
->dpc_flags
;
1812 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1813 ha
->host_no
, flags
));
1816 * If we have both an RSCN and PORT UPDATE pending then handle them
1817 * both at the same time.
1819 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1820 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1822 /* Determine what we need to do */
1823 if (ha
->current_topology
== ISP_CFG_FL
&&
1824 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1826 ha
->flags
.rscn_queue_overflow
= 1;
1827 set_bit(RSCN_UPDATE
, &flags
);
1829 } else if (ha
->current_topology
== ISP_CFG_F
&&
1830 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1832 ha
->flags
.rscn_queue_overflow
= 1;
1833 set_bit(RSCN_UPDATE
, &flags
);
1834 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1836 } else if (ha
->current_topology
== ISP_CFG_N
) {
1837 clear_bit(RSCN_UPDATE
, &flags
);
1839 } else if (!ha
->flags
.online
||
1840 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1842 ha
->flags
.rscn_queue_overflow
= 1;
1843 set_bit(RSCN_UPDATE
, &flags
);
1844 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1847 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1848 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1849 rval
= QLA_FUNCTION_FAILED
;
1851 rval
= qla2x00_configure_local_loop(ha
);
1855 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1856 if (LOOP_TRANSITION(ha
)) {
1857 rval
= QLA_FUNCTION_FAILED
;
1859 rval
= qla2x00_configure_fabric(ha
);
1863 if (rval
== QLA_SUCCESS
) {
1864 if (atomic_read(&ha
->loop_down_timer
) ||
1865 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1866 rval
= QLA_FUNCTION_FAILED
;
1868 atomic_set(&ha
->loop_state
, LOOP_READY
);
1870 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1875 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1876 __func__
, ha
->host_no
));
1878 DEBUG3(printk("%s: exiting normally\n", __func__
));
1881 /* Restore state if a resync event occured during processing */
1882 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1883 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1884 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1885 if (test_bit(RSCN_UPDATE
, &save_flags
))
1886 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1895 * qla2x00_configure_local_loop
1896 * Updates Fibre Channel Device Database with local loop devices.
1899 * ha = adapter block pointer.
1905 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1910 fc_port_t
*fcport
, *new_fcport
;
1916 uint8_t domain
, area
, al_pa
;
1920 entries
= MAX_FIBRE_DEVICES
;
1922 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1923 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1925 /* Get list of logged in devices. */
1926 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1927 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1929 if (rval
!= QLA_SUCCESS
)
1930 goto cleanup_allocation
;
1932 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1933 ha
->host_no
, entries
));
1934 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1935 entries
* sizeof(struct gid_list_info
)));
1937 /* Allocate temporary fcport for any new fcports discovered. */
1938 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1939 if (new_fcport
== NULL
) {
1940 rval
= QLA_MEMORY_ALLOC_FAILED
;
1941 goto cleanup_allocation
;
1943 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1946 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1948 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
1949 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1950 fcport
->port_type
!= FCT_BROADCAST
&&
1951 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1953 DEBUG(printk("scsi(%ld): Marking port lost, "
1955 ha
->host_no
, fcport
->loop_id
));
1957 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1958 fcport
->flags
&= ~FCF_FARP_DONE
;
1962 /* Add devices to port list. */
1963 id_iter
= (char *)ha
->gid_list
;
1964 for (index
= 0; index
< entries
; index
++) {
1965 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1966 area
= ((struct gid_list_info
*)id_iter
)->area
;
1967 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1968 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1969 loop_id
= (uint16_t)
1970 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1972 loop_id
= le16_to_cpu(
1973 ((struct gid_list_info
*)id_iter
)->loop_id
);
1974 id_iter
+= ha
->gid_list_info_size
;
1976 /* Bypass reserved domain fields. */
1977 if ((domain
& 0xf0) == 0xf0)
1980 /* Bypass if not same domain and area of adapter. */
1981 if (area
&& domain
&&
1982 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
1985 /* Bypass invalid local loop ID. */
1986 if (loop_id
> LAST_LOCAL_LOOP_ID
)
1989 /* Fill in member data. */
1990 new_fcport
->d_id
.b
.domain
= domain
;
1991 new_fcport
->d_id
.b
.area
= area
;
1992 new_fcport
->d_id
.b
.al_pa
= al_pa
;
1993 new_fcport
->loop_id
= loop_id
;
1994 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
1995 if (rval2
!= QLA_SUCCESS
) {
1996 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
1997 "information -- get_port_database=%x, "
1999 ha
->host_no
, rval2
, new_fcport
->loop_id
));
2000 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2002 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2006 /* Check for matching device in port list. */
2009 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2010 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2014 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2015 FCF_PERSISTENT_BOUND
);
2016 fcport
->loop_id
= new_fcport
->loop_id
;
2017 fcport
->port_type
= new_fcport
->port_type
;
2018 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2019 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2027 /* New device, add to fcports list. */
2028 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2029 list_add_tail(&new_fcport
->list
, &ha
->fcports
);
2031 /* Allocate a new replacement fcport. */
2032 fcport
= new_fcport
;
2033 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2034 if (new_fcport
== NULL
) {
2035 rval
= QLA_MEMORY_ALLOC_FAILED
;
2036 goto cleanup_allocation
;
2038 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2041 /* Base iIDMA settings on HBA port speed. */
2042 switch (ha
->link_data_rate
) {
2043 case PORT_SPEED_1GB
:
2044 fcport
->fp_speed
= cpu_to_be16(BIT_15
);
2046 case PORT_SPEED_2GB
:
2047 fcport
->fp_speed
= cpu_to_be16(BIT_14
);
2049 case PORT_SPEED_4GB
:
2050 fcport
->fp_speed
= cpu_to_be16(BIT_13
);
2054 qla2x00_update_fcport(ha
, fcport
);
2062 if (rval
!= QLA_SUCCESS
) {
2063 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2064 "rval=%x\n", ha
->host_no
, rval
));
2068 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2069 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2076 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2080 qla2x00_mark_all_devices_lost(ha
, 0);
2081 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2082 if (fcport
->port_type
!= FCT_TARGET
)
2085 qla2x00_update_fcport(ha
, fcport
);
2090 qla2x00_iidma_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2092 #define LS_UNKNOWN 2
2093 static char *link_speeds
[5] = { "1", "2", "?", "4" };
2095 uint16_t port_speed
, mb
[6];
2097 if (!IS_QLA24XX(ha
))
2100 switch (be16_to_cpu(fcport
->fp_speed
)) {
2102 port_speed
= PORT_SPEED_1GB
;
2105 port_speed
= PORT_SPEED_2GB
;
2108 port_speed
= PORT_SPEED_4GB
;
2111 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2112 "unsupported FM port operating speed (%04x).\n",
2113 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2114 fcport
->port_name
[2], fcport
->port_name
[3],
2115 fcport
->port_name
[4], fcport
->port_name
[5],
2116 fcport
->port_name
[6], fcport
->port_name
[7],
2117 be16_to_cpu(fcport
->fp_speed
)));
2118 port_speed
= PORT_SPEED_UNKNOWN
;
2121 if (port_speed
== PORT_SPEED_UNKNOWN
)
2124 rval
= qla2x00_set_idma_speed(ha
, fcport
->loop_id
, port_speed
, mb
);
2125 if (rval
!= QLA_SUCCESS
) {
2126 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2127 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2128 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2129 fcport
->port_name
[2], fcport
->port_name
[3],
2130 fcport
->port_name
[4], fcport
->port_name
[5],
2131 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2132 port_speed
, mb
[0], mb
[1]));
2134 DEBUG2(qla_printk(KERN_INFO
, ha
,
2135 "iIDMA adjusted to %s GB/s on "
2136 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2137 link_speeds
[port_speed
], fcport
->port_name
[0],
2138 fcport
->port_name
[1], fcport
->port_name
[2],
2139 fcport
->port_name
[3], fcport
->port_name
[4],
2140 fcport
->port_name
[5], fcport
->port_name
[6],
2141 fcport
->port_name
[7]));
2146 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2148 struct fc_rport_identifiers rport_ids
;
2149 struct fc_rport
*rport
;
2150 unsigned long flags
;
2153 qla2x00_rport_del(fcport
);
2157 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2158 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2159 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2160 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2161 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2162 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2164 qla_printk(KERN_WARNING
, ha
,
2165 "Unable to allocate fc remote port!\n");
2168 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2169 fcport
->rport
= rport
;
2170 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2171 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2173 rport
->supported_classes
= fcport
->supported_classes
;
2175 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2176 if (fcport
->port_type
== FCT_INITIATOR
)
2177 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2178 if (fcport
->port_type
== FCT_TARGET
)
2179 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2180 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2182 if (rport
->scsi_target_id
!= -1 &&
2183 rport
->scsi_target_id
< ha
->host
->max_id
)
2184 fcport
->os_target_id
= rport
->scsi_target_id
;
2188 * qla2x00_update_fcport
2189 * Updates device on list.
2192 * ha = adapter block pointer.
2193 * fcport = port structure pointer.
2203 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2206 fcport
->login_retry
= 0;
2207 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2209 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2211 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2213 qla2x00_iidma_fcport(ha
, fcport
);
2215 atomic_set(&fcport
->state
, FCS_ONLINE
);
2217 qla2x00_reg_remote_port(ha
, fcport
);
2221 * qla2x00_configure_fabric
2222 * Setup SNS devices with loop ID's.
2225 * ha = adapter block pointer.
2232 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2235 fc_port_t
*fcport
, *fcptemp
;
2236 uint16_t next_loopid
;
2237 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2239 LIST_HEAD(new_fcports
);
2241 /* If FL port exists, then SNS is present */
2242 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2243 loop_id
= NPH_F_PORT
;
2245 loop_id
= SNS_FL_PORT
;
2246 rval
= qla2x00_get_port_name(ha
, loop_id
, ha
->fabric_node_name
, 1);
2247 if (rval
!= QLA_SUCCESS
) {
2248 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2249 "Port\n", ha
->host_no
));
2251 ha
->device_flags
&= ~SWITCH_FOUND
;
2252 return (QLA_SUCCESS
);
2254 ha
->device_flags
|= SWITCH_FOUND
;
2256 /* Mark devices that need re-synchronization. */
2257 rval2
= qla2x00_device_resync(ha
);
2258 if (rval2
== QLA_RSCNS_HANDLED
) {
2259 /* No point doing the scan, just continue. */
2260 return (QLA_SUCCESS
);
2264 if (ql2xfdmienable
&&
2265 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2266 qla2x00_fdmi_register(ha
);
2268 /* Ensure we are logged into the SNS. */
2269 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
))
2272 loop_id
= SIMPLE_NAME_SERVER
;
2273 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2274 0xfc, mb
, BIT_1
| BIT_0
);
2275 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2276 DEBUG2(qla_printk(KERN_INFO
, ha
,
2277 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2278 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2279 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2280 return (QLA_SUCCESS
);
2283 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2284 if (qla2x00_rft_id(ha
)) {
2286 DEBUG2(printk("scsi(%ld): Register FC-4 "
2287 "TYPE failed.\n", ha
->host_no
));
2289 if (qla2x00_rff_id(ha
)) {
2291 DEBUG2(printk("scsi(%ld): Register FC-4 "
2292 "Features failed.\n", ha
->host_no
));
2294 if (qla2x00_rnn_id(ha
)) {
2296 DEBUG2(printk("scsi(%ld): Register Node Name "
2297 "failed.\n", ha
->host_no
));
2298 } else if (qla2x00_rsnn_nn(ha
)) {
2300 DEBUG2(printk("scsi(%ld): Register Symbolic "
2301 "Node Name failed.\n", ha
->host_no
));
2305 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2306 if (rval
!= QLA_SUCCESS
)
2310 * Logout all previous fabric devices marked lost, except
2313 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2314 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2317 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2320 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2321 qla2x00_mark_device_lost(ha
, fcport
,
2322 ql2xplogiabsentdevice
, 0);
2323 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2324 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2325 fcport
->port_type
!= FCT_INITIATOR
&&
2326 fcport
->port_type
!= FCT_BROADCAST
) {
2327 ha
->isp_ops
.fabric_logout(ha
,
2329 fcport
->d_id
.b
.domain
,
2330 fcport
->d_id
.b
.area
,
2331 fcport
->d_id
.b
.al_pa
);
2332 fcport
->loop_id
= FC_NO_LOOP_ID
;
2337 /* Starting free loop ID. */
2338 next_loopid
= ha
->min_external_loopid
;
2341 * Scan through our port list and login entries that need to be
2344 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2345 if (atomic_read(&ha
->loop_down_timer
) ||
2346 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2349 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2350 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2353 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2354 fcport
->loop_id
= next_loopid
;
2355 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2356 if (rval
!= QLA_SUCCESS
) {
2357 /* Ran out of IDs to use */
2361 /* Login and update database */
2362 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2365 /* Exit if out of loop IDs. */
2366 if (rval
!= QLA_SUCCESS
) {
2371 * Login and add the new devices to our port list.
2373 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2374 if (atomic_read(&ha
->loop_down_timer
) ||
2375 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2378 /* Find a new loop ID to use. */
2379 fcport
->loop_id
= next_loopid
;
2380 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2381 if (rval
!= QLA_SUCCESS
) {
2382 /* Ran out of IDs to use */
2386 /* Remove device from the new list and add it to DB */
2387 list_move_tail(&fcport
->list
, &ha
->fcports
);
2389 /* Login and update database */
2390 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2394 /* Free all new device structures not processed. */
2395 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2396 list_del(&fcport
->list
);
2401 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2402 "rval=%d\n", ha
->host_no
, rval
));
2410 * qla2x00_find_all_fabric_devs
2413 * ha = adapter block pointer.
2414 * dev = database device entry pointer.
2423 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2427 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2432 int first_dev
, last_dev
;
2433 port_id_t wrap
, nxt_d_id
;
2437 /* Try GID_PT to get device list, else GAN. */
2438 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2441 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2442 "on GA_NXT\n", ha
->host_no
));
2444 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2445 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2448 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2451 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2454 } else if (qla2x00_gfpn_id(ha
, swl
) == QLA_SUCCESS
) {
2455 qla2x00_gpsc(ha
, swl
);
2460 /* Allocate temporary fcport for any new fcports discovered. */
2461 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2462 if (new_fcport
== NULL
) {
2464 return (QLA_MEMORY_ALLOC_FAILED
);
2466 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2468 /* Set start port ID scan at adapter ID. */
2472 /* Starting free loop ID. */
2473 loop_id
= ha
->min_external_loopid
;
2474 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2475 if (qla2x00_is_reserved_id(ha
, loop_id
))
2478 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2483 wrap
.b24
= new_fcport
->d_id
.b24
;
2485 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2486 memcpy(new_fcport
->node_name
,
2487 swl
[swl_idx
].node_name
, WWN_SIZE
);
2488 memcpy(new_fcport
->port_name
,
2489 swl
[swl_idx
].port_name
, WWN_SIZE
);
2490 memcpy(new_fcport
->fabric_port_name
,
2491 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2492 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2494 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2500 /* Send GA_NXT to the switch */
2501 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2502 if (rval
!= QLA_SUCCESS
) {
2503 qla_printk(KERN_WARNING
, ha
,
2504 "SNS scan failed -- assuming zero-entry "
2506 list_for_each_entry_safe(fcport
, fcptemp
,
2507 new_fcports
, list
) {
2508 list_del(&fcport
->list
);
2516 /* If wrap on switch device list, exit. */
2518 wrap
.b24
= new_fcport
->d_id
.b24
;
2520 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2521 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2522 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2523 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2527 /* Bypass if host adapter. */
2528 if (new_fcport
->d_id
.b24
== ha
->d_id
.b24
)
2531 /* Bypass if same domain and area of adapter. */
2532 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2533 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2537 /* Bypass reserved domain fields. */
2538 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2541 /* Locate matching device in database. */
2543 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2544 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2550 /* Update port state. */
2551 memcpy(fcport
->fabric_port_name
,
2552 new_fcport
->fabric_port_name
, WWN_SIZE
);
2553 fcport
->fp_speed
= new_fcport
->fp_speed
;
2556 * If address the same and state FCS_ONLINE, nothing
2559 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2560 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2565 * If device was not a fabric device before.
2567 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2568 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2569 fcport
->loop_id
= FC_NO_LOOP_ID
;
2570 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2572 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2577 * Port ID changed or device was marked to be updated;
2578 * Log it out if still logged in and mark it for
2581 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2582 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2583 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2584 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2585 fcport
->port_type
!= FCT_INITIATOR
&&
2586 fcport
->port_type
!= FCT_BROADCAST
) {
2587 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2588 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2589 fcport
->d_id
.b
.al_pa
);
2590 fcport
->loop_id
= FC_NO_LOOP_ID
;
2599 /* If device was not in our fcports list, then add it. */
2600 list_add_tail(&new_fcport
->list
, new_fcports
);
2602 /* Allocate a new replacement fcport. */
2603 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2604 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2605 if (new_fcport
== NULL
) {
2607 return (QLA_MEMORY_ALLOC_FAILED
);
2609 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2610 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2616 if (!list_empty(new_fcports
))
2617 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2623 * qla2x00_find_new_loop_id
2624 * Scan through our port list and find a new usable loop ID.
2627 * ha: adapter state pointer.
2628 * dev: port structure pointer.
2631 * qla2x00 local function return status code.
2637 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2642 uint16_t first_loop_id
;
2646 /* Save starting loop ID. */
2647 first_loop_id
= dev
->loop_id
;
2650 /* Skip loop ID if already used by adapter. */
2651 if (dev
->loop_id
== ha
->loop_id
) {
2655 /* Skip reserved loop IDs. */
2656 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2660 /* Reset loop ID if passed the end. */
2661 if (dev
->loop_id
> ha
->last_loop_id
) {
2662 /* first loop ID. */
2663 dev
->loop_id
= ha
->min_external_loopid
;
2666 /* Check for loop ID being already in use. */
2669 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2670 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2671 /* ID possibly in use */
2677 /* If not in use then it is free to use. */
2682 /* ID in use. Try next value. */
2685 /* If wrap around. No free ID to use. */
2686 if (dev
->loop_id
== first_loop_id
) {
2687 dev
->loop_id
= FC_NO_LOOP_ID
;
2688 rval
= QLA_FUNCTION_FAILED
;
2697 * qla2x00_device_resync
2698 * Marks devices in the database that needs resynchronization.
2701 * ha = adapter block pointer.
2707 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2712 uint32_t rscn_entry
;
2713 uint8_t rscn_out_iter
;
2717 rval
= QLA_RSCNS_HANDLED
;
2719 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2720 ha
->flags
.rscn_queue_overflow
) {
2722 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2723 format
= MSB(MSW(rscn_entry
));
2724 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2725 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2726 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2728 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2729 "[%02x/%02x%02x%02x].\n",
2730 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2731 d_id
.b
.area
, d_id
.b
.al_pa
));
2734 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2735 ha
->rscn_out_ptr
= 0;
2737 /* Skip duplicate entries. */
2738 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2739 !ha
->flags
.rscn_queue_overflow
&&
2740 rscn_out_iter
!= ha
->rscn_in_ptr
;
2741 rscn_out_iter
= (rscn_out_iter
==
2742 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2744 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2747 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2748 "entry found at [%d].\n", ha
->host_no
,
2751 ha
->rscn_out_ptr
= rscn_out_iter
;
2754 /* Queue overflow, set switch default case. */
2755 if (ha
->flags
.rscn_queue_overflow
) {
2756 DEBUG(printk("scsi(%ld): device_resync: rscn "
2757 "overflow.\n", ha
->host_no
));
2760 ha
->flags
.rscn_queue_overflow
= 0;
2776 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2782 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2783 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2784 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2785 fcport
->port_type
== FCT_BROADCAST
)
2788 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2790 fcport
->port_type
!= FCT_INITIATOR
) {
2791 qla2x00_mark_device_lost(ha
, fcport
,
2795 fcport
->flags
&= ~FCF_FARP_DONE
;
2802 * qla2x00_fabric_dev_login
2803 * Login fabric target device and update FC port database.
2806 * ha: adapter state pointer.
2807 * fcport: port structure list pointer.
2808 * next_loopid: contains value of a new loop ID that can be used
2809 * by the next login attempt.
2812 * qla2x00 local function return status code.
2818 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2819 uint16_t *next_loopid
)
2828 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2829 if (rval
== QLA_SUCCESS
) {
2830 /* Send an ADISC to tape devices.*/
2832 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2834 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2835 if (rval
!= QLA_SUCCESS
) {
2836 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2837 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2838 fcport
->d_id
.b
.al_pa
);
2839 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2841 qla2x00_update_fcport(ha
, fcport
);
2849 * qla2x00_fabric_login
2850 * Issue fabric login command.
2853 * ha = adapter block pointer.
2854 * device = pointer to FC device type structure.
2857 * 0 - Login successfully
2859 * 2 - Initiator device
2863 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2864 uint16_t *next_loopid
)
2868 uint16_t tmp_loopid
;
2869 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2875 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2876 "for port %02x%02x%02x.\n",
2877 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2878 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2880 /* Login fcport on switch. */
2881 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2882 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2883 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2884 if (mb
[0] == MBS_PORT_ID_USED
) {
2886 * Device has another loop ID. The firmware team
2887 * recommends the driver perform an implicit login with
2888 * the specified ID again. The ID we just used is save
2889 * here so we return with an ID that can be tried by
2893 tmp_loopid
= fcport
->loop_id
;
2894 fcport
->loop_id
= mb
[1];
2896 DEBUG(printk("Fabric Login: port in use - next "
2897 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2898 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2899 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2901 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2906 /* A retry occurred before. */
2907 *next_loopid
= tmp_loopid
;
2910 * No retry occurred before. Just increment the
2911 * ID value for next login.
2913 *next_loopid
= (fcport
->loop_id
+ 1);
2916 if (mb
[1] & BIT_0
) {
2917 fcport
->port_type
= FCT_INITIATOR
;
2919 fcport
->port_type
= FCT_TARGET
;
2920 if (mb
[1] & BIT_1
) {
2921 fcport
->flags
|= FCF_TAPE_PRESENT
;
2926 fcport
->supported_classes
|= FC_COS_CLASS2
;
2928 fcport
->supported_classes
|= FC_COS_CLASS3
;
2932 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
2934 * Loop ID already used, try next loop ID.
2937 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2938 if (rval
!= QLA_SUCCESS
) {
2939 /* Ran out of loop IDs to use */
2942 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
2944 * Firmware possibly timed out during login. If NO
2945 * retries are left to do then the device is declared
2948 *next_loopid
= fcport
->loop_id
;
2949 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2950 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2951 fcport
->d_id
.b
.al_pa
);
2952 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2958 * unrecoverable / not handled error
2960 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
2961 "loop_id=%x jiffies=%lx.\n",
2962 __func__
, ha
->host_no
, mb
[0],
2963 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2964 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
2966 *next_loopid
= fcport
->loop_id
;
2967 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2968 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2969 fcport
->d_id
.b
.al_pa
);
2970 fcport
->loop_id
= FC_NO_LOOP_ID
;
2971 fcport
->login_retry
= 0;
2982 * qla2x00_local_device_login
2983 * Issue local device login command.
2986 * ha = adapter block pointer.
2987 * loop_id = loop id of device to login to.
2989 * Returns (Where's the #define!!!!):
2990 * 0 - Login successfully
2995 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2998 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3000 memset(mb
, 0, sizeof(mb
));
3001 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
3002 if (rval
== QLA_SUCCESS
) {
3003 /* Interrogate mailbox registers for any errors */
3004 if (mb
[0] == MBS_COMMAND_ERROR
)
3006 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3007 /* device not in PCB table */
3015 * qla2x00_loop_resync
3016 * Resync with fibre channel devices.
3019 * ha = adapter block pointer.
3025 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
3032 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3033 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3034 if (ha
->flags
.online
) {
3035 if (!(rval
= qla2x00_fw_ready(ha
))) {
3036 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3039 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3041 /* Issue a marker after FW becomes ready. */
3042 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3043 ha
->marker_needed
= 0;
3045 /* Remap devices on Loop. */
3046 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3048 qla2x00_configure_loop(ha
);
3050 } while (!atomic_read(&ha
->loop_down_timer
) &&
3051 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3053 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3057 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3058 return (QLA_FUNCTION_FAILED
);
3062 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3069 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3075 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3076 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3079 qla2x00_update_fcport(ha
, fcport
);
3080 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3084 qla2x00_probe_for_all_luns(ha
);
3088 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3092 /* Go with deferred removal of rport references. */
3093 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3095 qla2x00_rport_del(fcport
);
3100 * Resets ISP and aborts all outstanding commands.
3103 * ha = adapter block pointer.
3109 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3112 unsigned long flags
= 0;
3117 if (ha
->flags
.online
) {
3118 ha
->flags
.online
= 0;
3119 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3121 qla_printk(KERN_INFO
, ha
,
3122 "Performing ISP error recovery - ha= %p.\n", ha
);
3123 ha
->isp_ops
.reset_chip(ha
);
3125 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3126 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3127 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3128 qla2x00_mark_all_devices_lost(ha
, 0);
3130 if (!atomic_read(&ha
->loop_down_timer
))
3131 atomic_set(&ha
->loop_down_timer
,
3135 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3136 /* Requeue all commands in outstanding command list. */
3137 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3138 sp
= ha
->outstanding_cmds
[cnt
];
3140 ha
->outstanding_cmds
[cnt
] = NULL
;
3142 sp
->cmd
->result
= DID_RESET
<< 16;
3143 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3144 qla2x00_sp_compl(ha
, sp
);
3147 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3149 ha
->isp_ops
.get_flash_version(ha
, ha
->request_ring
);
3151 ha
->isp_ops
.nvram_config(ha
);
3153 if (!qla2x00_restart_isp(ha
)) {
3154 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3156 if (!atomic_read(&ha
->loop_down_timer
)) {
3158 * Issue marker command only when we are going
3159 * to start the I/O .
3161 ha
->marker_needed
= 1;
3164 ha
->flags
.online
= 1;
3166 ha
->isp_ops
.enable_intrs(ha
);
3168 ha
->isp_abort_cnt
= 0;
3169 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3172 rval
= qla2x00_trace_control(ha
, TC_ENABLE
,
3173 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3175 qla_printk(KERN_WARNING
, ha
,
3176 "Unable to reinitialize EFT "
3180 } else { /* failed the ISP abort */
3181 ha
->flags
.online
= 1;
3182 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3183 if (ha
->isp_abort_cnt
== 0) {
3184 qla_printk(KERN_WARNING
, ha
,
3185 "ISP error recovery failed - "
3186 "board disabled\n");
3188 * The next call disables the board
3191 ha
->isp_ops
.reset_adapter(ha
);
3192 ha
->flags
.online
= 0;
3193 clear_bit(ISP_ABORT_RETRY
,
3196 } else { /* schedule another ISP abort */
3197 ha
->isp_abort_cnt
--;
3198 DEBUG(printk("qla%ld: ISP abort - "
3199 "retry remaining %d\n",
3200 ha
->host_no
, ha
->isp_abort_cnt
));
3204 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3205 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3206 "- retrying (%d) more times\n",
3207 ha
->host_no
, ha
->isp_abort_cnt
));
3208 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3216 qla_printk(KERN_INFO
, ha
,
3217 "qla2x00_abort_isp: **** FAILED ****\n");
3219 DEBUG(printk(KERN_INFO
3220 "qla2x00_abort_isp(%ld): exiting.\n",
3228 * qla2x00_restart_isp
3229 * restarts the ISP after a reset
3232 * ha = adapter block pointer.
3238 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3241 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3242 unsigned long flags
= 0;
3245 /* If firmware needs to be loaded */
3246 if (qla2x00_isp_firmware(ha
)) {
3247 ha
->flags
.online
= 0;
3248 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3249 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3250 status
= qla2x00_setup_chip(ha
);
3254 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3256 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3258 * Disable SRAM, Instruction RAM and GP RAM
3261 WRT_REG_WORD(®
->hccr
,
3262 (HCCR_ENABLE_PARITY
+ 0x0));
3263 RD_REG_WORD(®
->hccr
);
3266 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3268 status
= qla2x00_setup_chip(ha
);
3270 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3272 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3273 /* Enable proper parity */
3276 WRT_REG_WORD(®
->hccr
,
3277 (HCCR_ENABLE_PARITY
+ 0x1));
3280 * SRAM, Instruction RAM and GP RAM
3283 WRT_REG_WORD(®
->hccr
,
3284 (HCCR_ENABLE_PARITY
+ 0x7));
3285 RD_REG_WORD(®
->hccr
);
3288 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3293 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3294 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3295 if (!(status
= qla2x00_fw_ready(ha
))) {
3296 DEBUG(printk("%s(): Start configure loop, "
3297 "status = %d\n", __func__
, status
));
3299 /* Issue a marker after FW becomes ready. */
3300 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3302 ha
->flags
.online
= 1;
3303 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3306 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3307 qla2x00_configure_loop(ha
);
3309 } while (!atomic_read(&ha
->loop_down_timer
) &&
3310 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3312 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3315 /* if no cable then assume it's good */
3316 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3319 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3327 * qla2x00_reset_adapter
3331 * ha = adapter block pointer.
3334 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3336 unsigned long flags
= 0;
3337 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3339 ha
->flags
.online
= 0;
3340 ha
->isp_ops
.disable_intrs(ha
);
3342 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3343 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3344 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3345 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3346 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3347 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3351 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3353 unsigned long flags
= 0;
3354 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3356 ha
->flags
.online
= 0;
3357 ha
->isp_ops
.disable_intrs(ha
);
3359 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3360 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3361 RD_REG_DWORD(®
->hccr
);
3362 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3363 RD_REG_DWORD(®
->hccr
);
3364 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3367 /* On sparc systems, obtain port and node WWN from firmware
3370 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, struct nvram_24xx
*nv
)
3373 struct pci_dev
*pdev
= ha
->pdev
;
3374 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3378 val
= of_get_property(dp
, "port-wwn", &len
);
3379 if (val
&& len
>= WWN_SIZE
)
3380 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3382 val
= of_get_property(dp
, "node-wwn", &len
);
3383 if (val
&& len
>= WWN_SIZE
)
3384 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3389 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3392 struct init_cb_24xx
*icb
;
3393 struct nvram_24xx
*nv
;
3395 uint8_t *dptr1
, *dptr2
;
3400 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3401 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3403 /* Determine NVRAM starting address. */
3404 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3405 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3406 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3407 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3408 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3409 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3410 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3413 /* Get NVRAM data and calculate checksum. */
3414 dptr
= (uint32_t *)nv
;
3415 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3417 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3418 chksum
+= le32_to_cpu(*dptr
++);
3420 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3421 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3424 /* Bad NVRAM data, set defaults parameters. */
3425 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3426 || nv
->id
[3] != ' ' ||
3427 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3428 /* Reset NVRAM data. */
3429 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3430 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3431 le16_to_cpu(nv
->nvram_version
));
3432 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3433 "invalid -- WWPN) defaults.\n");
3436 * Set default initialization control block.
3438 memset(nv
, 0, ha
->nvram_size
);
3439 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3440 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3441 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3442 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3443 nv
->exchange_count
= __constant_cpu_to_le16(0);
3444 nv
->hard_address
= __constant_cpu_to_le16(124);
3445 nv
->port_name
[0] = 0x21;
3446 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3447 nv
->port_name
[2] = 0x00;
3448 nv
->port_name
[3] = 0xe0;
3449 nv
->port_name
[4] = 0x8b;
3450 nv
->port_name
[5] = 0x1c;
3451 nv
->port_name
[6] = 0x55;
3452 nv
->port_name
[7] = 0x86;
3453 nv
->node_name
[0] = 0x20;
3454 nv
->node_name
[1] = 0x00;
3455 nv
->node_name
[2] = 0x00;
3456 nv
->node_name
[3] = 0xe0;
3457 nv
->node_name
[4] = 0x8b;
3458 nv
->node_name
[5] = 0x1c;
3459 nv
->node_name
[6] = 0x55;
3460 nv
->node_name
[7] = 0x86;
3461 qla24xx_nvram_wwn_from_ofw(ha
, nv
);
3462 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3463 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3464 nv
->login_timeout
= __constant_cpu_to_le16(0);
3465 nv
->firmware_options_1
=
3466 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3467 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3468 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3469 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3470 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3471 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3472 nv
->reset_delay
= 5;
3473 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3474 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3475 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3480 /* Reset Initialization control block */
3481 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3483 /* Copy 1st segment. */
3484 dptr1
= (uint8_t *)icb
;
3485 dptr2
= (uint8_t *)&nv
->version
;
3486 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3488 *dptr1
++ = *dptr2
++;
3490 icb
->login_retry_count
= nv
->login_retry_count
;
3491 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3493 /* Copy 2nd segment. */
3494 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3495 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3496 cnt
= (uint8_t *)&icb
->reserved_3
-
3497 (uint8_t *)&icb
->interrupt_delay_timer
;
3499 *dptr1
++ = *dptr2
++;
3502 * Setup driver NVRAM options.
3504 qla2x00_set_model_info(ha
, nv
->model_name
, sizeof(nv
->model_name
),
3507 /* Use alternate WWN? */
3508 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3509 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3510 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3513 /* Prepare nodename */
3514 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3516 * Firmware will apply the following mask if the nodename was
3519 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3520 icb
->node_name
[0] &= 0xF0;
3523 /* Set host adapter parameters. */
3524 ha
->flags
.disable_risc_code_load
= 0;
3525 ha
->flags
.enable_lip_reset
= 0;
3526 ha
->flags
.enable_lip_full_login
=
3527 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3528 ha
->flags
.enable_target_reset
=
3529 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3530 ha
->flags
.enable_led_scheme
= 0;
3531 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3533 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3534 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3536 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3537 sizeof(ha
->fw_seriallink_options24
));
3539 /* save HBA serial number */
3540 ha
->serial0
= icb
->port_name
[5];
3541 ha
->serial1
= icb
->port_name
[6];
3542 ha
->serial2
= icb
->port_name
[7];
3543 ha
->node_name
= icb
->node_name
;
3544 ha
->port_name
= icb
->port_name
;
3546 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3548 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3550 /* Set minimum login_timeout to 4 seconds. */
3551 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3552 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3553 if (le16_to_cpu(nv
->login_timeout
) < 4)
3554 nv
->login_timeout
= __constant_cpu_to_le16(4);
3555 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3556 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3558 /* Set minimum RATOV to 200 tenths of a second. */
3561 ha
->loop_reset_delay
= nv
->reset_delay
;
3563 /* Link Down Timeout = 0:
3565 * When Port Down timer expires we will start returning
3566 * I/O's to OS with "DID_NO_CONNECT".
3568 * Link Down Timeout != 0:
3570 * The driver waits for the link to come up after link down
3571 * before returning I/Os to OS with "DID_NO_CONNECT".
3573 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3574 ha
->loop_down_abort_time
=
3575 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3577 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3578 ha
->loop_down_abort_time
=
3579 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3582 /* Need enough time to try and get the port back. */
3583 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3584 if (qlport_down_retry
)
3585 ha
->port_down_retry_count
= qlport_down_retry
;
3587 /* Set login_retry_count */
3588 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3589 if (ha
->port_down_retry_count
==
3590 le16_to_cpu(nv
->port_down_retry_count
) &&
3591 ha
->port_down_retry_count
> 3)
3592 ha
->login_retry_count
= ha
->port_down_retry_count
;
3593 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3594 ha
->login_retry_count
= ha
->port_down_retry_count
;
3595 if (ql2xloginretrycount
)
3596 ha
->login_retry_count
= ql2xloginretrycount
;
3599 if (!ha
->flags
.init_done
) {
3600 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3601 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3602 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3603 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3605 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3606 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3607 ha
->flags
.process_response_queue
= 0;
3608 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3609 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3611 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3612 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3613 ha
->zio_timer
* 100));
3614 qla_printk(KERN_INFO
, ha
,
3615 "ZIO mode %d enabled; timer delay (%d us).\n",
3616 ha
->zio_mode
, ha
->zio_timer
* 100);
3618 icb
->firmware_options_2
|= cpu_to_le32(
3619 (uint32_t)ha
->zio_mode
);
3620 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3621 ha
->flags
.process_response_queue
= 1;
3625 DEBUG2_3(printk(KERN_WARNING
3626 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3632 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3635 int segments
, fragment
;
3637 uint32_t *dcode
, dlen
;
3644 segments
= FA_RISC_CODE_SEGMENTS
;
3645 faddr
= FA_RISC_CODE_ADDR
;
3646 dcode
= (uint32_t *)ha
->request_ring
;
3649 /* Validate firmware image by checking version. */
3650 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3651 for (i
= 0; i
< 4; i
++)
3652 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3653 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3654 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3655 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3657 qla_printk(KERN_WARNING
, ha
,
3658 "Unable to verify integrity of flash firmware image!\n");
3659 qla_printk(KERN_WARNING
, ha
,
3660 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3661 dcode
[1], dcode
[2], dcode
[3]);
3663 return QLA_FUNCTION_FAILED
;
3666 while (segments
&& rval
== QLA_SUCCESS
) {
3667 /* Read segment's load information. */
3668 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3670 risc_addr
= be32_to_cpu(dcode
[2]);
3671 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3672 risc_size
= be32_to_cpu(dcode
[3]);
3675 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3676 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3677 if (dlen
> risc_size
)
3680 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3681 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3682 ha
->host_no
, risc_addr
, dlen
, faddr
));
3684 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3685 for (i
= 0; i
< dlen
; i
++)
3686 dcode
[i
] = swab32(dcode
[i
]);
3688 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3691 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3692 "segment %d of firmware\n", ha
->host_no
,
3694 qla_printk(KERN_WARNING
, ha
,
3695 "[ERROR] Failed to load segment %d of "
3696 "firmware\n", fragment
);
3713 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3716 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3720 uint16_t *wcode
, *fwcode
;
3721 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3722 struct fw_blob
*blob
;
3724 /* Load firmware blob. */
3725 blob
= qla2x00_request_firmware(ha
);
3727 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3728 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3729 "from: " QLA_FW_URL
".\n");
3730 return QLA_FUNCTION_FAILED
;
3735 wcode
= (uint16_t *)ha
->request_ring
;
3737 fwcode
= (uint16_t *)blob
->fw
->data
;
3740 /* Validate firmware image by checking version. */
3741 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3742 qla_printk(KERN_WARNING
, ha
,
3743 "Unable to verify integrity of firmware image (%Zd)!\n",
3745 goto fail_fw_integrity
;
3747 for (i
= 0; i
< 4; i
++)
3748 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3749 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3750 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3751 wcode
[2] == 0 && wcode
[3] == 0)) {
3752 qla_printk(KERN_WARNING
, ha
,
3753 "Unable to verify integrity of firmware image!\n");
3754 qla_printk(KERN_WARNING
, ha
,
3755 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3756 wcode
[1], wcode
[2], wcode
[3]);
3757 goto fail_fw_integrity
;
3761 while (*seg
&& rval
== QLA_SUCCESS
) {
3763 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3764 risc_size
= be16_to_cpu(fwcode
[3]);
3766 /* Validate firmware image size. */
3767 fwclen
+= risc_size
* sizeof(uint16_t);
3768 if (blob
->fw
->size
< fwclen
) {
3769 qla_printk(KERN_WARNING
, ha
,
3770 "Unable to verify integrity of firmware image "
3771 "(%Zd)!\n", blob
->fw
->size
);
3772 goto fail_fw_integrity
;
3776 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3777 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3778 if (wlen
> risc_size
)
3781 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3782 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3785 for (i
= 0; i
< wlen
; i
++)
3786 wcode
[i
] = swab16(fwcode
[i
]);
3788 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3791 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3792 "segment %d of firmware\n", ha
->host_no
,
3794 qla_printk(KERN_WARNING
, ha
,
3795 "[ERROR] Failed to load segment %d of "
3796 "firmware\n", fragment
);
3812 return QLA_FUNCTION_FAILED
;
3816 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3819 int segments
, fragment
;
3820 uint32_t *dcode
, dlen
;
3824 struct fw_blob
*blob
;
3825 uint32_t *fwcode
, fwclen
;
3827 /* Load firmware blob. */
3828 blob
= qla2x00_request_firmware(ha
);
3830 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3831 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3832 "from: " QLA_FW_URL
".\n");
3834 /* Try to load RISC code from flash. */
3835 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3836 "outdated) firmware from flash.\n");
3837 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3842 segments
= FA_RISC_CODE_SEGMENTS
;
3843 dcode
= (uint32_t *)ha
->request_ring
;
3845 fwcode
= (uint32_t *)blob
->fw
->data
;
3848 /* Validate firmware image by checking version. */
3849 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3850 qla_printk(KERN_WARNING
, ha
,
3851 "Unable to verify integrity of firmware image (%Zd)!\n",
3853 goto fail_fw_integrity
;
3855 for (i
= 0; i
< 4; i
++)
3856 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3857 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3858 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3859 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3861 qla_printk(KERN_WARNING
, ha
,
3862 "Unable to verify integrity of firmware image!\n");
3863 qla_printk(KERN_WARNING
, ha
,
3864 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3865 dcode
[1], dcode
[2], dcode
[3]);
3866 goto fail_fw_integrity
;
3869 while (segments
&& rval
== QLA_SUCCESS
) {
3870 risc_addr
= be32_to_cpu(fwcode
[2]);
3871 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3872 risc_size
= be32_to_cpu(fwcode
[3]);
3874 /* Validate firmware image size. */
3875 fwclen
+= risc_size
* sizeof(uint32_t);
3876 if (blob
->fw
->size
< fwclen
) {
3877 qla_printk(KERN_WARNING
, ha
,
3878 "Unable to verify integrity of firmware image "
3879 "(%Zd)!\n", blob
->fw
->size
);
3881 goto fail_fw_integrity
;
3885 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3886 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3887 if (dlen
> risc_size
)
3890 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3891 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3894 for (i
= 0; i
< dlen
; i
++)
3895 dcode
[i
] = swab32(fwcode
[i
]);
3897 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3900 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3901 "segment %d of firmware\n", ha
->host_no
,
3903 qla_printk(KERN_WARNING
, ha
,
3904 "[ERROR] Failed to load segment %d of "
3905 "firmware\n", fragment
);
3921 return QLA_FUNCTION_FAILED
;
3925 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*ha
)
3929 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
))
3932 ret
= qla2x00_stop_firmware(ha
);
3933 for (retries
= 5; ret
!= QLA_SUCCESS
&& retries
; retries
--) {
3934 qla2x00_reset_chip(ha
);
3935 if (qla2x00_chip_diag(ha
) != QLA_SUCCESS
)
3937 if (qla2x00_setup_chip(ha
) != QLA_SUCCESS
)
3939 qla_printk(KERN_INFO
, ha
,
3940 "Attempting retry of stop-firmware command...\n");
3941 ret
= qla2x00_stop_firmware(ha
);