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
= fce_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 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
764 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
765 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
769 memset(tc
, 0, EFT_SIZE
);
770 rval
= qla2x00_enable_eft_trace(ha
, tc_dma
, EFT_NUM_BUFFERS
);
772 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
773 "EFT (%d).\n", rval
);
774 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
779 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
783 ha
->eft_dma
= tc_dma
;
786 /* Allocate memory for Fibre Channel Event Buffer. */
790 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
793 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
794 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
798 memset(tc
, 0, FCE_SIZE
);
799 rval
= qla2x00_enable_fce_trace(ha
, tc_dma
, FCE_NUM_BUFFERS
,
800 ha
->fce_mb
, &ha
->fce_bufs
);
802 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
803 "FCE (%d).\n", rval
);
804 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
806 ha
->flags
.fce_enabled
= 0;
810 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
813 fce_size
= sizeof(struct qla2xxx_fce_chain
) + EFT_SIZE
;
814 ha
->flags
.fce_enabled
= 1;
815 ha
->fce_dma
= tc_dma
;
819 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
820 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
822 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
823 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
826 ha
->fw_dump
= vmalloc(dump_size
);
828 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
829 "firmware dump!!!\n", dump_size
/ 1024);
832 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
840 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
843 ha
->fw_dump_len
= dump_size
;
844 ha
->fw_dump
->signature
[0] = 'Q';
845 ha
->fw_dump
->signature
[1] = 'L';
846 ha
->fw_dump
->signature
[2] = 'G';
847 ha
->fw_dump
->signature
[3] = 'C';
848 ha
->fw_dump
->version
= __constant_htonl(1);
850 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
851 ha
->fw_dump
->mem_size
= htonl(mem_size
);
852 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
853 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
855 ha
->fw_dump
->eft_size
= htonl(eft_size
);
856 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
857 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
859 ha
->fw_dump
->header_size
=
860 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
864 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
867 * Returns 0 on success.
870 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
873 uint16_t fw_iocb_cnt
= 0;
874 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
875 dma_addr_t request_dma
;
876 request_t
*request_ring
;
878 /* Valid only on recent ISPs. */
879 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
882 /* Retrieve IOCB counts available to the firmware. */
883 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
,
884 &ha
->max_npiv_vports
);
887 /* No point in continuing if current settings are sufficient. */
888 if (fw_iocb_cnt
< 1024)
890 if (ha
->request_q_length
>= request_q_length
)
893 /* Attempt to claim larger area for request queue. */
894 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
895 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
897 if (request_ring
== NULL
)
900 /* Resize successful, report extensions. */
901 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
902 (ha
->fw_memory_size
+ 1) / 1024);
903 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
904 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
906 /* Clear old allocations. */
907 dma_free_coherent(&ha
->pdev
->dev
,
908 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
911 /* Begin using larger queue. */
912 ha
->request_q_length
= request_q_length
;
913 ha
->request_ring
= request_ring
;
914 ha
->request_dma
= request_dma
;
918 * qla2x00_setup_chip() - Load and start RISC firmware.
921 * Returns 0 on success.
924 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
927 uint32_t srisc_address
= 0;
928 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
931 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
932 /* Disable SRAM, Instruction RAM and GP RAM parity. */
933 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
934 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
935 RD_REG_WORD(®
->hccr
);
936 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
939 /* Load firmware sequences */
940 rval
= ha
->isp_ops
->load_risc(ha
, &srisc_address
);
941 if (rval
== QLA_SUCCESS
) {
942 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
943 "code.\n", ha
->host_no
));
945 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
946 if (rval
== QLA_SUCCESS
) {
947 /* Start firmware execution. */
948 DEBUG(printk("scsi(%ld): Checksum OK, start "
949 "firmware.\n", ha
->host_no
));
951 rval
= qla2x00_execute_fw(ha
, srisc_address
);
952 /* Retrieve firmware information. */
953 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
954 qla2x00_get_fw_version(ha
,
955 &ha
->fw_major_version
,
956 &ha
->fw_minor_version
,
957 &ha
->fw_subminor_version
,
958 &ha
->fw_attributes
, &ha
->fw_memory_size
);
959 qla2x00_resize_request_q(ha
);
960 ha
->flags
.npiv_supported
= 0;
961 if ((IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) &&
962 (ha
->fw_attributes
& BIT_2
)) {
963 ha
->flags
.npiv_supported
= 1;
964 if ((!ha
->max_npiv_vports
) ||
965 ((ha
->max_npiv_vports
+ 1) %
966 MIN_MULTI_ID_FABRIC
))
967 ha
->max_npiv_vports
=
968 MIN_MULTI_ID_FABRIC
- 1;
972 qla2x00_alloc_fw_dump(ha
);
975 DEBUG2(printk(KERN_INFO
976 "scsi(%ld): ISP Firmware failed checksum.\n",
981 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
982 /* Enable proper parity. */
983 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
986 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
988 /* SRAM, Instruction RAM and GP RAM parity */
989 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
990 RD_REG_WORD(®
->hccr
);
991 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
995 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1003 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1006 * Beginning of request ring has initialization control block already built
1007 * by nvram config routine.
1009 * Returns 0 on success.
1012 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
1017 pkt
= ha
->response_ring_ptr
;
1018 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
1019 pkt
->signature
= RESPONSE_PROCESSED
;
1026 * qla2x00_update_fw_options() - Read and process firmware options.
1029 * Returns 0 on success.
1032 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
1034 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1036 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1037 qla2x00_get_fw_options(ha
, ha
->fw_options
);
1039 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1042 /* Serial Link options. */
1043 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1045 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1046 sizeof(ha
->fw_seriallink_options
)));
1048 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1049 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1050 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1053 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1054 emphasis
= (ha
->fw_seriallink_options
[2] &
1055 (BIT_4
| BIT_3
)) >> 3;
1056 tx_sens
= ha
->fw_seriallink_options
[0] &
1057 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1058 rx_sens
= (ha
->fw_seriallink_options
[0] &
1059 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1060 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1061 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1064 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1065 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1066 ha
->fw_options
[10] |= BIT_5
|
1067 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1068 (tx_sens
& (BIT_1
| BIT_0
));
1071 swing
= (ha
->fw_seriallink_options
[2] &
1072 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1073 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1074 tx_sens
= ha
->fw_seriallink_options
[1] &
1075 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1076 rx_sens
= (ha
->fw_seriallink_options
[1] &
1077 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1078 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1079 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1082 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1083 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1084 ha
->fw_options
[11] |= BIT_5
|
1085 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1086 (tx_sens
& (BIT_1
| BIT_0
));
1090 /* Return command IOCBs without waiting for an ABTS to complete. */
1091 ha
->fw_options
[3] |= BIT_13
;
1094 if (ha
->flags
.enable_led_scheme
)
1095 ha
->fw_options
[2] |= BIT_12
;
1097 /* Detect ISP6312. */
1099 ha
->fw_options
[2] |= BIT_13
;
1101 /* Update firmware options. */
1102 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1106 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1110 /* Update Serial Link options. */
1111 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1114 rval
= qla2x00_set_serdes_params(ha
,
1115 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1116 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1117 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1118 if (rval
!= QLA_SUCCESS
) {
1119 qla_printk(KERN_WARNING
, ha
,
1120 "Unable to update Serial Link options (%x).\n", rval
);
1125 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1127 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1129 /* Setup ring parameters in initialization control block. */
1130 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1131 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1132 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1133 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1134 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1135 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1136 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1137 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1139 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1140 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1141 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1142 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1143 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1147 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1149 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1150 struct init_cb_24xx
*icb
;
1152 /* Setup ring parameters in initialization control block. */
1153 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1154 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1155 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1156 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1157 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1158 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1159 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1160 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1161 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1163 WRT_REG_DWORD(®
->req_q_in
, 0);
1164 WRT_REG_DWORD(®
->req_q_out
, 0);
1165 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1166 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1167 RD_REG_DWORD(®
->rsp_q_out
);
1171 * qla2x00_init_rings() - Initializes firmware.
1174 * Beginning of request ring has initialization control block already built
1175 * by nvram config routine.
1177 * Returns 0 on success.
1180 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1183 unsigned long flags
= 0;
1185 struct mid_init_cb_24xx
*mid_init_cb
=
1186 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1188 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1190 /* Clear outstanding commands array. */
1191 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1192 ha
->outstanding_cmds
[cnt
] = NULL
;
1194 ha
->current_outstanding_cmd
= 0;
1196 /* Clear RSCN queue. */
1197 ha
->rscn_in_ptr
= 0;
1198 ha
->rscn_out_ptr
= 0;
1200 /* Initialize firmware. */
1201 ha
->request_ring_ptr
= ha
->request_ring
;
1202 ha
->req_ring_index
= 0;
1203 ha
->req_q_cnt
= ha
->request_q_length
;
1204 ha
->response_ring_ptr
= ha
->response_ring
;
1205 ha
->rsp_ring_index
= 0;
1207 /* Initialize response queue entries */
1208 qla2x00_init_response_q_entries(ha
);
1210 ha
->isp_ops
->config_rings(ha
);
1212 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1214 /* Update any ISP specific firmware options before initialization. */
1215 ha
->isp_ops
->update_fw_options(ha
);
1217 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1219 if (ha
->flags
.npiv_supported
)
1220 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1222 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1224 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1226 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1229 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1237 * qla2x00_fw_ready() - Waits for firmware ready.
1240 * Returns 0 on success.
1243 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1246 unsigned long wtime
, mtime
;
1247 uint16_t min_wait
; /* Minimum wait time if loop is down */
1248 uint16_t wait_time
; /* Wait time if loop is coming ready */
1253 /* 20 seconds for loop down. */
1257 * Firmware should take at most one RATOV to login, plus 5 seconds for
1258 * our own processing.
1260 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1261 wait_time
= min_wait
;
1264 /* Min wait time if loop down */
1265 mtime
= jiffies
+ (min_wait
* HZ
);
1267 /* wait time before firmware ready */
1268 wtime
= jiffies
+ (wait_time
* HZ
);
1270 /* Wait for ISP to finish LIP */
1271 if (!ha
->flags
.init_done
)
1272 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1274 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1278 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1279 if (rval
== QLA_SUCCESS
) {
1280 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1281 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1283 if (fw_state
== FSTATE_READY
) {
1284 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1287 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1288 &ha
->login_timeout
, &ha
->r_a_tov
);
1294 rval
= QLA_FUNCTION_FAILED
;
1296 if (atomic_read(&ha
->loop_down_timer
) &&
1297 fw_state
!= FSTATE_READY
) {
1298 /* Loop down. Timeout on min_wait for states
1299 * other than Wait for Login.
1301 if (time_after_eq(jiffies
, mtime
)) {
1302 qla_printk(KERN_INFO
, ha
,
1303 "Cable is unplugged...\n");
1305 ha
->device_flags
|= DFLG_NO_CABLE
;
1310 /* Mailbox cmd failed. Timeout on min_wait. */
1311 if (time_after_eq(jiffies
, mtime
))
1315 if (time_after_eq(jiffies
, wtime
))
1318 /* Delay for a while */
1321 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1322 ha
->host_no
, fw_state
, jiffies
));
1325 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1326 ha
->host_no
, fw_state
, jiffies
));
1329 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1337 * qla2x00_configure_hba
1338 * Setup adapter context.
1341 * ha = adapter state pointer.
1350 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1359 char connect_type
[22];
1361 /* Get host addresses. */
1362 rval
= qla2x00_get_adapter_id(ha
,
1363 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1364 if (rval
!= QLA_SUCCESS
) {
1365 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1366 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1367 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1368 __func__
, ha
->host_no
));
1370 qla_printk(KERN_WARNING
, ha
,
1371 "ERROR -- Unable to get host loop ID.\n");
1372 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1378 qla_printk(KERN_INFO
, ha
,
1379 "Cannot get topology - retrying.\n");
1380 return (QLA_FUNCTION_FAILED
);
1383 ha
->loop_id
= loop_id
;
1386 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1387 ha
->operating_mode
= LOOP
;
1392 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1394 ha
->current_topology
= ISP_CFG_NL
;
1395 strcpy(connect_type
, "(Loop)");
1399 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1401 ha
->switch_cap
= sw_cap
;
1402 ha
->current_topology
= ISP_CFG_FL
;
1403 strcpy(connect_type
, "(FL_Port)");
1407 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1409 ha
->operating_mode
= P2P
;
1410 ha
->current_topology
= ISP_CFG_N
;
1411 strcpy(connect_type
, "(N_Port-to-N_Port)");
1415 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1417 ha
->switch_cap
= sw_cap
;
1418 ha
->operating_mode
= P2P
;
1419 ha
->current_topology
= ISP_CFG_F
;
1420 strcpy(connect_type
, "(F_Port)");
1424 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1426 ha
->host_no
, topo
));
1427 ha
->current_topology
= ISP_CFG_NL
;
1428 strcpy(connect_type
, "(Loop)");
1432 /* Save Host port and loop ID. */
1433 /* byte order - Big Endian */
1434 ha
->d_id
.b
.domain
= domain
;
1435 ha
->d_id
.b
.area
= area
;
1436 ha
->d_id
.b
.al_pa
= al_pa
;
1438 if (!ha
->flags
.init_done
)
1439 qla_printk(KERN_INFO
, ha
,
1440 "Topology - %s, Host Loop address 0x%x\n",
1441 connect_type
, ha
->loop_id
);
1444 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1446 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1453 qla2x00_set_model_info(scsi_qla_host_t
*ha
, uint8_t *model
, size_t len
, char *def
)
1458 if (memcmp(model
, BINZERO
, len
) != 0) {
1459 strncpy(ha
->model_number
, model
, len
);
1460 st
= en
= ha
->model_number
;
1463 if (*en
!= 0x20 && *en
!= 0x00)
1468 index
= (ha
->pdev
->subsystem_device
& 0xff);
1469 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1470 index
< QLA_MODEL_NAMES
)
1471 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1473 index
= (ha
->pdev
->subsystem_device
& 0xff);
1474 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1475 index
< QLA_MODEL_NAMES
) {
1476 strcpy(ha
->model_number
,
1477 qla2x00_model_name
[index
* 2]);
1478 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1480 strcpy(ha
->model_number
, def
);
1485 /* On sparc systems, obtain port and node WWN from firmware
1488 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, nvram_t
*nv
)
1491 struct pci_dev
*pdev
= ha
->pdev
;
1492 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1496 val
= of_get_property(dp
, "port-wwn", &len
);
1497 if (val
&& len
>= WWN_SIZE
)
1498 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1500 val
= of_get_property(dp
, "node-wwn", &len
);
1501 if (val
&& len
>= WWN_SIZE
)
1502 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1507 * NVRAM configuration for ISP 2xxx
1510 * ha = adapter block pointer.
1513 * initialization control block in response_ring
1514 * host adapters parameters in host adapter block
1520 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1525 uint8_t *dptr1
, *dptr2
;
1526 init_cb_t
*icb
= ha
->init_cb
;
1527 nvram_t
*nv
= ha
->nvram
;
1528 uint8_t *ptr
= ha
->nvram
;
1529 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1533 /* Determine NVRAM starting address. */
1534 ha
->nvram_size
= sizeof(nvram_t
);
1536 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1537 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1538 ha
->nvram_base
= 0x80;
1540 /* Get NVRAM data and calculate checksum. */
1541 ha
->isp_ops
->read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1542 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1545 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1546 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
1548 /* Bad NVRAM data, set defaults parameters. */
1549 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1550 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1551 /* Reset NVRAM data. */
1552 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1553 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1555 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1556 "invalid -- WWPN) defaults.\n");
1559 * Set default initialization control block.
1561 memset(nv
, 0, ha
->nvram_size
);
1562 nv
->parameter_block_version
= ICB_VERSION
;
1564 if (IS_QLA23XX(ha
)) {
1565 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1566 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1567 nv
->add_firmware_options
[0] = BIT_5
;
1568 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1569 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1570 nv
->special_options
[1] = BIT_7
;
1571 } else if (IS_QLA2200(ha
)) {
1572 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1573 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1574 nv
->add_firmware_options
[0] = BIT_5
;
1575 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1576 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1577 } else if (IS_QLA2100(ha
)) {
1578 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1579 nv
->firmware_options
[1] = BIT_5
;
1580 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1583 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1584 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1585 nv
->retry_count
= 8;
1586 nv
->retry_delay
= 1;
1588 nv
->port_name
[0] = 33;
1589 nv
->port_name
[3] = 224;
1590 nv
->port_name
[4] = 139;
1592 qla2xxx_nvram_wwn_from_ofw(ha
, nv
);
1594 nv
->login_timeout
= 4;
1597 * Set default host adapter parameters
1599 nv
->host_p
[1] = BIT_2
;
1600 nv
->reset_delay
= 5;
1601 nv
->port_down_retry_count
= 8;
1602 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1603 nv
->link_down_timeout
= 60;
1608 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1610 * The SN2 does not provide BIOS emulation which means you can't change
1611 * potentially bogus BIOS settings. Force the use of default settings
1612 * for link rate and frame size. Hope that the rest of the settings
1615 if (ia64_platform_is("sn2")) {
1616 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1618 nv
->special_options
[1] = BIT_7
;
1622 /* Reset Initialization control block */
1623 memset(icb
, 0, ha
->init_cb_size
);
1626 * Setup driver NVRAM options.
1628 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1629 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1630 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1631 nv
->firmware_options
[1] &= ~BIT_4
;
1633 if (IS_QLA23XX(ha
)) {
1634 nv
->firmware_options
[0] |= BIT_2
;
1635 nv
->firmware_options
[0] &= ~BIT_3
;
1636 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1638 if (IS_QLA2300(ha
)) {
1639 if (ha
->fb_rev
== FPM_2310
) {
1640 strcpy(ha
->model_number
, "QLA2310");
1642 strcpy(ha
->model_number
, "QLA2300");
1645 qla2x00_set_model_info(ha
, nv
->model_number
,
1646 sizeof(nv
->model_number
), "QLA23xx");
1648 } else if (IS_QLA2200(ha
)) {
1649 nv
->firmware_options
[0] |= BIT_2
;
1651 * 'Point-to-point preferred, else loop' is not a safe
1652 * connection mode setting.
1654 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1656 /* Force 'loop preferred, else point-to-point'. */
1657 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1658 nv
->add_firmware_options
[0] |= BIT_5
;
1660 strcpy(ha
->model_number
, "QLA22xx");
1661 } else /*if (IS_QLA2100(ha))*/ {
1662 strcpy(ha
->model_number
, "QLA2100");
1666 * Copy over NVRAM RISC parameter block to initialization control block.
1668 dptr1
= (uint8_t *)icb
;
1669 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1670 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1672 *dptr1
++ = *dptr2
++;
1674 /* Copy 2nd half. */
1675 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1676 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1678 *dptr1
++ = *dptr2
++;
1680 /* Use alternate WWN? */
1681 if (nv
->host_p
[1] & BIT_7
) {
1682 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1683 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1686 /* Prepare nodename */
1687 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1689 * Firmware will apply the following mask if the nodename was
1692 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1693 icb
->node_name
[0] &= 0xF0;
1697 * Set host adapter parameters.
1699 if (nv
->host_p
[0] & BIT_7
)
1700 ql2xextended_error_logging
= 1;
1701 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1702 /* Always load RISC code on non ISP2[12]00 chips. */
1703 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1704 ha
->flags
.disable_risc_code_load
= 0;
1705 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1706 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1707 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1708 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1709 ha
->flags
.disable_serdes
= 0;
1711 ha
->operating_mode
=
1712 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1714 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1715 sizeof(ha
->fw_seriallink_options
));
1717 /* save HBA serial number */
1718 ha
->serial0
= icb
->port_name
[5];
1719 ha
->serial1
= icb
->port_name
[6];
1720 ha
->serial2
= icb
->port_name
[7];
1721 ha
->node_name
= icb
->node_name
;
1722 ha
->port_name
= icb
->port_name
;
1724 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1726 ha
->retry_count
= nv
->retry_count
;
1728 /* Set minimum login_timeout to 4 seconds. */
1729 if (nv
->login_timeout
< ql2xlogintimeout
)
1730 nv
->login_timeout
= ql2xlogintimeout
;
1731 if (nv
->login_timeout
< 4)
1732 nv
->login_timeout
= 4;
1733 ha
->login_timeout
= nv
->login_timeout
;
1734 icb
->login_timeout
= nv
->login_timeout
;
1736 <<<<<<< HEAD
:drivers
/scsi
/qla2xxx
/qla_init
.c
1737 /* Set minimum RATOV to 200 tenths of a second. */
1740 /* Set minimum RATOV to 100 tenths of a second. */
1742 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/qla2xxx
/qla_init
.c
1744 ha
->loop_reset_delay
= nv
->reset_delay
;
1746 /* Link Down Timeout = 0:
1748 * When Port Down timer expires we will start returning
1749 * I/O's to OS with "DID_NO_CONNECT".
1751 * Link Down Timeout != 0:
1753 * The driver waits for the link to come up after link down
1754 * before returning I/Os to OS with "DID_NO_CONNECT".
1756 if (nv
->link_down_timeout
== 0) {
1757 ha
->loop_down_abort_time
=
1758 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1760 ha
->link_down_timeout
= nv
->link_down_timeout
;
1761 ha
->loop_down_abort_time
=
1762 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1766 * Need enough time to try and get the port back.
1768 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1769 if (qlport_down_retry
)
1770 ha
->port_down_retry_count
= qlport_down_retry
;
1771 /* Set login_retry_count */
1772 ha
->login_retry_count
= nv
->retry_count
;
1773 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1774 ha
->port_down_retry_count
> 3)
1775 ha
->login_retry_count
= ha
->port_down_retry_count
;
1776 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1777 ha
->login_retry_count
= ha
->port_down_retry_count
;
1778 if (ql2xloginretrycount
)
1779 ha
->login_retry_count
= ql2xloginretrycount
;
1781 icb
->lun_enables
= __constant_cpu_to_le16(0);
1782 icb
->command_resource_count
= 0;
1783 icb
->immediate_notify_resource_count
= 0;
1784 icb
->timeout
= __constant_cpu_to_le16(0);
1786 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1788 icb
->firmware_options
[0] &= ~BIT_3
;
1789 icb
->add_firmware_options
[0] &=
1790 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1791 icb
->add_firmware_options
[0] |= BIT_2
;
1792 icb
->response_accumulation_timer
= 3;
1793 icb
->interrupt_delay_timer
= 5;
1795 ha
->flags
.process_response_queue
= 1;
1798 if (!ha
->flags
.init_done
) {
1799 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1800 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1801 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1802 icb
->interrupt_delay_timer
: 2;
1804 icb
->add_firmware_options
[0] &=
1805 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1806 ha
->flags
.process_response_queue
= 0;
1807 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1808 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1810 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1811 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1812 ha
->zio_timer
* 100));
1813 qla_printk(KERN_INFO
, ha
,
1814 "ZIO mode %d enabled; timer delay (%d us).\n",
1815 ha
->zio_mode
, ha
->zio_timer
* 100);
1817 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1818 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1819 ha
->flags
.process_response_queue
= 1;
1824 DEBUG2_3(printk(KERN_WARNING
1825 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1831 qla2x00_rport_del(void *data
)
1833 fc_port_t
*fcport
= data
;
1834 struct fc_rport
*rport
;
1835 unsigned long flags
;
1837 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1838 rport
= fcport
->drport
;
1839 fcport
->drport
= NULL
;
1840 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1842 fc_remote_port_delete(rport
);
1846 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1848 * @flags: allocation flags
1850 * Returns a pointer to the allocated fcport, or NULL, if none available.
1853 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1857 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
1861 /* Setup fcport template structure. */
1863 fcport
->vp_idx
= ha
->vp_idx
;
1864 fcport
->port_type
= FCT_UNKNOWN
;
1865 fcport
->loop_id
= FC_NO_LOOP_ID
;
1866 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1867 fcport
->flags
= FCF_RLC_SUPPORT
;
1868 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1869 spin_lock_init(&fcport
->rport_lock
);
1875 * qla2x00_configure_loop
1876 * Updates Fibre Channel Device Database with what is actually on loop.
1879 * ha = adapter block pointer.
1884 * 2 = database was full and device was not configured.
1887 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1890 unsigned long flags
, save_flags
;
1894 /* Get Initiator ID */
1895 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1896 rval
= qla2x00_configure_hba(ha
);
1897 if (rval
!= QLA_SUCCESS
) {
1898 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1904 save_flags
= flags
= ha
->dpc_flags
;
1905 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1906 ha
->host_no
, flags
));
1909 * If we have both an RSCN and PORT UPDATE pending then handle them
1910 * both at the same time.
1912 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1913 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1915 /* Determine what we need to do */
1916 if (ha
->current_topology
== ISP_CFG_FL
&&
1917 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1919 ha
->flags
.rscn_queue_overflow
= 1;
1920 set_bit(RSCN_UPDATE
, &flags
);
1922 } else if (ha
->current_topology
== ISP_CFG_F
&&
1923 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1925 ha
->flags
.rscn_queue_overflow
= 1;
1926 set_bit(RSCN_UPDATE
, &flags
);
1927 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1929 } else if (ha
->current_topology
== ISP_CFG_N
) {
1930 clear_bit(RSCN_UPDATE
, &flags
);
1932 } else if (!ha
->flags
.online
||
1933 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1935 ha
->flags
.rscn_queue_overflow
= 1;
1936 set_bit(RSCN_UPDATE
, &flags
);
1937 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1940 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1941 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1942 rval
= QLA_FUNCTION_FAILED
;
1944 rval
= qla2x00_configure_local_loop(ha
);
1948 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1949 if (LOOP_TRANSITION(ha
)) {
1950 rval
= QLA_FUNCTION_FAILED
;
1952 rval
= qla2x00_configure_fabric(ha
);
1956 if (rval
== QLA_SUCCESS
) {
1957 if (atomic_read(&ha
->loop_down_timer
) ||
1958 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1959 rval
= QLA_FUNCTION_FAILED
;
1961 atomic_set(&ha
->loop_state
, LOOP_READY
);
1963 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1968 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1969 __func__
, ha
->host_no
));
1971 DEBUG3(printk("%s: exiting normally\n", __func__
));
1974 /* Restore state if a resync event occured during processing */
1975 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1976 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1977 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1978 if (test_bit(RSCN_UPDATE
, &save_flags
))
1979 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1988 * qla2x00_configure_local_loop
1989 * Updates Fibre Channel Device Database with local loop devices.
1992 * ha = adapter block pointer.
1998 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
2003 fc_port_t
*fcport
, *new_fcport
;
2009 uint8_t domain
, area
, al_pa
;
2010 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2014 entries
= MAX_FIBRE_DEVICES
;
2016 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
2017 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
2019 /* Get list of logged in devices. */
2020 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2021 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
2023 if (rval
!= QLA_SUCCESS
)
2024 goto cleanup_allocation
;
2026 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2027 ha
->host_no
, entries
));
2028 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2029 entries
* sizeof(struct gid_list_info
)));
2031 /* Allocate temporary fcport for any new fcports discovered. */
2032 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2033 if (new_fcport
== NULL
) {
2034 rval
= QLA_MEMORY_ALLOC_FAILED
;
2035 goto cleanup_allocation
;
2037 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2040 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2042 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2043 if (fcport
->vp_idx
!= ha
->vp_idx
)
2046 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2047 fcport
->port_type
!= FCT_BROADCAST
&&
2048 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2050 DEBUG(printk("scsi(%ld): Marking port lost, "
2052 ha
->host_no
, fcport
->loop_id
));
2054 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2055 fcport
->flags
&= ~FCF_FARP_DONE
;
2059 /* Add devices to port list. */
2060 id_iter
= (char *)ha
->gid_list
;
2061 for (index
= 0; index
< entries
; index
++) {
2062 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2063 area
= ((struct gid_list_info
*)id_iter
)->area
;
2064 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2065 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2066 loop_id
= (uint16_t)
2067 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2069 loop_id
= le16_to_cpu(
2070 ((struct gid_list_info
*)id_iter
)->loop_id
);
2071 id_iter
+= ha
->gid_list_info_size
;
2073 /* Bypass reserved domain fields. */
2074 if ((domain
& 0xf0) == 0xf0)
2077 /* Bypass if not same domain and area of adapter. */
2078 if (area
&& domain
&&
2079 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
2082 /* Bypass invalid local loop ID. */
2083 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2086 /* Fill in member data. */
2087 new_fcport
->d_id
.b
.domain
= domain
;
2088 new_fcport
->d_id
.b
.area
= area
;
2089 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2090 new_fcport
->loop_id
= loop_id
;
2091 new_fcport
->vp_idx
= ha
->vp_idx
;
2092 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
2093 if (rval2
!= QLA_SUCCESS
) {
2094 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2095 "information -- get_port_database=%x, "
2097 ha
->host_no
, rval2
, new_fcport
->loop_id
));
2098 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2100 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2104 /* Check for matching device in port list. */
2107 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2108 if (fcport
->vp_idx
!= ha
->vp_idx
)
2111 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2115 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2116 FCF_PERSISTENT_BOUND
);
2117 fcport
->loop_id
= new_fcport
->loop_id
;
2118 fcport
->port_type
= new_fcport
->port_type
;
2119 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2120 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2128 /* New device, add to fcports list. */
2129 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2131 new_fcport
->ha
= ha
;
2132 new_fcport
->vp_idx
= ha
->vp_idx
;
2133 list_add_tail(&new_fcport
->vp_fcport
,
2136 list_add_tail(&new_fcport
->list
, &pha
->fcports
);
2138 /* Allocate a new replacement fcport. */
2139 fcport
= new_fcport
;
2140 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2141 if (new_fcport
== NULL
) {
2142 rval
= QLA_MEMORY_ALLOC_FAILED
;
2143 goto cleanup_allocation
;
2145 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2148 /* Base iIDMA settings on HBA port speed. */
2149 fcport
->fp_speed
= ha
->link_data_rate
;
2151 qla2x00_update_fcport(ha
, fcport
);
2159 if (rval
!= QLA_SUCCESS
) {
2160 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2161 "rval=%x\n", ha
->host_no
, rval
));
2165 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2166 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2173 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2177 qla2x00_mark_all_devices_lost(ha
, 0);
2178 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2179 if (fcport
->port_type
!= FCT_TARGET
)
2182 qla2x00_update_fcport(ha
, fcport
);
2187 qla2x00_iidma_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2189 #define LS_UNKNOWN 2
2190 static char *link_speeds
[5] = { "1", "2", "?", "4", "8" };
2194 if (!IS_IIDMA_CAPABLE(ha
))
2197 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2198 fcport
->fp_speed
> ha
->link_data_rate
)
2201 rval
= qla2x00_set_idma_speed(ha
, fcport
->loop_id
, fcport
->fp_speed
,
2203 if (rval
!= QLA_SUCCESS
) {
2204 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2205 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2206 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2207 fcport
->port_name
[2], fcport
->port_name
[3],
2208 fcport
->port_name
[4], fcport
->port_name
[5],
2209 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2210 fcport
->fp_speed
, mb
[0], mb
[1]));
2212 DEBUG2(qla_printk(KERN_INFO
, ha
,
2213 "iIDMA adjusted to %s GB/s on "
2214 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2215 link_speeds
[fcport
->fp_speed
], fcport
->port_name
[0],
2216 fcport
->port_name
[1], fcport
->port_name
[2],
2217 fcport
->port_name
[3], fcport
->port_name
[4],
2218 fcport
->port_name
[5], fcport
->port_name
[6],
2219 fcport
->port_name
[7]));
2224 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2226 struct fc_rport_identifiers rport_ids
;
2227 struct fc_rport
*rport
;
2228 unsigned long flags
;
2231 qla2x00_rport_del(fcport
);
2235 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2236 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2237 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2238 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2239 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2240 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2242 qla_printk(KERN_WARNING
, ha
,
2243 "Unable to allocate fc remote port!\n");
2246 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2247 fcport
->rport
= rport
;
2248 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2249 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2251 rport
->supported_classes
= fcport
->supported_classes
;
2253 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2254 if (fcport
->port_type
== FCT_INITIATOR
)
2255 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2256 if (fcport
->port_type
== FCT_TARGET
)
2257 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2258 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2260 if (rport
->scsi_target_id
!= -1 &&
2261 rport
->scsi_target_id
< ha
->host
->max_id
)
2262 fcport
->os_target_id
= rport
->scsi_target_id
;
2266 * qla2x00_update_fcport
2267 * Updates device on list.
2270 * ha = adapter block pointer.
2271 * fcport = port structure pointer.
2281 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2283 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2286 fcport
->login_retry
= 0;
2287 fcport
->port_login_retry_count
= pha
->port_down_retry_count
*
2289 atomic_set(&fcport
->port_down_timer
, pha
->port_down_retry_count
*
2291 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2293 qla2x00_iidma_fcport(ha
, fcport
);
2295 atomic_set(&fcport
->state
, FCS_ONLINE
);
2297 qla2x00_reg_remote_port(ha
, fcport
);
2301 * qla2x00_configure_fabric
2302 * Setup SNS devices with loop ID's.
2305 * ha = adapter block pointer.
2312 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2315 fc_port_t
*fcport
, *fcptemp
;
2316 uint16_t next_loopid
;
2317 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2319 LIST_HEAD(new_fcports
);
2320 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2322 /* If FL port exists, then SNS is present */
2323 if (IS_FWI2_CAPABLE(ha
))
2324 loop_id
= NPH_F_PORT
;
2326 loop_id
= SNS_FL_PORT
;
2327 rval
= qla2x00_get_port_name(ha
, loop_id
, ha
->fabric_node_name
, 1);
2328 if (rval
!= QLA_SUCCESS
) {
2329 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2330 "Port\n", ha
->host_no
));
2332 ha
->device_flags
&= ~SWITCH_FOUND
;
2333 return (QLA_SUCCESS
);
2335 ha
->device_flags
|= SWITCH_FOUND
;
2337 /* Mark devices that need re-synchronization. */
2338 rval2
= qla2x00_device_resync(ha
);
2339 if (rval2
== QLA_RSCNS_HANDLED
) {
2340 /* No point doing the scan, just continue. */
2341 return (QLA_SUCCESS
);
2345 if (ql2xfdmienable
&&
2346 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2347 qla2x00_fdmi_register(ha
);
2349 /* Ensure we are logged into the SNS. */
2350 if (IS_FWI2_CAPABLE(ha
))
2353 loop_id
= SIMPLE_NAME_SERVER
;
2354 ha
->isp_ops
->fabric_login(ha
, loop_id
, 0xff, 0xff,
2355 0xfc, mb
, BIT_1
| BIT_0
);
2356 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2357 DEBUG2(qla_printk(KERN_INFO
, ha
,
2358 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2359 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2360 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2361 return (QLA_SUCCESS
);
2364 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2365 if (qla2x00_rft_id(ha
)) {
2367 DEBUG2(printk("scsi(%ld): Register FC-4 "
2368 "TYPE failed.\n", ha
->host_no
));
2370 if (qla2x00_rff_id(ha
)) {
2372 DEBUG2(printk("scsi(%ld): Register FC-4 "
2373 "Features failed.\n", ha
->host_no
));
2375 if (qla2x00_rnn_id(ha
)) {
2377 DEBUG2(printk("scsi(%ld): Register Node Name "
2378 "failed.\n", ha
->host_no
));
2379 } else if (qla2x00_rsnn_nn(ha
)) {
2381 DEBUG2(printk("scsi(%ld): Register Symbolic "
2382 "Node Name failed.\n", ha
->host_no
));
2386 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2387 if (rval
!= QLA_SUCCESS
)
2391 * Logout all previous fabric devices marked lost, except
2394 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2395 if (fcport
->vp_idx
!=ha
->vp_idx
)
2398 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2401 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2404 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2405 qla2x00_mark_device_lost(ha
, fcport
,
2406 ql2xplogiabsentdevice
, 0);
2407 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2408 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2409 fcport
->port_type
!= FCT_INITIATOR
&&
2410 fcport
->port_type
!= FCT_BROADCAST
) {
2411 ha
->isp_ops
->fabric_logout(ha
,
2413 fcport
->d_id
.b
.domain
,
2414 fcport
->d_id
.b
.area
,
2415 fcport
->d_id
.b
.al_pa
);
2416 fcport
->loop_id
= FC_NO_LOOP_ID
;
2421 /* Starting free loop ID. */
2422 next_loopid
= pha
->min_external_loopid
;
2425 * Scan through our port list and login entries that need to be
2428 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2429 if (fcport
->vp_idx
!= ha
->vp_idx
)
2432 if (atomic_read(&ha
->loop_down_timer
) ||
2433 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2436 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2437 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2440 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2441 fcport
->loop_id
= next_loopid
;
2442 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2443 if (rval
!= QLA_SUCCESS
) {
2444 /* Ran out of IDs to use */
2448 /* Login and update database */
2449 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2452 /* Exit if out of loop IDs. */
2453 if (rval
!= QLA_SUCCESS
) {
2458 * Login and add the new devices to our port list.
2460 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2461 if (atomic_read(&ha
->loop_down_timer
) ||
2462 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2465 /* Find a new loop ID to use. */
2466 fcport
->loop_id
= next_loopid
;
2467 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2468 if (rval
!= QLA_SUCCESS
) {
2469 /* Ran out of IDs to use */
2473 /* Login and update database */
2474 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2478 fcport
->vp_idx
= ha
->vp_idx
;
2479 list_add_tail(&fcport
->vp_fcport
,
2481 list_move_tail(&fcport
->list
,
2482 &ha
->parent
->fcports
);
2484 list_move_tail(&fcport
->list
, &ha
->fcports
);
2488 /* Free all new device structures not processed. */
2489 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2490 list_del(&fcport
->list
);
2495 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2496 "rval=%d\n", ha
->host_no
, rval
));
2504 * qla2x00_find_all_fabric_devs
2507 * ha = adapter block pointer.
2508 * dev = database device entry pointer.
2517 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2521 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2526 int first_dev
, last_dev
;
2527 port_id_t wrap
, nxt_d_id
;
2531 scsi_qla_host_t
*vha
;
2532 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2536 /* Try GID_PT to get device list, else GAN. */
2537 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_ATOMIC
);
2540 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2541 "on GA_NXT\n", ha
->host_no
));
2543 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2546 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2549 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2552 } else if (qla2x00_gfpn_id(ha
, swl
) == QLA_SUCCESS
) {
2553 qla2x00_gpsc(ha
, swl
);
2558 /* Allocate temporary fcport for any new fcports discovered. */
2559 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2560 if (new_fcport
== NULL
) {
2562 return (QLA_MEMORY_ALLOC_FAILED
);
2564 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2565 new_fcport
->vp_idx
= ha
->vp_idx
;
2566 /* Set start port ID scan at adapter ID. */
2570 /* Starting free loop ID. */
2571 loop_id
= pha
->min_external_loopid
;
2572 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2573 if (qla2x00_is_reserved_id(ha
, loop_id
))
2576 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2581 wrap
.b24
= new_fcport
->d_id
.b24
;
2583 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2584 memcpy(new_fcport
->node_name
,
2585 swl
[swl_idx
].node_name
, WWN_SIZE
);
2586 memcpy(new_fcport
->port_name
,
2587 swl
[swl_idx
].port_name
, WWN_SIZE
);
2588 memcpy(new_fcport
->fabric_port_name
,
2589 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2590 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2592 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2598 /* Send GA_NXT to the switch */
2599 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2600 if (rval
!= QLA_SUCCESS
) {
2601 qla_printk(KERN_WARNING
, ha
,
2602 "SNS scan failed -- assuming zero-entry "
2604 list_for_each_entry_safe(fcport
, fcptemp
,
2605 new_fcports
, list
) {
2606 list_del(&fcport
->list
);
2614 /* If wrap on switch device list, exit. */
2616 wrap
.b24
= new_fcport
->d_id
.b24
;
2618 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2619 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2620 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2621 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2625 /* Bypass if same physical adapter. */
2626 if (new_fcport
->d_id
.b24
== pha
->d_id
.b24
)
2629 /* Bypass virtual ports of the same host. */
2630 if (pha
->num_vhosts
) {
2631 for_each_mapped_vp_idx(pha
, vp_index
) {
2634 list_for_each_entry(vha
, &pha
->vp_list
,
2636 if (vp_index
== vha
->vp_idx
) {
2647 new_fcport
->d_id
.b24
== vha
->d_id
.b24
)
2651 if (vp_index
<= pha
->max_npiv_vports
)
2655 /* Bypass if same domain and area of adapter. */
2656 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2657 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2661 /* Bypass reserved domain fields. */
2662 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2665 /* Locate matching device in database. */
2667 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2668 if (new_fcport
->vp_idx
!= fcport
->vp_idx
)
2670 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2676 /* Update port state. */
2677 memcpy(fcport
->fabric_port_name
,
2678 new_fcport
->fabric_port_name
, WWN_SIZE
);
2679 fcport
->fp_speed
= new_fcport
->fp_speed
;
2682 * If address the same and state FCS_ONLINE, nothing
2685 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2686 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2691 * If device was not a fabric device before.
2693 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2694 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2695 fcport
->loop_id
= FC_NO_LOOP_ID
;
2696 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2698 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2703 * Port ID changed or device was marked to be updated;
2704 * Log it out if still logged in and mark it for
2707 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2708 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2709 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2710 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2711 fcport
->port_type
!= FCT_INITIATOR
&&
2712 fcport
->port_type
!= FCT_BROADCAST
) {
2713 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
2714 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2715 fcport
->d_id
.b
.al_pa
);
2716 fcport
->loop_id
= FC_NO_LOOP_ID
;
2725 /* If device was not in our fcports list, then add it. */
2726 list_add_tail(&new_fcport
->list
, new_fcports
);
2728 /* Allocate a new replacement fcport. */
2729 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2730 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2731 if (new_fcport
== NULL
) {
2733 return (QLA_MEMORY_ALLOC_FAILED
);
2735 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2736 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2737 new_fcport
->vp_idx
= ha
->vp_idx
;
2743 if (!list_empty(new_fcports
))
2744 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2750 * qla2x00_find_new_loop_id
2751 * Scan through our port list and find a new usable loop ID.
2754 * ha: adapter state pointer.
2755 * dev: port structure pointer.
2758 * qla2x00 local function return status code.
2764 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2769 uint16_t first_loop_id
;
2770 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2774 /* Save starting loop ID. */
2775 first_loop_id
= dev
->loop_id
;
2778 /* Skip loop ID if already used by adapter. */
2779 if (dev
->loop_id
== ha
->loop_id
) {
2783 /* Skip reserved loop IDs. */
2784 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2788 /* Reset loop ID if passed the end. */
2789 if (dev
->loop_id
> ha
->last_loop_id
) {
2790 /* first loop ID. */
2791 dev
->loop_id
= ha
->min_external_loopid
;
2794 /* Check for loop ID being already in use. */
2797 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2798 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2799 /* ID possibly in use */
2805 /* If not in use then it is free to use. */
2810 /* ID in use. Try next value. */
2813 /* If wrap around. No free ID to use. */
2814 if (dev
->loop_id
== first_loop_id
) {
2815 dev
->loop_id
= FC_NO_LOOP_ID
;
2816 rval
= QLA_FUNCTION_FAILED
;
2825 * qla2x00_device_resync
2826 * Marks devices in the database that needs resynchronization.
2829 * ha = adapter block pointer.
2835 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2840 uint32_t rscn_entry
;
2841 uint8_t rscn_out_iter
;
2844 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2846 rval
= QLA_RSCNS_HANDLED
;
2848 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2849 ha
->flags
.rscn_queue_overflow
) {
2851 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2852 format
= MSB(MSW(rscn_entry
));
2853 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2854 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2855 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2857 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2858 "[%02x/%02x%02x%02x].\n",
2859 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2860 d_id
.b
.area
, d_id
.b
.al_pa
));
2863 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2864 ha
->rscn_out_ptr
= 0;
2866 /* Skip duplicate entries. */
2867 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2868 !ha
->flags
.rscn_queue_overflow
&&
2869 rscn_out_iter
!= ha
->rscn_in_ptr
;
2870 rscn_out_iter
= (rscn_out_iter
==
2871 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2873 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2876 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2877 "entry found at [%d].\n", ha
->host_no
,
2880 ha
->rscn_out_ptr
= rscn_out_iter
;
2883 /* Queue overflow, set switch default case. */
2884 if (ha
->flags
.rscn_queue_overflow
) {
2885 DEBUG(printk("scsi(%ld): device_resync: rscn "
2886 "overflow.\n", ha
->host_no
));
2889 ha
->flags
.rscn_queue_overflow
= 0;
2905 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2911 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2912 if (fcport
->vp_idx
!= ha
->vp_idx
)
2915 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2916 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2917 fcport
->port_type
== FCT_BROADCAST
)
2920 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2922 fcport
->port_type
!= FCT_INITIATOR
) {
2923 qla2x00_mark_device_lost(ha
, fcport
,
2927 fcport
->flags
&= ~FCF_FARP_DONE
;
2934 * qla2x00_fabric_dev_login
2935 * Login fabric target device and update FC port database.
2938 * ha: adapter state pointer.
2939 * fcport: port structure list pointer.
2940 * next_loopid: contains value of a new loop ID that can be used
2941 * by the next login attempt.
2944 * qla2x00 local function return status code.
2950 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2951 uint16_t *next_loopid
)
2960 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2961 if (rval
== QLA_SUCCESS
) {
2962 /* Send an ADISC to tape devices.*/
2964 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2966 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2967 if (rval
!= QLA_SUCCESS
) {
2968 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
2969 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2970 fcport
->d_id
.b
.al_pa
);
2971 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2973 qla2x00_update_fcport(ha
, fcport
);
2981 * qla2x00_fabric_login
2982 * Issue fabric login command.
2985 * ha = adapter block pointer.
2986 * device = pointer to FC device type structure.
2989 * 0 - Login successfully
2991 * 2 - Initiator device
2995 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2996 uint16_t *next_loopid
)
3000 uint16_t tmp_loopid
;
3001 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3007 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3008 "for port %02x%02x%02x.\n",
3009 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3010 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3012 /* Login fcport on switch. */
3013 ha
->isp_ops
->fabric_login(ha
, fcport
->loop_id
,
3014 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3015 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3016 if (mb
[0] == MBS_PORT_ID_USED
) {
3018 * Device has another loop ID. The firmware team
3019 * recommends the driver perform an implicit login with
3020 * the specified ID again. The ID we just used is save
3021 * here so we return with an ID that can be tried by
3025 tmp_loopid
= fcport
->loop_id
;
3026 fcport
->loop_id
= mb
[1];
3028 DEBUG(printk("Fabric Login: port in use - next "
3029 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3030 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3031 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3033 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3038 /* A retry occurred before. */
3039 *next_loopid
= tmp_loopid
;
3042 * No retry occurred before. Just increment the
3043 * ID value for next login.
3045 *next_loopid
= (fcport
->loop_id
+ 1);
3048 if (mb
[1] & BIT_0
) {
3049 fcport
->port_type
= FCT_INITIATOR
;
3051 fcport
->port_type
= FCT_TARGET
;
3052 if (mb
[1] & BIT_1
) {
3053 fcport
->flags
|= FCF_TAPE_PRESENT
;
3058 fcport
->supported_classes
|= FC_COS_CLASS2
;
3060 fcport
->supported_classes
|= FC_COS_CLASS3
;
3064 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3066 * Loop ID already used, try next loop ID.
3069 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
3070 if (rval
!= QLA_SUCCESS
) {
3071 /* Ran out of loop IDs to use */
3074 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3076 * Firmware possibly timed out during login. If NO
3077 * retries are left to do then the device is declared
3080 *next_loopid
= fcport
->loop_id
;
3081 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
3082 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3083 fcport
->d_id
.b
.al_pa
);
3084 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
3090 * unrecoverable / not handled error
3092 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3093 "loop_id=%x jiffies=%lx.\n",
3094 __func__
, ha
->host_no
, mb
[0],
3095 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3096 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3098 *next_loopid
= fcport
->loop_id
;
3099 ha
->isp_ops
->fabric_logout(ha
, fcport
->loop_id
,
3100 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3101 fcport
->d_id
.b
.al_pa
);
3102 fcport
->loop_id
= FC_NO_LOOP_ID
;
3103 fcport
->login_retry
= 0;
3114 * qla2x00_local_device_login
3115 * Issue local device login command.
3118 * ha = adapter block pointer.
3119 * loop_id = loop id of device to login to.
3121 * Returns (Where's the #define!!!!):
3122 * 0 - Login successfully
3127 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
3130 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3132 memset(mb
, 0, sizeof(mb
));
3133 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
3134 if (rval
== QLA_SUCCESS
) {
3135 /* Interrogate mailbox registers for any errors */
3136 if (mb
[0] == MBS_COMMAND_ERROR
)
3138 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3139 /* device not in PCB table */
3147 * qla2x00_loop_resync
3148 * Resync with fibre channel devices.
3151 * ha = adapter block pointer.
3157 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
3164 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3165 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3166 if (ha
->flags
.online
) {
3167 if (!(rval
= qla2x00_fw_ready(ha
))) {
3168 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3171 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3173 /* Issue a marker after FW becomes ready. */
3174 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3175 ha
->marker_needed
= 0;
3177 /* Remap devices on Loop. */
3178 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3180 qla2x00_configure_loop(ha
);
3182 } while (!atomic_read(&ha
->loop_down_timer
) &&
3183 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3185 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3189 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3190 return (QLA_FUNCTION_FAILED
);
3194 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3201 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3207 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3208 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3211 qla2x00_update_fcport(ha
, fcport
);
3212 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3216 qla2x00_probe_for_all_luns(ha
);
3220 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3224 /* Go with deferred removal of rport references. */
3225 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3227 qla2x00_rport_del(fcport
);
3232 * Resets ISP and aborts all outstanding commands.
3235 * ha = adapter block pointer.
3241 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3246 if (ha
->flags
.online
) {
3247 ha
->flags
.online
= 0;
3248 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3250 qla_printk(KERN_INFO
, ha
,
3251 "Performing ISP error recovery - ha= %p.\n", ha
);
3252 ha
->isp_ops
->reset_chip(ha
);
3254 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3255 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3256 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3257 qla2x00_mark_all_devices_lost(ha
, 0);
3259 if (!atomic_read(&ha
->loop_down_timer
))
3260 atomic_set(&ha
->loop_down_timer
,
3264 /* Requeue all commands in outstanding command list. */
3265 qla2x00_abort_all_cmds(ha
, DID_RESET
<< 16);
3267 ha
->isp_ops
->get_flash_version(ha
, ha
->request_ring
);
3269 ha
->isp_ops
->nvram_config(ha
);
3271 if (!qla2x00_restart_isp(ha
)) {
3272 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3274 if (!atomic_read(&ha
->loop_down_timer
)) {
3276 * Issue marker command only when we are going
3277 * to start the I/O .
3279 ha
->marker_needed
= 1;
3282 ha
->flags
.online
= 1;
3284 ha
->isp_ops
->enable_intrs(ha
);
3286 ha
->isp_abort_cnt
= 0;
3287 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3290 memset(ha
->eft
, 0, EFT_SIZE
);
3291 rval
= qla2x00_enable_eft_trace(ha
,
3292 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3294 qla_printk(KERN_WARNING
, ha
,
3295 "Unable to reinitialize EFT "
3301 ha
->flags
.fce_enabled
= 1;
3303 fce_calc_size(ha
->fce_bufs
));
3304 rval
= qla2x00_enable_fce_trace(ha
,
3305 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3308 qla_printk(KERN_WARNING
, ha
,
3309 "Unable to reinitialize FCE "
3311 ha
->flags
.fce_enabled
= 0;
3314 } else { /* failed the ISP abort */
3315 ha
->flags
.online
= 1;
3316 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3317 if (ha
->isp_abort_cnt
== 0) {
3318 qla_printk(KERN_WARNING
, ha
,
3319 "ISP error recovery failed - "
3320 "board disabled\n");
3322 * The next call disables the board
3325 ha
->isp_ops
->reset_adapter(ha
);
3326 ha
->flags
.online
= 0;
3327 clear_bit(ISP_ABORT_RETRY
,
3330 } else { /* schedule another ISP abort */
3331 ha
->isp_abort_cnt
--;
3332 DEBUG(printk("qla%ld: ISP abort - "
3333 "retry remaining %d\n",
3334 ha
->host_no
, ha
->isp_abort_cnt
));
3338 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3339 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3340 "- retrying (%d) more times\n",
3341 ha
->host_no
, ha
->isp_abort_cnt
));
3342 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3350 qla_printk(KERN_INFO
, ha
,
3351 "qla2x00_abort_isp: **** FAILED ****\n");
3353 DEBUG(printk(KERN_INFO
3354 "qla2x00_abort_isp(%ld): exiting.\n",
3362 * qla2x00_restart_isp
3363 * restarts the ISP after a reset
3366 * ha = adapter block pointer.
3372 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3377 /* If firmware needs to be loaded */
3378 if (qla2x00_isp_firmware(ha
)) {
3379 ha
->flags
.online
= 0;
3380 if (!(status
= ha
->isp_ops
->chip_diag(ha
)))
3381 status
= qla2x00_setup_chip(ha
);
3384 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3385 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3386 if (!(status
= qla2x00_fw_ready(ha
))) {
3387 DEBUG(printk("%s(): Start configure loop, "
3388 "status = %d\n", __func__
, status
));
3390 /* Issue a marker after FW becomes ready. */
3391 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3393 ha
->flags
.online
= 1;
3394 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3397 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3398 qla2x00_configure_loop(ha
);
3400 } while (!atomic_read(&ha
->loop_down_timer
) &&
3401 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3403 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3406 /* if no cable then assume it's good */
3407 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3410 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3418 * qla2x00_reset_adapter
3422 * ha = adapter block pointer.
3425 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3427 unsigned long flags
= 0;
3428 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3430 ha
->flags
.online
= 0;
3431 ha
->isp_ops
->disable_intrs(ha
);
3433 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3434 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3435 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3436 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3437 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3438 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3442 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3444 unsigned long flags
= 0;
3445 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3447 ha
->flags
.online
= 0;
3448 ha
->isp_ops
->disable_intrs(ha
);
3450 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3451 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3452 RD_REG_DWORD(®
->hccr
);
3453 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3454 RD_REG_DWORD(®
->hccr
);
3455 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3458 /* On sparc systems, obtain port and node WWN from firmware
3461 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, struct nvram_24xx
*nv
)
3464 struct pci_dev
*pdev
= ha
->pdev
;
3465 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3469 val
= of_get_property(dp
, "port-wwn", &len
);
3470 if (val
&& len
>= WWN_SIZE
)
3471 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3473 val
= of_get_property(dp
, "node-wwn", &len
);
3474 if (val
&& len
>= WWN_SIZE
)
3475 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3480 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3483 struct init_cb_24xx
*icb
;
3484 struct nvram_24xx
*nv
;
3486 uint8_t *dptr1
, *dptr2
;
3491 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3494 /* Determine NVRAM starting address. */
3495 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3496 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3497 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3498 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3499 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3500 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3501 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3504 /* Get VPD data into cache */
3505 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
3506 ha
->isp_ops
->read_nvram(ha
, (uint8_t *)ha
->vpd
,
3507 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
3509 /* Get NVRAM data into cache and calculate checksum. */
3510 dptr
= (uint32_t *)nv
;
3511 ha
->isp_ops
->read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3513 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3514 chksum
+= le32_to_cpu(*dptr
++);
3516 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3517 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
3519 /* Bad NVRAM data, set defaults parameters. */
3520 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3521 || nv
->id
[3] != ' ' ||
3522 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3523 /* Reset NVRAM data. */
3524 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3525 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3526 le16_to_cpu(nv
->nvram_version
));
3527 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3528 "invalid -- WWPN) defaults.\n");
3531 * Set default initialization control block.
3533 memset(nv
, 0, ha
->nvram_size
);
3534 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3535 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3536 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3537 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3538 nv
->exchange_count
= __constant_cpu_to_le16(0);
3539 nv
->hard_address
= __constant_cpu_to_le16(124);
3540 nv
->port_name
[0] = 0x21;
3541 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3542 nv
->port_name
[2] = 0x00;
3543 nv
->port_name
[3] = 0xe0;
3544 nv
->port_name
[4] = 0x8b;
3545 nv
->port_name
[5] = 0x1c;
3546 nv
->port_name
[6] = 0x55;
3547 nv
->port_name
[7] = 0x86;
3548 nv
->node_name
[0] = 0x20;
3549 nv
->node_name
[1] = 0x00;
3550 nv
->node_name
[2] = 0x00;
3551 nv
->node_name
[3] = 0xe0;
3552 nv
->node_name
[4] = 0x8b;
3553 nv
->node_name
[5] = 0x1c;
3554 nv
->node_name
[6] = 0x55;
3555 nv
->node_name
[7] = 0x86;
3556 qla24xx_nvram_wwn_from_ofw(ha
, nv
);
3557 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3558 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3559 nv
->login_timeout
= __constant_cpu_to_le16(0);
3560 nv
->firmware_options_1
=
3561 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3562 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3563 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3564 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3565 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3566 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3567 nv
->reset_delay
= 5;
3568 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3569 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3570 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3575 /* Reset Initialization control block */
3576 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3578 /* Copy 1st segment. */
3579 dptr1
= (uint8_t *)icb
;
3580 dptr2
= (uint8_t *)&nv
->version
;
3581 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3583 *dptr1
++ = *dptr2
++;
3585 icb
->login_retry_count
= nv
->login_retry_count
;
3586 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3588 /* Copy 2nd segment. */
3589 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3590 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3591 cnt
= (uint8_t *)&icb
->reserved_3
-
3592 (uint8_t *)&icb
->interrupt_delay_timer
;
3594 *dptr1
++ = *dptr2
++;
3597 * Setup driver NVRAM options.
3599 qla2x00_set_model_info(ha
, nv
->model_name
, sizeof(nv
->model_name
),
3602 /* Use alternate WWN? */
3603 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3604 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3605 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3608 /* Prepare nodename */
3609 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3611 * Firmware will apply the following mask if the nodename was
3614 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3615 icb
->node_name
[0] &= 0xF0;
3618 /* Set host adapter parameters. */
3619 ha
->flags
.disable_risc_code_load
= 0;
3620 ha
->flags
.enable_lip_reset
= 0;
3621 ha
->flags
.enable_lip_full_login
=
3622 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3623 ha
->flags
.enable_target_reset
=
3624 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3625 ha
->flags
.enable_led_scheme
= 0;
3626 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3628 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3629 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3631 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3632 sizeof(ha
->fw_seriallink_options24
));
3634 /* save HBA serial number */
3635 ha
->serial0
= icb
->port_name
[5];
3636 ha
->serial1
= icb
->port_name
[6];
3637 ha
->serial2
= icb
->port_name
[7];
3638 ha
->node_name
= icb
->node_name
;
3639 ha
->port_name
= icb
->port_name
;
3641 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3643 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3645 /* Set minimum login_timeout to 4 seconds. */
3646 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3647 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3648 if (le16_to_cpu(nv
->login_timeout
) < 4)
3649 nv
->login_timeout
= __constant_cpu_to_le16(4);
3650 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3651 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3653 <<<<<<< HEAD
:drivers
/scsi
/qla2xxx
/qla_init
.c
3654 /* Set minimum RATOV to 200 tenths of a second. */
3657 /* Set minimum RATOV to 100 tenths of a second. */
3659 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/qla2xxx
/qla_init
.c
3661 ha
->loop_reset_delay
= nv
->reset_delay
;
3663 /* Link Down Timeout = 0:
3665 * When Port Down timer expires we will start returning
3666 * I/O's to OS with "DID_NO_CONNECT".
3668 * Link Down Timeout != 0:
3670 * The driver waits for the link to come up after link down
3671 * before returning I/Os to OS with "DID_NO_CONNECT".
3673 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3674 ha
->loop_down_abort_time
=
3675 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3677 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3678 ha
->loop_down_abort_time
=
3679 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3682 /* Need enough time to try and get the port back. */
3683 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3684 if (qlport_down_retry
)
3685 ha
->port_down_retry_count
= qlport_down_retry
;
3687 /* Set login_retry_count */
3688 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3689 if (ha
->port_down_retry_count
==
3690 le16_to_cpu(nv
->port_down_retry_count
) &&
3691 ha
->port_down_retry_count
> 3)
3692 ha
->login_retry_count
= ha
->port_down_retry_count
;
3693 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3694 ha
->login_retry_count
= ha
->port_down_retry_count
;
3695 if (ql2xloginretrycount
)
3696 ha
->login_retry_count
= ql2xloginretrycount
;
3699 if (!ha
->flags
.init_done
) {
3700 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3701 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3702 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3703 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3705 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3706 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3707 ha
->flags
.process_response_queue
= 0;
3708 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3709 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3711 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3712 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3713 ha
->zio_timer
* 100));
3714 qla_printk(KERN_INFO
, ha
,
3715 "ZIO mode %d enabled; timer delay (%d us).\n",
3716 ha
->zio_mode
, ha
->zio_timer
* 100);
3718 icb
->firmware_options_2
|= cpu_to_le32(
3719 (uint32_t)ha
->zio_mode
);
3720 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3721 ha
->flags
.process_response_queue
= 1;
3725 DEBUG2_3(printk(KERN_WARNING
3726 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3732 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3735 int segments
, fragment
;
3737 uint32_t *dcode
, dlen
;
3744 segments
= FA_RISC_CODE_SEGMENTS
;
3745 faddr
= FA_RISC_CODE_ADDR
;
3746 dcode
= (uint32_t *)ha
->request_ring
;
3749 /* Validate firmware image by checking version. */
3750 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3751 for (i
= 0; i
< 4; i
++)
3752 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3753 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3754 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3755 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3757 qla_printk(KERN_WARNING
, ha
,
3758 "Unable to verify integrity of flash firmware image!\n");
3759 qla_printk(KERN_WARNING
, ha
,
3760 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3761 dcode
[1], dcode
[2], dcode
[3]);
3763 return QLA_FUNCTION_FAILED
;
3766 while (segments
&& rval
== QLA_SUCCESS
) {
3767 /* Read segment's load information. */
3768 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3770 risc_addr
= be32_to_cpu(dcode
[2]);
3771 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3772 risc_size
= be32_to_cpu(dcode
[3]);
3775 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3776 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3777 if (dlen
> risc_size
)
3780 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3781 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3782 ha
->host_no
, risc_addr
, dlen
, faddr
));
3784 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3785 for (i
= 0; i
< dlen
; i
++)
3786 dcode
[i
] = swab32(dcode
[i
]);
3788 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3791 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3792 "segment %d of firmware\n", ha
->host_no
,
3794 qla_printk(KERN_WARNING
, ha
,
3795 "[ERROR] Failed to load segment %d of "
3796 "firmware\n", fragment
);
3813 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3816 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3820 uint16_t *wcode
, *fwcode
;
3821 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3822 struct fw_blob
*blob
;
3824 /* Load firmware blob. */
3825 blob
= qla2x00_request_firmware(ha
);
3827 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3828 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3829 "from: " QLA_FW_URL
".\n");
3830 return QLA_FUNCTION_FAILED
;
3835 wcode
= (uint16_t *)ha
->request_ring
;
3837 fwcode
= (uint16_t *)blob
->fw
->data
;
3840 /* Validate firmware image by checking version. */
3841 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3842 qla_printk(KERN_WARNING
, ha
,
3843 "Unable to verify integrity of firmware image (%Zd)!\n",
3845 goto fail_fw_integrity
;
3847 for (i
= 0; i
< 4; i
++)
3848 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3849 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3850 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3851 wcode
[2] == 0 && wcode
[3] == 0)) {
3852 qla_printk(KERN_WARNING
, ha
,
3853 "Unable to verify integrity of firmware image!\n");
3854 qla_printk(KERN_WARNING
, ha
,
3855 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3856 wcode
[1], wcode
[2], wcode
[3]);
3857 goto fail_fw_integrity
;
3861 while (*seg
&& rval
== QLA_SUCCESS
) {
3863 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3864 risc_size
= be16_to_cpu(fwcode
[3]);
3866 /* Validate firmware image size. */
3867 fwclen
+= risc_size
* sizeof(uint16_t);
3868 if (blob
->fw
->size
< fwclen
) {
3869 qla_printk(KERN_WARNING
, ha
,
3870 "Unable to verify integrity of firmware image "
3871 "(%Zd)!\n", blob
->fw
->size
);
3872 goto fail_fw_integrity
;
3876 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3877 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3878 if (wlen
> risc_size
)
3881 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3882 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3885 for (i
= 0; i
< wlen
; i
++)
3886 wcode
[i
] = swab16(fwcode
[i
]);
3888 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3891 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3892 "segment %d of firmware\n", ha
->host_no
,
3894 qla_printk(KERN_WARNING
, ha
,
3895 "[ERROR] Failed to load segment %d of "
3896 "firmware\n", fragment
);
3912 return QLA_FUNCTION_FAILED
;
3916 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3919 int segments
, fragment
;
3920 uint32_t *dcode
, dlen
;
3924 struct fw_blob
*blob
;
3925 uint32_t *fwcode
, fwclen
;
3927 /* Load firmware blob. */
3928 blob
= qla2x00_request_firmware(ha
);
3930 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3931 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3932 "from: " QLA_FW_URL
".\n");
3934 /* Try to load RISC code from flash. */
3935 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3936 "outdated) firmware from flash.\n");
3937 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3942 segments
= FA_RISC_CODE_SEGMENTS
;
3943 dcode
= (uint32_t *)ha
->request_ring
;
3945 fwcode
= (uint32_t *)blob
->fw
->data
;
3948 /* Validate firmware image by checking version. */
3949 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3950 qla_printk(KERN_WARNING
, ha
,
3951 "Unable to verify integrity of firmware image (%Zd)!\n",
3953 goto fail_fw_integrity
;
3955 for (i
= 0; i
< 4; i
++)
3956 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3957 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3958 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3959 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3961 qla_printk(KERN_WARNING
, ha
,
3962 "Unable to verify integrity of firmware image!\n");
3963 qla_printk(KERN_WARNING
, ha
,
3964 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3965 dcode
[1], dcode
[2], dcode
[3]);
3966 goto fail_fw_integrity
;
3969 while (segments
&& rval
== QLA_SUCCESS
) {
3970 risc_addr
= be32_to_cpu(fwcode
[2]);
3971 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3972 risc_size
= be32_to_cpu(fwcode
[3]);
3974 /* Validate firmware image size. */
3975 fwclen
+= risc_size
* sizeof(uint32_t);
3976 if (blob
->fw
->size
< fwclen
) {
3977 qla_printk(KERN_WARNING
, ha
,
3978 "Unable to verify integrity of firmware image "
3979 "(%Zd)!\n", blob
->fw
->size
);
3981 goto fail_fw_integrity
;
3985 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3986 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3987 if (dlen
> risc_size
)
3990 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3991 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3994 for (i
= 0; i
< dlen
; i
++)
3995 dcode
[i
] = swab32(fwcode
[i
]);
3997 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
4000 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4001 "segment %d of firmware\n", ha
->host_no
,
4003 qla_printk(KERN_WARNING
, ha
,
4004 "[ERROR] Failed to load segment %d of "
4005 "firmware\n", fragment
);
4021 return QLA_FUNCTION_FAILED
;
4025 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*ha
)
4029 if (!IS_FWI2_CAPABLE(ha
))
4031 if (!ha
->fw_major_version
)
4034 ret
= qla2x00_stop_firmware(ha
);
4035 <<<<<<< HEAD
:drivers
/scsi
/qla2xxx
/qla_init
.c
4036 for (retries
= 5; ret
!= QLA_SUCCESS
&& retries
; retries
--) {
4038 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4039 retries
; retries
--) {
4040 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/scsi
/qla2xxx
/qla_init
.c
4041 qla2x00_reset_chip(ha
);
4042 if (qla2x00_chip_diag(ha
) != QLA_SUCCESS
)
4044 if (qla2x00_setup_chip(ha
) != QLA_SUCCESS
)
4046 qla_printk(KERN_INFO
, ha
,
4047 "Attempting retry of stop-firmware command...\n");
4048 ret
= qla2x00_stop_firmware(ha
);
4053 qla24xx_configure_vhba(scsi_qla_host_t
*ha
)
4055 int rval
= QLA_SUCCESS
;
4056 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4061 rval
= qla2x00_fw_ready(ha
);
4062 if (rval
== QLA_SUCCESS
) {
4063 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
4064 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
4067 ha
->flags
.management_server_logged_in
= 0;
4069 /* Login to SNS first */
4070 qla24xx_login_fabric(ha
, NPH_SNS
, 0xff, 0xff, 0xfc,
4072 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4073 DEBUG15(qla_printk(KERN_INFO
, ha
,
4074 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4075 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4076 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4077 return (QLA_FUNCTION_FAILED
);
4080 atomic_set(&ha
->loop_down_timer
, 0);
4081 atomic_set(&ha
->loop_state
, LOOP_UP
);
4082 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
4083 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
4084 rval
= qla2x00_loop_resync(ha
);