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
)
136 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
138 pci_set_master(ha
->pdev
);
139 ret
= pci_set_mwi(ha
->pdev
);
141 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
142 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
143 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
145 /* Reset expansion ROM address decode enable */
146 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
147 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
148 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
150 /* Get PCI bus information. */
151 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
152 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
153 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
159 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
162 * Returns 0 on success.
165 qla2300_pci_config(scsi_qla_host_t
*ha
)
170 unsigned long flags
= 0;
172 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
174 pci_set_master(ha
->pdev
);
175 ret
= pci_set_mwi(ha
->pdev
);
177 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
178 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
180 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
181 w
&= ~PCI_COMMAND_INTX_DISABLE
;
182 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
185 * If this is a 2300 card and not 2312, reset the
186 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
187 * the 2310 also reports itself as a 2300 so we need to get the
188 * fb revision level -- a 6 indicates it really is a 2300 and
191 if (IS_QLA2300(ha
)) {
192 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
195 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
196 for (cnt
= 0; cnt
< 30000; cnt
++) {
197 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
203 /* Select FPM registers. */
204 WRT_REG_WORD(®
->ctrl_status
, 0x20);
205 RD_REG_WORD(®
->ctrl_status
);
207 /* Get the fb rev level */
208 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
210 if (ha
->fb_rev
== FPM_2300
)
211 pci_clear_mwi(ha
->pdev
);
213 /* Deselect FPM registers. */
214 WRT_REG_WORD(®
->ctrl_status
, 0x0);
215 RD_REG_WORD(®
->ctrl_status
);
217 /* Release RISC module. */
218 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
219 for (cnt
= 0; cnt
< 30000; cnt
++) {
220 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
226 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
229 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
231 /* Reset expansion ROM address decode enable */
232 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
233 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
234 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
236 /* Get PCI bus information. */
237 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
238 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
239 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
245 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
248 * Returns 0 on success.
251 qla24xx_pci_config(scsi_qla_host_t
*ha
)
256 unsigned long flags
= 0;
257 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
258 int pcix_cmd_reg
, pcie_dctl_reg
;
260 pci_set_master(ha
->pdev
);
261 ret
= pci_set_mwi(ha
->pdev
);
263 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
264 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
265 w
&= ~PCI_COMMAND_INTX_DISABLE
;
266 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
268 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
270 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
271 pcix_cmd_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
);
275 pcix_cmd_reg
+= PCI_X_CMD
;
276 pci_read_config_word(ha
->pdev
, pcix_cmd_reg
, &pcix_cmd
);
277 pcix_cmd
&= ~PCI_X_CMD_MAX_READ
;
279 pci_write_config_word(ha
->pdev
, pcix_cmd_reg
, pcix_cmd
);
282 /* PCIe -- adjust Maximum Read Request Size (2048). */
283 pcie_dctl_reg
= pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
);
287 pcie_dctl_reg
+= PCI_EXP_DEVCTL
;
288 pci_read_config_word(ha
->pdev
, pcie_dctl_reg
, &pcie_dctl
);
289 pcie_dctl
&= ~PCI_EXP_DEVCTL_READRQ
;
291 pci_write_config_word(ha
->pdev
, pcie_dctl_reg
, pcie_dctl
);
294 /* Reset expansion ROM address decode enable */
295 pci_read_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, &d
);
296 d
&= ~PCI_ROM_ADDRESS_ENABLE
;
297 pci_write_config_dword(ha
->pdev
, PCI_ROM_ADDRESS
, d
);
299 ha
->chip_revision
= ha
->pdev
->revision
;
301 /* Get PCI bus information. */
302 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
303 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
304 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
310 * qla2x00_isp_firmware() - Choose firmware image.
313 * Returns 0 on success.
316 qla2x00_isp_firmware(scsi_qla_host_t
*ha
)
320 /* Assume loading risc code */
321 rval
= QLA_FUNCTION_FAILED
;
323 if (ha
->flags
.disable_risc_code_load
) {
324 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
326 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
328 /* Verify checksum of loaded RISC code. */
329 rval
= qla2x00_verify_checksum(ha
, ha
->fw_srisc_address
);
333 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
341 * qla2x00_reset_chip() - Reset ISP chip.
344 * Returns 0 on success.
347 qla2x00_reset_chip(scsi_qla_host_t
*ha
)
349 unsigned long flags
= 0;
350 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
354 ha
->isp_ops
.disable_intrs(ha
);
356 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
358 /* Turn off master enable */
360 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
361 cmd
&= ~PCI_COMMAND_MASTER
;
362 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
364 if (!IS_QLA2100(ha
)) {
366 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
367 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
368 for (cnt
= 0; cnt
< 30000; cnt
++) {
369 if ((RD_REG_WORD(®
->hccr
) &
370 HCCR_RISC_PAUSE
) != 0)
375 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
379 /* Select FPM registers. */
380 WRT_REG_WORD(®
->ctrl_status
, 0x20);
381 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
383 /* FPM Soft Reset. */
384 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
385 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
387 /* Toggle Fpm Reset. */
388 if (!IS_QLA2200(ha
)) {
389 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
390 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
393 /* Select frame buffer registers. */
394 WRT_REG_WORD(®
->ctrl_status
, 0x10);
395 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
397 /* Reset frame buffer FIFOs. */
398 if (IS_QLA2200(ha
)) {
399 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
400 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
402 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
404 /* Read back fb_cmd until zero or 3 seconds max */
405 for (cnt
= 0; cnt
< 3000; cnt
++) {
406 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
412 /* Select RISC module registers. */
413 WRT_REG_WORD(®
->ctrl_status
, 0);
414 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
416 /* Reset RISC processor. */
417 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
418 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
420 /* Release RISC processor. */
421 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
422 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
425 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
426 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
428 /* Reset ISP chip. */
429 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
431 /* Wait for RISC to recover from reset. */
432 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
434 * It is necessary to for a delay here since the card doesn't
435 * respond to PCI reads during a reset. On some architectures
436 * this will result in an MCA.
439 for (cnt
= 30000; cnt
; cnt
--) {
440 if ((RD_REG_WORD(®
->ctrl_status
) &
441 CSR_ISP_SOFT_RESET
) == 0)
448 /* Reset RISC processor. */
449 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
451 WRT_REG_WORD(®
->semaphore
, 0);
453 /* Release RISC processor. */
454 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
455 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
457 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
458 for (cnt
= 0; cnt
< 30000; cnt
++) {
459 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
467 /* Turn on master enable */
468 cmd
|= PCI_COMMAND_MASTER
;
469 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
471 /* Disable RISC pause on FPM parity error. */
472 if (!IS_QLA2100(ha
)) {
473 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
474 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
477 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
481 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
484 * Returns 0 on success.
487 qla24xx_reset_risc(scsi_qla_host_t
*ha
)
489 unsigned long flags
= 0;
490 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
494 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
497 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
498 for (cnt
= 0; cnt
< 30000; cnt
++) {
499 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
505 WRT_REG_DWORD(®
->ctrl_status
,
506 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
507 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
510 /* Wait for firmware to complete NVRAM accesses. */
511 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
512 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
514 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
518 /* Wait for soft-reset to complete. */
519 d2
= RD_REG_DWORD(®
->ctrl_status
);
520 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
522 d2
= RD_REG_DWORD(®
->ctrl_status
);
526 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
527 RD_REG_DWORD(®
->hccr
);
529 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
530 RD_REG_DWORD(®
->hccr
);
532 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
533 RD_REG_DWORD(®
->hccr
);
535 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
536 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
538 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
542 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
546 * qla24xx_reset_chip() - Reset ISP24xx chip.
549 * Returns 0 on success.
552 qla24xx_reset_chip(scsi_qla_host_t
*ha
)
554 ha
->isp_ops
.disable_intrs(ha
);
556 /* Perform RISC reset. */
557 qla24xx_reset_risc(ha
);
561 * qla2x00_chip_diag() - Test chip for proper operation.
564 * Returns 0 on success.
567 qla2x00_chip_diag(scsi_qla_host_t
*ha
)
570 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
571 unsigned long flags
= 0;
576 /* Assume a failed state */
577 rval
= QLA_FUNCTION_FAILED
;
579 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
580 ha
->host_no
, (u_long
)®
->flash_address
));
582 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
584 /* Reset ISP chip. */
585 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
588 * We need to have a delay here since the card will not respond while
589 * in reset causing an MCA on some architectures.
592 data
= qla2x00_debounce_register(®
->ctrl_status
);
593 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
595 data
= RD_REG_WORD(®
->ctrl_status
);
600 goto chip_diag_failed
;
602 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
605 /* Reset RISC processor. */
606 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
607 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
609 /* Workaround for QLA2312 PCI parity error */
610 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
611 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
612 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
614 data
= RD_MAILBOX_REG(ha
, reg
, 0);
621 goto chip_diag_failed
;
623 /* Check product ID of chip */
624 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
626 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
627 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
628 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
629 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
630 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
631 mb
[3] != PROD_ID_3
) {
632 qla_printk(KERN_WARNING
, ha
,
633 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
635 goto chip_diag_failed
;
637 ha
->product_id
[0] = mb
[1];
638 ha
->product_id
[1] = mb
[2];
639 ha
->product_id
[2] = mb
[3];
640 ha
->product_id
[3] = mb
[4];
642 /* Adjust fw RISC transfer size */
643 if (ha
->request_q_length
> 1024)
644 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
646 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
647 ha
->request_q_length
;
649 if (IS_QLA2200(ha
) &&
650 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
651 /* Limit firmware transfer size with a 2200A */
652 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
655 ha
->device_type
|= DT_ISP2200A
;
656 ha
->fw_transfer_size
= 128;
659 /* Wrap Incoming Mailboxes Test. */
660 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
662 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha
->host_no
));
663 rval
= qla2x00_mbx_reg_test(ha
);
665 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
667 qla_printk(KERN_WARNING
, ha
,
668 "Failed mailbox send register test\n");
671 /* Flag a successful rval */
674 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
678 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
679 "****\n", ha
->host_no
));
681 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
687 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
690 * Returns 0 on success.
693 qla24xx_chip_diag(scsi_qla_host_t
*ha
)
697 /* Perform RISC reset. */
698 qla24xx_reset_risc(ha
);
700 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
702 rval
= qla2x00_mbx_reg_test(ha
);
704 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
706 qla_printk(KERN_WARNING
, ha
,
707 "Failed mailbox send register test\n");
709 /* Flag a successful rval */
717 qla2x00_alloc_fw_dump(scsi_qla_host_t
*ha
)
720 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
726 qla_printk(KERN_WARNING
, ha
,
727 "Firmware dump previously allocated.\n");
732 fixed_size
= mem_size
= eft_size
= 0;
733 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
734 fixed_size
= sizeof(struct qla2100_fw_dump
);
735 } else if (IS_QLA23XX(ha
)) {
736 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
737 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
739 } else if (IS_FWI2_CAPABLE(ha
)) {
740 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
741 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
744 /* Allocate memory for Extended Trace Buffer. */
745 eft
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &eft_dma
,
748 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
749 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
753 rval
= qla2x00_trace_control(ha
, TC_ENABLE
, eft_dma
,
756 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
757 "EFT (%d).\n", rval
);
758 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, eft
,
763 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
767 memset(eft
, 0, eft_size
);
768 ha
->eft_dma
= eft_dma
;
772 req_q_size
= ha
->request_q_length
* sizeof(request_t
);
773 rsp_q_size
= ha
->response_q_length
* sizeof(response_t
);
775 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
776 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
779 ha
->fw_dump
= vmalloc(dump_size
);
781 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
782 "firmware dump!!!\n", dump_size
/ 1024);
785 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
793 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
796 ha
->fw_dump_len
= dump_size
;
797 ha
->fw_dump
->signature
[0] = 'Q';
798 ha
->fw_dump
->signature
[1] = 'L';
799 ha
->fw_dump
->signature
[2] = 'G';
800 ha
->fw_dump
->signature
[3] = 'C';
801 ha
->fw_dump
->version
= __constant_htonl(1);
803 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
804 ha
->fw_dump
->mem_size
= htonl(mem_size
);
805 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
806 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
808 ha
->fw_dump
->eft_size
= htonl(eft_size
);
809 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
810 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
812 ha
->fw_dump
->header_size
=
813 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
817 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
820 * Returns 0 on success.
823 qla2x00_resize_request_q(scsi_qla_host_t
*ha
)
826 uint16_t fw_iocb_cnt
= 0;
827 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
828 dma_addr_t request_dma
;
829 request_t
*request_ring
;
831 /* Valid only on recent ISPs. */
832 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
835 /* Retrieve IOCB counts available to the firmware. */
836 rval
= qla2x00_get_resource_cnts(ha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
);
839 /* No point in continuing if current settings are sufficient. */
840 if (fw_iocb_cnt
< 1024)
842 if (ha
->request_q_length
>= request_q_length
)
845 /* Attempt to claim larger area for request queue. */
846 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
847 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
849 if (request_ring
== NULL
)
852 /* Resize successful, report extensions. */
853 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
854 (ha
->fw_memory_size
+ 1) / 1024);
855 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
856 "(%d -> %d)...\n", ha
->request_q_length
, request_q_length
);
858 /* Clear old allocations. */
859 dma_free_coherent(&ha
->pdev
->dev
,
860 (ha
->request_q_length
+ 1) * sizeof(request_t
), ha
->request_ring
,
863 /* Begin using larger queue. */
864 ha
->request_q_length
= request_q_length
;
865 ha
->request_ring
= request_ring
;
866 ha
->request_dma
= request_dma
;
870 * qla2x00_setup_chip() - Load and start RISC firmware.
873 * Returns 0 on success.
876 qla2x00_setup_chip(scsi_qla_host_t
*ha
)
879 uint32_t srisc_address
= 0;
881 /* Load firmware sequences */
882 rval
= ha
->isp_ops
.load_risc(ha
, &srisc_address
);
883 if (rval
== QLA_SUCCESS
) {
884 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
885 "code.\n", ha
->host_no
));
887 rval
= qla2x00_verify_checksum(ha
, srisc_address
);
888 if (rval
== QLA_SUCCESS
) {
889 /* Start firmware execution. */
890 DEBUG(printk("scsi(%ld): Checksum OK, start "
891 "firmware.\n", ha
->host_no
));
893 rval
= qla2x00_execute_fw(ha
, srisc_address
);
894 /* Retrieve firmware information. */
895 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
896 qla2x00_get_fw_version(ha
,
897 &ha
->fw_major_version
,
898 &ha
->fw_minor_version
,
899 &ha
->fw_subminor_version
,
900 &ha
->fw_attributes
, &ha
->fw_memory_size
);
901 qla2x00_resize_request_q(ha
);
902 ha
->flags
.npiv_supported
= 0;
903 if (IS_QLA24XX(ha
) &&
904 (ha
->fw_attributes
& BIT_2
))
905 ha
->flags
.npiv_supported
= 1;
908 qla2x00_alloc_fw_dump(ha
);
911 DEBUG2(printk(KERN_INFO
912 "scsi(%ld): ISP Firmware failed checksum.\n",
918 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
926 * qla2x00_init_response_q_entries() - Initializes response queue entries.
929 * Beginning of request ring has initialization control block already built
930 * by nvram config routine.
932 * Returns 0 on success.
935 qla2x00_init_response_q_entries(scsi_qla_host_t
*ha
)
940 pkt
= ha
->response_ring_ptr
;
941 for (cnt
= 0; cnt
< ha
->response_q_length
; cnt
++) {
942 pkt
->signature
= RESPONSE_PROCESSED
;
949 * qla2x00_update_fw_options() - Read and process firmware options.
952 * Returns 0 on success.
955 qla2x00_update_fw_options(scsi_qla_host_t
*ha
)
957 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
959 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
960 qla2x00_get_fw_options(ha
, ha
->fw_options
);
962 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
965 /* Serial Link options. */
966 DEBUG3(printk("scsi(%ld): Serial link options:\n",
968 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
969 sizeof(ha
->fw_seriallink_options
)));
971 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
972 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
973 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
976 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
977 emphasis
= (ha
->fw_seriallink_options
[2] &
978 (BIT_4
| BIT_3
)) >> 3;
979 tx_sens
= ha
->fw_seriallink_options
[0] &
980 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
981 rx_sens
= (ha
->fw_seriallink_options
[0] &
982 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
983 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
984 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
987 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
988 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
989 ha
->fw_options
[10] |= BIT_5
|
990 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
991 (tx_sens
& (BIT_1
| BIT_0
));
994 swing
= (ha
->fw_seriallink_options
[2] &
995 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
996 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
997 tx_sens
= ha
->fw_seriallink_options
[1] &
998 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
999 rx_sens
= (ha
->fw_seriallink_options
[1] &
1000 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1001 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1002 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1005 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1006 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1007 ha
->fw_options
[11] |= BIT_5
|
1008 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1009 (tx_sens
& (BIT_1
| BIT_0
));
1013 /* Return command IOCBs without waiting for an ABTS to complete. */
1014 ha
->fw_options
[3] |= BIT_13
;
1017 if (ha
->flags
.enable_led_scheme
)
1018 ha
->fw_options
[2] |= BIT_12
;
1020 /* Detect ISP6312. */
1022 ha
->fw_options
[2] |= BIT_13
;
1024 /* Update firmware options. */
1025 qla2x00_set_fw_options(ha
, ha
->fw_options
);
1029 qla24xx_update_fw_options(scsi_qla_host_t
*ha
)
1033 /* Update Serial Link options. */
1034 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1037 rval
= qla2x00_set_serdes_params(ha
,
1038 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1039 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1040 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1041 if (rval
!= QLA_SUCCESS
) {
1042 qla_printk(KERN_WARNING
, ha
,
1043 "Unable to update Serial Link options (%x).\n", rval
);
1048 qla2x00_config_rings(struct scsi_qla_host
*ha
)
1050 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1052 /* Setup ring parameters in initialization control block. */
1053 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1054 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1055 ha
->init_cb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1056 ha
->init_cb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1057 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1058 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1059 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1060 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1062 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1063 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1064 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1065 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1066 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1070 qla24xx_config_rings(struct scsi_qla_host
*ha
)
1072 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1073 struct init_cb_24xx
*icb
;
1075 /* Setup ring parameters in initialization control block. */
1076 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1077 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1078 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1079 icb
->request_q_length
= cpu_to_le16(ha
->request_q_length
);
1080 icb
->response_q_length
= cpu_to_le16(ha
->response_q_length
);
1081 icb
->request_q_address
[0] = cpu_to_le32(LSD(ha
->request_dma
));
1082 icb
->request_q_address
[1] = cpu_to_le32(MSD(ha
->request_dma
));
1083 icb
->response_q_address
[0] = cpu_to_le32(LSD(ha
->response_dma
));
1084 icb
->response_q_address
[1] = cpu_to_le32(MSD(ha
->response_dma
));
1086 WRT_REG_DWORD(®
->req_q_in
, 0);
1087 WRT_REG_DWORD(®
->req_q_out
, 0);
1088 WRT_REG_DWORD(®
->rsp_q_in
, 0);
1089 WRT_REG_DWORD(®
->rsp_q_out
, 0);
1090 RD_REG_DWORD(®
->rsp_q_out
);
1094 * qla2x00_init_rings() - Initializes firmware.
1097 * Beginning of request ring has initialization control block already built
1098 * by nvram config routine.
1100 * Returns 0 on success.
1103 qla2x00_init_rings(scsi_qla_host_t
*ha
)
1106 unsigned long flags
= 0;
1108 struct mid_init_cb_24xx
*mid_init_cb
=
1109 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1111 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1113 /* Clear outstanding commands array. */
1114 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1115 ha
->outstanding_cmds
[cnt
] = NULL
;
1117 ha
->current_outstanding_cmd
= 0;
1119 /* Clear RSCN queue. */
1120 ha
->rscn_in_ptr
= 0;
1121 ha
->rscn_out_ptr
= 0;
1123 /* Initialize firmware. */
1124 ha
->request_ring_ptr
= ha
->request_ring
;
1125 ha
->req_ring_index
= 0;
1126 ha
->req_q_cnt
= ha
->request_q_length
;
1127 ha
->response_ring_ptr
= ha
->response_ring
;
1128 ha
->rsp_ring_index
= 0;
1130 /* Initialize response queue entries */
1131 qla2x00_init_response_q_entries(ha
);
1133 ha
->isp_ops
.config_rings(ha
);
1135 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1137 /* Update any ISP specific firmware options before initialization. */
1138 ha
->isp_ops
.update_fw_options(ha
);
1140 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha
->host_no
));
1142 mid_init_cb
->count
= MAX_NUM_VPORT_FABRIC
;
1143 ha
->max_npiv_vports
= MAX_NUM_VPORT_FABRIC
;
1145 rval
= qla2x00_init_firmware(ha
, ha
->init_cb_size
);
1147 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1150 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1158 * qla2x00_fw_ready() - Waits for firmware ready.
1161 * Returns 0 on success.
1164 qla2x00_fw_ready(scsi_qla_host_t
*ha
)
1167 unsigned long wtime
, mtime
;
1168 uint16_t min_wait
; /* Minimum wait time if loop is down */
1169 uint16_t wait_time
; /* Wait time if loop is coming ready */
1174 /* 20 seconds for loop down. */
1178 * Firmware should take at most one RATOV to login, plus 5 seconds for
1179 * our own processing.
1181 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1182 wait_time
= min_wait
;
1185 /* Min wait time if loop down */
1186 mtime
= jiffies
+ (min_wait
* HZ
);
1188 /* wait time before firmware ready */
1189 wtime
= jiffies
+ (wait_time
* HZ
);
1191 /* Wait for ISP to finish LIP */
1192 if (!ha
->flags
.init_done
)
1193 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1195 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1199 rval
= qla2x00_get_firmware_state(ha
, &fw_state
);
1200 if (rval
== QLA_SUCCESS
) {
1201 if (fw_state
< FSTATE_LOSS_OF_SYNC
) {
1202 ha
->device_flags
&= ~DFLG_NO_CABLE
;
1204 if (fw_state
== FSTATE_READY
) {
1205 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1208 qla2x00_get_retry_cnt(ha
, &ha
->retry_count
,
1209 &ha
->login_timeout
, &ha
->r_a_tov
);
1215 rval
= QLA_FUNCTION_FAILED
;
1217 if (atomic_read(&ha
->loop_down_timer
) &&
1218 fw_state
!= FSTATE_READY
) {
1219 /* Loop down. Timeout on min_wait for states
1220 * other than Wait for Login.
1222 if (time_after_eq(jiffies
, mtime
)) {
1223 qla_printk(KERN_INFO
, ha
,
1224 "Cable is unplugged...\n");
1226 ha
->device_flags
|= DFLG_NO_CABLE
;
1231 /* Mailbox cmd failed. Timeout on min_wait. */
1232 if (time_after_eq(jiffies
, mtime
))
1236 if (time_after_eq(jiffies
, wtime
))
1239 /* Delay for a while */
1242 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1243 ha
->host_no
, fw_state
, jiffies
));
1246 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1247 ha
->host_no
, fw_state
, jiffies
));
1250 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1258 * qla2x00_configure_hba
1259 * Setup adapter context.
1262 * ha = adapter state pointer.
1271 qla2x00_configure_hba(scsi_qla_host_t
*ha
)
1280 char connect_type
[22];
1282 /* Get host addresses. */
1283 rval
= qla2x00_get_adapter_id(ha
,
1284 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1285 if (rval
!= QLA_SUCCESS
) {
1286 if (LOOP_TRANSITION(ha
) || atomic_read(&ha
->loop_down_timer
) ||
1287 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1288 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1289 __func__
, ha
->host_no
));
1291 qla_printk(KERN_WARNING
, ha
,
1292 "ERROR -- Unable to get host loop ID.\n");
1293 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
1299 qla_printk(KERN_INFO
, ha
,
1300 "Cannot get topology - retrying.\n");
1301 return (QLA_FUNCTION_FAILED
);
1304 ha
->loop_id
= loop_id
;
1307 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1308 ha
->operating_mode
= LOOP
;
1313 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1315 ha
->current_topology
= ISP_CFG_NL
;
1316 strcpy(connect_type
, "(Loop)");
1320 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1322 ha
->switch_cap
= sw_cap
;
1323 ha
->current_topology
= ISP_CFG_FL
;
1324 strcpy(connect_type
, "(FL_Port)");
1328 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1330 ha
->operating_mode
= P2P
;
1331 ha
->current_topology
= ISP_CFG_N
;
1332 strcpy(connect_type
, "(N_Port-to-N_Port)");
1336 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1338 ha
->switch_cap
= sw_cap
;
1339 ha
->operating_mode
= P2P
;
1340 ha
->current_topology
= ISP_CFG_F
;
1341 strcpy(connect_type
, "(F_Port)");
1345 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1347 ha
->host_no
, topo
));
1348 ha
->current_topology
= ISP_CFG_NL
;
1349 strcpy(connect_type
, "(Loop)");
1353 /* Save Host port and loop ID. */
1354 /* byte order - Big Endian */
1355 ha
->d_id
.b
.domain
= domain
;
1356 ha
->d_id
.b
.area
= area
;
1357 ha
->d_id
.b
.al_pa
= al_pa
;
1359 if (!ha
->flags
.init_done
)
1360 qla_printk(KERN_INFO
, ha
,
1361 "Topology - %s, Host Loop address 0x%x\n",
1362 connect_type
, ha
->loop_id
);
1365 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha
->host_no
));
1367 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha
->host_no
));
1374 qla2x00_set_model_info(scsi_qla_host_t
*ha
, uint8_t *model
, size_t len
, char *def
)
1379 if (memcmp(model
, BINZERO
, len
) != 0) {
1380 strncpy(ha
->model_number
, model
, len
);
1381 st
= en
= ha
->model_number
;
1384 if (*en
!= 0x20 && *en
!= 0x00)
1389 index
= (ha
->pdev
->subsystem_device
& 0xff);
1390 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1391 index
< QLA_MODEL_NAMES
)
1392 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1394 index
= (ha
->pdev
->subsystem_device
& 0xff);
1395 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1396 index
< QLA_MODEL_NAMES
) {
1397 strcpy(ha
->model_number
,
1398 qla2x00_model_name
[index
* 2]);
1399 ha
->model_desc
= qla2x00_model_name
[index
* 2 + 1];
1401 strcpy(ha
->model_number
, def
);
1406 /* On sparc systems, obtain port and node WWN from firmware
1409 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, nvram_t
*nv
)
1412 struct pci_dev
*pdev
= ha
->pdev
;
1413 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1417 val
= of_get_property(dp
, "port-wwn", &len
);
1418 if (val
&& len
>= WWN_SIZE
)
1419 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1421 val
= of_get_property(dp
, "node-wwn", &len
);
1422 if (val
&& len
>= WWN_SIZE
)
1423 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1428 * NVRAM configuration for ISP 2xxx
1431 * ha = adapter block pointer.
1434 * initialization control block in response_ring
1435 * host adapters parameters in host adapter block
1441 qla2x00_nvram_config(scsi_qla_host_t
*ha
)
1446 uint8_t *dptr1
, *dptr2
;
1447 init_cb_t
*icb
= ha
->init_cb
;
1448 nvram_t
*nv
= (nvram_t
*)ha
->request_ring
;
1449 uint8_t *ptr
= (uint8_t *)ha
->request_ring
;
1450 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1454 /* Determine NVRAM starting address. */
1455 ha
->nvram_size
= sizeof(nvram_t
);
1457 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1458 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1459 ha
->nvram_base
= 0x80;
1461 /* Get NVRAM data and calculate checksum. */
1462 ha
->isp_ops
.read_nvram(ha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1463 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1466 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
1467 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
1470 /* Bad NVRAM data, set defaults parameters. */
1471 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1472 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1473 /* Reset NVRAM data. */
1474 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1475 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1477 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1478 "invalid -- WWPN) defaults.\n");
1481 * Set default initialization control block.
1483 memset(nv
, 0, ha
->nvram_size
);
1484 nv
->parameter_block_version
= ICB_VERSION
;
1486 if (IS_QLA23XX(ha
)) {
1487 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1488 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1489 nv
->add_firmware_options
[0] = BIT_5
;
1490 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1491 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1492 nv
->special_options
[1] = BIT_7
;
1493 } else if (IS_QLA2200(ha
)) {
1494 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1495 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1496 nv
->add_firmware_options
[0] = BIT_5
;
1497 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1498 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1499 } else if (IS_QLA2100(ha
)) {
1500 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1501 nv
->firmware_options
[1] = BIT_5
;
1502 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1505 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1506 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1507 nv
->retry_count
= 8;
1508 nv
->retry_delay
= 1;
1510 nv
->port_name
[0] = 33;
1511 nv
->port_name
[3] = 224;
1512 nv
->port_name
[4] = 139;
1514 qla2xxx_nvram_wwn_from_ofw(ha
, nv
);
1516 nv
->login_timeout
= 4;
1519 * Set default host adapter parameters
1521 nv
->host_p
[1] = BIT_2
;
1522 nv
->reset_delay
= 5;
1523 nv
->port_down_retry_count
= 8;
1524 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1525 nv
->link_down_timeout
= 60;
1530 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1532 * The SN2 does not provide BIOS emulation which means you can't change
1533 * potentially bogus BIOS settings. Force the use of default settings
1534 * for link rate and frame size. Hope that the rest of the settings
1537 if (ia64_platform_is("sn2")) {
1538 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1540 nv
->special_options
[1] = BIT_7
;
1544 /* Reset Initialization control block */
1545 memset(icb
, 0, ha
->init_cb_size
);
1548 * Setup driver NVRAM options.
1550 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1551 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1552 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1553 nv
->firmware_options
[1] &= ~BIT_4
;
1555 if (IS_QLA23XX(ha
)) {
1556 nv
->firmware_options
[0] |= BIT_2
;
1557 nv
->firmware_options
[0] &= ~BIT_3
;
1558 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1560 if (IS_QLA2300(ha
)) {
1561 if (ha
->fb_rev
== FPM_2310
) {
1562 strcpy(ha
->model_number
, "QLA2310");
1564 strcpy(ha
->model_number
, "QLA2300");
1567 qla2x00_set_model_info(ha
, nv
->model_number
,
1568 sizeof(nv
->model_number
), "QLA23xx");
1570 } else if (IS_QLA2200(ha
)) {
1571 nv
->firmware_options
[0] |= BIT_2
;
1573 * 'Point-to-point preferred, else loop' is not a safe
1574 * connection mode setting.
1576 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1578 /* Force 'loop preferred, else point-to-point'. */
1579 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1580 nv
->add_firmware_options
[0] |= BIT_5
;
1582 strcpy(ha
->model_number
, "QLA22xx");
1583 } else /*if (IS_QLA2100(ha))*/ {
1584 strcpy(ha
->model_number
, "QLA2100");
1588 * Copy over NVRAM RISC parameter block to initialization control block.
1590 dptr1
= (uint8_t *)icb
;
1591 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1592 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1594 *dptr1
++ = *dptr2
++;
1596 /* Copy 2nd half. */
1597 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1598 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1600 *dptr1
++ = *dptr2
++;
1602 /* Use alternate WWN? */
1603 if (nv
->host_p
[1] & BIT_7
) {
1604 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1605 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1608 /* Prepare nodename */
1609 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1611 * Firmware will apply the following mask if the nodename was
1614 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1615 icb
->node_name
[0] &= 0xF0;
1619 * Set host adapter parameters.
1621 if (nv
->host_p
[0] & BIT_7
)
1622 ql2xextended_error_logging
= 1;
1623 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1624 /* Always load RISC code on non ISP2[12]00 chips. */
1625 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1626 ha
->flags
.disable_risc_code_load
= 0;
1627 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1628 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1629 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1630 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1631 ha
->flags
.disable_serdes
= 0;
1633 ha
->operating_mode
=
1634 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1636 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1637 sizeof(ha
->fw_seriallink_options
));
1639 /* save HBA serial number */
1640 ha
->serial0
= icb
->port_name
[5];
1641 ha
->serial1
= icb
->port_name
[6];
1642 ha
->serial2
= icb
->port_name
[7];
1643 ha
->node_name
= icb
->node_name
;
1644 ha
->port_name
= icb
->port_name
;
1646 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1648 ha
->retry_count
= nv
->retry_count
;
1650 /* Set minimum login_timeout to 4 seconds. */
1651 if (nv
->login_timeout
< ql2xlogintimeout
)
1652 nv
->login_timeout
= ql2xlogintimeout
;
1653 if (nv
->login_timeout
< 4)
1654 nv
->login_timeout
= 4;
1655 ha
->login_timeout
= nv
->login_timeout
;
1656 icb
->login_timeout
= nv
->login_timeout
;
1658 /* Set minimum RATOV to 200 tenths of a second. */
1661 ha
->loop_reset_delay
= nv
->reset_delay
;
1663 /* Link Down Timeout = 0:
1665 * When Port Down timer expires we will start returning
1666 * I/O's to OS with "DID_NO_CONNECT".
1668 * Link Down Timeout != 0:
1670 * The driver waits for the link to come up after link down
1671 * before returning I/Os to OS with "DID_NO_CONNECT".
1673 if (nv
->link_down_timeout
== 0) {
1674 ha
->loop_down_abort_time
=
1675 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1677 ha
->link_down_timeout
= nv
->link_down_timeout
;
1678 ha
->loop_down_abort_time
=
1679 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1683 * Need enough time to try and get the port back.
1685 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1686 if (qlport_down_retry
)
1687 ha
->port_down_retry_count
= qlport_down_retry
;
1688 /* Set login_retry_count */
1689 ha
->login_retry_count
= nv
->retry_count
;
1690 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1691 ha
->port_down_retry_count
> 3)
1692 ha
->login_retry_count
= ha
->port_down_retry_count
;
1693 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1694 ha
->login_retry_count
= ha
->port_down_retry_count
;
1695 if (ql2xloginretrycount
)
1696 ha
->login_retry_count
= ql2xloginretrycount
;
1698 icb
->lun_enables
= __constant_cpu_to_le16(0);
1699 icb
->command_resource_count
= 0;
1700 icb
->immediate_notify_resource_count
= 0;
1701 icb
->timeout
= __constant_cpu_to_le16(0);
1703 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1705 icb
->firmware_options
[0] &= ~BIT_3
;
1706 icb
->add_firmware_options
[0] &=
1707 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1708 icb
->add_firmware_options
[0] |= BIT_2
;
1709 icb
->response_accumulation_timer
= 3;
1710 icb
->interrupt_delay_timer
= 5;
1712 ha
->flags
.process_response_queue
= 1;
1715 if (!ha
->flags
.init_done
) {
1716 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1717 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1718 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1719 icb
->interrupt_delay_timer
: 2;
1721 icb
->add_firmware_options
[0] &=
1722 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1723 ha
->flags
.process_response_queue
= 0;
1724 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1725 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1727 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1728 "delay (%d us).\n", ha
->host_no
, ha
->zio_mode
,
1729 ha
->zio_timer
* 100));
1730 qla_printk(KERN_INFO
, ha
,
1731 "ZIO mode %d enabled; timer delay (%d us).\n",
1732 ha
->zio_mode
, ha
->zio_timer
* 100);
1734 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1735 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1736 ha
->flags
.process_response_queue
= 1;
1741 DEBUG2_3(printk(KERN_WARNING
1742 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
1748 qla2x00_rport_del(void *data
)
1750 fc_port_t
*fcport
= data
;
1751 struct fc_rport
*rport
;
1752 unsigned long flags
;
1754 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
1755 rport
= fcport
->drport
;
1756 fcport
->drport
= NULL
;
1757 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
1759 fc_remote_port_delete(rport
);
1763 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1765 * @flags: allocation flags
1767 * Returns a pointer to the allocated fcport, or NULL, if none available.
1770 qla2x00_alloc_fcport(scsi_qla_host_t
*ha
, gfp_t flags
)
1774 fcport
= kmalloc(sizeof(fc_port_t
), flags
);
1778 /* Setup fcport template structure. */
1779 memset(fcport
, 0, sizeof (fc_port_t
));
1781 fcport
->vp_idx
= ha
->vp_idx
;
1782 fcport
->port_type
= FCT_UNKNOWN
;
1783 fcport
->loop_id
= FC_NO_LOOP_ID
;
1784 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1785 fcport
->flags
= FCF_RLC_SUPPORT
;
1786 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1787 spin_lock_init(&fcport
->rport_lock
);
1793 * qla2x00_configure_loop
1794 * Updates Fibre Channel Device Database with what is actually on loop.
1797 * ha = adapter block pointer.
1802 * 2 = database was full and device was not configured.
1805 qla2x00_configure_loop(scsi_qla_host_t
*ha
)
1808 unsigned long flags
, save_flags
;
1812 /* Get Initiator ID */
1813 if (test_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
)) {
1814 rval
= qla2x00_configure_hba(ha
);
1815 if (rval
!= QLA_SUCCESS
) {
1816 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1822 save_flags
= flags
= ha
->dpc_flags
;
1823 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1824 ha
->host_no
, flags
));
1827 * If we have both an RSCN and PORT UPDATE pending then handle them
1828 * both at the same time.
1830 clear_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1831 clear_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1833 /* Determine what we need to do */
1834 if (ha
->current_topology
== ISP_CFG_FL
&&
1835 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1837 ha
->flags
.rscn_queue_overflow
= 1;
1838 set_bit(RSCN_UPDATE
, &flags
);
1840 } else if (ha
->current_topology
== ISP_CFG_F
&&
1841 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
1843 ha
->flags
.rscn_queue_overflow
= 1;
1844 set_bit(RSCN_UPDATE
, &flags
);
1845 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
1847 } else if (ha
->current_topology
== ISP_CFG_N
) {
1848 clear_bit(RSCN_UPDATE
, &flags
);
1850 } else if (!ha
->flags
.online
||
1851 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
1853 ha
->flags
.rscn_queue_overflow
= 1;
1854 set_bit(RSCN_UPDATE
, &flags
);
1855 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
1858 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
1859 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1860 rval
= QLA_FUNCTION_FAILED
;
1862 rval
= qla2x00_configure_local_loop(ha
);
1866 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
1867 if (LOOP_TRANSITION(ha
)) {
1868 rval
= QLA_FUNCTION_FAILED
;
1870 rval
= qla2x00_configure_fabric(ha
);
1874 if (rval
== QLA_SUCCESS
) {
1875 if (atomic_read(&ha
->loop_down_timer
) ||
1876 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1877 rval
= QLA_FUNCTION_FAILED
;
1879 atomic_set(&ha
->loop_state
, LOOP_READY
);
1881 DEBUG(printk("scsi(%ld): LOOP READY\n", ha
->host_no
));
1886 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1887 __func__
, ha
->host_no
));
1889 DEBUG3(printk("%s: exiting normally\n", __func__
));
1892 /* Restore state if a resync event occured during processing */
1893 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)) {
1894 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
1895 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
1896 if (test_bit(RSCN_UPDATE
, &save_flags
))
1897 set_bit(RSCN_UPDATE
, &ha
->dpc_flags
);
1906 * qla2x00_configure_local_loop
1907 * Updates Fibre Channel Device Database with local loop devices.
1910 * ha = adapter block pointer.
1916 qla2x00_configure_local_loop(scsi_qla_host_t
*ha
)
1921 fc_port_t
*fcport
, *new_fcport
;
1927 uint8_t domain
, area
, al_pa
;
1928 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
1932 entries
= MAX_FIBRE_DEVICES
;
1934 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha
->host_no
));
1935 DEBUG3(qla2x00_get_fcal_position_map(ha
, NULL
));
1937 /* Get list of logged in devices. */
1938 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
1939 rval
= qla2x00_get_id_list(ha
, ha
->gid_list
, ha
->gid_list_dma
,
1941 if (rval
!= QLA_SUCCESS
)
1942 goto cleanup_allocation
;
1944 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1945 ha
->host_no
, entries
));
1946 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
1947 entries
* sizeof(struct gid_list_info
)));
1949 /* Allocate temporary fcport for any new fcports discovered. */
1950 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
1951 if (new_fcport
== NULL
) {
1952 rval
= QLA_MEMORY_ALLOC_FAILED
;
1953 goto cleanup_allocation
;
1955 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
1958 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1960 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
1961 if (fcport
->vp_idx
!= ha
->vp_idx
)
1964 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
1965 fcport
->port_type
!= FCT_BROADCAST
&&
1966 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
1968 DEBUG(printk("scsi(%ld): Marking port lost, "
1970 ha
->host_no
, fcport
->loop_id
));
1972 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
1973 fcport
->flags
&= ~FCF_FARP_DONE
;
1977 /* Add devices to port list. */
1978 id_iter
= (char *)ha
->gid_list
;
1979 for (index
= 0; index
< entries
; index
++) {
1980 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
1981 area
= ((struct gid_list_info
*)id_iter
)->area
;
1982 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
1983 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1984 loop_id
= (uint16_t)
1985 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
1987 loop_id
= le16_to_cpu(
1988 ((struct gid_list_info
*)id_iter
)->loop_id
);
1989 id_iter
+= ha
->gid_list_info_size
;
1991 /* Bypass reserved domain fields. */
1992 if ((domain
& 0xf0) == 0xf0)
1995 /* Bypass if not same domain and area of adapter. */
1996 if (area
&& domain
&&
1997 (area
!= ha
->d_id
.b
.area
|| domain
!= ha
->d_id
.b
.domain
))
2000 /* Bypass invalid local loop ID. */
2001 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2004 /* Fill in member data. */
2005 new_fcport
->d_id
.b
.domain
= domain
;
2006 new_fcport
->d_id
.b
.area
= area
;
2007 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2008 new_fcport
->loop_id
= loop_id
;
2009 new_fcport
->vp_idx
= ha
->vp_idx
;
2010 rval2
= qla2x00_get_port_database(ha
, new_fcport
, 0);
2011 if (rval2
!= QLA_SUCCESS
) {
2012 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2013 "information -- get_port_database=%x, "
2015 ha
->host_no
, rval2
, new_fcport
->loop_id
));
2016 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2018 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
2022 /* Check for matching device in port list. */
2025 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2026 if (fcport
->vp_idx
!= ha
->vp_idx
)
2029 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2033 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2034 FCF_PERSISTENT_BOUND
);
2035 fcport
->loop_id
= new_fcport
->loop_id
;
2036 fcport
->port_type
= new_fcport
->port_type
;
2037 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2038 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2046 /* New device, add to fcports list. */
2047 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2049 new_fcport
->ha
= ha
;
2050 new_fcport
->vp_idx
= ha
->vp_idx
;
2051 list_add_tail(&new_fcport
->vp_fcport
,
2054 list_add_tail(&new_fcport
->list
, &pha
->fcports
);
2056 /* Allocate a new replacement fcport. */
2057 fcport
= new_fcport
;
2058 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2059 if (new_fcport
== NULL
) {
2060 rval
= QLA_MEMORY_ALLOC_FAILED
;
2061 goto cleanup_allocation
;
2063 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2066 /* Base iIDMA settings on HBA port speed. */
2067 switch (ha
->link_data_rate
) {
2068 case PORT_SPEED_1GB
:
2069 fcport
->fp_speed
= cpu_to_be16(BIT_15
);
2071 case PORT_SPEED_2GB
:
2072 fcport
->fp_speed
= cpu_to_be16(BIT_14
);
2074 case PORT_SPEED_4GB
:
2075 fcport
->fp_speed
= cpu_to_be16(BIT_13
);
2079 qla2x00_update_fcport(ha
, fcport
);
2087 if (rval
!= QLA_SUCCESS
) {
2088 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2089 "rval=%x\n", ha
->host_no
, rval
));
2093 ha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2094 ha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2101 qla2x00_probe_for_all_luns(scsi_qla_host_t
*ha
)
2105 qla2x00_mark_all_devices_lost(ha
, 0);
2106 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
2107 if (fcport
->port_type
!= FCT_TARGET
)
2110 qla2x00_update_fcport(ha
, fcport
);
2115 qla2x00_iidma_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2117 #define LS_UNKNOWN 2
2118 static char *link_speeds
[5] = { "1", "2", "?", "4" };
2120 uint16_t port_speed
, mb
[6];
2122 if (!IS_IIDMA_CAPABLE(ha
))
2125 switch (be16_to_cpu(fcport
->fp_speed
)) {
2127 port_speed
= PORT_SPEED_1GB
;
2130 port_speed
= PORT_SPEED_2GB
;
2133 port_speed
= PORT_SPEED_4GB
;
2136 DEBUG2(printk("scsi(%ld): %02x%02x%02x%02x%02x%02x%02x%02x -- "
2137 "unsupported FM port operating speed (%04x).\n",
2138 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2139 fcport
->port_name
[2], fcport
->port_name
[3],
2140 fcport
->port_name
[4], fcport
->port_name
[5],
2141 fcport
->port_name
[6], fcport
->port_name
[7],
2142 be16_to_cpu(fcport
->fp_speed
)));
2143 port_speed
= PORT_SPEED_UNKNOWN
;
2146 if (port_speed
== PORT_SPEED_UNKNOWN
)
2149 rval
= qla2x00_set_idma_speed(ha
, fcport
->loop_id
, port_speed
, mb
);
2150 if (rval
!= QLA_SUCCESS
) {
2151 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2152 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2153 ha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2154 fcport
->port_name
[2], fcport
->port_name
[3],
2155 fcport
->port_name
[4], fcport
->port_name
[5],
2156 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2157 port_speed
, mb
[0], mb
[1]));
2159 DEBUG2(qla_printk(KERN_INFO
, ha
,
2160 "iIDMA adjusted to %s GB/s on "
2161 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2162 link_speeds
[port_speed
], fcport
->port_name
[0],
2163 fcport
->port_name
[1], fcport
->port_name
[2],
2164 fcport
->port_name
[3], fcport
->port_name
[4],
2165 fcport
->port_name
[5], fcport
->port_name
[6],
2166 fcport
->port_name
[7]));
2171 qla2x00_reg_remote_port(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2173 struct fc_rport_identifiers rport_ids
;
2174 struct fc_rport
*rport
;
2175 unsigned long flags
;
2178 qla2x00_rport_del(fcport
);
2182 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2183 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2184 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2185 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2186 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2187 rport
= fc_remote_port_add(ha
->host
, 0, &rport_ids
);
2189 qla_printk(KERN_WARNING
, ha
,
2190 "Unable to allocate fc remote port!\n");
2193 spin_lock_irqsave(&fcport
->rport_lock
, flags
);
2194 fcport
->rport
= rport
;
2195 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2196 spin_unlock_irqrestore(&fcport
->rport_lock
, flags
);
2198 rport
->supported_classes
= fcport
->supported_classes
;
2200 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2201 if (fcport
->port_type
== FCT_INITIATOR
)
2202 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2203 if (fcport
->port_type
== FCT_TARGET
)
2204 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2205 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2207 if (rport
->scsi_target_id
!= -1 &&
2208 rport
->scsi_target_id
< ha
->host
->max_id
)
2209 fcport
->os_target_id
= rport
->scsi_target_id
;
2213 * qla2x00_update_fcport
2214 * Updates device on list.
2217 * ha = adapter block pointer.
2218 * fcport = port structure pointer.
2228 qla2x00_update_fcport(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
2230 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2233 fcport
->login_retry
= 0;
2234 fcport
->port_login_retry_count
= pha
->port_down_retry_count
*
2236 atomic_set(&fcport
->port_down_timer
, pha
->port_down_retry_count
*
2238 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2240 qla2x00_iidma_fcport(ha
, fcport
);
2242 atomic_set(&fcport
->state
, FCS_ONLINE
);
2244 qla2x00_reg_remote_port(ha
, fcport
);
2248 * qla2x00_configure_fabric
2249 * Setup SNS devices with loop ID's.
2252 * ha = adapter block pointer.
2259 qla2x00_configure_fabric(scsi_qla_host_t
*ha
)
2262 fc_port_t
*fcport
, *fcptemp
;
2263 uint16_t next_loopid
;
2264 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2266 LIST_HEAD(new_fcports
);
2267 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2269 /* If FL port exists, then SNS is present */
2270 if (IS_FWI2_CAPABLE(ha
))
2271 loop_id
= NPH_F_PORT
;
2273 loop_id
= SNS_FL_PORT
;
2274 rval
= qla2x00_get_port_name(ha
, loop_id
, ha
->fabric_node_name
, 1);
2275 if (rval
!= QLA_SUCCESS
) {
2276 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2277 "Port\n", ha
->host_no
));
2279 ha
->device_flags
&= ~SWITCH_FOUND
;
2280 return (QLA_SUCCESS
);
2282 ha
->device_flags
|= SWITCH_FOUND
;
2284 /* Mark devices that need re-synchronization. */
2285 rval2
= qla2x00_device_resync(ha
);
2286 if (rval2
== QLA_RSCNS_HANDLED
) {
2287 /* No point doing the scan, just continue. */
2288 return (QLA_SUCCESS
);
2292 if (ql2xfdmienable
&&
2293 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
))
2294 qla2x00_fdmi_register(ha
);
2296 /* Ensure we are logged into the SNS. */
2297 if (IS_FWI2_CAPABLE(ha
))
2300 loop_id
= SIMPLE_NAME_SERVER
;
2301 ha
->isp_ops
.fabric_login(ha
, loop_id
, 0xff, 0xff,
2302 0xfc, mb
, BIT_1
| BIT_0
);
2303 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2304 DEBUG2(qla_printk(KERN_INFO
, ha
,
2305 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2306 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2307 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2308 return (QLA_SUCCESS
);
2311 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
)) {
2312 if (qla2x00_rft_id(ha
)) {
2314 DEBUG2(printk("scsi(%ld): Register FC-4 "
2315 "TYPE failed.\n", ha
->host_no
));
2317 if (qla2x00_rff_id(ha
)) {
2319 DEBUG2(printk("scsi(%ld): Register FC-4 "
2320 "Features failed.\n", ha
->host_no
));
2322 if (qla2x00_rnn_id(ha
)) {
2324 DEBUG2(printk("scsi(%ld): Register Node Name "
2325 "failed.\n", ha
->host_no
));
2326 } else if (qla2x00_rsnn_nn(ha
)) {
2328 DEBUG2(printk("scsi(%ld): Register Symbolic "
2329 "Node Name failed.\n", ha
->host_no
));
2333 rval
= qla2x00_find_all_fabric_devs(ha
, &new_fcports
);
2334 if (rval
!= QLA_SUCCESS
)
2338 * Logout all previous fabric devices marked lost, except
2341 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2342 if (fcport
->vp_idx
!=ha
->vp_idx
)
2345 if (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2348 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2351 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2352 qla2x00_mark_device_lost(ha
, fcport
,
2353 ql2xplogiabsentdevice
, 0);
2354 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2355 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2356 fcport
->port_type
!= FCT_INITIATOR
&&
2357 fcport
->port_type
!= FCT_BROADCAST
) {
2358 ha
->isp_ops
.fabric_logout(ha
,
2360 fcport
->d_id
.b
.domain
,
2361 fcport
->d_id
.b
.area
,
2362 fcport
->d_id
.b
.al_pa
);
2363 fcport
->loop_id
= FC_NO_LOOP_ID
;
2368 /* Starting free loop ID. */
2369 next_loopid
= pha
->min_external_loopid
;
2372 * Scan through our port list and login entries that need to be
2375 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2376 if (fcport
->vp_idx
!= ha
->vp_idx
)
2379 if (atomic_read(&ha
->loop_down_timer
) ||
2380 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2383 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2384 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2387 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2388 fcport
->loop_id
= next_loopid
;
2389 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2390 if (rval
!= QLA_SUCCESS
) {
2391 /* Ran out of IDs to use */
2395 /* Login and update database */
2396 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2399 /* Exit if out of loop IDs. */
2400 if (rval
!= QLA_SUCCESS
) {
2405 * Login and add the new devices to our port list.
2407 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2408 if (atomic_read(&ha
->loop_down_timer
) ||
2409 test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
))
2412 /* Find a new loop ID to use. */
2413 fcport
->loop_id
= next_loopid
;
2414 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
2415 if (rval
!= QLA_SUCCESS
) {
2416 /* Ran out of IDs to use */
2420 /* Login and update database */
2421 qla2x00_fabric_dev_login(ha
, fcport
, &next_loopid
);
2425 fcport
->vp_idx
= ha
->vp_idx
;
2426 list_add_tail(&fcport
->vp_fcport
,
2428 list_move_tail(&fcport
->list
,
2429 &ha
->parent
->fcports
);
2431 list_move_tail(&fcport
->list
, &ha
->fcports
);
2435 /* Free all new device structures not processed. */
2436 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2437 list_del(&fcport
->list
);
2442 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2443 "rval=%d\n", ha
->host_no
, rval
));
2451 * qla2x00_find_all_fabric_devs
2454 * ha = adapter block pointer.
2455 * dev = database device entry pointer.
2464 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*ha
, struct list_head
*new_fcports
)
2468 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2473 int first_dev
, last_dev
;
2474 port_id_t wrap
, nxt_d_id
;
2478 scsi_qla_host_t
*vha
;
2479 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2483 /* Try GID_PT to get device list, else GAN. */
2484 swl
= kmalloc(sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
, GFP_ATOMIC
);
2487 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2488 "on GA_NXT\n", ha
->host_no
));
2490 memset(swl
, 0, sizeof(sw_info_t
) * MAX_FIBRE_DEVICES
);
2491 if (qla2x00_gid_pt(ha
, swl
) != QLA_SUCCESS
) {
2494 } else if (qla2x00_gpn_id(ha
, swl
) != QLA_SUCCESS
) {
2497 } else if (qla2x00_gnn_id(ha
, swl
) != QLA_SUCCESS
) {
2500 } else if (qla2x00_gfpn_id(ha
, swl
) == QLA_SUCCESS
) {
2501 qla2x00_gpsc(ha
, swl
);
2506 /* Allocate temporary fcport for any new fcports discovered. */
2507 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2508 if (new_fcport
== NULL
) {
2510 return (QLA_MEMORY_ALLOC_FAILED
);
2512 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2513 new_fcport
->vp_idx
= ha
->vp_idx
;
2514 /* Set start port ID scan at adapter ID. */
2518 /* Starting free loop ID. */
2519 loop_id
= pha
->min_external_loopid
;
2520 for (; loop_id
<= ha
->last_loop_id
; loop_id
++) {
2521 if (qla2x00_is_reserved_id(ha
, loop_id
))
2524 if (atomic_read(&ha
->loop_down_timer
) || LOOP_TRANSITION(ha
))
2529 wrap
.b24
= new_fcport
->d_id
.b24
;
2531 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2532 memcpy(new_fcport
->node_name
,
2533 swl
[swl_idx
].node_name
, WWN_SIZE
);
2534 memcpy(new_fcport
->port_name
,
2535 swl
[swl_idx
].port_name
, WWN_SIZE
);
2536 memcpy(new_fcport
->fabric_port_name
,
2537 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2538 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2540 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2546 /* Send GA_NXT to the switch */
2547 rval
= qla2x00_ga_nxt(ha
, new_fcport
);
2548 if (rval
!= QLA_SUCCESS
) {
2549 qla_printk(KERN_WARNING
, ha
,
2550 "SNS scan failed -- assuming zero-entry "
2552 list_for_each_entry_safe(fcport
, fcptemp
,
2553 new_fcports
, list
) {
2554 list_del(&fcport
->list
);
2562 /* If wrap on switch device list, exit. */
2564 wrap
.b24
= new_fcport
->d_id
.b24
;
2566 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2567 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2568 ha
->host_no
, new_fcport
->d_id
.b
.domain
,
2569 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2573 /* Bypass if same physical adapter. */
2574 if (new_fcport
->d_id
.b24
== pha
->d_id
.b24
)
2577 /* Bypass virtual ports of the same host. */
2578 if (pha
->num_vhosts
) {
2579 vp_index
= find_next_bit(
2580 (unsigned long *)pha
->vp_idx_map
,
2581 MAX_MULTI_ID_FABRIC
+ 1, 1);
2583 for (;vp_index
<= MAX_MULTI_ID_FABRIC
;
2584 vp_index
= find_next_bit(
2585 (unsigned long *)pha
->vp_idx_map
,
2586 MAX_MULTI_ID_FABRIC
+ 1, vp_index
+ 1)) {
2589 list_for_each_entry(vha
, &pha
->vp_list
,
2591 if (vp_index
== vha
->vp_idx
) {
2602 new_fcport
->d_id
.b24
== vha
->d_id
.b24
)
2605 if (vp_index
<= MAX_MULTI_ID_FABRIC
)
2609 /* Bypass if same domain and area of adapter. */
2610 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2611 (ha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2615 /* Bypass reserved domain fields. */
2616 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2619 /* Locate matching device in database. */
2621 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2622 if (new_fcport
->vp_idx
!= fcport
->vp_idx
)
2624 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2630 /* Update port state. */
2631 memcpy(fcport
->fabric_port_name
,
2632 new_fcport
->fabric_port_name
, WWN_SIZE
);
2633 fcport
->fp_speed
= new_fcport
->fp_speed
;
2636 * If address the same and state FCS_ONLINE, nothing
2639 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2640 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2645 * If device was not a fabric device before.
2647 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2648 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2649 fcport
->loop_id
= FC_NO_LOOP_ID
;
2650 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2652 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2657 * Port ID changed or device was marked to be updated;
2658 * Log it out if still logged in and mark it for
2661 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2662 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2663 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2664 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2665 fcport
->port_type
!= FCT_INITIATOR
&&
2666 fcport
->port_type
!= FCT_BROADCAST
) {
2667 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2668 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2669 fcport
->d_id
.b
.al_pa
);
2670 fcport
->loop_id
= FC_NO_LOOP_ID
;
2679 /* If device was not in our fcports list, then add it. */
2680 list_add_tail(&new_fcport
->list
, new_fcports
);
2682 /* Allocate a new replacement fcport. */
2683 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2684 new_fcport
= qla2x00_alloc_fcport(ha
, GFP_KERNEL
);
2685 if (new_fcport
== NULL
) {
2687 return (QLA_MEMORY_ALLOC_FAILED
);
2689 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2690 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2691 new_fcport
->vp_idx
= ha
->vp_idx
;
2697 if (!list_empty(new_fcports
))
2698 ha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2704 * qla2x00_find_new_loop_id
2705 * Scan through our port list and find a new usable loop ID.
2708 * ha: adapter state pointer.
2709 * dev: port structure pointer.
2712 * qla2x00 local function return status code.
2718 qla2x00_find_new_loop_id(scsi_qla_host_t
*ha
, fc_port_t
*dev
)
2723 uint16_t first_loop_id
;
2724 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2728 /* Save starting loop ID. */
2729 first_loop_id
= dev
->loop_id
;
2732 /* Skip loop ID if already used by adapter. */
2733 if (dev
->loop_id
== ha
->loop_id
) {
2737 /* Skip reserved loop IDs. */
2738 while (qla2x00_is_reserved_id(ha
, dev
->loop_id
)) {
2742 /* Reset loop ID if passed the end. */
2743 if (dev
->loop_id
> ha
->last_loop_id
) {
2744 /* first loop ID. */
2745 dev
->loop_id
= ha
->min_external_loopid
;
2748 /* Check for loop ID being already in use. */
2751 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2752 if (fcport
->loop_id
== dev
->loop_id
&& fcport
!= dev
) {
2753 /* ID possibly in use */
2759 /* If not in use then it is free to use. */
2764 /* ID in use. Try next value. */
2767 /* If wrap around. No free ID to use. */
2768 if (dev
->loop_id
== first_loop_id
) {
2769 dev
->loop_id
= FC_NO_LOOP_ID
;
2770 rval
= QLA_FUNCTION_FAILED
;
2779 * qla2x00_device_resync
2780 * Marks devices in the database that needs resynchronization.
2783 * ha = adapter block pointer.
2789 qla2x00_device_resync(scsi_qla_host_t
*ha
)
2794 uint32_t rscn_entry
;
2795 uint8_t rscn_out_iter
;
2798 scsi_qla_host_t
*pha
= to_qla_parent(ha
);
2800 rval
= QLA_RSCNS_HANDLED
;
2802 while (ha
->rscn_out_ptr
!= ha
->rscn_in_ptr
||
2803 ha
->flags
.rscn_queue_overflow
) {
2805 rscn_entry
= ha
->rscn_queue
[ha
->rscn_out_ptr
];
2806 format
= MSB(MSW(rscn_entry
));
2807 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2808 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2809 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2811 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2812 "[%02x/%02x%02x%02x].\n",
2813 ha
->host_no
, ha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2814 d_id
.b
.area
, d_id
.b
.al_pa
));
2817 if (ha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2818 ha
->rscn_out_ptr
= 0;
2820 /* Skip duplicate entries. */
2821 for (rscn_out_iter
= ha
->rscn_out_ptr
;
2822 !ha
->flags
.rscn_queue_overflow
&&
2823 rscn_out_iter
!= ha
->rscn_in_ptr
;
2824 rscn_out_iter
= (rscn_out_iter
==
2825 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2827 if (rscn_entry
!= ha
->rscn_queue
[rscn_out_iter
])
2830 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2831 "entry found at [%d].\n", ha
->host_no
,
2834 ha
->rscn_out_ptr
= rscn_out_iter
;
2837 /* Queue overflow, set switch default case. */
2838 if (ha
->flags
.rscn_queue_overflow
) {
2839 DEBUG(printk("scsi(%ld): device_resync: rscn "
2840 "overflow.\n", ha
->host_no
));
2843 ha
->flags
.rscn_queue_overflow
= 0;
2859 ha
->rscn_out_ptr
= ha
->rscn_in_ptr
;
2865 list_for_each_entry(fcport
, &pha
->fcports
, list
) {
2866 if (fcport
->vp_idx
!= ha
->vp_idx
)
2869 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2870 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2871 fcport
->port_type
== FCT_BROADCAST
)
2874 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2876 fcport
->port_type
!= FCT_INITIATOR
) {
2877 qla2x00_mark_device_lost(ha
, fcport
,
2881 fcport
->flags
&= ~FCF_FARP_DONE
;
2888 * qla2x00_fabric_dev_login
2889 * Login fabric target device and update FC port database.
2892 * ha: adapter state pointer.
2893 * fcport: port structure list pointer.
2894 * next_loopid: contains value of a new loop ID that can be used
2895 * by the next login attempt.
2898 * qla2x00 local function return status code.
2904 qla2x00_fabric_dev_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2905 uint16_t *next_loopid
)
2914 rval
= qla2x00_fabric_login(ha
, fcport
, next_loopid
);
2915 if (rval
== QLA_SUCCESS
) {
2916 /* Send an ADISC to tape devices.*/
2918 if (fcport
->flags
& FCF_TAPE_PRESENT
)
2920 rval
= qla2x00_get_port_database(ha
, fcport
, opts
);
2921 if (rval
!= QLA_SUCCESS
) {
2922 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
2923 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2924 fcport
->d_id
.b
.al_pa
);
2925 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
2927 qla2x00_update_fcport(ha
, fcport
);
2935 * qla2x00_fabric_login
2936 * Issue fabric login command.
2939 * ha = adapter block pointer.
2940 * device = pointer to FC device type structure.
2943 * 0 - Login successfully
2945 * 2 - Initiator device
2949 qla2x00_fabric_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
,
2950 uint16_t *next_loopid
)
2954 uint16_t tmp_loopid
;
2955 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2961 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2962 "for port %02x%02x%02x.\n",
2963 ha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2964 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2966 /* Login fcport on switch. */
2967 ha
->isp_ops
.fabric_login(ha
, fcport
->loop_id
,
2968 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2969 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
2970 if (mb
[0] == MBS_PORT_ID_USED
) {
2972 * Device has another loop ID. The firmware team
2973 * recommends the driver perform an implicit login with
2974 * the specified ID again. The ID we just used is save
2975 * here so we return with an ID that can be tried by
2979 tmp_loopid
= fcport
->loop_id
;
2980 fcport
->loop_id
= mb
[1];
2982 DEBUG(printk("Fabric Login: port in use - next "
2983 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2984 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2985 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
2987 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
2992 /* A retry occurred before. */
2993 *next_loopid
= tmp_loopid
;
2996 * No retry occurred before. Just increment the
2997 * ID value for next login.
2999 *next_loopid
= (fcport
->loop_id
+ 1);
3002 if (mb
[1] & BIT_0
) {
3003 fcport
->port_type
= FCT_INITIATOR
;
3005 fcport
->port_type
= FCT_TARGET
;
3006 if (mb
[1] & BIT_1
) {
3007 fcport
->flags
|= FCF_TAPE_PRESENT
;
3012 fcport
->supported_classes
|= FC_COS_CLASS2
;
3014 fcport
->supported_classes
|= FC_COS_CLASS3
;
3018 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3020 * Loop ID already used, try next loop ID.
3023 rval
= qla2x00_find_new_loop_id(ha
, fcport
);
3024 if (rval
!= QLA_SUCCESS
) {
3025 /* Ran out of loop IDs to use */
3028 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3030 * Firmware possibly timed out during login. If NO
3031 * retries are left to do then the device is declared
3034 *next_loopid
= fcport
->loop_id
;
3035 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
3036 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3037 fcport
->d_id
.b
.al_pa
);
3038 qla2x00_mark_device_lost(ha
, fcport
, 1, 0);
3044 * unrecoverable / not handled error
3046 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3047 "loop_id=%x jiffies=%lx.\n",
3048 __func__
, ha
->host_no
, mb
[0],
3049 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3050 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3052 *next_loopid
= fcport
->loop_id
;
3053 ha
->isp_ops
.fabric_logout(ha
, fcport
->loop_id
,
3054 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3055 fcport
->d_id
.b
.al_pa
);
3056 fcport
->loop_id
= FC_NO_LOOP_ID
;
3057 fcport
->login_retry
= 0;
3068 * qla2x00_local_device_login
3069 * Issue local device login command.
3072 * ha = adapter block pointer.
3073 * loop_id = loop id of device to login to.
3075 * Returns (Where's the #define!!!!):
3076 * 0 - Login successfully
3081 qla2x00_local_device_login(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
3084 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3086 memset(mb
, 0, sizeof(mb
));
3087 rval
= qla2x00_login_local_device(ha
, fcport
, mb
, BIT_0
);
3088 if (rval
== QLA_SUCCESS
) {
3089 /* Interrogate mailbox registers for any errors */
3090 if (mb
[0] == MBS_COMMAND_ERROR
)
3092 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3093 /* device not in PCB table */
3101 * qla2x00_loop_resync
3102 * Resync with fibre channel devices.
3105 * ha = adapter block pointer.
3111 qla2x00_loop_resync(scsi_qla_host_t
*ha
)
3118 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3119 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3120 if (ha
->flags
.online
) {
3121 if (!(rval
= qla2x00_fw_ready(ha
))) {
3122 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3125 atomic_set(&ha
->loop_state
, LOOP_UPDATE
);
3127 /* Issue a marker after FW becomes ready. */
3128 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3129 ha
->marker_needed
= 0;
3131 /* Remap devices on Loop. */
3132 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3134 qla2x00_configure_loop(ha
);
3136 } while (!atomic_read(&ha
->loop_down_timer
) &&
3137 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3139 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3143 if (test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) {
3144 return (QLA_FUNCTION_FAILED
);
3148 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3155 qla2x00_rescan_fcports(scsi_qla_host_t
*ha
)
3161 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
3162 if ((fcport
->flags
& FCF_RESCAN_NEEDED
) == 0)
3165 qla2x00_update_fcport(ha
, fcport
);
3166 fcport
->flags
&= ~FCF_RESCAN_NEEDED
;
3170 qla2x00_probe_for_all_luns(ha
);
3174 qla2x00_update_fcports(scsi_qla_host_t
*ha
)
3178 /* Go with deferred removal of rport references. */
3179 list_for_each_entry(fcport
, &ha
->fcports
, list
)
3181 qla2x00_rport_del(fcport
);
3186 * Resets ISP and aborts all outstanding commands.
3189 * ha = adapter block pointer.
3195 qla2x00_abort_isp(scsi_qla_host_t
*ha
)
3198 unsigned long flags
= 0;
3203 if (ha
->flags
.online
) {
3204 ha
->flags
.online
= 0;
3205 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
3207 qla_printk(KERN_INFO
, ha
,
3208 "Performing ISP error recovery - ha= %p.\n", ha
);
3209 ha
->isp_ops
.reset_chip(ha
);
3211 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3212 if (atomic_read(&ha
->loop_state
) != LOOP_DOWN
) {
3213 atomic_set(&ha
->loop_state
, LOOP_DOWN
);
3214 qla2x00_mark_all_devices_lost(ha
, 0);
3216 if (!atomic_read(&ha
->loop_down_timer
))
3217 atomic_set(&ha
->loop_down_timer
,
3221 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3222 /* Requeue all commands in outstanding command list. */
3223 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++) {
3224 sp
= ha
->outstanding_cmds
[cnt
];
3226 ha
->outstanding_cmds
[cnt
] = NULL
;
3228 sp
->cmd
->result
= DID_RESET
<< 16;
3229 sp
->cmd
->host_scribble
= (unsigned char *)NULL
;
3230 qla2x00_sp_compl(ha
, sp
);
3233 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3235 ha
->isp_ops
.get_flash_version(ha
, ha
->request_ring
);
3237 ha
->isp_ops
.nvram_config(ha
);
3239 if (!qla2x00_restart_isp(ha
)) {
3240 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3242 if (!atomic_read(&ha
->loop_down_timer
)) {
3244 * Issue marker command only when we are going
3245 * to start the I/O .
3247 ha
->marker_needed
= 1;
3250 ha
->flags
.online
= 1;
3252 ha
->isp_ops
.enable_intrs(ha
);
3254 ha
->isp_abort_cnt
= 0;
3255 clear_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3258 rval
= qla2x00_trace_control(ha
, TC_ENABLE
,
3259 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3261 qla_printk(KERN_WARNING
, ha
,
3262 "Unable to reinitialize EFT "
3266 } else { /* failed the ISP abort */
3267 ha
->flags
.online
= 1;
3268 if (test_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
)) {
3269 if (ha
->isp_abort_cnt
== 0) {
3270 qla_printk(KERN_WARNING
, ha
,
3271 "ISP error recovery failed - "
3272 "board disabled\n");
3274 * The next call disables the board
3277 ha
->isp_ops
.reset_adapter(ha
);
3278 ha
->flags
.online
= 0;
3279 clear_bit(ISP_ABORT_RETRY
,
3282 } else { /* schedule another ISP abort */
3283 ha
->isp_abort_cnt
--;
3284 DEBUG(printk("qla%ld: ISP abort - "
3285 "retry remaining %d\n",
3286 ha
->host_no
, ha
->isp_abort_cnt
));
3290 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3291 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3292 "- retrying (%d) more times\n",
3293 ha
->host_no
, ha
->isp_abort_cnt
));
3294 set_bit(ISP_ABORT_RETRY
, &ha
->dpc_flags
);
3302 qla_printk(KERN_INFO
, ha
,
3303 "qla2x00_abort_isp: **** FAILED ****\n");
3305 DEBUG(printk(KERN_INFO
3306 "qla2x00_abort_isp(%ld): exiting.\n",
3314 * qla2x00_restart_isp
3315 * restarts the ISP after a reset
3318 * ha = adapter block pointer.
3324 qla2x00_restart_isp(scsi_qla_host_t
*ha
)
3327 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3328 unsigned long flags
= 0;
3331 /* If firmware needs to be loaded */
3332 if (qla2x00_isp_firmware(ha
)) {
3333 ha
->flags
.online
= 0;
3334 if (!(status
= ha
->isp_ops
.chip_diag(ha
))) {
3335 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3336 status
= qla2x00_setup_chip(ha
);
3340 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3342 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3344 * Disable SRAM, Instruction RAM and GP RAM
3347 WRT_REG_WORD(®
->hccr
,
3348 (HCCR_ENABLE_PARITY
+ 0x0));
3349 RD_REG_WORD(®
->hccr
);
3352 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3354 status
= qla2x00_setup_chip(ha
);
3356 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3358 if (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)) {
3359 /* Enable proper parity */
3362 WRT_REG_WORD(®
->hccr
,
3363 (HCCR_ENABLE_PARITY
+ 0x1));
3366 * SRAM, Instruction RAM and GP RAM
3369 WRT_REG_WORD(®
->hccr
,
3370 (HCCR_ENABLE_PARITY
+ 0x7));
3371 RD_REG_WORD(®
->hccr
);
3374 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3379 if (!status
&& !(status
= qla2x00_init_rings(ha
))) {
3380 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
3381 if (!(status
= qla2x00_fw_ready(ha
))) {
3382 DEBUG(printk("%s(): Start configure loop, "
3383 "status = %d\n", __func__
, status
));
3385 /* Issue a marker after FW becomes ready. */
3386 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
3388 ha
->flags
.online
= 1;
3389 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3392 clear_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3393 qla2x00_configure_loop(ha
);
3395 } while (!atomic_read(&ha
->loop_down_timer
) &&
3396 !(test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
)) &&
3398 (test_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
)));
3401 /* if no cable then assume it's good */
3402 if ((ha
->device_flags
& DFLG_NO_CABLE
))
3405 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3413 * qla2x00_reset_adapter
3417 * ha = adapter block pointer.
3420 qla2x00_reset_adapter(scsi_qla_host_t
*ha
)
3422 unsigned long flags
= 0;
3423 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3425 ha
->flags
.online
= 0;
3426 ha
->isp_ops
.disable_intrs(ha
);
3428 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3429 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3430 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3431 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3432 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3433 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3437 qla24xx_reset_adapter(scsi_qla_host_t
*ha
)
3439 unsigned long flags
= 0;
3440 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3442 ha
->flags
.online
= 0;
3443 ha
->isp_ops
.disable_intrs(ha
);
3445 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3446 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3447 RD_REG_DWORD(®
->hccr
);
3448 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3449 RD_REG_DWORD(®
->hccr
);
3450 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3453 /* On sparc systems, obtain port and node WWN from firmware
3456 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*ha
, struct nvram_24xx
*nv
)
3459 struct pci_dev
*pdev
= ha
->pdev
;
3460 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3464 val
= of_get_property(dp
, "port-wwn", &len
);
3465 if (val
&& len
>= WWN_SIZE
)
3466 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3468 val
= of_get_property(dp
, "node-wwn", &len
);
3469 if (val
&& len
>= WWN_SIZE
)
3470 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3475 qla24xx_nvram_config(scsi_qla_host_t
*ha
)
3478 struct init_cb_24xx
*icb
;
3479 struct nvram_24xx
*nv
;
3481 uint8_t *dptr1
, *dptr2
;
3486 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3487 nv
= (struct nvram_24xx
*)ha
->request_ring
;
3489 /* Determine NVRAM starting address. */
3490 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3491 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3492 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3493 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3494 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3495 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3496 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3499 /* Get NVRAM data and calculate checksum. */
3500 dptr
= (uint32_t *)nv
;
3501 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)dptr
, ha
->nvram_base
,
3503 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3504 chksum
+= le32_to_cpu(*dptr
++);
3506 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3507 DEBUG5(qla2x00_dump_buffer((uint8_t *)ha
->request_ring
,
3510 /* Bad NVRAM data, set defaults parameters. */
3511 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3512 || nv
->id
[3] != ' ' ||
3513 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3514 /* Reset NVRAM data. */
3515 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3516 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3517 le16_to_cpu(nv
->nvram_version
));
3518 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3519 "invalid -- WWPN) defaults.\n");
3522 * Set default initialization control block.
3524 memset(nv
, 0, ha
->nvram_size
);
3525 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3526 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3527 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3528 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3529 nv
->exchange_count
= __constant_cpu_to_le16(0);
3530 nv
->hard_address
= __constant_cpu_to_le16(124);
3531 nv
->port_name
[0] = 0x21;
3532 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3533 nv
->port_name
[2] = 0x00;
3534 nv
->port_name
[3] = 0xe0;
3535 nv
->port_name
[4] = 0x8b;
3536 nv
->port_name
[5] = 0x1c;
3537 nv
->port_name
[6] = 0x55;
3538 nv
->port_name
[7] = 0x86;
3539 nv
->node_name
[0] = 0x20;
3540 nv
->node_name
[1] = 0x00;
3541 nv
->node_name
[2] = 0x00;
3542 nv
->node_name
[3] = 0xe0;
3543 nv
->node_name
[4] = 0x8b;
3544 nv
->node_name
[5] = 0x1c;
3545 nv
->node_name
[6] = 0x55;
3546 nv
->node_name
[7] = 0x86;
3547 qla24xx_nvram_wwn_from_ofw(ha
, nv
);
3548 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3549 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3550 nv
->login_timeout
= __constant_cpu_to_le16(0);
3551 nv
->firmware_options_1
=
3552 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3553 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3554 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3555 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3556 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3557 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3558 nv
->reset_delay
= 5;
3559 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3560 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3561 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3566 /* Reset Initialization control block */
3567 memset(icb
, 0, sizeof(struct init_cb_24xx
));
3569 /* Copy 1st segment. */
3570 dptr1
= (uint8_t *)icb
;
3571 dptr2
= (uint8_t *)&nv
->version
;
3572 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3574 *dptr1
++ = *dptr2
++;
3576 icb
->login_retry_count
= nv
->login_retry_count
;
3577 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3579 /* Copy 2nd segment. */
3580 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3581 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3582 cnt
= (uint8_t *)&icb
->reserved_3
-
3583 (uint8_t *)&icb
->interrupt_delay_timer
;
3585 *dptr1
++ = *dptr2
++;
3588 * Setup driver NVRAM options.
3590 qla2x00_set_model_info(ha
, nv
->model_name
, sizeof(nv
->model_name
),
3593 /* Use alternate WWN? */
3594 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3595 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3596 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3599 /* Prepare nodename */
3600 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3602 * Firmware will apply the following mask if the nodename was
3605 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3606 icb
->node_name
[0] &= 0xF0;
3609 /* Set host adapter parameters. */
3610 ha
->flags
.disable_risc_code_load
= 0;
3611 ha
->flags
.enable_lip_reset
= 0;
3612 ha
->flags
.enable_lip_full_login
=
3613 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3614 ha
->flags
.enable_target_reset
=
3615 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3616 ha
->flags
.enable_led_scheme
= 0;
3617 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3619 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3620 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3622 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3623 sizeof(ha
->fw_seriallink_options24
));
3625 /* save HBA serial number */
3626 ha
->serial0
= icb
->port_name
[5];
3627 ha
->serial1
= icb
->port_name
[6];
3628 ha
->serial2
= icb
->port_name
[7];
3629 ha
->node_name
= icb
->node_name
;
3630 ha
->port_name
= icb
->port_name
;
3632 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3634 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3636 /* Set minimum login_timeout to 4 seconds. */
3637 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3638 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3639 if (le16_to_cpu(nv
->login_timeout
) < 4)
3640 nv
->login_timeout
= __constant_cpu_to_le16(4);
3641 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3642 icb
->login_timeout
= cpu_to_le16(nv
->login_timeout
);
3644 /* Set minimum RATOV to 200 tenths of a second. */
3647 ha
->loop_reset_delay
= nv
->reset_delay
;
3649 /* Link Down Timeout = 0:
3651 * When Port Down timer expires we will start returning
3652 * I/O's to OS with "DID_NO_CONNECT".
3654 * Link Down Timeout != 0:
3656 * The driver waits for the link to come up after link down
3657 * before returning I/Os to OS with "DID_NO_CONNECT".
3659 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3660 ha
->loop_down_abort_time
=
3661 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3663 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3664 ha
->loop_down_abort_time
=
3665 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3668 /* Need enough time to try and get the port back. */
3669 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3670 if (qlport_down_retry
)
3671 ha
->port_down_retry_count
= qlport_down_retry
;
3673 /* Set login_retry_count */
3674 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3675 if (ha
->port_down_retry_count
==
3676 le16_to_cpu(nv
->port_down_retry_count
) &&
3677 ha
->port_down_retry_count
> 3)
3678 ha
->login_retry_count
= ha
->port_down_retry_count
;
3679 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3680 ha
->login_retry_count
= ha
->port_down_retry_count
;
3681 if (ql2xloginretrycount
)
3682 ha
->login_retry_count
= ql2xloginretrycount
;
3685 if (!ha
->flags
.init_done
) {
3686 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3687 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3688 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3689 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3691 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3692 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3693 ha
->flags
.process_response_queue
= 0;
3694 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3695 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3697 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3698 "(%d us).\n", ha
->host_no
, ha
->zio_mode
,
3699 ha
->zio_timer
* 100));
3700 qla_printk(KERN_INFO
, ha
,
3701 "ZIO mode %d enabled; timer delay (%d us).\n",
3702 ha
->zio_mode
, ha
->zio_timer
* 100);
3704 icb
->firmware_options_2
|= cpu_to_le32(
3705 (uint32_t)ha
->zio_mode
);
3706 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3707 ha
->flags
.process_response_queue
= 1;
3711 DEBUG2_3(printk(KERN_WARNING
3712 "scsi(%ld): NVRAM configuration failed!\n", ha
->host_no
));
3718 qla24xx_load_risc_flash(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3721 int segments
, fragment
;
3723 uint32_t *dcode
, dlen
;
3730 segments
= FA_RISC_CODE_SEGMENTS
;
3731 faddr
= FA_RISC_CODE_ADDR
;
3732 dcode
= (uint32_t *)ha
->request_ring
;
3735 /* Validate firmware image by checking version. */
3736 qla24xx_read_flash_data(ha
, dcode
, faddr
+ 4, 4);
3737 for (i
= 0; i
< 4; i
++)
3738 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3739 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3740 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3741 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3743 qla_printk(KERN_WARNING
, ha
,
3744 "Unable to verify integrity of flash firmware image!\n");
3745 qla_printk(KERN_WARNING
, ha
,
3746 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3747 dcode
[1], dcode
[2], dcode
[3]);
3749 return QLA_FUNCTION_FAILED
;
3752 while (segments
&& rval
== QLA_SUCCESS
) {
3753 /* Read segment's load information. */
3754 qla24xx_read_flash_data(ha
, dcode
, faddr
, 4);
3756 risc_addr
= be32_to_cpu(dcode
[2]);
3757 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3758 risc_size
= be32_to_cpu(dcode
[3]);
3761 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3762 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3763 if (dlen
> risc_size
)
3766 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3767 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3768 ha
->host_no
, risc_addr
, dlen
, faddr
));
3770 qla24xx_read_flash_data(ha
, dcode
, faddr
, dlen
);
3771 for (i
= 0; i
< dlen
; i
++)
3772 dcode
[i
] = swab32(dcode
[i
]);
3774 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3777 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3778 "segment %d of firmware\n", ha
->host_no
,
3780 qla_printk(KERN_WARNING
, ha
,
3781 "[ERROR] Failed to load segment %d of "
3782 "firmware\n", fragment
);
3799 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3802 qla2x00_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3806 uint16_t *wcode
, *fwcode
;
3807 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3808 struct fw_blob
*blob
;
3810 /* Load firmware blob. */
3811 blob
= qla2x00_request_firmware(ha
);
3813 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3814 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3815 "from: " QLA_FW_URL
".\n");
3816 return QLA_FUNCTION_FAILED
;
3821 wcode
= (uint16_t *)ha
->request_ring
;
3823 fwcode
= (uint16_t *)blob
->fw
->data
;
3826 /* Validate firmware image by checking version. */
3827 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3828 qla_printk(KERN_WARNING
, ha
,
3829 "Unable to verify integrity of firmware image (%Zd)!\n",
3831 goto fail_fw_integrity
;
3833 for (i
= 0; i
< 4; i
++)
3834 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3835 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3836 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3837 wcode
[2] == 0 && wcode
[3] == 0)) {
3838 qla_printk(KERN_WARNING
, ha
,
3839 "Unable to verify integrity of firmware image!\n");
3840 qla_printk(KERN_WARNING
, ha
,
3841 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3842 wcode
[1], wcode
[2], wcode
[3]);
3843 goto fail_fw_integrity
;
3847 while (*seg
&& rval
== QLA_SUCCESS
) {
3849 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3850 risc_size
= be16_to_cpu(fwcode
[3]);
3852 /* Validate firmware image size. */
3853 fwclen
+= risc_size
* sizeof(uint16_t);
3854 if (blob
->fw
->size
< fwclen
) {
3855 qla_printk(KERN_WARNING
, ha
,
3856 "Unable to verify integrity of firmware image "
3857 "(%Zd)!\n", blob
->fw
->size
);
3858 goto fail_fw_integrity
;
3862 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3863 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3864 if (wlen
> risc_size
)
3867 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3868 "addr %x, number of words 0x%x.\n", ha
->host_no
,
3871 for (i
= 0; i
< wlen
; i
++)
3872 wcode
[i
] = swab16(fwcode
[i
]);
3874 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3877 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3878 "segment %d of firmware\n", ha
->host_no
,
3880 qla_printk(KERN_WARNING
, ha
,
3881 "[ERROR] Failed to load segment %d of "
3882 "firmware\n", fragment
);
3898 return QLA_FUNCTION_FAILED
;
3902 qla24xx_load_risc(scsi_qla_host_t
*ha
, uint32_t *srisc_addr
)
3905 int segments
, fragment
;
3906 uint32_t *dcode
, dlen
;
3910 struct fw_blob
*blob
;
3911 uint32_t *fwcode
, fwclen
;
3913 /* Load firmware blob. */
3914 blob
= qla2x00_request_firmware(ha
);
3916 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3917 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3918 "from: " QLA_FW_URL
".\n");
3920 /* Try to load RISC code from flash. */
3921 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
3922 "outdated) firmware from flash.\n");
3923 return qla24xx_load_risc_flash(ha
, srisc_addr
);
3928 segments
= FA_RISC_CODE_SEGMENTS
;
3929 dcode
= (uint32_t *)ha
->request_ring
;
3931 fwcode
= (uint32_t *)blob
->fw
->data
;
3934 /* Validate firmware image by checking version. */
3935 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
3936 qla_printk(KERN_WARNING
, ha
,
3937 "Unable to verify integrity of firmware image (%Zd)!\n",
3939 goto fail_fw_integrity
;
3941 for (i
= 0; i
< 4; i
++)
3942 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
3943 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3944 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3945 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3947 qla_printk(KERN_WARNING
, ha
,
3948 "Unable to verify integrity of firmware image!\n");
3949 qla_printk(KERN_WARNING
, ha
,
3950 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3951 dcode
[1], dcode
[2], dcode
[3]);
3952 goto fail_fw_integrity
;
3955 while (segments
&& rval
== QLA_SUCCESS
) {
3956 risc_addr
= be32_to_cpu(fwcode
[2]);
3957 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3958 risc_size
= be32_to_cpu(fwcode
[3]);
3960 /* Validate firmware image size. */
3961 fwclen
+= risc_size
* sizeof(uint32_t);
3962 if (blob
->fw
->size
< fwclen
) {
3963 qla_printk(KERN_WARNING
, ha
,
3964 "Unable to verify integrity of firmware image "
3965 "(%Zd)!\n", blob
->fw
->size
);
3967 goto fail_fw_integrity
;
3971 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3972 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3973 if (dlen
> risc_size
)
3976 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3977 "addr %x, number of dwords 0x%x.\n", ha
->host_no
,
3980 for (i
= 0; i
< dlen
; i
++)
3981 dcode
[i
] = swab32(fwcode
[i
]);
3983 rval
= qla2x00_load_ram(ha
, ha
->request_dma
, risc_addr
,
3986 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3987 "segment %d of firmware\n", ha
->host_no
,
3989 qla_printk(KERN_WARNING
, ha
,
3990 "[ERROR] Failed to load segment %d of "
3991 "firmware\n", fragment
);
4007 return QLA_FUNCTION_FAILED
;
4011 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*ha
)
4015 if (!IS_FWI2_CAPABLE(ha
))
4017 if (!ha
->fw_major_version
)
4020 ret
= qla2x00_stop_firmware(ha
);
4021 for (retries
= 5; ret
!= QLA_SUCCESS
&& retries
; retries
--) {
4022 qla2x00_reset_chip(ha
);
4023 if (qla2x00_chip_diag(ha
) != QLA_SUCCESS
)
4025 if (qla2x00_setup_chip(ha
) != QLA_SUCCESS
)
4027 qla_printk(KERN_INFO
, ha
,
4028 "Attempting retry of stop-firmware command...\n");
4029 ret
= qla2x00_stop_firmware(ha
);
4034 qla24xx_configure_vhba(scsi_qla_host_t
*ha
)
4036 int rval
= QLA_SUCCESS
;
4037 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4042 rval
= qla2x00_fw_ready(ha
);
4043 if (rval
== QLA_SUCCESS
) {
4044 clear_bit(RESET_MARKER_NEEDED
, &ha
->dpc_flags
);
4045 qla2x00_marker(ha
, 0, 0, MK_SYNC_ALL
);
4048 ha
->flags
.management_server_logged_in
= 0;
4050 /* Login to SNS first */
4051 qla24xx_login_fabric(ha
, NPH_SNS
, 0xff, 0xff, 0xfc,
4053 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4054 DEBUG15(qla_printk(KERN_INFO
, ha
,
4055 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4056 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4057 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4058 return (QLA_FUNCTION_FAILED
);
4061 atomic_set(&ha
->loop_down_timer
, 0);
4062 atomic_set(&ha
->loop_state
, LOOP_UP
);
4063 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
4064 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
4065 rval
= qla2x00_loop_resync(ha
);