2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
20 * QLogic ISP2x00 Hardware Support Function Prototypes.
22 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
23 static void qla2x00_resize_request_q(scsi_qla_host_t
*);
24 static int qla2x00_setup_chip(scsi_qla_host_t
*);
25 static int qla2x00_init_rings(scsi_qla_host_t
*);
26 static int qla2x00_fw_ready(scsi_qla_host_t
*);
27 static int qla2x00_configure_hba(scsi_qla_host_t
*);
28 static int qla2x00_configure_loop(scsi_qla_host_t
*);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
30 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
32 static int qla2x00_device_resync(scsi_qla_host_t
*);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
36 static int qla2x00_restart_isp(scsi_qla_host_t
*);
38 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*, fc_port_t
*);
40 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
41 static int qla84xx_init_chip(scsi_qla_host_t
*);
42 static int qla25xx_init_queues(struct qla_hw_data
*);
44 /****************************************************************************/
45 /* QLogic ISP2x00 Hardware Support Functions. */
46 /****************************************************************************/
49 * qla2x00_initialize_adapter
53 * ha = adapter block pointer.
59 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
62 struct qla_hw_data
*ha
= vha
->hw
;
63 struct req_que
*req
= ha
->req_q_map
[0];
64 /* Clear adapter flags. */
65 vha
->flags
.online
= 0;
66 vha
->flags
.reset_active
= 0;
67 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
68 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
69 vha
->device_flags
= DFLG_NO_CABLE
;
71 vha
->flags
.management_server_logged_in
= 0;
72 vha
->marker_needed
= 0;
74 ha
->isp_abort_cnt
= 0;
75 ha
->beacon_blink_led
= 0;
76 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
78 set_bit(0, ha
->req_qid_map
);
79 set_bit(0, ha
->rsp_qid_map
);
81 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
82 rval
= ha
->isp_ops
->pci_config(vha
);
84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
89 ha
->isp_ops
->reset_chip(vha
);
91 rval
= qla2xxx_get_flash_info(vha
);
93 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
98 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
100 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
102 ha
->isp_ops
->nvram_config(vha
);
104 if (ha
->flags
.disable_serdes
) {
105 /* Mask HBA via NVRAM settings? */
106 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
107 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
108 vha
->port_name
[0], vha
->port_name
[1],
109 vha
->port_name
[2], vha
->port_name
[3],
110 vha
->port_name
[4], vha
->port_name
[5],
111 vha
->port_name
[6], vha
->port_name
[7]);
112 return QLA_FUNCTION_FAILED
;
115 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
117 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
118 rval
= ha
->isp_ops
->chip_diag(vha
);
121 rval
= qla2x00_setup_chip(vha
);
125 if (IS_QLA84XX(ha
)) {
126 ha
->cs84xx
= qla84xx_get_chip(vha
);
128 qla_printk(KERN_ERR
, ha
,
129 "Unable to configure ISP84XX.\n");
130 return QLA_FUNCTION_FAILED
;
133 rval
= qla2x00_init_rings(vha
);
139 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
142 * Returns 0 on success.
145 qla2100_pci_config(scsi_qla_host_t
*vha
)
149 struct qla_hw_data
*ha
= vha
->hw
;
150 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
152 pci_set_master(ha
->pdev
);
153 pci_try_set_mwi(ha
->pdev
);
155 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
156 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
157 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
159 pci_disable_rom(ha
->pdev
);
161 /* Get PCI bus information. */
162 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
163 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
164 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
170 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
173 * Returns 0 on success.
176 qla2300_pci_config(scsi_qla_host_t
*vha
)
179 unsigned long flags
= 0;
181 struct qla_hw_data
*ha
= vha
->hw
;
182 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
184 pci_set_master(ha
->pdev
);
185 pci_try_set_mwi(ha
->pdev
);
187 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
188 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
190 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
191 w
&= ~PCI_COMMAND_INTX_DISABLE
;
192 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
195 * If this is a 2300 card and not 2312, reset the
196 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
197 * the 2310 also reports itself as a 2300 so we need to get the
198 * fb revision level -- a 6 indicates it really is a 2300 and
201 if (IS_QLA2300(ha
)) {
202 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
205 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
206 for (cnt
= 0; cnt
< 30000; cnt
++) {
207 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
213 /* Select FPM registers. */
214 WRT_REG_WORD(®
->ctrl_status
, 0x20);
215 RD_REG_WORD(®
->ctrl_status
);
217 /* Get the fb rev level */
218 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
220 if (ha
->fb_rev
== FPM_2300
)
221 pci_clear_mwi(ha
->pdev
);
223 /* Deselect FPM registers. */
224 WRT_REG_WORD(®
->ctrl_status
, 0x0);
225 RD_REG_WORD(®
->ctrl_status
);
227 /* Release RISC module. */
228 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
229 for (cnt
= 0; cnt
< 30000; cnt
++) {
230 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
236 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
239 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
241 pci_disable_rom(ha
->pdev
);
243 /* Get PCI bus information. */
244 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
245 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
246 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
252 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
255 * Returns 0 on success.
258 qla24xx_pci_config(scsi_qla_host_t
*vha
)
261 unsigned long flags
= 0;
262 struct qla_hw_data
*ha
= vha
->hw
;
263 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
265 pci_set_master(ha
->pdev
);
266 pci_try_set_mwi(ha
->pdev
);
268 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
269 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
270 w
&= ~PCI_COMMAND_INTX_DISABLE
;
271 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
273 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
275 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
276 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
277 pcix_set_mmrbc(ha
->pdev
, 2048);
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
280 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
281 pcie_set_readrq(ha
->pdev
, 2048);
283 pci_disable_rom(ha
->pdev
);
285 ha
->chip_revision
= ha
->pdev
->revision
;
287 /* Get PCI bus information. */
288 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
289 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
290 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
296 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
299 * Returns 0 on success.
302 qla25xx_pci_config(scsi_qla_host_t
*vha
)
305 struct qla_hw_data
*ha
= vha
->hw
;
307 pci_set_master(ha
->pdev
);
308 pci_try_set_mwi(ha
->pdev
);
310 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
311 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
312 w
&= ~PCI_COMMAND_INTX_DISABLE
;
313 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
315 /* PCIe -- adjust Maximum Read Request Size (2048). */
316 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
317 pcie_set_readrq(ha
->pdev
, 2048);
319 pci_disable_rom(ha
->pdev
);
321 ha
->chip_revision
= ha
->pdev
->revision
;
327 * qla2x00_isp_firmware() - Choose firmware image.
330 * Returns 0 on success.
333 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
336 uint16_t loop_id
, topo
, sw_cap
;
337 uint8_t domain
, area
, al_pa
;
338 struct qla_hw_data
*ha
= vha
->hw
;
340 /* Assume loading risc code */
341 rval
= QLA_FUNCTION_FAILED
;
343 if (ha
->flags
.disable_risc_code_load
) {
344 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
346 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
348 /* Verify checksum of loaded RISC code. */
349 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
350 if (rval
== QLA_SUCCESS
) {
351 /* And, verify we are not in ROM code. */
352 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
353 &area
, &domain
, &topo
, &sw_cap
);
358 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
366 * qla2x00_reset_chip() - Reset ISP chip.
369 * Returns 0 on success.
372 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
374 unsigned long flags
= 0;
375 struct qla_hw_data
*ha
= vha
->hw
;
376 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
380 ha
->isp_ops
->disable_intrs(ha
);
382 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
384 /* Turn off master enable */
386 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
387 cmd
&= ~PCI_COMMAND_MASTER
;
388 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
390 if (!IS_QLA2100(ha
)) {
392 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
393 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
394 for (cnt
= 0; cnt
< 30000; cnt
++) {
395 if ((RD_REG_WORD(®
->hccr
) &
396 HCCR_RISC_PAUSE
) != 0)
401 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
405 /* Select FPM registers. */
406 WRT_REG_WORD(®
->ctrl_status
, 0x20);
407 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
409 /* FPM Soft Reset. */
410 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
411 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
413 /* Toggle Fpm Reset. */
414 if (!IS_QLA2200(ha
)) {
415 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
416 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
419 /* Select frame buffer registers. */
420 WRT_REG_WORD(®
->ctrl_status
, 0x10);
421 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
423 /* Reset frame buffer FIFOs. */
424 if (IS_QLA2200(ha
)) {
425 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
426 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
428 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
430 /* Read back fb_cmd until zero or 3 seconds max */
431 for (cnt
= 0; cnt
< 3000; cnt
++) {
432 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
438 /* Select RISC module registers. */
439 WRT_REG_WORD(®
->ctrl_status
, 0);
440 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
442 /* Reset RISC processor. */
443 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
444 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
446 /* Release RISC processor. */
447 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
448 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
451 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
452 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
454 /* Reset ISP chip. */
455 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
457 /* Wait for RISC to recover from reset. */
458 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
460 * It is necessary to for a delay here since the card doesn't
461 * respond to PCI reads during a reset. On some architectures
462 * this will result in an MCA.
465 for (cnt
= 30000; cnt
; cnt
--) {
466 if ((RD_REG_WORD(®
->ctrl_status
) &
467 CSR_ISP_SOFT_RESET
) == 0)
474 /* Reset RISC processor. */
475 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
477 WRT_REG_WORD(®
->semaphore
, 0);
479 /* Release RISC processor. */
480 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
481 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
483 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
484 for (cnt
= 0; cnt
< 30000; cnt
++) {
485 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
493 /* Turn on master enable */
494 cmd
|= PCI_COMMAND_MASTER
;
495 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
497 /* Disable RISC pause on FPM parity error. */
498 if (!IS_QLA2100(ha
)) {
499 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
500 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
503 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
507 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
510 * Returns 0 on success.
513 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
516 unsigned long flags
= 0;
517 struct qla_hw_data
*ha
= vha
->hw
;
518 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
522 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
525 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
526 for (cnt
= 0; cnt
< 30000; cnt
++) {
527 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
533 WRT_REG_DWORD(®
->ctrl_status
,
534 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
535 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
538 /* Wait for firmware to complete NVRAM accesses. */
539 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
540 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
542 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
548 /* Wait for soft-reset to complete. */
549 d2
= RD_REG_DWORD(®
->ctrl_status
);
550 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
552 d2
= RD_REG_DWORD(®
->ctrl_status
);
556 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
557 RD_REG_DWORD(®
->hccr
);
559 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
560 RD_REG_DWORD(®
->hccr
);
562 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
563 RD_REG_DWORD(®
->hccr
);
565 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
566 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
568 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
572 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
574 if (IS_NOPOLLING_TYPE(ha
))
575 ha
->isp_ops
->enable_intrs(ha
);
579 * qla24xx_reset_chip() - Reset ISP24xx chip.
582 * Returns 0 on success.
585 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
587 struct qla_hw_data
*ha
= vha
->hw
;
588 ha
->isp_ops
->disable_intrs(ha
);
590 /* Perform RISC reset. */
591 qla24xx_reset_risc(vha
);
595 * qla2x00_chip_diag() - Test chip for proper operation.
598 * Returns 0 on success.
601 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
604 struct qla_hw_data
*ha
= vha
->hw
;
605 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
606 unsigned long flags
= 0;
610 struct req_que
*req
= ha
->req_q_map
[0];
612 /* Assume a failed state */
613 rval
= QLA_FUNCTION_FAILED
;
615 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
616 vha
->host_no
, (u_long
)®
->flash_address
));
618 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
620 /* Reset ISP chip. */
621 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
624 * We need to have a delay here since the card will not respond while
625 * in reset causing an MCA on some architectures.
628 data
= qla2x00_debounce_register(®
->ctrl_status
);
629 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
631 data
= RD_REG_WORD(®
->ctrl_status
);
636 goto chip_diag_failed
;
638 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
641 /* Reset RISC processor. */
642 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
643 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
645 /* Workaround for QLA2312 PCI parity error */
646 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
647 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
648 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
650 data
= RD_MAILBOX_REG(ha
, reg
, 0);
657 goto chip_diag_failed
;
659 /* Check product ID of chip */
660 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
662 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
663 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
664 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
665 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
666 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
667 mb
[3] != PROD_ID_3
) {
668 qla_printk(KERN_WARNING
, ha
,
669 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
671 goto chip_diag_failed
;
673 ha
->product_id
[0] = mb
[1];
674 ha
->product_id
[1] = mb
[2];
675 ha
->product_id
[2] = mb
[3];
676 ha
->product_id
[3] = mb
[4];
678 /* Adjust fw RISC transfer size */
679 if (req
->length
> 1024)
680 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
682 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
685 if (IS_QLA2200(ha
) &&
686 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
687 /* Limit firmware transfer size with a 2200A */
688 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
691 ha
->device_type
|= DT_ISP2200A
;
692 ha
->fw_transfer_size
= 128;
695 /* Wrap Incoming Mailboxes Test. */
696 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
698 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
699 rval
= qla2x00_mbx_reg_test(vha
);
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
703 qla_printk(KERN_WARNING
, ha
,
704 "Failed mailbox send register test\n");
707 /* Flag a successful rval */
710 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
714 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
715 "****\n", vha
->host_no
));
717 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
723 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
726 * Returns 0 on success.
729 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
732 struct qla_hw_data
*ha
= vha
->hw
;
733 struct req_que
*req
= ha
->req_q_map
[0];
735 /* Perform RISC reset. */
736 qla24xx_reset_risc(vha
);
738 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
740 rval
= qla2x00_mbx_reg_test(vha
);
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
744 qla_printk(KERN_WARNING
, ha
,
745 "Failed mailbox send register test\n");
747 /* Flag a successful rval */
755 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
758 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
759 eft_size
, fce_size
, mq_size
;
762 struct qla_hw_data
*ha
= vha
->hw
;
763 struct req_que
*req
= ha
->req_q_map
[0];
764 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
767 qla_printk(KERN_WARNING
, ha
,
768 "Firmware dump previously allocated.\n");
773 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
774 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
775 fixed_size
= sizeof(struct qla2100_fw_dump
);
776 } else if (IS_QLA23XX(ha
)) {
777 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
778 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
780 } else if (IS_FWI2_CAPABLE(ha
)) {
781 fixed_size
= IS_QLA25XX(ha
) ?
782 offsetof(struct qla25xx_fw_dump
, ext_mem
) :
783 offsetof(struct qla24xx_fw_dump
, ext_mem
);
784 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
787 mq_size
= sizeof(struct qla2xxx_mq_chain
);
789 /* Allocate memory for Fibre Channel Event Buffer. */
793 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
796 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
797 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
801 memset(tc
, 0, FCE_SIZE
);
802 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
803 ha
->fce_mb
, &ha
->fce_bufs
);
805 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
806 "FCE (%d).\n", rval
);
807 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
809 ha
->flags
.fce_enabled
= 0;
813 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
816 fce_size
= sizeof(struct qla2xxx_fce_chain
) + EFT_SIZE
;
817 ha
->flags
.fce_enabled
= 1;
818 ha
->fce_dma
= tc_dma
;
821 /* Allocate memory for Extended Trace Buffer. */
822 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
825 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
826 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
830 memset(tc
, 0, EFT_SIZE
);
831 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
833 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
834 "EFT (%d).\n", rval
);
835 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
840 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
844 ha
->eft_dma
= tc_dma
;
848 req_q_size
= req
->length
* sizeof(request_t
);
849 rsp_q_size
= rsp
->length
* sizeof(response_t
);
851 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
852 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
854 ha
->chain_offset
= dump_size
;
855 dump_size
+= mq_size
+ fce_size
;
857 ha
->fw_dump
= vmalloc(dump_size
);
859 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
860 "firmware dump!!!\n", dump_size
/ 1024);
863 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
870 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
873 ha
->fw_dump_len
= dump_size
;
874 ha
->fw_dump
->signature
[0] = 'Q';
875 ha
->fw_dump
->signature
[1] = 'L';
876 ha
->fw_dump
->signature
[2] = 'G';
877 ha
->fw_dump
->signature
[3] = 'C';
878 ha
->fw_dump
->version
= __constant_htonl(1);
880 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
881 ha
->fw_dump
->mem_size
= htonl(mem_size
);
882 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
883 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
885 ha
->fw_dump
->eft_size
= htonl(eft_size
);
886 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
887 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
889 ha
->fw_dump
->header_size
=
890 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
894 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
897 * Returns 0 on success.
900 qla2x00_resize_request_q(scsi_qla_host_t
*vha
)
903 uint16_t fw_iocb_cnt
= 0;
904 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
905 dma_addr_t request_dma
;
906 request_t
*request_ring
;
907 struct qla_hw_data
*ha
= vha
->hw
;
908 struct req_que
*req
= ha
->req_q_map
[0];
910 /* Valid only on recent ISPs. */
911 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
914 /* Retrieve IOCB counts available to the firmware. */
915 rval
= qla2x00_get_resource_cnts(vha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
,
916 &ha
->max_npiv_vports
);
919 /* No point in continuing if current settings are sufficient. */
920 if (fw_iocb_cnt
< 1024)
922 if (req
->length
>= request_q_length
)
925 /* Attempt to claim larger area for request queue. */
926 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
927 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
929 if (request_ring
== NULL
)
932 /* Resize successful, report extensions. */
933 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
934 (ha
->fw_memory_size
+ 1) / 1024);
935 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
936 "(%d -> %d)...\n", req
->length
, request_q_length
);
938 /* Clear old allocations. */
939 dma_free_coherent(&ha
->pdev
->dev
,
940 (req
->length
+ 1) * sizeof(request_t
), req
->ring
,
943 /* Begin using larger queue. */
944 req
->length
= request_q_length
;
945 req
->ring
= request_ring
;
946 req
->dma
= request_dma
;
950 * qla2x00_setup_chip() - Load and start RISC firmware.
953 * Returns 0 on success.
956 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
959 uint32_t srisc_address
= 0;
960 struct qla_hw_data
*ha
= vha
->hw
;
961 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
964 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
965 /* Disable SRAM, Instruction RAM and GP RAM parity. */
966 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
967 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
968 RD_REG_WORD(®
->hccr
);
969 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
972 /* Load firmware sequences */
973 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
974 if (rval
== QLA_SUCCESS
) {
975 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
976 "code.\n", vha
->host_no
));
978 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
979 if (rval
== QLA_SUCCESS
) {
980 /* Start firmware execution. */
981 DEBUG(printk("scsi(%ld): Checksum OK, start "
982 "firmware.\n", vha
->host_no
));
984 rval
= qla2x00_execute_fw(vha
, srisc_address
);
985 /* Retrieve firmware information. */
986 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
987 qla2x00_get_fw_version(vha
,
988 &ha
->fw_major_version
,
989 &ha
->fw_minor_version
,
990 &ha
->fw_subminor_version
,
991 &ha
->fw_attributes
, &ha
->fw_memory_size
);
992 ha
->flags
.npiv_supported
= 0;
993 if (IS_QLA2XXX_MIDTYPE(ha
) &&
994 (ha
->fw_attributes
& BIT_2
)) {
995 ha
->flags
.npiv_supported
= 1;
996 if ((!ha
->max_npiv_vports
) ||
997 ((ha
->max_npiv_vports
+ 1) %
998 MIN_MULTI_ID_FABRIC
))
999 ha
->max_npiv_vports
=
1000 MIN_MULTI_ID_FABRIC
- 1;
1002 qla2x00_resize_request_q(vha
);
1004 if (ql2xallocfwdump
)
1005 qla2x00_alloc_fw_dump(vha
);
1008 DEBUG2(printk(KERN_INFO
1009 "scsi(%ld): ISP Firmware failed checksum.\n",
1014 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1015 /* Enable proper parity. */
1016 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1019 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1021 /* SRAM, Instruction RAM and GP RAM parity */
1022 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1023 RD_REG_WORD(®
->hccr
);
1024 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1028 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1036 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1039 * Beginning of request ring has initialization control block already built
1040 * by nvram config routine.
1042 * Returns 0 on success.
1045 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1050 pkt
= rsp
->ring_ptr
;
1051 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1052 pkt
->signature
= RESPONSE_PROCESSED
;
1059 * qla2x00_update_fw_options() - Read and process firmware options.
1062 * Returns 0 on success.
1065 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1067 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1068 struct qla_hw_data
*ha
= vha
->hw
;
1070 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1071 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1073 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1076 /* Serial Link options. */
1077 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1079 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1080 sizeof(ha
->fw_seriallink_options
)));
1082 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1083 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1084 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1087 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1088 emphasis
= (ha
->fw_seriallink_options
[2] &
1089 (BIT_4
| BIT_3
)) >> 3;
1090 tx_sens
= ha
->fw_seriallink_options
[0] &
1091 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1092 rx_sens
= (ha
->fw_seriallink_options
[0] &
1093 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1094 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1095 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1098 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1099 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1100 ha
->fw_options
[10] |= BIT_5
|
1101 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1102 (tx_sens
& (BIT_1
| BIT_0
));
1105 swing
= (ha
->fw_seriallink_options
[2] &
1106 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1107 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1108 tx_sens
= ha
->fw_seriallink_options
[1] &
1109 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1110 rx_sens
= (ha
->fw_seriallink_options
[1] &
1111 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1112 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1113 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1116 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1117 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1118 ha
->fw_options
[11] |= BIT_5
|
1119 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1120 (tx_sens
& (BIT_1
| BIT_0
));
1124 /* Return command IOCBs without waiting for an ABTS to complete. */
1125 ha
->fw_options
[3] |= BIT_13
;
1128 if (ha
->flags
.enable_led_scheme
)
1129 ha
->fw_options
[2] |= BIT_12
;
1131 /* Detect ISP6312. */
1133 ha
->fw_options
[2] |= BIT_13
;
1135 /* Update firmware options. */
1136 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1140 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1143 struct qla_hw_data
*ha
= vha
->hw
;
1145 /* Update Serial Link options. */
1146 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1149 rval
= qla2x00_set_serdes_params(vha
,
1150 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1151 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1152 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1153 if (rval
!= QLA_SUCCESS
) {
1154 qla_printk(KERN_WARNING
, ha
,
1155 "Unable to update Serial Link options (%x).\n", rval
);
1160 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1162 struct qla_hw_data
*ha
= vha
->hw
;
1163 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1164 struct req_que
*req
= ha
->req_q_map
[0];
1165 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1167 /* Setup ring parameters in initialization control block. */
1168 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1169 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1170 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1171 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1172 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1173 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1174 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1175 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1177 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1178 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1179 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1180 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1181 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1185 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1187 struct qla_hw_data
*ha
= vha
->hw
;
1188 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1189 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1190 struct qla_msix_entry
*msix
;
1191 struct init_cb_24xx
*icb
;
1193 struct req_que
*req
= ha
->req_q_map
[0];
1194 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1196 /* Setup ring parameters in initialization control block. */
1197 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1198 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1199 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1200 icb
->request_q_length
= cpu_to_le16(req
->length
);
1201 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1202 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1203 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1204 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1205 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1208 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1209 icb
->rid
= __constant_cpu_to_le16(rid
);
1210 if (ha
->flags
.msix_enabled
) {
1211 msix
= &ha
->msix_entries
[1];
1212 DEBUG2_17(printk(KERN_INFO
1213 "Reistering vector 0x%x for base que\n", msix
->entry
));
1214 icb
->msix
= cpu_to_le16(msix
->entry
);
1216 /* Use alternate PCI bus number */
1218 icb
->firmware_options_2
|=
1219 __constant_cpu_to_le32(BIT_19
);
1220 /* Use alternate PCI devfn */
1222 icb
->firmware_options_2
|=
1223 __constant_cpu_to_le32(BIT_18
);
1225 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_22
);
1226 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1227 ha
->rsp_q_map
[0]->options
= icb
->firmware_options_2
;
1229 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1230 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1231 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1232 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1234 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1235 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1236 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1237 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1240 RD_REG_DWORD(&ioreg
->hccr
);
1244 * qla2x00_init_rings() - Initializes firmware.
1247 * Beginning of request ring has initialization control block already built
1248 * by nvram config routine.
1250 * Returns 0 on success.
1253 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1256 unsigned long flags
= 0;
1258 struct qla_hw_data
*ha
= vha
->hw
;
1259 struct req_que
*req
= ha
->req_q_map
[0];
1260 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1261 struct mid_init_cb_24xx
*mid_init_cb
=
1262 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1264 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1266 /* Clear outstanding commands array. */
1267 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1268 req
->outstanding_cmds
[cnt
] = NULL
;
1270 req
->current_outstanding_cmd
= 0;
1272 /* Clear RSCN queue. */
1273 vha
->rscn_in_ptr
= 0;
1274 vha
->rscn_out_ptr
= 0;
1276 /* Initialize firmware. */
1277 req
->ring_ptr
= req
->ring
;
1278 req
->ring_index
= 0;
1279 req
->cnt
= req
->length
;
1280 rsp
->ring_ptr
= rsp
->ring
;
1281 rsp
->ring_index
= 0;
1283 /* Initialize response queue entries */
1284 qla2x00_init_response_q_entries(rsp
);
1286 ha
->isp_ops
->config_rings(vha
);
1288 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1290 /* Update any ISP specific firmware options before initialization. */
1291 ha
->isp_ops
->update_fw_options(vha
);
1293 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1295 if (ha
->flags
.npiv_supported
)
1296 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1298 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1300 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1302 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1305 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1313 * qla2x00_fw_ready() - Waits for firmware ready.
1316 * Returns 0 on success.
1319 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1322 unsigned long wtime
, mtime
, cs84xx_time
;
1323 uint16_t min_wait
; /* Minimum wait time if loop is down */
1324 uint16_t wait_time
; /* Wait time if loop is coming ready */
1326 struct qla_hw_data
*ha
= vha
->hw
;
1330 /* 20 seconds for loop down. */
1334 * Firmware should take at most one RATOV to login, plus 5 seconds for
1335 * our own processing.
1337 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1338 wait_time
= min_wait
;
1341 /* Min wait time if loop down */
1342 mtime
= jiffies
+ (min_wait
* HZ
);
1344 /* wait time before firmware ready */
1345 wtime
= jiffies
+ (wait_time
* HZ
);
1347 /* Wait for ISP to finish LIP */
1348 if (!vha
->flags
.init_done
)
1349 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1351 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1355 rval
= qla2x00_get_firmware_state(vha
, state
);
1356 if (rval
== QLA_SUCCESS
) {
1357 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1358 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1360 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1361 DEBUG16(printk("scsi(%ld): fw_state=%x "
1362 "84xx=%x.\n", vha
->host_no
, state
[0],
1364 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1365 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1366 DEBUG16(printk("scsi(%ld): Sending "
1367 "verify iocb.\n", vha
->host_no
));
1369 cs84xx_time
= jiffies
;
1370 rval
= qla84xx_init_chip(vha
);
1371 if (rval
!= QLA_SUCCESS
)
1374 /* Add time taken to initialize. */
1375 cs84xx_time
= jiffies
- cs84xx_time
;
1376 wtime
+= cs84xx_time
;
1377 mtime
+= cs84xx_time
;
1378 DEBUG16(printk("scsi(%ld): Increasing "
1379 "wait time by %ld. New time %ld\n",
1380 vha
->host_no
, cs84xx_time
, wtime
));
1382 } else if (state
[0] == FSTATE_READY
) {
1383 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1386 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1387 &ha
->login_timeout
, &ha
->r_a_tov
);
1393 rval
= QLA_FUNCTION_FAILED
;
1395 if (atomic_read(&vha
->loop_down_timer
) &&
1396 state
[0] != FSTATE_READY
) {
1397 /* Loop down. Timeout on min_wait for states
1398 * other than Wait for Login.
1400 if (time_after_eq(jiffies
, mtime
)) {
1401 qla_printk(KERN_INFO
, ha
,
1402 "Cable is unplugged...\n");
1404 vha
->device_flags
|= DFLG_NO_CABLE
;
1409 /* Mailbox cmd failed. Timeout on min_wait. */
1410 if (time_after_eq(jiffies
, mtime
))
1414 if (time_after_eq(jiffies
, wtime
))
1417 /* Delay for a while */
1420 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1421 vha
->host_no
, state
[0], jiffies
));
1424 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1425 vha
->host_no
, state
[0], jiffies
));
1428 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1436 * qla2x00_configure_hba
1437 * Setup adapter context.
1440 * ha = adapter state pointer.
1449 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1458 char connect_type
[22];
1459 struct qla_hw_data
*ha
= vha
->hw
;
1461 /* Get host addresses. */
1462 rval
= qla2x00_get_adapter_id(vha
,
1463 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1464 if (rval
!= QLA_SUCCESS
) {
1465 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
1466 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1467 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1468 __func__
, vha
->host_no
));
1470 qla_printk(KERN_WARNING
, ha
,
1471 "ERROR -- Unable to get host loop ID.\n");
1472 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1478 qla_printk(KERN_INFO
, ha
,
1479 "Cannot get topology - retrying.\n");
1480 return (QLA_FUNCTION_FAILED
);
1483 vha
->loop_id
= loop_id
;
1486 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1487 ha
->operating_mode
= LOOP
;
1492 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1494 ha
->current_topology
= ISP_CFG_NL
;
1495 strcpy(connect_type
, "(Loop)");
1499 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1501 ha
->switch_cap
= sw_cap
;
1502 ha
->current_topology
= ISP_CFG_FL
;
1503 strcpy(connect_type
, "(FL_Port)");
1507 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1509 ha
->operating_mode
= P2P
;
1510 ha
->current_topology
= ISP_CFG_N
;
1511 strcpy(connect_type
, "(N_Port-to-N_Port)");
1515 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1517 ha
->switch_cap
= sw_cap
;
1518 ha
->operating_mode
= P2P
;
1519 ha
->current_topology
= ISP_CFG_F
;
1520 strcpy(connect_type
, "(F_Port)");
1524 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1526 vha
->host_no
, topo
));
1527 ha
->current_topology
= ISP_CFG_NL
;
1528 strcpy(connect_type
, "(Loop)");
1532 /* Save Host port and loop ID. */
1533 /* byte order - Big Endian */
1534 vha
->d_id
.b
.domain
= domain
;
1535 vha
->d_id
.b
.area
= area
;
1536 vha
->d_id
.b
.al_pa
= al_pa
;
1538 if (!vha
->flags
.init_done
)
1539 qla_printk(KERN_INFO
, ha
,
1540 "Topology - %s, Host Loop address 0x%x\n",
1541 connect_type
, vha
->loop_id
);
1544 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
1546 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
1553 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
1558 struct qla_hw_data
*ha
= vha
->hw
;
1560 if (memcmp(model
, BINZERO
, len
) != 0) {
1561 strncpy(ha
->model_number
, model
, len
);
1562 st
= en
= ha
->model_number
;
1565 if (*en
!= 0x20 && *en
!= 0x00)
1570 index
= (ha
->pdev
->subsystem_device
& 0xff);
1571 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1572 index
< QLA_MODEL_NAMES
)
1573 strncpy(ha
->model_desc
,
1574 qla2x00_model_name
[index
* 2 + 1],
1575 sizeof(ha
->model_desc
) - 1);
1577 index
= (ha
->pdev
->subsystem_device
& 0xff);
1578 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1579 index
< QLA_MODEL_NAMES
) {
1580 strcpy(ha
->model_number
,
1581 qla2x00_model_name
[index
* 2]);
1582 strncpy(ha
->model_desc
,
1583 qla2x00_model_name
[index
* 2 + 1],
1584 sizeof(ha
->model_desc
) - 1);
1586 strcpy(ha
->model_number
, def
);
1589 if (IS_FWI2_CAPABLE(ha
))
1590 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
1591 sizeof(ha
->model_desc
));
1594 /* On sparc systems, obtain port and node WWN from firmware
1597 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
1600 struct qla_hw_data
*ha
= vha
->hw
;
1601 struct pci_dev
*pdev
= ha
->pdev
;
1602 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1606 val
= of_get_property(dp
, "port-wwn", &len
);
1607 if (val
&& len
>= WWN_SIZE
)
1608 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1610 val
= of_get_property(dp
, "node-wwn", &len
);
1611 if (val
&& len
>= WWN_SIZE
)
1612 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1617 * NVRAM configuration for ISP 2xxx
1620 * ha = adapter block pointer.
1623 * initialization control block in response_ring
1624 * host adapters parameters in host adapter block
1630 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
1635 uint8_t *dptr1
, *dptr2
;
1636 struct qla_hw_data
*ha
= vha
->hw
;
1637 init_cb_t
*icb
= ha
->init_cb
;
1638 nvram_t
*nv
= ha
->nvram
;
1639 uint8_t *ptr
= ha
->nvram
;
1640 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1644 /* Determine NVRAM starting address. */
1645 ha
->nvram_size
= sizeof(nvram_t
);
1647 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1648 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1649 ha
->nvram_base
= 0x80;
1651 /* Get NVRAM data and calculate checksum. */
1652 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1653 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1656 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
1657 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
1659 /* Bad NVRAM data, set defaults parameters. */
1660 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1661 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1662 /* Reset NVRAM data. */
1663 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1664 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1666 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1667 "invalid -- WWPN) defaults.\n");
1670 * Set default initialization control block.
1672 memset(nv
, 0, ha
->nvram_size
);
1673 nv
->parameter_block_version
= ICB_VERSION
;
1675 if (IS_QLA23XX(ha
)) {
1676 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1677 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1678 nv
->add_firmware_options
[0] = BIT_5
;
1679 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1680 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1681 nv
->special_options
[1] = BIT_7
;
1682 } else if (IS_QLA2200(ha
)) {
1683 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1684 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1685 nv
->add_firmware_options
[0] = BIT_5
;
1686 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1687 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1688 } else if (IS_QLA2100(ha
)) {
1689 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1690 nv
->firmware_options
[1] = BIT_5
;
1691 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1694 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1695 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1696 nv
->retry_count
= 8;
1697 nv
->retry_delay
= 1;
1699 nv
->port_name
[0] = 33;
1700 nv
->port_name
[3] = 224;
1701 nv
->port_name
[4] = 139;
1703 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
1705 nv
->login_timeout
= 4;
1708 * Set default host adapter parameters
1710 nv
->host_p
[1] = BIT_2
;
1711 nv
->reset_delay
= 5;
1712 nv
->port_down_retry_count
= 8;
1713 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1714 nv
->link_down_timeout
= 60;
1719 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1721 * The SN2 does not provide BIOS emulation which means you can't change
1722 * potentially bogus BIOS settings. Force the use of default settings
1723 * for link rate and frame size. Hope that the rest of the settings
1726 if (ia64_platform_is("sn2")) {
1727 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1729 nv
->special_options
[1] = BIT_7
;
1733 /* Reset Initialization control block */
1734 memset(icb
, 0, ha
->init_cb_size
);
1737 * Setup driver NVRAM options.
1739 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1740 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1741 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1742 nv
->firmware_options
[1] &= ~BIT_4
;
1744 if (IS_QLA23XX(ha
)) {
1745 nv
->firmware_options
[0] |= BIT_2
;
1746 nv
->firmware_options
[0] &= ~BIT_3
;
1747 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1749 if (IS_QLA2300(ha
)) {
1750 if (ha
->fb_rev
== FPM_2310
) {
1751 strcpy(ha
->model_number
, "QLA2310");
1753 strcpy(ha
->model_number
, "QLA2300");
1756 qla2x00_set_model_info(vha
, nv
->model_number
,
1757 sizeof(nv
->model_number
), "QLA23xx");
1759 } else if (IS_QLA2200(ha
)) {
1760 nv
->firmware_options
[0] |= BIT_2
;
1762 * 'Point-to-point preferred, else loop' is not a safe
1763 * connection mode setting.
1765 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1767 /* Force 'loop preferred, else point-to-point'. */
1768 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1769 nv
->add_firmware_options
[0] |= BIT_5
;
1771 strcpy(ha
->model_number
, "QLA22xx");
1772 } else /*if (IS_QLA2100(ha))*/ {
1773 strcpy(ha
->model_number
, "QLA2100");
1777 * Copy over NVRAM RISC parameter block to initialization control block.
1779 dptr1
= (uint8_t *)icb
;
1780 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1781 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1783 *dptr1
++ = *dptr2
++;
1785 /* Copy 2nd half. */
1786 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1787 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1789 *dptr1
++ = *dptr2
++;
1791 /* Use alternate WWN? */
1792 if (nv
->host_p
[1] & BIT_7
) {
1793 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1794 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1797 /* Prepare nodename */
1798 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1800 * Firmware will apply the following mask if the nodename was
1803 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1804 icb
->node_name
[0] &= 0xF0;
1808 * Set host adapter parameters.
1810 if (nv
->host_p
[0] & BIT_7
)
1811 ql2xextended_error_logging
= 1;
1812 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1813 /* Always load RISC code on non ISP2[12]00 chips. */
1814 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1815 ha
->flags
.disable_risc_code_load
= 0;
1816 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1817 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1818 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1819 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1820 ha
->flags
.disable_serdes
= 0;
1822 ha
->operating_mode
=
1823 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1825 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1826 sizeof(ha
->fw_seriallink_options
));
1828 /* save HBA serial number */
1829 ha
->serial0
= icb
->port_name
[5];
1830 ha
->serial1
= icb
->port_name
[6];
1831 ha
->serial2
= icb
->port_name
[7];
1832 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
1833 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
1835 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1837 ha
->retry_count
= nv
->retry_count
;
1839 /* Set minimum login_timeout to 4 seconds. */
1840 if (nv
->login_timeout
< ql2xlogintimeout
)
1841 nv
->login_timeout
= ql2xlogintimeout
;
1842 if (nv
->login_timeout
< 4)
1843 nv
->login_timeout
= 4;
1844 ha
->login_timeout
= nv
->login_timeout
;
1845 icb
->login_timeout
= nv
->login_timeout
;
1847 /* Set minimum RATOV to 100 tenths of a second. */
1850 ha
->loop_reset_delay
= nv
->reset_delay
;
1852 /* Link Down Timeout = 0:
1854 * When Port Down timer expires we will start returning
1855 * I/O's to OS with "DID_NO_CONNECT".
1857 * Link Down Timeout != 0:
1859 * The driver waits for the link to come up after link down
1860 * before returning I/Os to OS with "DID_NO_CONNECT".
1862 if (nv
->link_down_timeout
== 0) {
1863 ha
->loop_down_abort_time
=
1864 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1866 ha
->link_down_timeout
= nv
->link_down_timeout
;
1867 ha
->loop_down_abort_time
=
1868 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1872 * Need enough time to try and get the port back.
1874 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1875 if (qlport_down_retry
)
1876 ha
->port_down_retry_count
= qlport_down_retry
;
1877 /* Set login_retry_count */
1878 ha
->login_retry_count
= nv
->retry_count
;
1879 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1880 ha
->port_down_retry_count
> 3)
1881 ha
->login_retry_count
= ha
->port_down_retry_count
;
1882 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1883 ha
->login_retry_count
= ha
->port_down_retry_count
;
1884 if (ql2xloginretrycount
)
1885 ha
->login_retry_count
= ql2xloginretrycount
;
1887 icb
->lun_enables
= __constant_cpu_to_le16(0);
1888 icb
->command_resource_count
= 0;
1889 icb
->immediate_notify_resource_count
= 0;
1890 icb
->timeout
= __constant_cpu_to_le16(0);
1892 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1894 icb
->firmware_options
[0] &= ~BIT_3
;
1895 icb
->add_firmware_options
[0] &=
1896 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1897 icb
->add_firmware_options
[0] |= BIT_2
;
1898 icb
->response_accumulation_timer
= 3;
1899 icb
->interrupt_delay_timer
= 5;
1901 vha
->flags
.process_response_queue
= 1;
1904 if (!vha
->flags
.init_done
) {
1905 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1906 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1907 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1908 icb
->interrupt_delay_timer
: 2;
1910 icb
->add_firmware_options
[0] &=
1911 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1912 vha
->flags
.process_response_queue
= 0;
1913 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1914 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1916 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1917 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
1918 ha
->zio_timer
* 100));
1919 qla_printk(KERN_INFO
, ha
,
1920 "ZIO mode %d enabled; timer delay (%d us).\n",
1921 ha
->zio_mode
, ha
->zio_timer
* 100);
1923 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1924 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1925 vha
->flags
.process_response_queue
= 1;
1930 DEBUG2_3(printk(KERN_WARNING
1931 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
1937 qla2x00_rport_del(void *data
)
1939 fc_port_t
*fcport
= data
;
1940 struct fc_rport
*rport
;
1942 spin_lock_irq(fcport
->vha
->host
->host_lock
);
1943 rport
= fcport
->drport
;
1944 fcport
->drport
= NULL
;
1945 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
1947 fc_remote_port_delete(rport
);
1951 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1953 * @flags: allocation flags
1955 * Returns a pointer to the allocated fcport, or NULL, if none available.
1958 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
1962 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
1966 /* Setup fcport template structure. */
1968 fcport
->vp_idx
= vha
->vp_idx
;
1969 fcport
->port_type
= FCT_UNKNOWN
;
1970 fcport
->loop_id
= FC_NO_LOOP_ID
;
1971 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1972 fcport
->flags
= FCF_RLC_SUPPORT
;
1973 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1979 * qla2x00_configure_loop
1980 * Updates Fibre Channel Device Database with what is actually on loop.
1983 * ha = adapter block pointer.
1988 * 2 = database was full and device was not configured.
1991 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
1994 unsigned long flags
, save_flags
;
1995 struct qla_hw_data
*ha
= vha
->hw
;
1998 /* Get Initiator ID */
1999 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2000 rval
= qla2x00_configure_hba(vha
);
2001 if (rval
!= QLA_SUCCESS
) {
2002 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2008 save_flags
= flags
= vha
->dpc_flags
;
2009 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2010 vha
->host_no
, flags
));
2013 * If we have both an RSCN and PORT UPDATE pending then handle them
2014 * both at the same time.
2016 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2017 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2019 /* Determine what we need to do */
2020 if (ha
->current_topology
== ISP_CFG_FL
&&
2021 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2023 vha
->flags
.rscn_queue_overflow
= 1;
2024 set_bit(RSCN_UPDATE
, &flags
);
2026 } else if (ha
->current_topology
== ISP_CFG_F
&&
2027 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2029 vha
->flags
.rscn_queue_overflow
= 1;
2030 set_bit(RSCN_UPDATE
, &flags
);
2031 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2033 } else if (ha
->current_topology
== ISP_CFG_N
) {
2034 clear_bit(RSCN_UPDATE
, &flags
);
2036 } else if (!vha
->flags
.online
||
2037 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2039 vha
->flags
.rscn_queue_overflow
= 1;
2040 set_bit(RSCN_UPDATE
, &flags
);
2041 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2044 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2045 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2046 rval
= QLA_FUNCTION_FAILED
;
2048 rval
= qla2x00_configure_local_loop(vha
);
2051 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2052 if (LOOP_TRANSITION(vha
))
2053 rval
= QLA_FUNCTION_FAILED
;
2055 rval
= qla2x00_configure_fabric(vha
);
2058 if (rval
== QLA_SUCCESS
) {
2059 if (atomic_read(&vha
->loop_down_timer
) ||
2060 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2061 rval
= QLA_FUNCTION_FAILED
;
2063 atomic_set(&vha
->loop_state
, LOOP_READY
);
2065 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2070 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2071 __func__
, vha
->host_no
));
2073 DEBUG3(printk("%s: exiting normally\n", __func__
));
2076 /* Restore state if a resync event occurred during processing */
2077 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2078 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2079 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2080 if (test_bit(RSCN_UPDATE
, &save_flags
))
2081 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2090 * qla2x00_configure_local_loop
2091 * Updates Fibre Channel Device Database with local loop devices.
2094 * ha = adapter block pointer.
2100 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2105 fc_port_t
*fcport
, *new_fcport
;
2111 uint8_t domain
, area
, al_pa
;
2112 struct qla_hw_data
*ha
= vha
->hw
;
2116 entries
= MAX_FIBRE_DEVICES
;
2118 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2119 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2121 /* Get list of logged in devices. */
2122 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2123 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2125 if (rval
!= QLA_SUCCESS
)
2126 goto cleanup_allocation
;
2128 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2129 ha
->host_no
, entries
));
2130 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2131 entries
* sizeof(struct gid_list_info
)));
2133 /* Allocate temporary fcport for any new fcports discovered. */
2134 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2135 if (new_fcport
== NULL
) {
2136 rval
= QLA_MEMORY_ALLOC_FAILED
;
2137 goto cleanup_allocation
;
2139 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2142 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2144 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2145 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2146 fcport
->port_type
!= FCT_BROADCAST
&&
2147 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2149 DEBUG(printk("scsi(%ld): Marking port lost, "
2151 vha
->host_no
, fcport
->loop_id
));
2153 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2154 fcport
->flags
&= ~FCF_FARP_DONE
;
2158 /* Add devices to port list. */
2159 id_iter
= (char *)ha
->gid_list
;
2160 for (index
= 0; index
< entries
; index
++) {
2161 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2162 area
= ((struct gid_list_info
*)id_iter
)->area
;
2163 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2164 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2165 loop_id
= (uint16_t)
2166 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2168 loop_id
= le16_to_cpu(
2169 ((struct gid_list_info
*)id_iter
)->loop_id
);
2170 id_iter
+= ha
->gid_list_info_size
;
2172 /* Bypass reserved domain fields. */
2173 if ((domain
& 0xf0) == 0xf0)
2176 /* Bypass if not same domain and area of adapter. */
2177 if (area
&& domain
&&
2178 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2181 /* Bypass invalid local loop ID. */
2182 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2185 /* Fill in member data. */
2186 new_fcport
->d_id
.b
.domain
= domain
;
2187 new_fcport
->d_id
.b
.area
= area
;
2188 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2189 new_fcport
->loop_id
= loop_id
;
2190 new_fcport
->vp_idx
= vha
->vp_idx
;
2191 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2192 if (rval2
!= QLA_SUCCESS
) {
2193 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2194 "information -- get_port_database=%x, "
2196 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2197 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2199 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2203 /* Check for matching device in port list. */
2206 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2207 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2211 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2212 FCF_PERSISTENT_BOUND
);
2213 fcport
->loop_id
= new_fcport
->loop_id
;
2214 fcport
->port_type
= new_fcport
->port_type
;
2215 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2216 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2224 /* New device, add to fcports list. */
2225 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2227 new_fcport
->vha
= vha
;
2228 new_fcport
->vp_idx
= vha
->vp_idx
;
2230 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2232 /* Allocate a new replacement fcport. */
2233 fcport
= new_fcport
;
2234 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2235 if (new_fcport
== NULL
) {
2236 rval
= QLA_MEMORY_ALLOC_FAILED
;
2237 goto cleanup_allocation
;
2239 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2242 /* Base iIDMA settings on HBA port speed. */
2243 fcport
->fp_speed
= ha
->link_data_rate
;
2245 qla2x00_update_fcport(vha
, fcport
);
2253 if (rval
!= QLA_SUCCESS
) {
2254 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2255 "rval=%x\n", vha
->host_no
, rval
));
2259 vha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2260 vha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2267 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2269 #define LS_UNKNOWN 2
2270 static char *link_speeds
[5] = { "1", "2", "?", "4", "8" };
2273 struct qla_hw_data
*ha
= vha
->hw
;
2275 if (!IS_IIDMA_CAPABLE(ha
))
2278 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2279 fcport
->fp_speed
> ha
->link_data_rate
)
2282 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2284 if (rval
!= QLA_SUCCESS
) {
2285 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2286 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2287 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2288 fcport
->port_name
[2], fcport
->port_name
[3],
2289 fcport
->port_name
[4], fcport
->port_name
[5],
2290 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2291 fcport
->fp_speed
, mb
[0], mb
[1]));
2293 DEBUG2(qla_printk(KERN_INFO
, ha
,
2294 "iIDMA adjusted to %s GB/s on "
2295 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2296 link_speeds
[fcport
->fp_speed
], fcport
->port_name
[0],
2297 fcport
->port_name
[1], fcport
->port_name
[2],
2298 fcport
->port_name
[3], fcport
->port_name
[4],
2299 fcport
->port_name
[5], fcport
->port_name
[6],
2300 fcport
->port_name
[7]));
2305 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2307 struct fc_rport_identifiers rport_ids
;
2308 struct fc_rport
*rport
;
2309 struct qla_hw_data
*ha
= vha
->hw
;
2312 qla2x00_rport_del(fcport
);
2314 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2315 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2316 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2317 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2318 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2319 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2321 qla_printk(KERN_WARNING
, ha
,
2322 "Unable to allocate fc remote port!\n");
2325 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2326 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2327 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2329 rport
->supported_classes
= fcport
->supported_classes
;
2331 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2332 if (fcport
->port_type
== FCT_INITIATOR
)
2333 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2334 if (fcport
->port_type
== FCT_TARGET
)
2335 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2336 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2340 * qla2x00_update_fcport
2341 * Updates device on list.
2344 * ha = adapter block pointer.
2345 * fcport = port structure pointer.
2355 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2357 struct qla_hw_data
*ha
= vha
->hw
;
2360 fcport
->login_retry
= 0;
2361 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2363 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2365 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2367 qla2x00_iidma_fcport(vha
, fcport
);
2369 atomic_set(&fcport
->state
, FCS_ONLINE
);
2371 qla2x00_reg_remote_port(vha
, fcport
);
2375 * qla2x00_configure_fabric
2376 * Setup SNS devices with loop ID's.
2379 * ha = adapter block pointer.
2386 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2389 fc_port_t
*fcport
, *fcptemp
;
2390 uint16_t next_loopid
;
2391 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2393 LIST_HEAD(new_fcports
);
2394 struct qla_hw_data
*ha
= vha
->hw
;
2395 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2397 /* If FL port exists, then SNS is present */
2398 if (IS_FWI2_CAPABLE(ha
))
2399 loop_id
= NPH_F_PORT
;
2401 loop_id
= SNS_FL_PORT
;
2402 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2403 if (rval
!= QLA_SUCCESS
) {
2404 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2405 "Port\n", vha
->host_no
));
2407 vha
->device_flags
&= ~SWITCH_FOUND
;
2408 return (QLA_SUCCESS
);
2410 vha
->device_flags
|= SWITCH_FOUND
;
2412 /* Mark devices that need re-synchronization. */
2413 rval2
= qla2x00_device_resync(vha
);
2414 if (rval2
== QLA_RSCNS_HANDLED
) {
2415 /* No point doing the scan, just continue. */
2416 return (QLA_SUCCESS
);
2420 if (ql2xfdmienable
&&
2421 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2422 qla2x00_fdmi_register(vha
);
2424 /* Ensure we are logged into the SNS. */
2425 if (IS_FWI2_CAPABLE(ha
))
2428 loop_id
= SIMPLE_NAME_SERVER
;
2429 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2430 0xfc, mb
, BIT_1
| BIT_0
);
2431 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2432 DEBUG2(qla_printk(KERN_INFO
, ha
,
2433 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2434 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2435 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2436 return (QLA_SUCCESS
);
2439 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
2440 if (qla2x00_rft_id(vha
)) {
2442 DEBUG2(printk("scsi(%ld): Register FC-4 "
2443 "TYPE failed.\n", vha
->host_no
));
2445 if (qla2x00_rff_id(vha
)) {
2447 DEBUG2(printk("scsi(%ld): Register FC-4 "
2448 "Features failed.\n", vha
->host_no
));
2450 if (qla2x00_rnn_id(vha
)) {
2452 DEBUG2(printk("scsi(%ld): Register Node Name "
2453 "failed.\n", vha
->host_no
));
2454 } else if (qla2x00_rsnn_nn(vha
)) {
2456 DEBUG2(printk("scsi(%ld): Register Symbolic "
2457 "Node Name failed.\n", vha
->host_no
));
2461 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
2462 if (rval
!= QLA_SUCCESS
)
2466 * Logout all previous fabric devices marked lost, except
2469 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2470 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2473 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2476 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2477 qla2x00_mark_device_lost(vha
, fcport
,
2478 ql2xplogiabsentdevice
, 0);
2479 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2480 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2481 fcport
->port_type
!= FCT_INITIATOR
&&
2482 fcport
->port_type
!= FCT_BROADCAST
) {
2483 ha
->isp_ops
->fabric_logout(vha
,
2485 fcport
->d_id
.b
.domain
,
2486 fcport
->d_id
.b
.area
,
2487 fcport
->d_id
.b
.al_pa
);
2488 fcport
->loop_id
= FC_NO_LOOP_ID
;
2493 /* Starting free loop ID. */
2494 next_loopid
= ha
->min_external_loopid
;
2497 * Scan through our port list and login entries that need to be
2500 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2501 if (atomic_read(&vha
->loop_down_timer
) ||
2502 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2505 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2506 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2509 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2510 fcport
->loop_id
= next_loopid
;
2511 rval
= qla2x00_find_new_loop_id(
2513 if (rval
!= QLA_SUCCESS
) {
2514 /* Ran out of IDs to use */
2518 /* Login and update database */
2519 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2522 /* Exit if out of loop IDs. */
2523 if (rval
!= QLA_SUCCESS
) {
2528 * Login and add the new devices to our port list.
2530 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2531 if (atomic_read(&vha
->loop_down_timer
) ||
2532 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2535 /* Find a new loop ID to use. */
2536 fcport
->loop_id
= next_loopid
;
2537 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
2538 if (rval
!= QLA_SUCCESS
) {
2539 /* Ran out of IDs to use */
2543 /* Login and update database */
2544 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2548 fcport
->vp_idx
= vha
->vp_idx
;
2550 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
2554 /* Free all new device structures not processed. */
2555 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2556 list_del(&fcport
->list
);
2561 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2562 "rval=%d\n", vha
->host_no
, rval
));
2570 * qla2x00_find_all_fabric_devs
2573 * ha = adapter block pointer.
2574 * dev = database device entry pointer.
2583 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
2584 struct list_head
*new_fcports
)
2588 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2593 int first_dev
, last_dev
;
2594 port_id_t wrap
, nxt_d_id
;
2595 struct qla_hw_data
*ha
= vha
->hw
;
2596 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
2600 /* Try GID_PT to get device list, else GAN. */
2601 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
2604 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2605 "on GA_NXT\n", vha
->host_no
));
2607 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
2610 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
2613 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
2616 } else if (ql2xiidmaenable
&&
2617 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
2618 qla2x00_gpsc(vha
, swl
);
2623 /* Allocate temporary fcport for any new fcports discovered. */
2624 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2625 if (new_fcport
== NULL
) {
2627 return (QLA_MEMORY_ALLOC_FAILED
);
2629 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2630 /* Set start port ID scan at adapter ID. */
2634 /* Starting free loop ID. */
2635 loop_id
= ha
->min_external_loopid
;
2636 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
2637 if (qla2x00_is_reserved_id(vha
, loop_id
))
2640 if (atomic_read(&vha
->loop_down_timer
) || LOOP_TRANSITION(vha
))
2645 wrap
.b24
= new_fcport
->d_id
.b24
;
2647 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2648 memcpy(new_fcport
->node_name
,
2649 swl
[swl_idx
].node_name
, WWN_SIZE
);
2650 memcpy(new_fcport
->port_name
,
2651 swl
[swl_idx
].port_name
, WWN_SIZE
);
2652 memcpy(new_fcport
->fabric_port_name
,
2653 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2654 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2656 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2662 /* Send GA_NXT to the switch */
2663 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
2664 if (rval
!= QLA_SUCCESS
) {
2665 qla_printk(KERN_WARNING
, ha
,
2666 "SNS scan failed -- assuming zero-entry "
2668 list_for_each_entry_safe(fcport
, fcptemp
,
2669 new_fcports
, list
) {
2670 list_del(&fcport
->list
);
2678 /* If wrap on switch device list, exit. */
2680 wrap
.b24
= new_fcport
->d_id
.b24
;
2682 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2683 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2684 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
2685 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2689 /* Bypass if same physical adapter. */
2690 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
2693 /* Bypass virtual ports of the same host. */
2695 if (ha
->num_vhosts
) {
2696 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
2697 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
2706 /* Bypass if same domain and area of adapter. */
2707 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2708 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2712 /* Bypass reserved domain fields. */
2713 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2716 /* Locate matching device in database. */
2718 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2719 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2725 /* Update port state. */
2726 memcpy(fcport
->fabric_port_name
,
2727 new_fcport
->fabric_port_name
, WWN_SIZE
);
2728 fcport
->fp_speed
= new_fcport
->fp_speed
;
2731 * If address the same and state FCS_ONLINE, nothing
2734 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2735 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2740 * If device was not a fabric device before.
2742 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2743 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2744 fcport
->loop_id
= FC_NO_LOOP_ID
;
2745 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2747 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2752 * Port ID changed or device was marked to be updated;
2753 * Log it out if still logged in and mark it for
2756 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2757 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2758 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2759 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2760 fcport
->port_type
!= FCT_INITIATOR
&&
2761 fcport
->port_type
!= FCT_BROADCAST
) {
2762 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
2763 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2764 fcport
->d_id
.b
.al_pa
);
2765 fcport
->loop_id
= FC_NO_LOOP_ID
;
2773 /* If device was not in our fcports list, then add it. */
2774 list_add_tail(&new_fcport
->list
, new_fcports
);
2776 /* Allocate a new replacement fcport. */
2777 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2778 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2779 if (new_fcport
== NULL
) {
2781 return (QLA_MEMORY_ALLOC_FAILED
);
2783 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2784 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2790 if (!list_empty(new_fcports
))
2791 vha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2797 * qla2x00_find_new_loop_id
2798 * Scan through our port list and find a new usable loop ID.
2801 * ha: adapter state pointer.
2802 * dev: port structure pointer.
2805 * qla2x00 local function return status code.
2811 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
2816 uint16_t first_loop_id
;
2817 struct qla_hw_data
*ha
= vha
->hw
;
2818 struct scsi_qla_host
*vp
;
2822 /* Save starting loop ID. */
2823 first_loop_id
= dev
->loop_id
;
2826 /* Skip loop ID if already used by adapter. */
2827 if (dev
->loop_id
== vha
->loop_id
)
2830 /* Skip reserved loop IDs. */
2831 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
2834 /* Reset loop ID if passed the end. */
2835 if (dev
->loop_id
> ha
->max_loop_id
) {
2836 /* first loop ID. */
2837 dev
->loop_id
= ha
->min_external_loopid
;
2840 /* Check for loop ID being already in use. */
2843 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
2844 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
2845 if (fcport
->loop_id
== dev
->loop_id
&&
2847 /* ID possibly in use */
2856 /* If not in use then it is free to use. */
2861 /* ID in use. Try next value. */
2864 /* If wrap around. No free ID to use. */
2865 if (dev
->loop_id
== first_loop_id
) {
2866 dev
->loop_id
= FC_NO_LOOP_ID
;
2867 rval
= QLA_FUNCTION_FAILED
;
2876 * qla2x00_device_resync
2877 * Marks devices in the database that needs resynchronization.
2880 * ha = adapter block pointer.
2886 qla2x00_device_resync(scsi_qla_host_t
*vha
)
2891 uint32_t rscn_entry
;
2892 uint8_t rscn_out_iter
;
2896 rval
= QLA_RSCNS_HANDLED
;
2898 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
2899 vha
->flags
.rscn_queue_overflow
) {
2901 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
2902 format
= MSB(MSW(rscn_entry
));
2903 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2904 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2905 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2907 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2908 "[%02x/%02x%02x%02x].\n",
2909 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2910 d_id
.b
.area
, d_id
.b
.al_pa
));
2912 vha
->rscn_out_ptr
++;
2913 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2914 vha
->rscn_out_ptr
= 0;
2916 /* Skip duplicate entries. */
2917 for (rscn_out_iter
= vha
->rscn_out_ptr
;
2918 !vha
->flags
.rscn_queue_overflow
&&
2919 rscn_out_iter
!= vha
->rscn_in_ptr
;
2920 rscn_out_iter
= (rscn_out_iter
==
2921 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2923 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
2926 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2927 "entry found at [%d].\n", vha
->host_no
,
2930 vha
->rscn_out_ptr
= rscn_out_iter
;
2933 /* Queue overflow, set switch default case. */
2934 if (vha
->flags
.rscn_queue_overflow
) {
2935 DEBUG(printk("scsi(%ld): device_resync: rscn "
2936 "overflow.\n", vha
->host_no
));
2939 vha
->flags
.rscn_queue_overflow
= 0;
2955 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
2961 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2962 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2963 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2964 fcport
->port_type
== FCT_BROADCAST
)
2967 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2969 fcport
->port_type
!= FCT_INITIATOR
) {
2970 qla2x00_mark_device_lost(vha
, fcport
,
2974 fcport
->flags
&= ~FCF_FARP_DONE
;
2981 * qla2x00_fabric_dev_login
2982 * Login fabric target device and update FC port database.
2985 * ha: adapter state pointer.
2986 * fcport: port structure list pointer.
2987 * next_loopid: contains value of a new loop ID that can be used
2988 * by the next login attempt.
2991 * qla2x00 local function return status code.
2997 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
2998 uint16_t *next_loopid
)
3003 struct qla_hw_data
*ha
= vha
->hw
;
3008 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3009 if (rval
== QLA_SUCCESS
) {
3010 /* Send an ADISC to tape devices.*/
3012 if (fcport
->flags
& FCF_TAPE_PRESENT
)
3014 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3015 if (rval
!= QLA_SUCCESS
) {
3016 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3017 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3018 fcport
->d_id
.b
.al_pa
);
3019 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3021 qla2x00_update_fcport(vha
, fcport
);
3029 * qla2x00_fabric_login
3030 * Issue fabric login command.
3033 * ha = adapter block pointer.
3034 * device = pointer to FC device type structure.
3037 * 0 - Login successfully
3039 * 2 - Initiator device
3043 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3044 uint16_t *next_loopid
)
3048 uint16_t tmp_loopid
;
3049 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3050 struct qla_hw_data
*ha
= vha
->hw
;
3056 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3057 "for port %02x%02x%02x.\n",
3058 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3059 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3061 /* Login fcport on switch. */
3062 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3063 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3064 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3065 if (mb
[0] == MBS_PORT_ID_USED
) {
3067 * Device has another loop ID. The firmware team
3068 * recommends the driver perform an implicit login with
3069 * the specified ID again. The ID we just used is save
3070 * here so we return with an ID that can be tried by
3074 tmp_loopid
= fcport
->loop_id
;
3075 fcport
->loop_id
= mb
[1];
3077 DEBUG(printk("Fabric Login: port in use - next "
3078 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3079 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3080 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3082 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3087 /* A retry occurred before. */
3088 *next_loopid
= tmp_loopid
;
3091 * No retry occurred before. Just increment the
3092 * ID value for next login.
3094 *next_loopid
= (fcport
->loop_id
+ 1);
3097 if (mb
[1] & BIT_0
) {
3098 fcport
->port_type
= FCT_INITIATOR
;
3100 fcport
->port_type
= FCT_TARGET
;
3101 if (mb
[1] & BIT_1
) {
3102 fcport
->flags
|= FCF_TAPE_PRESENT
;
3107 fcport
->supported_classes
|= FC_COS_CLASS2
;
3109 fcport
->supported_classes
|= FC_COS_CLASS3
;
3113 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3115 * Loop ID already used, try next loop ID.
3118 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3119 if (rval
!= QLA_SUCCESS
) {
3120 /* Ran out of loop IDs to use */
3123 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3125 * Firmware possibly timed out during login. If NO
3126 * retries are left to do then the device is declared
3129 *next_loopid
= fcport
->loop_id
;
3130 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3131 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3132 fcport
->d_id
.b
.al_pa
);
3133 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3139 * unrecoverable / not handled error
3141 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3142 "loop_id=%x jiffies=%lx.\n",
3143 __func__
, vha
->host_no
, mb
[0],
3144 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3145 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3147 *next_loopid
= fcport
->loop_id
;
3148 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3149 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3150 fcport
->d_id
.b
.al_pa
);
3151 fcport
->loop_id
= FC_NO_LOOP_ID
;
3152 fcport
->login_retry
= 0;
3163 * qla2x00_local_device_login
3164 * Issue local device login command.
3167 * ha = adapter block pointer.
3168 * loop_id = loop id of device to login to.
3170 * Returns (Where's the #define!!!!):
3171 * 0 - Login successfully
3176 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3179 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3181 memset(mb
, 0, sizeof(mb
));
3182 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3183 if (rval
== QLA_SUCCESS
) {
3184 /* Interrogate mailbox registers for any errors */
3185 if (mb
[0] == MBS_COMMAND_ERROR
)
3187 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3188 /* device not in PCB table */
3196 * qla2x00_loop_resync
3197 * Resync with fibre channel devices.
3200 * ha = adapter block pointer.
3206 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3208 int rval
= QLA_SUCCESS
;
3210 struct qla_hw_data
*ha
= vha
->hw
;
3211 struct req_que
*req
= ha
->req_q_map
[0];
3212 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3214 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3215 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3216 if (vha
->flags
.online
) {
3217 if (!(rval
= qla2x00_fw_ready(vha
))) {
3218 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3221 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3223 /* Issue a marker after FW becomes ready. */
3224 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3226 vha
->marker_needed
= 0;
3228 /* Remap devices on Loop. */
3229 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3231 qla2x00_configure_loop(vha
);
3233 } while (!atomic_read(&vha
->loop_down_timer
) &&
3234 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3235 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3240 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3241 return (QLA_FUNCTION_FAILED
);
3244 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3250 qla2x00_update_fcports(scsi_qla_host_t
*vha
)
3254 /* Go with deferred removal of rport references. */
3255 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3256 if (fcport
&& fcport
->drport
&&
3257 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
)
3258 qla2x00_rport_del(fcport
);
3263 * Resets ISP and aborts all outstanding commands.
3266 * ha = adapter block pointer.
3272 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3276 struct qla_hw_data
*ha
= vha
->hw
;
3277 struct scsi_qla_host
*vp
;
3278 struct req_que
*req
= ha
->req_q_map
[0];
3280 if (vha
->flags
.online
) {
3281 vha
->flags
.online
= 0;
3282 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3283 ha
->qla_stats
.total_isp_aborts
++;
3285 qla_printk(KERN_INFO
, ha
,
3286 "Performing ISP error recovery - ha= %p.\n", ha
);
3287 ha
->isp_ops
->reset_chip(vha
);
3289 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3290 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3291 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3292 qla2x00_mark_all_devices_lost(vha
, 0);
3293 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3294 qla2x00_mark_all_devices_lost(vp
, 0);
3296 if (!atomic_read(&vha
->loop_down_timer
))
3297 atomic_set(&vha
->loop_down_timer
,
3301 /* Requeue all commands in outstanding command list. */
3302 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3304 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3306 ha
->isp_ops
->nvram_config(vha
);
3308 if (!qla2x00_restart_isp(vha
)) {
3309 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3311 if (!atomic_read(&vha
->loop_down_timer
)) {
3313 * Issue marker command only when we are going
3314 * to start the I/O .
3316 vha
->marker_needed
= 1;
3319 vha
->flags
.online
= 1;
3321 ha
->isp_ops
->enable_intrs(ha
);
3323 ha
->isp_abort_cnt
= 0;
3324 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3327 ha
->flags
.fce_enabled
= 1;
3329 fce_calc_size(ha
->fce_bufs
));
3330 rval
= qla2x00_enable_fce_trace(vha
,
3331 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3334 qla_printk(KERN_WARNING
, ha
,
3335 "Unable to reinitialize FCE "
3337 ha
->flags
.fce_enabled
= 0;
3342 memset(ha
->eft
, 0, EFT_SIZE
);
3343 rval
= qla2x00_enable_eft_trace(vha
,
3344 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3346 qla_printk(KERN_WARNING
, ha
,
3347 "Unable to reinitialize EFT "
3351 } else { /* failed the ISP abort */
3352 vha
->flags
.online
= 1;
3353 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3354 if (ha
->isp_abort_cnt
== 0) {
3355 qla_printk(KERN_WARNING
, ha
,
3356 "ISP error recovery failed - "
3357 "board disabled\n");
3359 * The next call disables the board
3362 ha
->isp_ops
->reset_adapter(vha
);
3363 vha
->flags
.online
= 0;
3364 clear_bit(ISP_ABORT_RETRY
,
3367 } else { /* schedule another ISP abort */
3368 ha
->isp_abort_cnt
--;
3369 DEBUG(printk("qla%ld: ISP abort - "
3370 "retry remaining %d\n",
3371 vha
->host_no
, ha
->isp_abort_cnt
));
3375 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3376 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3377 "- retrying (%d) more times\n",
3378 vha
->host_no
, ha
->isp_abort_cnt
));
3379 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3387 DEBUG(printk(KERN_INFO
3388 "qla2x00_abort_isp(%ld): succeeded.\n",
3390 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3392 qla2x00_vp_abort_isp(vp
);
3395 qla_printk(KERN_INFO
, ha
,
3396 "qla2x00_abort_isp: **** FAILED ****\n");
3403 * qla2x00_restart_isp
3404 * restarts the ISP after a reset
3407 * ha = adapter block pointer.
3413 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
3417 struct qla_hw_data
*ha
= vha
->hw
;
3418 struct req_que
*req
= ha
->req_q_map
[0];
3419 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3421 /* If firmware needs to be loaded */
3422 if (qla2x00_isp_firmware(vha
)) {
3423 vha
->flags
.online
= 0;
3424 status
= ha
->isp_ops
->chip_diag(vha
);
3426 status
= qla2x00_setup_chip(vha
);
3429 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
3430 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3431 /* Initialize the queues in use */
3432 qla25xx_init_queues(ha
);
3434 status
= qla2x00_fw_ready(vha
);
3436 DEBUG(printk("%s(): Start configure loop, "
3437 "status = %d\n", __func__
, status
));
3439 /* Issue a marker after FW becomes ready. */
3440 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
3442 vha
->flags
.online
= 1;
3443 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3446 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3447 qla2x00_configure_loop(vha
);
3449 } while (!atomic_read(&vha
->loop_down_timer
) &&
3450 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3451 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3455 /* if no cable then assume it's good */
3456 if ((vha
->device_flags
& DFLG_NO_CABLE
))
3459 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3467 qla25xx_init_queues(struct qla_hw_data
*ha
)
3469 struct rsp_que
*rsp
= NULL
;
3470 struct req_que
*req
= NULL
;
3471 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3475 for (i
= 1; i
< ha
->max_queues
; i
++) {
3476 rsp
= ha
->rsp_q_map
[i
];
3478 rsp
->options
&= ~BIT_0
;
3479 ret
= qla25xx_init_rsp_que(base_vha
, rsp
, rsp
->options
);
3480 if (ret
!= QLA_SUCCESS
)
3481 DEBUG2_17(printk(KERN_WARNING
3482 "%s Rsp que:%d init failed\n", __func__
,
3485 DEBUG2_17(printk(KERN_INFO
3486 "%s Rsp que:%d inited\n", __func__
,
3489 req
= ha
->req_q_map
[i
];
3491 req
->options
&= ~BIT_0
;
3492 ret
= qla25xx_init_req_que(base_vha
, req
, req
->options
);
3493 if (ret
!= QLA_SUCCESS
)
3494 DEBUG2_17(printk(KERN_WARNING
3495 "%s Req que:%d init failed\n", __func__
,
3498 DEBUG2_17(printk(KERN_WARNING
3499 "%s Rsp que:%d inited\n", __func__
,
3507 * qla2x00_reset_adapter
3511 * ha = adapter block pointer.
3514 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
3516 unsigned long flags
= 0;
3517 struct qla_hw_data
*ha
= vha
->hw
;
3518 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3520 vha
->flags
.online
= 0;
3521 ha
->isp_ops
->disable_intrs(ha
);
3523 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3524 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3525 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3526 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3527 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3528 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3532 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
3534 unsigned long flags
= 0;
3535 struct qla_hw_data
*ha
= vha
->hw
;
3536 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3538 vha
->flags
.online
= 0;
3539 ha
->isp_ops
->disable_intrs(ha
);
3541 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3542 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3543 RD_REG_DWORD(®
->hccr
);
3544 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3545 RD_REG_DWORD(®
->hccr
);
3546 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3549 /* On sparc systems, obtain port and node WWN from firmware
3552 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
3553 struct nvram_24xx
*nv
)
3556 struct qla_hw_data
*ha
= vha
->hw
;
3557 struct pci_dev
*pdev
= ha
->pdev
;
3558 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3562 val
= of_get_property(dp
, "port-wwn", &len
);
3563 if (val
&& len
>= WWN_SIZE
)
3564 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3566 val
= of_get_property(dp
, "node-wwn", &len
);
3567 if (val
&& len
>= WWN_SIZE
)
3568 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3573 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
3576 struct init_cb_24xx
*icb
;
3577 struct nvram_24xx
*nv
;
3579 uint8_t *dptr1
, *dptr2
;
3582 struct qla_hw_data
*ha
= vha
->hw
;
3585 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3588 /* Determine NVRAM starting address. */
3589 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3590 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3591 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3592 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3593 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3594 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3595 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3598 /* Get VPD data into cache */
3599 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
3600 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
3601 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
3603 /* Get NVRAM data into cache and calculate checksum. */
3604 dptr
= (uint32_t *)nv
;
3605 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
3607 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3608 chksum
+= le32_to_cpu(*dptr
++);
3610 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3611 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
3613 /* Bad NVRAM data, set defaults parameters. */
3614 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3615 || nv
->id
[3] != ' ' ||
3616 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3617 /* Reset NVRAM data. */
3618 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3619 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3620 le16_to_cpu(nv
->nvram_version
));
3621 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3622 "invalid -- WWPN) defaults.\n");
3625 * Set default initialization control block.
3627 memset(nv
, 0, ha
->nvram_size
);
3628 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3629 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3630 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3631 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3632 nv
->exchange_count
= __constant_cpu_to_le16(0);
3633 nv
->hard_address
= __constant_cpu_to_le16(124);
3634 nv
->port_name
[0] = 0x21;
3635 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3636 nv
->port_name
[2] = 0x00;
3637 nv
->port_name
[3] = 0xe0;
3638 nv
->port_name
[4] = 0x8b;
3639 nv
->port_name
[5] = 0x1c;
3640 nv
->port_name
[6] = 0x55;
3641 nv
->port_name
[7] = 0x86;
3642 nv
->node_name
[0] = 0x20;
3643 nv
->node_name
[1] = 0x00;
3644 nv
->node_name
[2] = 0x00;
3645 nv
->node_name
[3] = 0xe0;
3646 nv
->node_name
[4] = 0x8b;
3647 nv
->node_name
[5] = 0x1c;
3648 nv
->node_name
[6] = 0x55;
3649 nv
->node_name
[7] = 0x86;
3650 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
3651 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3652 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3653 nv
->login_timeout
= __constant_cpu_to_le16(0);
3654 nv
->firmware_options_1
=
3655 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3656 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3657 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3658 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3659 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3660 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3661 nv
->reset_delay
= 5;
3662 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3663 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3664 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3669 /* Reset Initialization control block */
3670 memset(icb
, 0, ha
->init_cb_size
);
3672 /* Copy 1st segment. */
3673 dptr1
= (uint8_t *)icb
;
3674 dptr2
= (uint8_t *)&nv
->version
;
3675 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3677 *dptr1
++ = *dptr2
++;
3679 icb
->login_retry_count
= nv
->login_retry_count
;
3680 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3682 /* Copy 2nd segment. */
3683 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3684 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3685 cnt
= (uint8_t *)&icb
->reserved_3
-
3686 (uint8_t *)&icb
->interrupt_delay_timer
;
3688 *dptr1
++ = *dptr2
++;
3691 * Setup driver NVRAM options.
3693 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
3696 /* Use alternate WWN? */
3697 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3698 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3699 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3702 /* Prepare nodename */
3703 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3705 * Firmware will apply the following mask if the nodename was
3708 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3709 icb
->node_name
[0] &= 0xF0;
3712 /* Set host adapter parameters. */
3713 ha
->flags
.disable_risc_code_load
= 0;
3714 ha
->flags
.enable_lip_reset
= 0;
3715 ha
->flags
.enable_lip_full_login
=
3716 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3717 ha
->flags
.enable_target_reset
=
3718 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3719 ha
->flags
.enable_led_scheme
= 0;
3720 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3722 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3723 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3725 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3726 sizeof(ha
->fw_seriallink_options24
));
3728 /* save HBA serial number */
3729 ha
->serial0
= icb
->port_name
[5];
3730 ha
->serial1
= icb
->port_name
[6];
3731 ha
->serial2
= icb
->port_name
[7];
3732 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
3733 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
3735 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3737 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3739 /* Set minimum login_timeout to 4 seconds. */
3740 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3741 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3742 if (le16_to_cpu(nv
->login_timeout
) < 4)
3743 nv
->login_timeout
= __constant_cpu_to_le16(4);
3744 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3745 icb
->login_timeout
= nv
->login_timeout
;
3747 /* Set minimum RATOV to 100 tenths of a second. */
3750 ha
->loop_reset_delay
= nv
->reset_delay
;
3752 /* Link Down Timeout = 0:
3754 * When Port Down timer expires we will start returning
3755 * I/O's to OS with "DID_NO_CONNECT".
3757 * Link Down Timeout != 0:
3759 * The driver waits for the link to come up after link down
3760 * before returning I/Os to OS with "DID_NO_CONNECT".
3762 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3763 ha
->loop_down_abort_time
=
3764 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3766 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3767 ha
->loop_down_abort_time
=
3768 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3771 /* Need enough time to try and get the port back. */
3772 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3773 if (qlport_down_retry
)
3774 ha
->port_down_retry_count
= qlport_down_retry
;
3776 /* Set login_retry_count */
3777 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3778 if (ha
->port_down_retry_count
==
3779 le16_to_cpu(nv
->port_down_retry_count
) &&
3780 ha
->port_down_retry_count
> 3)
3781 ha
->login_retry_count
= ha
->port_down_retry_count
;
3782 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3783 ha
->login_retry_count
= ha
->port_down_retry_count
;
3784 if (ql2xloginretrycount
)
3785 ha
->login_retry_count
= ql2xloginretrycount
;
3788 if (!vha
->flags
.init_done
) {
3789 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3790 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3791 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3792 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3794 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3795 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3796 vha
->flags
.process_response_queue
= 0;
3797 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3798 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3800 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3801 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
3802 ha
->zio_timer
* 100));
3803 qla_printk(KERN_INFO
, ha
,
3804 "ZIO mode %d enabled; timer delay (%d us).\n",
3805 ha
->zio_mode
, ha
->zio_timer
* 100);
3807 icb
->firmware_options_2
|= cpu_to_le32(
3808 (uint32_t)ha
->zio_mode
);
3809 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3810 vha
->flags
.process_response_queue
= 1;
3814 DEBUG2_3(printk(KERN_WARNING
3815 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
3821 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
3823 int rval
= QLA_SUCCESS
;
3824 int segments
, fragment
;
3826 uint32_t *dcode
, dlen
;
3830 struct qla_hw_data
*ha
= vha
->hw
;
3831 struct req_que
*req
= ha
->req_q_map
[0];
3834 segments
= FA_RISC_CODE_SEGMENTS
;
3835 faddr
= ha
->flt_region_fw
;
3836 dcode
= (uint32_t *)req
->ring
;
3839 /* Validate firmware image by checking version. */
3840 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
3841 for (i
= 0; i
< 4; i
++)
3842 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3843 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3844 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3845 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3847 qla_printk(KERN_WARNING
, ha
,
3848 "Unable to verify integrity of flash firmware image!\n");
3849 qla_printk(KERN_WARNING
, ha
,
3850 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3851 dcode
[1], dcode
[2], dcode
[3]);
3853 return QLA_FUNCTION_FAILED
;
3856 while (segments
&& rval
== QLA_SUCCESS
) {
3857 /* Read segment's load information. */
3858 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
3860 risc_addr
= be32_to_cpu(dcode
[2]);
3861 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3862 risc_size
= be32_to_cpu(dcode
[3]);
3865 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3866 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3867 if (dlen
> risc_size
)
3870 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3871 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3872 vha
->host_no
, risc_addr
, dlen
, faddr
));
3874 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
3875 for (i
= 0; i
< dlen
; i
++)
3876 dcode
[i
] = swab32(dcode
[i
]);
3878 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
3881 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3882 "segment %d of firmware\n", vha
->host_no
,
3884 qla_printk(KERN_WARNING
, ha
,
3885 "[ERROR] Failed to load segment %d of "
3886 "firmware\n", fragment
);
3903 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3906 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
3910 uint16_t *wcode
, *fwcode
;
3911 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3912 struct fw_blob
*blob
;
3913 struct qla_hw_data
*ha
= vha
->hw
;
3914 struct req_que
*req
= ha
->req_q_map
[0];
3916 /* Load firmware blob. */
3917 blob
= qla2x00_request_firmware(vha
);
3919 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3920 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3921 "from: " QLA_FW_URL
".\n");
3922 return QLA_FUNCTION_FAILED
;
3927 wcode
= (uint16_t *)req
->ring
;
3929 fwcode
= (uint16_t *)blob
->fw
->data
;
3932 /* Validate firmware image by checking version. */
3933 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3934 qla_printk(KERN_WARNING
, ha
,
3935 "Unable to verify integrity of firmware image (%Zd)!\n",
3937 goto fail_fw_integrity
;
3939 for (i
= 0; i
< 4; i
++)
3940 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3941 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3942 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3943 wcode
[2] == 0 && wcode
[3] == 0)) {
3944 qla_printk(KERN_WARNING
, ha
,
3945 "Unable to verify integrity of firmware image!\n");
3946 qla_printk(KERN_WARNING
, ha
,
3947 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3948 wcode
[1], wcode
[2], wcode
[3]);
3949 goto fail_fw_integrity
;
3953 while (*seg
&& rval
== QLA_SUCCESS
) {
3955 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3956 risc_size
= be16_to_cpu(fwcode
[3]);
3958 /* Validate firmware image size. */
3959 fwclen
+= risc_size
* sizeof(uint16_t);
3960 if (blob
->fw
->size
< fwclen
) {
3961 qla_printk(KERN_WARNING
, ha
,
3962 "Unable to verify integrity of firmware image "
3963 "(%Zd)!\n", blob
->fw
->size
);
3964 goto fail_fw_integrity
;
3968 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3969 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3970 if (wlen
> risc_size
)
3973 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3974 "addr %x, number of words 0x%x.\n", vha
->host_no
,
3977 for (i
= 0; i
< wlen
; i
++)
3978 wcode
[i
] = swab16(fwcode
[i
]);
3980 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
3983 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3984 "segment %d of firmware\n", vha
->host_no
,
3986 qla_printk(KERN_WARNING
, ha
,
3987 "[ERROR] Failed to load segment %d of "
3988 "firmware\n", fragment
);
4004 return QLA_FUNCTION_FAILED
;
4008 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4011 int segments
, fragment
;
4012 uint32_t *dcode
, dlen
;
4016 struct fw_blob
*blob
;
4017 uint32_t *fwcode
, fwclen
;
4018 struct qla_hw_data
*ha
= vha
->hw
;
4019 struct req_que
*req
= ha
->req_q_map
[0];
4021 /* Load firmware blob. */
4022 blob
= qla2x00_request_firmware(vha
);
4024 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4025 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4026 "from: " QLA_FW_URL
".\n");
4028 /* Try to load RISC code from flash. */
4029 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
4030 "outdated) firmware from flash.\n");
4031 return qla24xx_load_risc_flash(vha
, srisc_addr
);
4036 segments
= FA_RISC_CODE_SEGMENTS
;
4037 dcode
= (uint32_t *)req
->ring
;
4039 fwcode
= (uint32_t *)blob
->fw
->data
;
4042 /* Validate firmware image by checking version. */
4043 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4044 qla_printk(KERN_WARNING
, ha
,
4045 "Unable to verify integrity of firmware image (%Zd)!\n",
4047 goto fail_fw_integrity
;
4049 for (i
= 0; i
< 4; i
++)
4050 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4051 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4052 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4053 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4055 qla_printk(KERN_WARNING
, ha
,
4056 "Unable to verify integrity of firmware image!\n");
4057 qla_printk(KERN_WARNING
, ha
,
4058 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4059 dcode
[1], dcode
[2], dcode
[3]);
4060 goto fail_fw_integrity
;
4063 while (segments
&& rval
== QLA_SUCCESS
) {
4064 risc_addr
= be32_to_cpu(fwcode
[2]);
4065 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4066 risc_size
= be32_to_cpu(fwcode
[3]);
4068 /* Validate firmware image size. */
4069 fwclen
+= risc_size
* sizeof(uint32_t);
4070 if (blob
->fw
->size
< fwclen
) {
4071 qla_printk(KERN_WARNING
, ha
,
4072 "Unable to verify integrity of firmware image "
4073 "(%Zd)!\n", blob
->fw
->size
);
4075 goto fail_fw_integrity
;
4079 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4080 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4081 if (dlen
> risc_size
)
4084 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4085 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4088 for (i
= 0; i
< dlen
; i
++)
4089 dcode
[i
] = swab32(fwcode
[i
]);
4091 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4094 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4095 "segment %d of firmware\n", vha
->host_no
,
4097 qla_printk(KERN_WARNING
, ha
,
4098 "[ERROR] Failed to load segment %d of "
4099 "firmware\n", fragment
);
4115 return QLA_FUNCTION_FAILED
;
4119 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4122 struct qla_hw_data
*ha
= vha
->hw
;
4124 if (!IS_FWI2_CAPABLE(ha
))
4126 if (!ha
->fw_major_version
)
4129 ret
= qla2x00_stop_firmware(vha
);
4130 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4131 retries
; retries
--) {
4132 ha
->isp_ops
->reset_chip(vha
);
4133 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4135 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4137 qla_printk(KERN_INFO
, ha
,
4138 "Attempting retry of stop-firmware command...\n");
4139 ret
= qla2x00_stop_firmware(vha
);
4144 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4146 int rval
= QLA_SUCCESS
;
4147 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4148 struct qla_hw_data
*ha
= vha
->hw
;
4149 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4150 struct req_que
*req
= ha
->req_q_map
[0];
4151 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4156 rval
= qla2x00_fw_ready(base_vha
);
4157 if (rval
== QLA_SUCCESS
) {
4158 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4159 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4162 vha
->flags
.management_server_logged_in
= 0;
4164 /* Login to SNS first */
4165 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
4166 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4167 DEBUG15(qla_printk(KERN_INFO
, ha
,
4168 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4169 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4170 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4171 return (QLA_FUNCTION_FAILED
);
4174 atomic_set(&vha
->loop_down_timer
, 0);
4175 atomic_set(&vha
->loop_state
, LOOP_UP
);
4176 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4177 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4178 rval
= qla2x00_loop_resync(base_vha
);
4183 /* 84XX Support **************************************************************/
4185 static LIST_HEAD(qla_cs84xx_list
);
4186 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4188 static struct qla_chip_state_84xx
*
4189 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4191 struct qla_chip_state_84xx
*cs84xx
;
4192 struct qla_hw_data
*ha
= vha
->hw
;
4194 mutex_lock(&qla_cs84xx_mutex
);
4196 /* Find any shared 84xx chip. */
4197 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4198 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4199 kref_get(&cs84xx
->kref
);
4204 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4208 kref_init(&cs84xx
->kref
);
4209 spin_lock_init(&cs84xx
->access_lock
);
4210 mutex_init(&cs84xx
->fw_update_mutex
);
4211 cs84xx
->bus
= ha
->pdev
->bus
;
4213 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4215 mutex_unlock(&qla_cs84xx_mutex
);
4220 __qla84xx_chip_release(struct kref
*kref
)
4222 struct qla_chip_state_84xx
*cs84xx
=
4223 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4225 mutex_lock(&qla_cs84xx_mutex
);
4226 list_del(&cs84xx
->list
);
4227 mutex_unlock(&qla_cs84xx_mutex
);
4232 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4234 struct qla_hw_data
*ha
= vha
->hw
;
4236 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4240 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4244 struct qla_hw_data
*ha
= vha
->hw
;
4246 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4248 rval
= qla84xx_verify_chip(vha
, status
);
4250 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4252 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
: