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
);
138 pci_try_set_mwi(ha
->pdev
);
140 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
141 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
142 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
144 /* Reset expansion ROM address decode enable */
145 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
146 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
147 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
149 /* Get PCI bus information. */
150 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
151 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
152 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
158 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
161 * Returns 0 on success.
164 qla2300_pci_config(scsi_qla_host_t
*ha
)
168 unsigned long flags
= 0;
170 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
172 pci_set_master(ha
->pdev
);
173 pci_try_set_mwi(ha
->pdev
);
175 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
176 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
178 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
179 w
&= ~PCI_COMMAND_INTX_DISABLE
;
180 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
183 * If this is a 2300 card and not 2312, reset the
184 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
185 * the 2310 also reports itself as a 2300 so we need to get the
186 * fb revision level -- a 6 indicates it really is a 2300 and
189 if (IS_QLA2300(ha
)) {
190 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
193 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
194 for (cnt
= 0; cnt
< 30000; cnt
++) {
195 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
201 /* Select FPM registers. */
202 WRT_REG_WORD(®
->ctrl_status
, 0x20);
203 RD_REG_WORD(®
->ctrl_status
);
205 /* Get the fb rev level */
206 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
208 if (ha
->fb_rev
== FPM_2300
)
209 pci_clear_mwi(ha
->pdev
);
211 /* Deselect FPM registers. */
212 WRT_REG_WORD(®
->ctrl_status
, 0x0);
213 RD_REG_WORD(®
->ctrl_status
);
215 /* Release RISC module. */
216 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
217 for (cnt
= 0; cnt
< 30000; cnt
++) {
218 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
224 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
227 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
229 /* Reset expansion ROM address decode enable */
230 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
231 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
232 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
234 /* Get PCI bus information. */
235 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
236 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
237 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
243 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
246 * Returns 0 on success.
249 qla24xx_pci_config(scsi_qla_host_t
*ha
)
253 unsigned long flags
= 0;
254 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
256 pci_set_master(ha
->pdev
);
257 pci_try_set_mwi(ha
->pdev
);
259 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
260 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
261 w
&= ~PCI_COMMAND_INTX_DISABLE
;
262 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
264 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
266 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
267 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
268 pcix_set_mmrbc(ha
->pdev
, 2048);
270 /* PCIe -- adjust Maximum Read Request Size (2048). */
271 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
272 pcie_set_readrq(ha
->pdev
, 2048);
274 /* Reset expansion ROM address decode enable */
275 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
276 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
277 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
279 ha
->chip_revision
= ha
->pdev
->revision
;
281 /* Get PCI bus information. */
282 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
283 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
284 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
290 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
293 * Returns 0 on success.
296 qla25xx_pci_config(scsi_qla_host_t
*ha
)
301 pci_set_master(ha
->pdev
);
302 pci_try_set_mwi(ha
->pdev
);
304 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
305 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
306 w
&= ~PCI_COMMAND_INTX_DISABLE
;
307 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
309 /* PCIe -- adjust Maximum Read Request Size (2048). */
310 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
311 pcie_set_readrq(ha
->pdev
, 2048);
313 /* Reset expansion ROM address decode enable */
314 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
315 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
316 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
318 ha
->chip_revision
= ha
->pdev
->revision
;
324 * qla2x00_isp_firmware() - Choose firmware image.
327 * Returns 0 on success.
330 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
334 /* Assume loading risc code */
335 rval
= QLA_FUNCTION_FAILED
;
337 if (ha
->flags
.disable_risc_code_load
) {
338 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
340 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
342 /* Verify checksum of loaded RISC code. */
343 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
347 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
355 * qla2x00_reset_chip() - Reset ISP chip.
358 * Returns 0 on success.
361 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
363 unsigned long flags
= 0;
364 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
368 ha
->isp_ops
->disable_intrs(ha
);
370 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
372 /* Turn off master enable */
374 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
375 cmd
&= ~PCI_COMMAND_MASTER
;
376 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
378 if (!IS_QLA2100(ha
)) {
380 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
381 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
382 for (cnt
= 0; cnt
< 30000; cnt
++) {
383 if ((RD_REG_WORD(®
->hccr
) &
384 HCCR_RISC_PAUSE
) != 0)
389 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
393 /* Select FPM registers. */
394 WRT_REG_WORD(®
->ctrl_status
, 0x20);
395 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
397 /* FPM Soft Reset. */
398 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
399 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
401 /* Toggle Fpm Reset. */
402 if (!IS_QLA2200(ha
)) {
403 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
404 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
407 /* Select frame buffer registers. */
408 WRT_REG_WORD(®
->ctrl_status
, 0x10);
409 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
411 /* Reset frame buffer FIFOs. */
412 if (IS_QLA2200(ha
)) {
413 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
414 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
416 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
418 /* Read back fb_cmd until zero or 3 seconds max */
419 for (cnt
= 0; cnt
< 3000; cnt
++) {
420 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
426 /* Select RISC module registers. */
427 WRT_REG_WORD(®
->ctrl_status
, 0);
428 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
430 /* Reset RISC processor. */
431 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
432 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
434 /* Release RISC processor. */
435 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
436 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
439 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
440 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
442 /* Reset ISP chip. */
443 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
445 /* Wait for RISC to recover from reset. */
446 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
448 * It is necessary to for a delay here since the card doesn't
449 * respond to PCI reads during a reset. On some architectures
450 * this will result in an MCA.
453 for (cnt
= 30000; cnt
; cnt
--) {
454 if ((RD_REG_WORD(®
->ctrl_status
) &
455 CSR_ISP_SOFT_RESET
) == 0)
462 /* Reset RISC processor. */
463 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
465 WRT_REG_WORD(®
->semaphore
, 0);
467 /* Release RISC processor. */
468 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
469 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
471 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
472 for (cnt
= 0; cnt
< 30000; cnt
++) {
473 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
481 /* Turn on master enable */
482 cmd
|= PCI_COMMAND_MASTER
;
483 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
485 /* Disable RISC pause on FPM parity error. */
486 if (!IS_QLA2100(ha
)) {
487 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
488 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
491 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
495 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
498 * Returns 0 on success.
501 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
503 unsigned long flags
= 0;
504 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
508 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
511 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
512 for (cnt
= 0; cnt
< 30000; cnt
++) {
513 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
519 WRT_REG_DWORD(®
->ctrl_status
,
520 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
521 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
524 /* Wait for firmware to complete NVRAM accesses. */
525 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
526 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
528 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
532 /* Wait for soft-reset to complete. */
533 d2
= RD_REG_DWORD(®
->ctrl_status
);
534 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
536 d2
= RD_REG_DWORD(®
->ctrl_status
);
540 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
541 RD_REG_DWORD(®
->hccr
);
543 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
544 RD_REG_DWORD(®
->hccr
);
546 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
547 RD_REG_DWORD(®
->hccr
);
549 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
550 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
552 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
556 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
560 * qla24xx_reset_chip() - Reset ISP24xx chip.
563 * Returns 0 on success.
566 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
568 ha
->isp_ops
->disable_intrs(ha
);
570 /* Perform RISC reset. */
571 qla24xx_reset_risc(ha
);
575 * qla2x00_chip_diag() - Test chip for proper operation.
578 * Returns 0 on success.
581 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
584 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
585 unsigned long flags
= 0;
590 /* Assume a failed state */
591 rval
= QLA_FUNCTION_FAILED
;
593 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
594 ha
->host_no
, (u_long
)®
->flash_address
));
596 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
598 /* Reset ISP chip. */
599 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
602 * We need to have a delay here since the card will not respond while
603 * in reset causing an MCA on some architectures.
606 data
= qla2x00_debounce_register(®
->ctrl_status
);
607 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
609 data
= RD_REG_WORD(®
->ctrl_status
);
614 goto chip_diag_failed
;
616 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
619 /* Reset RISC processor. */
620 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
621 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
623 /* Workaround for QLA2312 PCI parity error */
624 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
625 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
626 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
628 data
= RD_MAILBOX_REG(ha
, reg
, 0);
635 goto chip_diag_failed
;
637 /* Check product ID of chip */
638 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
640 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
641 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
642 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
643 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
644 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
645 mb
[3] != PROD_ID_3
) {
646 qla_printk(KERN_WARNING
, ha
,
647 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
649 goto chip_diag_failed
;
651 ha
->product_id
[0] = mb
[1];
652 ha
->product_id
[1] = mb
[2];
653 ha
->product_id
[2] = mb
[3];
654 ha
->product_id
[3] = mb
[4];
656 /* Adjust fw RISC transfer size */
657 if (ha
->request_q_length
> 1024)
658 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
660 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
661 ha
->request_q_length
;
663 if (IS_QLA2200(ha
) &&
664 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
665 /* Limit firmware transfer size with a 2200A */
666 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
669 ha
->device_type
|= DT_ISP2200A
;
670 ha
->fw_transfer_size
= 128;
673 /* Wrap Incoming Mailboxes Test. */
674 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
676 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
677 rval
= qla2x00_mbx_reg_test(ha
);
679 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
681 qla_printk(KERN_WARNING
, ha
,
682 "Failed mailbox send register test\n");
685 /* Flag a successful rval */
688 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
692 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
693 "****\n", ha
->host_no
));
695 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
701 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
704 * Returns 0 on success.
707 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
711 /* Perform RISC reset. */
712 qla24xx_reset_risc(ha
);
714 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
716 rval
= qla2x00_mbx_reg_test(ha
);
718 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
720 qla_printk(KERN_WARNING
, ha
,
721 "Failed mailbox send register test\n");
723 /* Flag a successful rval */
731 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
734 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
740 qla_printk(KERN_WARNING
, ha
,
741 "Firmware dump previously allocated.\n");
746 fixed_size
= mem_size
= eft_size
= 0;
747 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
748 fixed_size
= sizeof(struct qla2100_fw_dump
);
749 } else if (IS_QLA23XX(ha
)) {
750 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
751 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
753 } else if (IS_FWI2_CAPABLE(ha
)) {
754 fixed_size
= IS_QLA25XX(ha
) ?
755 offsetof(struct qla25xx_fw_dump
, ext_mem
):
756 offsetof(struct qla24xx_fw_dump
, ext_mem
);
757 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
760 /* Allocate memory for Extended Trace Buffer. */
761 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
764 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
765 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
769 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
772 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
773 "EFT (%d).\n", rval
);
774 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
779 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
783 memset(eft
, 0, eft_size
);
784 ha
->eft_dma
= eft_dma
;
788 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
789 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
791 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
792 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
795 ha
->fw_dump
= vmalloc(dump_size
);
797 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
798 "firmware dump!!!\n", dump_size
/ 1024);
801 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
809 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
812 ha
->fw_dump_len
= dump_size
;
813 ha
->fw_dump
->signature
[0] = 'Q';
814 ha
->fw_dump
->signature
[1] = 'L';
815 ha
->fw_dump
->signature
[2] = 'G';
816 ha
->fw_dump
->signature
[3] = 'C';
817 ha
->fw_dump
->version
= __constant_htonl(1);
819 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
820 ha
->fw_dump
->mem_size
= htonl(mem_size
);
821 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
822 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
824 ha
->fw_dump
->eft_size
= htonl(eft_size
);
825 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
826 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
828 ha
->fw_dump
->header_size
=
829 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
833 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
836 * Returns 0 on success.
839 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
842 uint16_t fw_iocb_cnt
= 0;
843 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
844 dma_addr_t request_dma
;
845 request_t
*request_ring
;
847 /* Valid only on recent ISPs. */
848 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
851 /* Retrieve IOCB counts available to the firmware. */
852 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
,
853 &ha
->max_npiv_vports
);
856 /* No point in continuing if current settings are sufficient. */
857 if (fw_iocb_cnt
< 1024)
859 if (ha
->request_q_length
>= request_q_length
)
862 /* Attempt to claim larger area for request queue. */
863 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
864 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
866 if (request_ring
== NULL
)
869 /* Resize successful, report extensions. */
870 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
871 (ha
->fw_memory_size
+ 1) / 1024);
872 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
873 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
875 /* Clear old allocations. */
876 dma_free_coherent(&ha
->pdev
->dev
,
877 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
880 /* Begin using larger queue. */
881 ha
->request_q_length
= request_q_length
;
882 ha
->request_ring
= request_ring
;
883 ha
->request_dma
= request_dma
;
887 * qla2x00_setup_chip() - Load and start RISC firmware.
890 * Returns 0 on success.
893 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
896 uint32_t srisc_address
= 0;
898 /* Load firmware sequences */
899 rval
= ha
->isp_ops
->load_risc(ha
, &srisc_address
);
900 if (rval
== QLA_SUCCESS
) {
901 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
902 "code.\n", ha
->host_no
));
904 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
905 if (rval
== QLA_SUCCESS
) {
906 /* Start firmware execution. */
907 DEBUG(printk("scsi(%ld): Checksum OK, start "
908 "firmware.\n", ha
->host_no
));
910 rval
= qla2x00_execute_fw(ha
, srisc_address
);
911 /* Retrieve firmware information. */
912 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
913 qla2x00_get_fw_version(ha
,
914 &ha
->fw_major_version
,
915 &ha
->fw_minor_version
,
916 &ha
->fw_subminor_version
,
917 &ha
->fw_attributes
, &ha
->fw_memory_size
);
918 qla2x00_resize_request_q(ha
);
919 ha
->flags
.npiv_supported
= 0;
920 if ((IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) &&
921 (ha
->fw_attributes
& BIT_2
)) {
922 ha
->flags
.npiv_supported
= 1;
923 if ((!ha
->max_npiv_vports
) ||
924 ((ha
->max_npiv_vports
+ 1) %
925 MAX_MULTI_ID_FABRIC
))
926 ha
->max_npiv_vports
=
927 MAX_NUM_VPORT_FABRIC
;
931 qla2x00_alloc_fw_dump(ha
);
934 DEBUG2(printk(KERN_INFO
935 "scsi(%ld): ISP Firmware failed checksum.\n",
941 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
949 * qla2x00_init_response_q_entries() - Initializes response queue entries.
952 * Beginning of request ring has initialization control block already built
953 * by nvram config routine.
955 * Returns 0 on success.
958 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
963 pkt
= ha
->response_ring_ptr
;
964 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
965 pkt
->signature
= RESPONSE_PROCESSED
;
972 * qla2x00_update_fw_options() - Read and process firmware options.
975 * Returns 0 on success.
978 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
980 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
982 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
983 qla2x00_get_fw_options(ha
, ha
->fw_options
);
985 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
988 /* Serial Link options. */
989 DEBUG3(printk("scsi(%ld): Serial link options:\n",
991 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
992 sizeof(ha
->fw_seriallink_options
)));
994 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
995 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
996 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
999 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1000 emphasis
= (ha
->fw_seriallink_options
[2] &
1001 (BIT_4
| BIT_3
)) >> 3;
1002 tx_sens
= ha
->fw_seriallink_options
[0] &
1003 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1004 rx_sens
= (ha
->fw_seriallink_options
[0] &
1005 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1006 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1007 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1010 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1011 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1012 ha
->fw_options
[10] |= BIT_5
|
1013 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1014 (tx_sens
& (BIT_1
| BIT_0
));
1017 swing
= (ha
->fw_seriallink_options
[2] &
1018 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1019 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1020 tx_sens
= ha
->fw_seriallink_options
[1] &
1021 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1022 rx_sens
= (ha
->fw_seriallink_options
[1] &
1023 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1024 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1025 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1028 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1029 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1030 ha
->fw_options
[11] |= BIT_5
|
1031 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1032 (tx_sens
& (BIT_1
| BIT_0
));
1036 /* Return command IOCBs without waiting for an ABTS to complete. */
1037 ha
->fw_options
[3] |= BIT_13
;
1040 if (ha
->flags
.enable_led_scheme
)
1041 ha
->fw_options
[2] |= BIT_12
;
1043 /* Detect ISP6312. */
1045 ha
->fw_options
[2] |= BIT_13
;
1047 /* Update firmware options. */
1048 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1052 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1056 /* Update Serial Link options. */
1057 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1060 rval
= qla2x00_set_serdes_params(ha
,
1061 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1062 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1063 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1064 if (rval
!= QLA_SUCCESS
) {
1065 qla_printk(KERN_WARNING
, ha
,
1066 "Unable to update Serial Link options (%x).\n", rval
);
1071 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1073 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1075 /* Setup ring parameters in initialization control block. */
1076 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1077 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1078 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1079 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1080 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1081 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1082 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1083 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1085 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1086 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1087 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1088 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1089 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1093 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1095 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1096 struct init_cb_24xx
*icb
;
1098 /* Setup ring parameters in initialization control block. */
1099 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1100 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1101 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1102 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1103 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1104 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1105 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1106 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1107 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1109 WRT_REG_DWORD(®
->req_q_in
, 0);
1110 WRT_REG_DWORD(®
->req_q_out
, 0);
1111 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1112 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1113 RD_REG_DWORD(®
->rsp_q_out
);
1117 * qla2x00_init_rings() - Initializes firmware.
1120 * Beginning of request ring has initialization control block already built
1121 * by nvram config routine.
1123 * Returns 0 on success.
1126 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1129 unsigned long flags
= 0;
1131 struct mid_init_cb_24xx
*mid_init_cb
=
1132 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1134 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1136 /* Clear outstanding commands array. */
1137 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1138 ha
->outstanding_cmds
[cnt
] = NULL
;
1140 ha
->current_outstanding_cmd
= 0;
1142 /* Clear RSCN queue. */
1143 ha
->rscn_in_ptr
= 0;
1144 ha
->rscn_out_ptr
= 0;
1146 /* Initialize firmware. */
1147 ha
->request_ring_ptr
= ha
->request_ring
;
1148 ha
->req_ring_index
= 0;
1149 ha
->req_q_cnt
= ha
->request_q_length
;
1150 ha
->response_ring_ptr
= ha
->response_ring
;
1151 ha
->rsp_ring_index
= 0;
1153 /* Initialize response queue entries */
1154 qla2x00_init_response_q_entries(ha
);
1156 ha
->isp_ops
->config_rings(ha
);
1158 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1160 /* Update any ISP specific firmware options before initialization. */
1161 ha
->isp_ops
->update_fw_options(ha
);
1163 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1165 mid_init_cb
->count
= ha
->max_npiv_vports
;
1167 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1169 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1172 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1180 * qla2x00_fw_ready() - Waits for firmware ready.
1183 * Returns 0 on success.
1186 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1189 unsigned long wtime
, mtime
;
1190 uint16_t min_wait
; /* Minimum wait time if loop is down */
1191 uint16_t wait_time
; /* Wait time if loop is coming ready */
1196 /* 20 seconds for loop down. */
1200 * Firmware should take at most one RATOV to login, plus 5 seconds for
1201 * our own processing.
1203 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1204 wait_time
= min_wait
;
1207 /* Min wait time if loop down */
1208 mtime
= jiffies
+ (min_wait
* HZ
);
1210 /* wait time before firmware ready */
1211 wtime
= jiffies
+ (wait_time
* HZ
);
1213 /* Wait for ISP to finish LIP */
1214 if (!ha
->flags
.init_done
)
1215 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1217 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1221 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1222 if (rval
== QLA_SUCCESS
) {
1223 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1224 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1226 if (fw_state
== FSTATE_READY
) {
1227 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1230 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1231 &ha
->login_timeout
, &ha
->r_a_tov
);
1237 rval
= QLA_FUNCTION_FAILED
;
1239 if (atomic_read(&ha
->loop_down_timer
) &&
1240 fw_state
!= FSTATE_READY
) {
1241 /* Loop down. Timeout on min_wait for states
1242 * other than Wait for Login.
1244 if (time_after_eq(jiffies
, mtime
)) {
1245 qla_printk(KERN_INFO
, ha
,
1246 "Cable is unplugged...\n");
1248 ha
->device_flags
|= DFLG_NO_CABLE
;
1253 /* Mailbox cmd failed. Timeout on min_wait. */
1254 if (time_after_eq(jiffies
, mtime
))
1258 if (time_after_eq(jiffies
, wtime
))
1261 /* Delay for a while */
1264 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1265 ha
->host_no
, fw_state
, jiffies
));
1268 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1269 ha
->host_no
, fw_state
, jiffies
));
1272 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1280 * qla2x00_configure_hba
1281 * Setup adapter context.
1284 * ha = adapter state pointer.
1293 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1302 char connect_type
[22];
1304 /* Get host addresses. */
1305 rval
= qla2x00_get_adapter_id(ha
,
1306 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1307 if (rval
!= QLA_SUCCESS
) {
1308 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1309 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1310 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1311 __func__
, ha
->host_no
));
1313 qla_printk(KERN_WARNING
, ha
,
1314 "ERROR -- Unable to get host loop ID.\n");
1315 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1321 qla_printk(KERN_INFO
, ha
,
1322 "Cannot get topology - retrying.\n");
1323 return (QLA_FUNCTION_FAILED
);
1326 ha
->loop_id
= loop_id
;
1329 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1330 ha
->operating_mode
= LOOP
;
1335 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1337 ha
->current_topology
= ISP_CFG_NL
;
1338 strcpy(connect_type
, "(Loop)");
1342 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1344 ha
->switch_cap
= sw_cap
;
1345 ha
->current_topology
= ISP_CFG_FL
;
1346 strcpy(connect_type
, "(FL_Port)");
1350 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1352 ha
->operating_mode
= P2P
;
1353 ha
->current_topology
= ISP_CFG_N
;
1354 strcpy(connect_type
, "(N_Port-to-N_Port)");
1358 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1360 ha
->switch_cap
= sw_cap
;
1361 ha
->operating_mode
= P2P
;
1362 ha
->current_topology
= ISP_CFG_F
;
1363 strcpy(connect_type
, "(F_Port)");
1367 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1369 ha
->host_no
, topo
));
1370 ha
->current_topology
= ISP_CFG_NL
;
1371 strcpy(connect_type
, "(Loop)");
1375 /* Save Host port and loop ID. */
1376 /* byte order - Big Endian */
1377 ha
->d_id
.b
.domain
= domain
;
1378 ha
->d_id
.b
.area
= area
;
1379 ha
->d_id
.b
.al_pa
= al_pa
;
1381 if (!ha
->flags
.init_done
)
1382 qla_printk(KERN_INFO
, ha
,
1383 "Topology - %s, Host Loop address 0x%x\n",
1384 connect_type
, ha
->loop_id
);
1387 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1389 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1396 qla2x00_set_model_info(scsi_qla_host_t
*ha
, uint8_t *model
, size_t len
, char *def
)
1401 if (memcmp(model
, BINZERO
, len
) != 0) {
1402 strncpy(ha
->model_number
, model
, len
);
1403 st
= en
= ha
->model_number
;
1406 if (*en
!= 0x20 && *en
!= 0x00)
1411 index
= (ha
->pdev
->subsystem_device
& 0xff);
1412 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1413 index
< QLA_MODEL_NAMES
)
1414 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1416 index
= (ha
->pdev
->subsystem_device
& 0xff);
1417 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1418 index
< QLA_MODEL_NAMES
) {
1419 strcpy(ha
->model_number
,
1420 qla2x00_model_name
[index
* 2]);
1421 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1423 strcpy(ha
->model_number
, def
);
1428 /* On sparc systems, obtain port and node WWN from firmware
1431 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, nvram_t
*nv
)
1434 struct pci_dev
*pdev
= ha
->pdev
;
1435 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1439 val
= of_get_property(dp
, "port-wwn", &len
);
1440 if (val
&& len
>= WWN_SIZE
)
1441 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1443 val
= of_get_property(dp
, "node-wwn", &len
);
1444 if (val
&& len
>= WWN_SIZE
)
1445 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1450 * NVRAM configuration for ISP 2xxx
1453 * ha = adapter block pointer.
1456 * initialization control block in response_ring
1457 * host adapters parameters in host adapter block
1463 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1468 uint8_t *dptr1
, *dptr2
;
1469 init_cb_t
*icb
= ha
->init_cb
;
1470 nvram_t
*nv
= ha
->nvram
;
1471 uint8_t *ptr
= ha
->nvram
;
1472 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1476 /* Determine NVRAM starting address. */
1477 ha
->nvram_size
= sizeof(nvram_t
);
1479 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1480 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1481 ha
->nvram_base
= 0x80;
1483 /* Get NVRAM data and calculate checksum. */
1484 ha
->isp_ops
->read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1485 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1488 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1489 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
1491 /* Bad NVRAM data, set defaults parameters. */
1492 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1493 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1494 /* Reset NVRAM data. */
1495 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1496 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1498 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1499 "invalid -- WWPN) defaults.\n");
1502 * Set default initialization control block.
1504 memset(nv
, 0, ha
->nvram_size
);
1505 nv
->parameter_block_version
= ICB_VERSION
;
1507 if (IS_QLA23XX(ha
)) {
1508 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1509 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1510 nv
->add_firmware_options
[0] = BIT_5
;
1511 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1512 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1513 nv
->special_options
[1] = BIT_7
;
1514 } else if (IS_QLA2200(ha
)) {
1515 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1516 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1517 nv
->add_firmware_options
[0] = BIT_5
;
1518 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1519 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1520 } else if (IS_QLA2100(ha
)) {
1521 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1522 nv
->firmware_options
[1] = BIT_5
;
1523 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1526 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1527 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1528 nv
->retry_count
= 8;
1529 nv
->retry_delay
= 1;
1531 nv
->port_name
[0] = 33;
1532 nv
->port_name
[3] = 224;
1533 nv
->port_name
[4] = 139;
1535 qla2xxx_nvram_wwn_from_ofw(ha
, nv
);
1537 nv
->login_timeout
= 4;
1540 * Set default host adapter parameters
1542 nv
->host_p
[1] = BIT_2
;
1543 nv
->reset_delay
= 5;
1544 nv
->port_down_retry_count
= 8;
1545 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1546 nv
->link_down_timeout
= 60;
1551 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1553 * The SN2 does not provide BIOS emulation which means you can't change
1554 * potentially bogus BIOS settings. Force the use of default settings
1555 * for link rate and frame size. Hope that the rest of the settings
1558 if (ia64_platform_is("sn2")) {
1559 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1561 nv
->special_options
[1] = BIT_7
;
1565 /* Reset Initialization control block */
1566 memset(icb
, 0, ha
->init_cb_size
);
1569 * Setup driver NVRAM options.
1571 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1572 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1573 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1574 nv
->firmware_options
[1] &= ~BIT_4
;
1576 if (IS_QLA23XX(ha
)) {
1577 nv
->firmware_options
[0] |= BIT_2
;
1578 nv
->firmware_options
[0] &= ~BIT_3
;
1579 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1581 if (IS_QLA2300(ha
)) {
1582 if (ha
->fb_rev
== FPM_2310
) {
1583 strcpy(ha
->model_number
, "QLA2310");
1585 strcpy(ha
->model_number
, "QLA2300");
1588 qla2x00_set_model_info(ha
, nv
->model_number
,
1589 sizeof(nv
->model_number
), "QLA23xx");
1591 } else if (IS_QLA2200(ha
)) {
1592 nv
->firmware_options
[0] |= BIT_2
;
1594 * 'Point-to-point preferred, else loop' is not a safe
1595 * connection mode setting.
1597 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1599 /* Force 'loop preferred, else point-to-point'. */
1600 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1601 nv
->add_firmware_options
[0] |= BIT_5
;
1603 strcpy(ha
->model_number
, "QLA22xx");
1604 } else /*if (IS_QLA2100(ha))*/ {
1605 strcpy(ha
->model_number
, "QLA2100");
1609 * Copy over NVRAM RISC parameter block to initialization control block.
1611 dptr1
= (uint8_t *)icb
;
1612 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1613 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1615 *dptr1
++ = *dptr2
++;
1617 /* Copy 2nd half. */
1618 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1619 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1621 *dptr1
++ = *dptr2
++;
1623 /* Use alternate WWN? */
1624 if (nv
->host_p
[1] & BIT_7
) {
1625 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1626 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1629 /* Prepare nodename */
1630 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1632 * Firmware will apply the following mask if the nodename was
1635 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1636 icb
->node_name
[0] &= 0xF0;
1640 * Set host adapter parameters.
1642 if (nv
->host_p
[0] & BIT_7
)
1643 ql2xextended_error_logging
= 1;
1644 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1645 /* Always load RISC code on non ISP2[12]00 chips. */
1646 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1647 ha
->flags
.disable_risc_code_load
= 0;
1648 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1649 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1650 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1651 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1652 ha
->flags
.disable_serdes
= 0;
1654 ha
->operating_mode
=
1655 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1657 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1658 sizeof(ha
->fw_seriallink_options
));
1660 /* save HBA serial number */
1661 ha
->serial0
= icb
->port_name
[5];
1662 ha
->serial1
= icb
->port_name
[6];
1663 ha
->serial2
= icb
->port_name
[7];
1664 ha
->node_name
= icb
->node_name
;
1665 ha
->port_name
= icb
->port_name
;
1667 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1669 ha
->retry_count
= nv
->retry_count
;
1671 /* Set minimum login_timeout to 4 seconds. */
1672 if (nv
->login_timeout
< ql2xlogintimeout
)
1673 nv
->login_timeout
= ql2xlogintimeout
;
1674 if (nv
->login_timeout
< 4)
1675 nv
->login_timeout
= 4;
1676 ha
->login_timeout
= nv
->login_timeout
;
1677 icb
->login_timeout
= nv
->login_timeout
;
1679 /* Set minimum RATOV to 200 tenths of a second. */
1682 ha
->loop_reset_delay
= nv
->reset_delay
;
1684 /* Link Down Timeout = 0:
1686 * When Port Down timer expires we will start returning
1687 * I/O's to OS with "DID_NO_CONNECT".
1689 * Link Down Timeout != 0:
1691 * The driver waits for the link to come up after link down
1692 * before returning I/Os to OS with "DID_NO_CONNECT".
1694 if (nv
->link_down_timeout
== 0) {
1695 ha
->loop_down_abort_time
=
1696 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1698 ha
->link_down_timeout
= nv
->link_down_timeout
;
1699 ha
->loop_down_abort_time
=
1700 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1704 * Need enough time to try and get the port back.
1706 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1707 if (qlport_down_retry
)
1708 ha
->port_down_retry_count
= qlport_down_retry
;
1709 /* Set login_retry_count */
1710 ha
->login_retry_count
= nv
->retry_count
;
1711 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1712 ha
->port_down_retry_count
> 3)
1713 ha
->login_retry_count
= ha
->port_down_retry_count
;
1714 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1715 ha
->login_retry_count
= ha
->port_down_retry_count
;
1716 if (ql2xloginretrycount
)
1717 ha
->login_retry_count
= ql2xloginretrycount
;
1719 icb
->lun_enables
= __constant_cpu_to_le16(0);
1720 icb
->command_resource_count
= 0;
1721 icb
->immediate_notify_resource_count
= 0;
1722 icb
->timeout
= __constant_cpu_to_le16(0);
1724 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1726 icb
->firmware_options
[0] &= ~BIT_3
;
1727 icb
->add_firmware_options
[0] &=
1728 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1729 icb
->add_firmware_options
[0] |= BIT_2
;
1730 icb
->response_accumulation_timer
= 3;
1731 icb
->interrupt_delay_timer
= 5;
1733 ha
->flags
.process_response_queue
= 1;
1736 if (!ha
->flags
.init_done
) {
1737 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1738 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1739 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1740 icb
->interrupt_delay_timer
: 2;
1742 icb
->add_firmware_options
[0] &=
1743 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1744 ha
->flags
.process_response_queue
= 0;
1745 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1746 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1748 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1749 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1750 ha
->zio_timer
* 100));
1751 qla_printk(KERN_INFO
, ha
,
1752 "ZIO mode %d enabled; timer delay (%d us).\n",
1753 ha
->zio_mode
, ha
->zio_timer
* 100);
1755 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1756 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1757 ha
->flags
.process_response_queue
= 1;
1762 DEBUG2_3(printk(KERN_WARNING
1763 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1769 qla2x00_rport_del(void *data
)
1771 fc_port_t
*fcport
= data
;
1772 struct fc_rport
*rport
;
1773 unsigned long flags
;
1775 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1776 rport
= fcport
->drport
;
1777 fcport
->drport
= NULL
;
1778 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1780 fc_remote_port_delete(rport
);
1784 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1786 * @flags: allocation flags
1788 * Returns a pointer to the allocated fcport, or NULL, if none available.
1791 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1795 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
1799 /* Setup fcport template structure. */
1801 fcport
->vp_idx
= ha
->vp_idx
;
1802 fcport
->port_type
= FCT_UNKNOWN
;
1803 fcport
->loop_id
= FC_NO_LOOP_ID
;
1804 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1805 fcport
->flags
= FCF_RLC_SUPPORT
;
1806 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1807 spin_lock_init(&fcport
->rport_lock
);
1813 * qla2x00_configure_loop
1814 * Updates Fibre Channel Device Database with what is actually on loop.
1817 * ha = adapter block pointer.
1822 * 2 = database was full and device was not configured.
1825 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1828 unsigned long flags
, save_flags
;
1832 /* Get Initiator ID */
1833 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1834 rval
= qla2x00_configure_hba(ha
);
1835 if (rval
!= QLA_SUCCESS
) {
1836 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1842 save_flags
= flags
= ha
->dpc_flags
;
1843 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1844 ha
->host_no
, flags
));
1847 * If we have both an RSCN and PORT UPDATE pending then handle them
1848 * both at the same time.
1850 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1851 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1853 /* Determine what we need to do */
1854 if (ha
->current_topology
== ISP_CFG_FL
&&
1855 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1857 ha
->flags
.rscn_queue_overflow
= 1;
1858 set_bit(RSCN_UPDATE
, &flags
);
1860 } else if (ha
->current_topology
== ISP_CFG_F
&&
1861 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1863 ha
->flags
.rscn_queue_overflow
= 1;
1864 set_bit(RSCN_UPDATE
, &flags
);
1865 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1867 } else if (ha
->current_topology
== ISP_CFG_N
) {
1868 clear_bit(RSCN_UPDATE
, &flags
);
1870 } else if (!ha
->flags
.online
||
1871 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1873 ha
->flags
.rscn_queue_overflow
= 1;
1874 set_bit(RSCN_UPDATE
, &flags
);
1875 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1878 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1879 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1880 rval
= QLA_FUNCTION_FAILED
;
1882 rval
= qla2x00_configure_local_loop(ha
);
1886 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1887 if (LOOP_TRANSITION(ha
)) {
1888 rval
= QLA_FUNCTION_FAILED
;
1890 rval
= qla2x00_configure_fabric(ha
);
1894 if (rval
== QLA_SUCCESS
) {
1895 if (atomic_read(&ha
->loop_down_timer
) ||
1896 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1897 rval
= QLA_FUNCTION_FAILED
;
1899 atomic_set(&ha
->loop_state
, LOOP_READY
);
1901 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1906 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1907 __func__
, ha
->host_no
));
1909 DEBUG3(printk("%s: exiting normally\n", __func__
));
1912 /* Restore state if a resync event occured during processing */
1913 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1914 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1915 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1916 if (test_bit(RSCN_UPDATE
, &save_flags
))
1917 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1926 * qla2x00_configure_local_loop
1927 * Updates Fibre Channel Device Database with local loop devices.
1930 * ha = adapter block pointer.
1936 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1941 fc_port_t
*fcport
, *new_fcport
;
1947 uint8_t domain
, area
, al_pa
;
1948 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
1952 entries
= MAX_FIBRE_DEVICES
;
1954 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1955 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1957 /* Get list of logged in devices. */
1958 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1959 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1961 if (rval
!= QLA_SUCCESS
)
1962 goto cleanup_allocation
;
1964 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1965 ha
->host_no
, entries
));
1966 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1967 entries
* sizeof(struct gid_list_info
)));
1969 /* Allocate temporary fcport for any new fcports discovered. */
1970 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1971 if (new_fcport
== NULL
) {
1972 rval
= QLA_MEMORY_ALLOC_FAILED
;
1973 goto cleanup_allocation
;
1975 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1978 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1980 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
1981 if (fcport
->vp_idx
!= ha
->vp_idx
)
1984 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1985 fcport
->port_type
!= FCT_BROADCAST
&&
1986 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1988 DEBUG(printk("scsi(%ld): Marking port lost, "
1990 ha
->host_no
, fcport
->loop_id
));
1992 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1993 fcport
->flags
&= ~FCF_FARP_DONE
;
1997 /* Add devices to port list. */
1998 id_iter
= (char *)ha
->gid_list
;
1999 for (index
= 0; index
< entries
; index
++) {
2000 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2001 area
= ((struct gid_list_info
*)id_iter
)->area
;
2002 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2003 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2004 loop_id
= (uint16_t)
2005 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2007 loop_id
= le16_to_cpu(
2008 ((struct gid_list_info
*)id_iter
)->loop_id
);
2009 id_iter
+= ha
->gid_list_info_size
;
2011 /* Bypass reserved domain fields. */
2012 if ((domain
& 0xf0) == 0xf0)
2015 /* Bypass if not same domain and area of adapter. */
2016 if (area
&& domain
&&
2017 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
2020 /* Bypass invalid local loop ID. */
2021 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2024 /* Fill in member data. */
2025 new_fcport
->d_id
.b
.domain
= domain
;
2026 new_fcport
->d_id
.b
.area
= area
;
2027 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2028 new_fcport
->loop_id
= loop_id
;
2029 new_fcport
->vp_idx
= ha
->vp_idx
;
2030 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
2031 if (rval2
!= QLA_SUCCESS
) {
2032 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2033 "information -- get_port_database=%x, "
2035 ha
->host_no
, rval2
, new_fcport
->loop_id
));
2036 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2038 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2042 /* Check for matching device in port list. */
2045 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2046 if (fcport
->vp_idx
!= ha
->vp_idx
)
2049 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2053 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2054 FCF_PERSISTENT_BOUND
);
2055 fcport
->loop_id
= new_fcport
->loop_id
;
2056 fcport
->port_type
= new_fcport
->port_type
;
2057 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2058 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2066 /* New device, add to fcports list. */
2067 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2069 new_fcport
->ha
= ha
;
2070 new_fcport
->vp_idx
= ha
->vp_idx
;
2071 list_add_tail(&new_fcport
->vp_fcport
,
2074 list_add_tail(&new_fcport
->list
, &pha
->fcports
);
2076 /* Allocate a new replacement fcport. */
2077 fcport
= new_fcport
;
2078 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2079 if (new_fcport
== NULL
) {
2080 rval
= QLA_MEMORY_ALLOC_FAILED
;
2081 goto cleanup_allocation
;
2083 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2086 /* Base iIDMA settings on HBA port speed. */
2087 fcport
->fp_speed
= ha
->link_data_rate
;
2089 qla2x00_update_fcport(ha
, fcport
);
2097 if (rval
!= QLA_SUCCESS
) {
2098 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2099 "rval=%x\n", ha
->host_no
, rval
));
2103 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2104 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2111 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2115 qla2x00_mark_all_devices_lost(ha
, 0);
2116 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2117 if (fcport
->port_type
!= FCT_TARGET
)
2120 qla2x00_update_fcport(ha
, fcport
);
2125 qla2x00_iidma_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2127 #define LS_UNKNOWN 2
2128 static char *link_speeds
[5] = { "1", "2", "?", "4", "8" };
2132 if (!IS_IIDMA_CAPABLE(ha
))
2135 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2136 fcport
->fp_speed
> ha
->link_data_rate
)
2139 rval
= qla2x00_set_idma_speed(ha
, fcport
->loop_id
, fcport
->fp_speed
,
2141 if (rval
!= QLA_SUCCESS
) {
2142 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2143 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2144 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2145 fcport
->port_name
[2], fcport
->port_name
[3],
2146 fcport
->port_name
[4], fcport
->port_name
[5],
2147 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2148 fcport
->fp_speed
, mb
[0], mb
[1]));
2150 DEBUG2(qla_printk(KERN_INFO
, ha
,
2151 "iIDMA adjusted to %s GB/s on "
2152 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2153 link_speeds
[fcport
->fp_speed
], fcport
->port_name
[0],
2154 fcport
->port_name
[1], fcport
->port_name
[2],
2155 fcport
->port_name
[3], fcport
->port_name
[4],
2156 fcport
->port_name
[5], fcport
->port_name
[6],
2157 fcport
->port_name
[7]));
2162 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2164 struct fc_rport_identifiers rport_ids
;
2165 struct fc_rport
*rport
;
2166 unsigned long flags
;
2169 qla2x00_rport_del(fcport
);
2173 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2174 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2175 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2176 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2177 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2178 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2180 qla_printk(KERN_WARNING
, ha
,
2181 "Unable to allocate fc remote port!\n");
2184 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2185 fcport
->rport
= rport
;
2186 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2187 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2189 rport
->supported_classes
= fcport
->supported_classes
;
2191 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2192 if (fcport
->port_type
== FCT_INITIATOR
)
2193 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2194 if (fcport
->port_type
== FCT_TARGET
)
2195 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2196 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2198 if (rport
->scsi_target_id
!= -1 &&
2199 rport
->scsi_target_id
< ha
->host
->max_id
)
2200 fcport
->os_target_id
= rport
->scsi_target_id
;
2204 * qla2x00_update_fcport
2205 * Updates device on list.
2208 * ha = adapter block pointer.
2209 * fcport = port structure pointer.
2219 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2221 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2224 fcport
->login_retry
= 0;
2225 fcport
->port_login_retry_count
= pha
->port_down_retry_count
*
2227 atomic_set(&fcport
->port_down_timer
, pha
->port_down_retry_count
*
2229 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2231 qla2x00_iidma_fcport(ha
, fcport
);
2233 atomic_set(&fcport
->state
, FCS_ONLINE
);
2235 qla2x00_reg_remote_port(ha
, fcport
);
2239 * qla2x00_configure_fabric
2240 * Setup SNS devices with loop ID's.
2243 * ha = adapter block pointer.
2250 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2253 fc_port_t
*fcport
, *fcptemp
;
2254 uint16_t next_loopid
;
2255 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2257 LIST_HEAD(new_fcports
);
2258 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2260 /* If FL port exists, then SNS is present */
2261 if (IS_FWI2_CAPABLE(ha
))
2262 loop_id
= NPH_F_PORT
;
2264 loop_id
= SNS_FL_PORT
;
2265 rval
= qla2x00_get_port_name(ha
, loop_id
, ha
->fabric_node_name
, 1);
2266 if (rval
!= QLA_SUCCESS
) {
2267 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2268 "Port\n", ha
->host_no
));
2270 ha
->device_flags
&= ~SWITCH_FOUND
;
2271 return (QLA_SUCCESS
);
2273 ha
->device_flags
|= SWITCH_FOUND
;
2275 /* Mark devices that need re-synchronization. */
2276 rval2
= qla2x00_device_resync(ha
);
2277 if (rval2
== QLA_RSCNS_HANDLED
) {
2278 /* No point doing the scan, just continue. */
2279 return (QLA_SUCCESS
);
2283 if (ql2xfdmienable
&&
2284 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2285 qla2x00_fdmi_register(ha
);
2287 /* Ensure we are logged into the SNS. */
2288 if (IS_FWI2_CAPABLE(ha
))
2291 loop_id
= SIMPLE_NAME_SERVER
;
2292 ha
->isp_ops
->fabric_login(ha
, loop_id
, 0xff, 0xff,
2293 0xfc, mb
, BIT_1
| BIT_0
);
2294 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2295 DEBUG2(qla_printk(KERN_INFO
, ha
,
2296 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2297 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2298 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2299 return (QLA_SUCCESS
);
2302 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2303 if (qla2x00_rft_id(ha
)) {
2305 DEBUG2(printk("scsi(%ld): Register FC-4 "
2306 "TYPE failed.\n", ha
->host_no
));
2308 if (qla2x00_rff_id(ha
)) {
2310 DEBUG2(printk("scsi(%ld): Register FC-4 "
2311 "Features failed.\n", ha
->host_no
));
2313 if (qla2x00_rnn_id(ha
)) {
2315 DEBUG2(printk("scsi(%ld): Register Node Name "
2316 "failed.\n", ha
->host_no
));
2317 } else if (qla2x00_rsnn_nn(ha
)) {
2319 DEBUG2(printk("scsi(%ld): Register Symbolic "
2320 "Node Name failed.\n", ha
->host_no
));
2324 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2325 if (rval
!= QLA_SUCCESS
)
2329 * Logout all previous fabric devices marked lost, except
2332 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2333 if (fcport
->vp_idx
!=ha
->vp_idx
)
2336 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2339 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2342 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2343 qla2x00_mark_device_lost(ha
, fcport
,
2344 ql2xplogiabsentdevice
, 0);
2345 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2346 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2347 fcport
->port_type
!= FCT_INITIATOR
&&
2348 fcport
->port_type
!= FCT_BROADCAST
) {
2349 ha
->isp_ops
->fabric_logout(ha
,
2351 fcport
->d_id
.b
.domain
,
2352 fcport
->d_id
.b
.area
,
2353 fcport
->d_id
.b
.al_pa
);
2354 fcport
->loop_id
= FC_NO_LOOP_ID
;
2359 /* Starting free loop ID. */
2360 next_loopid
= pha
->min_external_loopid
;
2363 * Scan through our port list and login entries that need to be
2366 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2367 if (fcport
->vp_idx
!= ha
->vp_idx
)
2370 if (atomic_read(&ha
->loop_down_timer
) ||
2371 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2374 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2375 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2378 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
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 /* Login and update database */
2387 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2390 /* Exit if out of loop IDs. */
2391 if (rval
!= QLA_SUCCESS
) {
2396 * Login and add the new devices to our port list.
2398 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2399 if (atomic_read(&ha
->loop_down_timer
) ||
2400 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2403 /* Find a new loop ID to use. */
2404 fcport
->loop_id
= next_loopid
;
2405 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2406 if (rval
!= QLA_SUCCESS
) {
2407 /* Ran out of IDs to use */
2411 /* Login and update database */
2412 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2416 fcport
->vp_idx
= ha
->vp_idx
;
2417 list_add_tail(&fcport
->vp_fcport
,
2419 list_move_tail(&fcport
->list
,
2420 &ha
->parent
->fcports
);
2422 list_move_tail(&fcport
->list
, &ha
->fcports
);
2426 /* Free all new device structures not processed. */
2427 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2428 list_del(&fcport
->list
);
2433 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2434 "rval=%d\n", ha
->host_no
, rval
));
2442 * qla2x00_find_all_fabric_devs
2445 * ha = adapter block pointer.
2446 * dev = database device entry pointer.
2455 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2459 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2464 int first_dev
, last_dev
;
2465 port_id_t wrap
, nxt_d_id
;
2469 scsi_qla_host_t
*vha
;
2470 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2474 /* Try GID_PT to get device list, else GAN. */
2475 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_ATOMIC
);
2478 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2479 "on GA_NXT\n", ha
->host_no
));
2481 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2484 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2487 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2490 } else if (qla2x00_gfpn_id(ha
, swl
) == QLA_SUCCESS
) {
2491 qla2x00_gpsc(ha
, swl
);
2496 /* Allocate temporary fcport for any new fcports discovered. */
2497 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2498 if (new_fcport
== NULL
) {
2500 return (QLA_MEMORY_ALLOC_FAILED
);
2502 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2503 new_fcport
->vp_idx
= ha
->vp_idx
;
2504 /* Set start port ID scan at adapter ID. */
2508 /* Starting free loop ID. */
2509 loop_id
= pha
->min_external_loopid
;
2510 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2511 if (qla2x00_is_reserved_id(ha
, loop_id
))
2514 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2519 wrap
.b24
= new_fcport
->d_id
.b24
;
2521 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2522 memcpy(new_fcport
->node_name
,
2523 swl
[swl_idx
].node_name
, WWN_SIZE
);
2524 memcpy(new_fcport
->port_name
,
2525 swl
[swl_idx
].port_name
, WWN_SIZE
);
2526 memcpy(new_fcport
->fabric_port_name
,
2527 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2528 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2530 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2536 /* Send GA_NXT to the switch */
2537 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2538 if (rval
!= QLA_SUCCESS
) {
2539 qla_printk(KERN_WARNING
, ha
,
2540 "SNS scan failed -- assuming zero-entry "
2542 list_for_each_entry_safe(fcport
, fcptemp
,
2543 new_fcports
, list
) {
2544 list_del(&fcport
->list
);
2552 /* If wrap on switch device list, exit. */
2554 wrap
.b24
= new_fcport
->d_id
.b24
;
2556 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2557 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2558 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2559 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2563 /* Bypass if same physical adapter. */
2564 if (new_fcport
->d_id
.b24
== pha
->d_id
.b24
)
2567 /* Bypass virtual ports of the same host. */
2568 if (pha
->num_vhosts
) {
2569 vp_index
= find_next_bit(
2570 (unsigned long *)pha
->vp_idx_map
,
2571 MAX_MULTI_ID_FABRIC
+ 1, 1);
2573 for (;vp_index
<= MAX_MULTI_ID_FABRIC
;
2574 vp_index
= find_next_bit(
2575 (unsigned long *)pha
->vp_idx_map
,
2576 MAX_MULTI_ID_FABRIC
+ 1, vp_index
+ 1)) {
2579 list_for_each_entry(vha
, &pha
->vp_list
,
2581 if (vp_index
== vha
->vp_idx
) {
2592 new_fcport
->d_id
.b24
== vha
->d_id
.b24
)
2595 if (vp_index
<= MAX_MULTI_ID_FABRIC
)
2599 /* Bypass if same domain and area of adapter. */
2600 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2601 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2605 /* Bypass reserved domain fields. */
2606 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2609 /* Locate matching device in database. */
2611 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2612 if (new_fcport
->vp_idx
!= fcport
->vp_idx
)
2614 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2620 /* Update port state. */
2621 memcpy(fcport
->fabric_port_name
,
2622 new_fcport
->fabric_port_name
, WWN_SIZE
);
2623 fcport
->fp_speed
= new_fcport
->fp_speed
;
2626 * If address the same and state FCS_ONLINE, nothing
2629 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2630 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2635 * If device was not a fabric device before.
2637 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2638 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2639 fcport
->loop_id
= FC_NO_LOOP_ID
;
2640 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2642 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2647 * Port ID changed or device was marked to be updated;
2648 * Log it out if still logged in and mark it for
2651 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2652 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2653 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2654 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2655 fcport
->port_type
!= FCT_INITIATOR
&&
2656 fcport
->port_type
!= FCT_BROADCAST
) {
2657 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
2658 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2659 fcport
->d_id
.b
.al_pa
);
2660 fcport
->loop_id
= FC_NO_LOOP_ID
;
2669 /* If device was not in our fcports list, then add it. */
2670 list_add_tail(&new_fcport
->list
, new_fcports
);
2672 /* Allocate a new replacement fcport. */
2673 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2674 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2675 if (new_fcport
== NULL
) {
2677 return (QLA_MEMORY_ALLOC_FAILED
);
2679 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2680 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2681 new_fcport
->vp_idx
= ha
->vp_idx
;
2687 if (!list_empty(new_fcports
))
2688 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2694 * qla2x00_find_new_loop_id
2695 * Scan through our port list and find a new usable loop ID.
2698 * ha: adapter state pointer.
2699 * dev: port structure pointer.
2702 * qla2x00 local function return status code.
2708 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2713 uint16_t first_loop_id
;
2714 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2718 /* Save starting loop ID. */
2719 first_loop_id
= dev
->loop_id
;
2722 /* Skip loop ID if already used by adapter. */
2723 if (dev
->loop_id
== ha
->loop_id
) {
2727 /* Skip reserved loop IDs. */
2728 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2732 /* Reset loop ID if passed the end. */
2733 if (dev
->loop_id
> ha
->last_loop_id
) {
2734 /* first loop ID. */
2735 dev
->loop_id
= ha
->min_external_loopid
;
2738 /* Check for loop ID being already in use. */
2741 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2742 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2743 /* ID possibly in use */
2749 /* If not in use then it is free to use. */
2754 /* ID in use. Try next value. */
2757 /* If wrap around. No free ID to use. */
2758 if (dev
->loop_id
== first_loop_id
) {
2759 dev
->loop_id
= FC_NO_LOOP_ID
;
2760 rval
= QLA_FUNCTION_FAILED
;
2769 * qla2x00_device_resync
2770 * Marks devices in the database that needs resynchronization.
2773 * ha = adapter block pointer.
2779 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2784 uint32_t rscn_entry
;
2785 uint8_t rscn_out_iter
;
2788 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2790 rval
= QLA_RSCNS_HANDLED
;
2792 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2793 ha
->flags
.rscn_queue_overflow
) {
2795 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2796 format
= MSB(MSW(rscn_entry
));
2797 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2798 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2799 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2801 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2802 "[%02x/%02x%02x%02x].\n",
2803 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2804 d_id
.b
.area
, d_id
.b
.al_pa
));
2807 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2808 ha
->rscn_out_ptr
= 0;
2810 /* Skip duplicate entries. */
2811 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2812 !ha
->flags
.rscn_queue_overflow
&&
2813 rscn_out_iter
!= ha
->rscn_in_ptr
;
2814 rscn_out_iter
= (rscn_out_iter
==
2815 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2817 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2820 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2821 "entry found at [%d].\n", ha
->host_no
,
2824 ha
->rscn_out_ptr
= rscn_out_iter
;
2827 /* Queue overflow, set switch default case. */
2828 if (ha
->flags
.rscn_queue_overflow
) {
2829 DEBUG(printk("scsi(%ld): device_resync: rscn "
2830 "overflow.\n", ha
->host_no
));
2833 ha
->flags
.rscn_queue_overflow
= 0;
2849 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2855 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2856 if (fcport
->vp_idx
!= ha
->vp_idx
)
2859 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2860 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2861 fcport
->port_type
== FCT_BROADCAST
)
2864 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2866 fcport
->port_type
!= FCT_INITIATOR
) {
2867 qla2x00_mark_device_lost(ha
, fcport
,
2871 fcport
->flags
&= ~FCF_FARP_DONE
;
2878 * qla2x00_fabric_dev_login
2879 * Login fabric target device and update FC port database.
2882 * ha: adapter state pointer.
2883 * fcport: port structure list pointer.
2884 * next_loopid: contains value of a new loop ID that can be used
2885 * by the next login attempt.
2888 * qla2x00 local function return status code.
2894 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2895 uint16_t *next_loopid
)
2904 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2905 if (rval
== QLA_SUCCESS
) {
2906 /* Send an ADISC to tape devices.*/
2908 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2910 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2911 if (rval
!= QLA_SUCCESS
) {
2912 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
2913 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2914 fcport
->d_id
.b
.al_pa
);
2915 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2917 qla2x00_update_fcport(ha
, fcport
);
2925 * qla2x00_fabric_login
2926 * Issue fabric login command.
2929 * ha = adapter block pointer.
2930 * device = pointer to FC device type structure.
2933 * 0 - Login successfully
2935 * 2 - Initiator device
2939 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2940 uint16_t *next_loopid
)
2944 uint16_t tmp_loopid
;
2945 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2951 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2952 "for port %02x%02x%02x.\n",
2953 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2954 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2956 /* Login fcport on switch. */
2957 ha
->isp_ops
->fabric_login(ha
, fcport
->loop_id
,
2958 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2959 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2960 if (mb
[0] == MBS_PORT_ID_USED
) {
2962 * Device has another loop ID. The firmware team
2963 * recommends the driver perform an implicit login with
2964 * the specified ID again. The ID we just used is save
2965 * here so we return with an ID that can be tried by
2969 tmp_loopid
= fcport
->loop_id
;
2970 fcport
->loop_id
= mb
[1];
2972 DEBUG(printk("Fabric Login: port in use - next "
2973 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2974 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2975 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2977 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2982 /* A retry occurred before. */
2983 *next_loopid
= tmp_loopid
;
2986 * No retry occurred before. Just increment the
2987 * ID value for next login.
2989 *next_loopid
= (fcport
->loop_id
+ 1);
2992 if (mb
[1] & BIT_0
) {
2993 fcport
->port_type
= FCT_INITIATOR
;
2995 fcport
->port_type
= FCT_TARGET
;
2996 if (mb
[1] & BIT_1
) {
2997 fcport
->flags
|= FCF_TAPE_PRESENT
;
3002 fcport
->supported_classes
|= FC_COS_CLASS2
;
3004 fcport
->supported_classes
|= FC_COS_CLASS3
;
3008 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3010 * Loop ID already used, try next loop ID.
3013 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
3014 if (rval
!= QLA_SUCCESS
) {
3015 /* Ran out of loop IDs to use */
3018 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3020 * Firmware possibly timed out during login. If NO
3021 * retries are left to do then the device is declared
3024 *next_loopid
= fcport
->loop_id
;
3025 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
3026 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3027 fcport
->d_id
.b
.al_pa
);
3028 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
3034 * unrecoverable / not handled error
3036 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3037 "loop_id=%x jiffies=%lx.\n",
3038 __func__
, ha
->host_no
, mb
[0],
3039 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3040 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3042 *next_loopid
= fcport
->loop_id
;
3043 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
3044 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3045 fcport
->d_id
.b
.al_pa
);
3046 fcport
->loop_id
= FC_NO_LOOP_ID
;
3047 fcport
->login_retry
= 0;
3058 * qla2x00_local_device_login
3059 * Issue local device login command.
3062 * ha = adapter block pointer.
3063 * loop_id = loop id of device to login to.
3065 * Returns (Where's the #define!!!!):
3066 * 0 - Login successfully
3071 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
3074 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3076 memset(mb
, 0, sizeof(mb
));
3077 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
3078 if (rval
== QLA_SUCCESS
) {
3079 /* Interrogate mailbox registers for any errors */
3080 if (mb
[0] == MBS_COMMAND_ERROR
)
3082 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3083 /* device not in PCB table */
3091 * qla2x00_loop_resync
3092 * Resync with fibre channel devices.
3095 * ha = adapter block pointer.
3101 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
3108 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3109 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3110 if (ha
->flags
.online
) {
3111 if (!(rval
= qla2x00_fw_ready(ha
))) {
3112 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3115 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3117 /* Issue a marker after FW becomes ready. */
3118 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3119 ha
->marker_needed
= 0;
3121 /* Remap devices on Loop. */
3122 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3124 qla2x00_configure_loop(ha
);
3126 } while (!atomic_read(&ha
->loop_down_timer
) &&
3127 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3129 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3133 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3134 return (QLA_FUNCTION_FAILED
);
3138 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3145 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3151 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3152 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3155 qla2x00_update_fcport(ha
, fcport
);
3156 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3160 qla2x00_probe_for_all_luns(ha
);
3164 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3168 /* Go with deferred removal of rport references. */
3169 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3171 qla2x00_rport_del(fcport
);
3176 * Resets ISP and aborts all outstanding commands.
3179 * ha = adapter block pointer.
3185 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3188 unsigned long flags
= 0;
3193 if (ha
->flags
.online
) {
3194 ha
->flags
.online
= 0;
3195 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3197 qla_printk(KERN_INFO
, ha
,
3198 "Performing ISP error recovery - ha= %p.\n", ha
);
3199 ha
->isp_ops
->reset_chip(ha
);
3201 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3202 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3203 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3204 qla2x00_mark_all_devices_lost(ha
, 0);
3206 if (!atomic_read(&ha
->loop_down_timer
))
3207 atomic_set(&ha
->loop_down_timer
,
3211 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3212 /* Requeue all commands in outstanding command list. */
3213 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3214 sp
= ha
->outstanding_cmds
[cnt
];
3216 ha
->outstanding_cmds
[cnt
] = NULL
;
3218 sp
->cmd
->result
= DID_RESET
<< 16;
3219 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3220 qla2x00_sp_compl(ha
, sp
);
3223 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3225 ha
->isp_ops
->get_flash_version(ha
, ha
->request_ring
);
3227 ha
->isp_ops
->nvram_config(ha
);
3229 if (!qla2x00_restart_isp(ha
)) {
3230 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3232 if (!atomic_read(&ha
->loop_down_timer
)) {
3234 * Issue marker command only when we are going
3235 * to start the I/O .
3237 ha
->marker_needed
= 1;
3240 ha
->flags
.online
= 1;
3242 ha
->isp_ops
->enable_intrs(ha
);
3244 ha
->isp_abort_cnt
= 0;
3245 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3248 rval
= qla2x00_trace_control(ha
, TC_ENABLE
,
3249 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3251 qla_printk(KERN_WARNING
, ha
,
3252 "Unable to reinitialize EFT "
3256 } else { /* failed the ISP abort */
3257 ha
->flags
.online
= 1;
3258 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3259 if (ha
->isp_abort_cnt
== 0) {
3260 qla_printk(KERN_WARNING
, ha
,
3261 "ISP error recovery failed - "
3262 "board disabled\n");
3264 * The next call disables the board
3267 ha
->isp_ops
->reset_adapter(ha
);
3268 ha
->flags
.online
= 0;
3269 clear_bit(ISP_ABORT_RETRY
,
3272 } else { /* schedule another ISP abort */
3273 ha
->isp_abort_cnt
--;
3274 DEBUG(printk("qla%ld: ISP abort - "
3275 "retry remaining %d\n",
3276 ha
->host_no
, ha
->isp_abort_cnt
));
3280 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3281 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3282 "- retrying (%d) more times\n",
3283 ha
->host_no
, ha
->isp_abort_cnt
));
3284 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3292 qla_printk(KERN_INFO
, ha
,
3293 "qla2x00_abort_isp: **** FAILED ****\n");
3295 DEBUG(printk(KERN_INFO
3296 "qla2x00_abort_isp(%ld): exiting.\n",
3304 * qla2x00_restart_isp
3305 * restarts the ISP after a reset
3308 * ha = adapter block pointer.
3314 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3317 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3318 unsigned long flags
= 0;
3321 /* If firmware needs to be loaded */
3322 if (qla2x00_isp_firmware(ha
)) {
3323 ha
->flags
.online
= 0;
3324 if (!(status
= ha
->isp_ops
->chip_diag(ha
))) {
3325 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3326 status
= qla2x00_setup_chip(ha
);
3330 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3332 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
) &&
3335 * Disable SRAM, Instruction RAM and GP RAM
3338 WRT_REG_WORD(®
->hccr
,
3339 (HCCR_ENABLE_PARITY
+ 0x0));
3340 RD_REG_WORD(®
->hccr
);
3343 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3345 status
= qla2x00_setup_chip(ha
);
3347 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3349 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
) &&
3351 /* Enable proper parity */
3354 WRT_REG_WORD(®
->hccr
,
3355 (HCCR_ENABLE_PARITY
+ 0x1));
3358 * SRAM, Instruction RAM and GP RAM
3361 WRT_REG_WORD(®
->hccr
,
3362 (HCCR_ENABLE_PARITY
+ 0x7));
3363 RD_REG_WORD(®
->hccr
);
3366 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3371 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3372 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3373 if (!(status
= qla2x00_fw_ready(ha
))) {
3374 DEBUG(printk("%s(): Start configure loop, "
3375 "status = %d\n", __func__
, status
));
3377 /* Issue a marker after FW becomes ready. */
3378 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3380 ha
->flags
.online
= 1;
3381 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3384 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3385 qla2x00_configure_loop(ha
);
3387 } while (!atomic_read(&ha
->loop_down_timer
) &&
3388 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3390 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3393 /* if no cable then assume it's good */
3394 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3397 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3405 * qla2x00_reset_adapter
3409 * ha = adapter block pointer.
3412 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3414 unsigned long flags
= 0;
3415 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3417 ha
->flags
.online
= 0;
3418 ha
->isp_ops
->disable_intrs(ha
);
3420 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3421 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3422 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3423 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3424 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3425 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3429 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3431 unsigned long flags
= 0;
3432 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3434 ha
->flags
.online
= 0;
3435 ha
->isp_ops
->disable_intrs(ha
);
3437 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3438 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3439 RD_REG_DWORD(®
->hccr
);
3440 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3441 RD_REG_DWORD(®
->hccr
);
3442 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3445 /* On sparc systems, obtain port and node WWN from firmware
3448 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, struct nvram_24xx
*nv
)
3451 struct pci_dev
*pdev
= ha
->pdev
;
3452 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3456 val
= of_get_property(dp
, "port-wwn", &len
);
3457 if (val
&& len
>= WWN_SIZE
)
3458 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3460 val
= of_get_property(dp
, "node-wwn", &len
);
3461 if (val
&& len
>= WWN_SIZE
)
3462 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3467 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3470 struct init_cb_24xx
*icb
;
3471 struct nvram_24xx
*nv
;
3473 uint8_t *dptr1
, *dptr2
;
3478 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3481 /* Determine NVRAM starting address. */
3482 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3483 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3484 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3485 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3486 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3487 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3488 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3491 /* Get VPD data into cache */
3492 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
3493 ha
->isp_ops
->read_nvram(ha
, (uint8_t *)ha
->vpd
,
3494 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
3496 /* Get NVRAM data into cache and calculate checksum. */
3497 dptr
= (uint32_t *)nv
;
3498 ha
->isp_ops
->read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3500 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3501 chksum
+= le32_to_cpu(*dptr
++);
3503 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3504 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
3506 /* Bad NVRAM data, set defaults parameters. */
3507 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3508 || nv
->id
[3] != ' ' ||
3509 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3510 /* Reset NVRAM data. */
3511 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3512 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3513 le16_to_cpu(nv
->nvram_version
));
3514 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3515 "invalid -- WWPN) defaults.\n");
3518 * Set default initialization control block.
3520 memset(nv
, 0, ha
->nvram_size
);
3521 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3522 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3523 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3524 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3525 nv
->exchange_count
= __constant_cpu_to_le16(0);
3526 nv
->hard_address
= __constant_cpu_to_le16(124);
3527 nv
->port_name
[0] = 0x21;
3528 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3529 nv
->port_name
[2] = 0x00;
3530 nv
->port_name
[3] = 0xe0;
3531 nv
->port_name
[4] = 0x8b;
3532 nv
->port_name
[5] = 0x1c;
3533 nv
->port_name
[6] = 0x55;
3534 nv
->port_name
[7] = 0x86;
3535 nv
->node_name
[0] = 0x20;
3536 nv
->node_name
[1] = 0x00;
3537 nv
->node_name
[2] = 0x00;
3538 nv
->node_name
[3] = 0xe0;
3539 nv
->node_name
[4] = 0x8b;
3540 nv
->node_name
[5] = 0x1c;
3541 nv
->node_name
[6] = 0x55;
3542 nv
->node_name
[7] = 0x86;
3543 qla24xx_nvram_wwn_from_ofw(ha
, nv
);
3544 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3545 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3546 nv
->login_timeout
= __constant_cpu_to_le16(0);
3547 nv
->firmware_options_1
=
3548 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3549 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3550 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3551 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3552 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3553 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3554 nv
->reset_delay
= 5;
3555 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3556 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3557 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3562 /* Reset Initialization control block */
3563 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3565 /* Copy 1st segment. */
3566 dptr1
= (uint8_t *)icb
;
3567 dptr2
= (uint8_t *)&nv
->version
;
3568 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3570 *dptr1
++ = *dptr2
++;
3572 icb
->login_retry_count
= nv
->login_retry_count
;
3573 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3575 /* Copy 2nd segment. */
3576 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3577 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3578 cnt
= (uint8_t *)&icb
->reserved_3
-
3579 (uint8_t *)&icb
->interrupt_delay_timer
;
3581 *dptr1
++ = *dptr2
++;
3584 * Setup driver NVRAM options.
3586 qla2x00_set_model_info(ha
, nv
->model_name
, sizeof(nv
->model_name
),
3589 /* Use alternate WWN? */
3590 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3591 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3592 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3595 /* Prepare nodename */
3596 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3598 * Firmware will apply the following mask if the nodename was
3601 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3602 icb
->node_name
[0] &= 0xF0;
3605 /* Set host adapter parameters. */
3606 ha
->flags
.disable_risc_code_load
= 0;
3607 ha
->flags
.enable_lip_reset
= 0;
3608 ha
->flags
.enable_lip_full_login
=
3609 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3610 ha
->flags
.enable_target_reset
=
3611 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3612 ha
->flags
.enable_led_scheme
= 0;
3613 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3615 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3616 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3618 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3619 sizeof(ha
->fw_seriallink_options24
));
3621 /* save HBA serial number */
3622 ha
->serial0
= icb
->port_name
[5];
3623 ha
->serial1
= icb
->port_name
[6];
3624 ha
->serial2
= icb
->port_name
[7];
3625 ha
->node_name
= icb
->node_name
;
3626 ha
->port_name
= icb
->port_name
;
3628 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3630 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3632 /* Set minimum login_timeout to 4 seconds. */
3633 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3634 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3635 if (le16_to_cpu(nv
->login_timeout
) < 4)
3636 nv
->login_timeout
= __constant_cpu_to_le16(4);
3637 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3638 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3640 /* Set minimum RATOV to 200 tenths of a second. */
3643 ha
->loop_reset_delay
= nv
->reset_delay
;
3645 /* Link Down Timeout = 0:
3647 * When Port Down timer expires we will start returning
3648 * I/O's to OS with "DID_NO_CONNECT".
3650 * Link Down Timeout != 0:
3652 * The driver waits for the link to come up after link down
3653 * before returning I/Os to OS with "DID_NO_CONNECT".
3655 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3656 ha
->loop_down_abort_time
=
3657 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3659 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3660 ha
->loop_down_abort_time
=
3661 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3664 /* Need enough time to try and get the port back. */
3665 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3666 if (qlport_down_retry
)
3667 ha
->port_down_retry_count
= qlport_down_retry
;
3669 /* Set login_retry_count */
3670 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3671 if (ha
->port_down_retry_count
==
3672 le16_to_cpu(nv
->port_down_retry_count
) &&
3673 ha
->port_down_retry_count
> 3)
3674 ha
->login_retry_count
= ha
->port_down_retry_count
;
3675 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3676 ha
->login_retry_count
= ha
->port_down_retry_count
;
3677 if (ql2xloginretrycount
)
3678 ha
->login_retry_count
= ql2xloginretrycount
;
3681 if (!ha
->flags
.init_done
) {
3682 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3683 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3684 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3685 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3687 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3688 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3689 ha
->flags
.process_response_queue
= 0;
3690 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3691 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3693 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3694 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3695 ha
->zio_timer
* 100));
3696 qla_printk(KERN_INFO
, ha
,
3697 "ZIO mode %d enabled; timer delay (%d us).\n",
3698 ha
->zio_mode
, ha
->zio_timer
* 100);
3700 icb
->firmware_options_2
|= cpu_to_le32(
3701 (uint32_t)ha
->zio_mode
);
3702 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3703 ha
->flags
.process_response_queue
= 1;
3707 DEBUG2_3(printk(KERN_WARNING
3708 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3714 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3717 int segments
, fragment
;
3719 uint32_t *dcode
, dlen
;
3726 segments
= FA_RISC_CODE_SEGMENTS
;
3727 faddr
= FA_RISC_CODE_ADDR
;
3728 dcode
= (uint32_t *)ha
->request_ring
;
3731 /* Validate firmware image by checking version. */
3732 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3733 for (i
= 0; i
< 4; i
++)
3734 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3735 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3736 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3737 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3739 qla_printk(KERN_WARNING
, ha
,
3740 "Unable to verify integrity of flash firmware image!\n");
3741 qla_printk(KERN_WARNING
, ha
,
3742 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3743 dcode
[1], dcode
[2], dcode
[3]);
3745 return QLA_FUNCTION_FAILED
;
3748 while (segments
&& rval
== QLA_SUCCESS
) {
3749 /* Read segment's load information. */
3750 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3752 risc_addr
= be32_to_cpu(dcode
[2]);
3753 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3754 risc_size
= be32_to_cpu(dcode
[3]);
3757 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3758 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3759 if (dlen
> risc_size
)
3762 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3763 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3764 ha
->host_no
, risc_addr
, dlen
, faddr
));
3766 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3767 for (i
= 0; i
< dlen
; i
++)
3768 dcode
[i
] = swab32(dcode
[i
]);
3770 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3773 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3774 "segment %d of firmware\n", ha
->host_no
,
3776 qla_printk(KERN_WARNING
, ha
,
3777 "[ERROR] Failed to load segment %d of "
3778 "firmware\n", fragment
);
3795 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3798 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3802 uint16_t *wcode
, *fwcode
;
3803 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3804 struct fw_blob
*blob
;
3806 /* Load firmware blob. */
3807 blob
= qla2x00_request_firmware(ha
);
3809 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3810 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3811 "from: " QLA_FW_URL
".\n");
3812 return QLA_FUNCTION_FAILED
;
3817 wcode
= (uint16_t *)ha
->request_ring
;
3819 fwcode
= (uint16_t *)blob
->fw
->data
;
3822 /* Validate firmware image by checking version. */
3823 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3824 qla_printk(KERN_WARNING
, ha
,
3825 "Unable to verify integrity of firmware image (%Zd)!\n",
3827 goto fail_fw_integrity
;
3829 for (i
= 0; i
< 4; i
++)
3830 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3831 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3832 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3833 wcode
[2] == 0 && wcode
[3] == 0)) {
3834 qla_printk(KERN_WARNING
, ha
,
3835 "Unable to verify integrity of firmware image!\n");
3836 qla_printk(KERN_WARNING
, ha
,
3837 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3838 wcode
[1], wcode
[2], wcode
[3]);
3839 goto fail_fw_integrity
;
3843 while (*seg
&& rval
== QLA_SUCCESS
) {
3845 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3846 risc_size
= be16_to_cpu(fwcode
[3]);
3848 /* Validate firmware image size. */
3849 fwclen
+= risc_size
* sizeof(uint16_t);
3850 if (blob
->fw
->size
< fwclen
) {
3851 qla_printk(KERN_WARNING
, ha
,
3852 "Unable to verify integrity of firmware image "
3853 "(%Zd)!\n", blob
->fw
->size
);
3854 goto fail_fw_integrity
;
3858 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3859 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3860 if (wlen
> risc_size
)
3863 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3864 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3867 for (i
= 0; i
< wlen
; i
++)
3868 wcode
[i
] = swab16(fwcode
[i
]);
3870 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3873 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3874 "segment %d of firmware\n", ha
->host_no
,
3876 qla_printk(KERN_WARNING
, ha
,
3877 "[ERROR] Failed to load segment %d of "
3878 "firmware\n", fragment
);
3894 return QLA_FUNCTION_FAILED
;
3898 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3901 int segments
, fragment
;
3902 uint32_t *dcode
, dlen
;
3906 struct fw_blob
*blob
;
3907 uint32_t *fwcode
, fwclen
;
3909 /* Load firmware blob. */
3910 blob
= qla2x00_request_firmware(ha
);
3912 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3913 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3914 "from: " QLA_FW_URL
".\n");
3916 /* Try to load RISC code from flash. */
3917 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3918 "outdated) firmware from flash.\n");
3919 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3924 segments
= FA_RISC_CODE_SEGMENTS
;
3925 dcode
= (uint32_t *)ha
->request_ring
;
3927 fwcode
= (uint32_t *)blob
->fw
->data
;
3930 /* Validate firmware image by checking version. */
3931 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3932 qla_printk(KERN_WARNING
, ha
,
3933 "Unable to verify integrity of firmware image (%Zd)!\n",
3935 goto fail_fw_integrity
;
3937 for (i
= 0; i
< 4; i
++)
3938 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3939 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3940 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3941 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3943 qla_printk(KERN_WARNING
, ha
,
3944 "Unable to verify integrity of firmware image!\n");
3945 qla_printk(KERN_WARNING
, ha
,
3946 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3947 dcode
[1], dcode
[2], dcode
[3]);
3948 goto fail_fw_integrity
;
3951 while (segments
&& rval
== QLA_SUCCESS
) {
3952 risc_addr
= be32_to_cpu(fwcode
[2]);
3953 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3954 risc_size
= be32_to_cpu(fwcode
[3]);
3956 /* Validate firmware image size. */
3957 fwclen
+= risc_size
* sizeof(uint32_t);
3958 if (blob
->fw
->size
< fwclen
) {
3959 qla_printk(KERN_WARNING
, ha
,
3960 "Unable to verify integrity of firmware image "
3961 "(%Zd)!\n", blob
->fw
->size
);
3963 goto fail_fw_integrity
;
3967 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3968 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3969 if (dlen
> risc_size
)
3972 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3973 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3976 for (i
= 0; i
< dlen
; i
++)
3977 dcode
[i
] = swab32(fwcode
[i
]);
3979 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3982 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3983 "segment %d of firmware\n", ha
->host_no
,
3985 qla_printk(KERN_WARNING
, ha
,
3986 "[ERROR] Failed to load segment %d of "
3987 "firmware\n", fragment
);
4003 return QLA_FUNCTION_FAILED
;
4007 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*ha
)
4011 if (!IS_FWI2_CAPABLE(ha
))
4013 if (!ha
->fw_major_version
)
4016 ret
= qla2x00_stop_firmware(ha
);
4017 for (retries
= 5; ret
!= QLA_SUCCESS
&& retries
; retries
--) {
4018 qla2x00_reset_chip(ha
);
4019 if (qla2x00_chip_diag(ha
) != QLA_SUCCESS
)
4021 if (qla2x00_setup_chip(ha
) != QLA_SUCCESS
)
4023 qla_printk(KERN_INFO
, ha
,
4024 "Attempting retry of stop-firmware command...\n");
4025 ret
= qla2x00_stop_firmware(ha
);
4030 qla24xx_configure_vhba(scsi_qla_host_t
*ha
)
4032 int rval
= QLA_SUCCESS
;
4033 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4038 rval
= qla2x00_fw_ready(ha
);
4039 if (rval
== QLA_SUCCESS
) {
4040 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
4041 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
4044 ha
->flags
.management_server_logged_in
= 0;
4046 /* Login to SNS first */
4047 qla24xx_login_fabric(ha
, NPH_SNS
, 0xff, 0xff, 0xfc,
4049 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4050 DEBUG15(qla_printk(KERN_INFO
, ha
,
4051 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4052 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4053 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4054 return (QLA_FUNCTION_FAILED
);
4057 atomic_set(&ha
->loop_down_timer
, 0);
4058 atomic_set(&ha
->loop_state
, LOOP_UP
);
4059 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
4060 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
4061 rval
= qla2x00_loop_resync(ha
);