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
);
555 if (cnt
== 0 || hw_evt
)
556 qla2xxx_hw_event_log(vha
, HW_EVENT_RESET_ERR
,
557 RD_REG_WORD(®
->mailbox1
), RD_REG_WORD(®
->mailbox2
),
558 RD_REG_WORD(®
->mailbox3
));
560 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
561 RD_REG_DWORD(®
->hccr
);
563 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
564 RD_REG_DWORD(®
->hccr
);
566 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
567 RD_REG_DWORD(®
->hccr
);
569 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
570 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
572 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
576 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
580 * qla24xx_reset_chip() - Reset ISP24xx chip.
583 * Returns 0 on success.
586 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
588 struct qla_hw_data
*ha
= vha
->hw
;
589 ha
->isp_ops
->disable_intrs(ha
);
591 /* Perform RISC reset. */
592 qla24xx_reset_risc(vha
);
596 * qla2x00_chip_diag() - Test chip for proper operation.
599 * Returns 0 on success.
602 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
605 struct qla_hw_data
*ha
= vha
->hw
;
606 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
607 unsigned long flags
= 0;
611 struct req_que
*req
= ha
->req_q_map
[0];
613 /* Assume a failed state */
614 rval
= QLA_FUNCTION_FAILED
;
616 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
617 vha
->host_no
, (u_long
)®
->flash_address
));
619 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
621 /* Reset ISP chip. */
622 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
625 * We need to have a delay here since the card will not respond while
626 * in reset causing an MCA on some architectures.
629 data
= qla2x00_debounce_register(®
->ctrl_status
);
630 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
632 data
= RD_REG_WORD(®
->ctrl_status
);
637 goto chip_diag_failed
;
639 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
642 /* Reset RISC processor. */
643 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
644 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
646 /* Workaround for QLA2312 PCI parity error */
647 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
648 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
649 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
651 data
= RD_MAILBOX_REG(ha
, reg
, 0);
658 goto chip_diag_failed
;
660 /* Check product ID of chip */
661 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha
->host_no
));
663 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
664 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
665 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
666 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
667 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
668 mb
[3] != PROD_ID_3
) {
669 qla_printk(KERN_WARNING
, ha
,
670 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
672 goto chip_diag_failed
;
674 ha
->product_id
[0] = mb
[1];
675 ha
->product_id
[1] = mb
[2];
676 ha
->product_id
[2] = mb
[3];
677 ha
->product_id
[3] = mb
[4];
679 /* Adjust fw RISC transfer size */
680 if (req
->length
> 1024)
681 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
683 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
686 if (IS_QLA2200(ha
) &&
687 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
688 /* Limit firmware transfer size with a 2200A */
689 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
692 ha
->device_type
|= DT_ISP2200A
;
693 ha
->fw_transfer_size
= 128;
696 /* Wrap Incoming Mailboxes Test. */
697 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
699 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
700 rval
= qla2x00_mbx_reg_test(vha
);
702 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
704 qla_printk(KERN_WARNING
, ha
,
705 "Failed mailbox send register test\n");
708 /* Flag a successful rval */
711 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
715 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
716 "****\n", vha
->host_no
));
718 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
724 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
727 * Returns 0 on success.
730 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
733 struct qla_hw_data
*ha
= vha
->hw
;
734 struct req_que
*req
= ha
->req_q_map
[0];
736 /* Perform RISC reset. */
737 qla24xx_reset_risc(vha
);
739 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
741 rval
= qla2x00_mbx_reg_test(vha
);
743 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
745 qla_printk(KERN_WARNING
, ha
,
746 "Failed mailbox send register test\n");
748 /* Flag a successful rval */
756 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
759 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
760 eft_size
, fce_size
, mq_size
;
763 struct qla_hw_data
*ha
= vha
->hw
;
764 struct req_que
*req
= ha
->req_q_map
[0];
765 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
768 qla_printk(KERN_WARNING
, ha
,
769 "Firmware dump previously allocated.\n");
774 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
775 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
776 fixed_size
= sizeof(struct qla2100_fw_dump
);
777 } else if (IS_QLA23XX(ha
)) {
778 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
779 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
781 } else if (IS_FWI2_CAPABLE(ha
)) {
782 fixed_size
= IS_QLA25XX(ha
) ?
783 offsetof(struct qla25xx_fw_dump
, ext_mem
) :
784 offsetof(struct qla24xx_fw_dump
, ext_mem
);
785 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
788 mq_size
= sizeof(struct qla2xxx_mq_chain
);
790 /* Allocate memory for Fibre Channel Event Buffer. */
794 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
797 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
798 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
802 memset(tc
, 0, FCE_SIZE
);
803 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
804 ha
->fce_mb
, &ha
->fce_bufs
);
806 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
807 "FCE (%d).\n", rval
);
808 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
810 ha
->flags
.fce_enabled
= 0;
814 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
817 fce_size
= sizeof(struct qla2xxx_fce_chain
) + EFT_SIZE
;
818 ha
->flags
.fce_enabled
= 1;
819 ha
->fce_dma
= tc_dma
;
822 /* Allocate memory for Extended Trace Buffer. */
823 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
826 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
827 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
831 memset(tc
, 0, EFT_SIZE
);
832 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
834 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
835 "EFT (%d).\n", rval
);
836 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
841 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
845 ha
->eft_dma
= tc_dma
;
849 req_q_size
= req
->length
* sizeof(request_t
);
850 rsp_q_size
= rsp
->length
* sizeof(response_t
);
852 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
853 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+
854 mq_size
+ eft_size
+ fce_size
;
856 ha
->fw_dump
= vmalloc(dump_size
);
858 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
859 "firmware dump!!!\n", dump_size
/ 1024);
862 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
869 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
872 ha
->fw_dump_len
= dump_size
;
873 ha
->fw_dump
->signature
[0] = 'Q';
874 ha
->fw_dump
->signature
[1] = 'L';
875 ha
->fw_dump
->signature
[2] = 'G';
876 ha
->fw_dump
->signature
[3] = 'C';
877 ha
->fw_dump
->version
= __constant_htonl(1);
879 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
880 ha
->fw_dump
->mem_size
= htonl(mem_size
);
881 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
882 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
884 ha
->fw_dump
->eft_size
= htonl(eft_size
);
885 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
886 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
888 ha
->fw_dump
->header_size
=
889 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
893 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
896 * Returns 0 on success.
899 qla2x00_resize_request_q(scsi_qla_host_t
*vha
)
902 uint16_t fw_iocb_cnt
= 0;
903 uint16_t request_q_length
= REQUEST_ENTRY_CNT_2XXX_EXT_MEM
;
904 dma_addr_t request_dma
;
905 request_t
*request_ring
;
906 struct qla_hw_data
*ha
= vha
->hw
;
907 struct req_que
*req
= ha
->req_q_map
[0];
909 /* Valid only on recent ISPs. */
910 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
913 /* Retrieve IOCB counts available to the firmware. */
914 rval
= qla2x00_get_resource_cnts(vha
, NULL
, NULL
, NULL
, &fw_iocb_cnt
,
915 &ha
->max_npiv_vports
);
918 /* No point in continuing if current settings are sufficient. */
919 if (fw_iocb_cnt
< 1024)
921 if (req
->length
>= request_q_length
)
924 /* Attempt to claim larger area for request queue. */
925 request_ring
= dma_alloc_coherent(&ha
->pdev
->dev
,
926 (request_q_length
+ 1) * sizeof(request_t
), &request_dma
,
928 if (request_ring
== NULL
)
931 /* Resize successful, report extensions. */
932 qla_printk(KERN_INFO
, ha
, "Extended memory detected (%d KB)...\n",
933 (ha
->fw_memory_size
+ 1) / 1024);
934 qla_printk(KERN_INFO
, ha
, "Resizing request queue depth "
935 "(%d -> %d)...\n", req
->length
, request_q_length
);
937 /* Clear old allocations. */
938 dma_free_coherent(&ha
->pdev
->dev
,
939 (req
->length
+ 1) * sizeof(request_t
), req
->ring
,
942 /* Begin using larger queue. */
943 req
->length
= request_q_length
;
944 req
->ring
= request_ring
;
945 req
->dma
= request_dma
;
949 * qla2x00_setup_chip() - Load and start RISC firmware.
952 * Returns 0 on success.
955 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
958 uint32_t srisc_address
= 0;
959 struct qla_hw_data
*ha
= vha
->hw
;
960 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
963 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
964 /* Disable SRAM, Instruction RAM and GP RAM parity. */
965 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
966 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
967 RD_REG_WORD(®
->hccr
);
968 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
971 /* Load firmware sequences */
972 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
973 if (rval
== QLA_SUCCESS
) {
974 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
975 "code.\n", vha
->host_no
));
977 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
978 if (rval
== QLA_SUCCESS
) {
979 /* Start firmware execution. */
980 DEBUG(printk("scsi(%ld): Checksum OK, start "
981 "firmware.\n", vha
->host_no
));
983 rval
= qla2x00_execute_fw(vha
, srisc_address
);
984 /* Retrieve firmware information. */
985 if (rval
== QLA_SUCCESS
&& ha
->fw_major_version
== 0) {
986 qla2x00_get_fw_version(vha
,
987 &ha
->fw_major_version
,
988 &ha
->fw_minor_version
,
989 &ha
->fw_subminor_version
,
990 &ha
->fw_attributes
, &ha
->fw_memory_size
);
991 ha
->flags
.npiv_supported
= 0;
992 if (IS_QLA2XXX_MIDTYPE(ha
) &&
993 (ha
->fw_attributes
& BIT_2
)) {
994 ha
->flags
.npiv_supported
= 1;
995 if ((!ha
->max_npiv_vports
) ||
996 ((ha
->max_npiv_vports
+ 1) %
997 MIN_MULTI_ID_FABRIC
))
998 ha
->max_npiv_vports
=
999 MIN_MULTI_ID_FABRIC
- 1;
1001 qla2x00_resize_request_q(vha
);
1003 if (ql2xallocfwdump
)
1004 qla2x00_alloc_fw_dump(vha
);
1007 DEBUG2(printk(KERN_INFO
1008 "scsi(%ld): ISP Firmware failed checksum.\n",
1013 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1014 /* Enable proper parity. */
1015 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1018 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1020 /* SRAM, Instruction RAM and GP RAM parity */
1021 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1022 RD_REG_WORD(®
->hccr
);
1023 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1027 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1035 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1038 * Beginning of request ring has initialization control block already built
1039 * by nvram config routine.
1041 * Returns 0 on success.
1044 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1049 pkt
= rsp
->ring_ptr
;
1050 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1051 pkt
->signature
= RESPONSE_PROCESSED
;
1058 * qla2x00_update_fw_options() - Read and process firmware options.
1061 * Returns 0 on success.
1064 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1066 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1067 struct qla_hw_data
*ha
= vha
->hw
;
1069 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1070 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1072 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1075 /* Serial Link options. */
1076 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1078 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1079 sizeof(ha
->fw_seriallink_options
)));
1081 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1082 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1083 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1086 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1087 emphasis
= (ha
->fw_seriallink_options
[2] &
1088 (BIT_4
| BIT_3
)) >> 3;
1089 tx_sens
= ha
->fw_seriallink_options
[0] &
1090 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1091 rx_sens
= (ha
->fw_seriallink_options
[0] &
1092 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1093 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1094 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1097 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1098 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1099 ha
->fw_options
[10] |= BIT_5
|
1100 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1101 (tx_sens
& (BIT_1
| BIT_0
));
1104 swing
= (ha
->fw_seriallink_options
[2] &
1105 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1106 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1107 tx_sens
= ha
->fw_seriallink_options
[1] &
1108 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1109 rx_sens
= (ha
->fw_seriallink_options
[1] &
1110 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1111 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1112 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1115 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1116 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1117 ha
->fw_options
[11] |= BIT_5
|
1118 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1119 (tx_sens
& (BIT_1
| BIT_0
));
1123 /* Return command IOCBs without waiting for an ABTS to complete. */
1124 ha
->fw_options
[3] |= BIT_13
;
1127 if (ha
->flags
.enable_led_scheme
)
1128 ha
->fw_options
[2] |= BIT_12
;
1130 /* Detect ISP6312. */
1132 ha
->fw_options
[2] |= BIT_13
;
1134 /* Update firmware options. */
1135 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1139 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1142 struct qla_hw_data
*ha
= vha
->hw
;
1144 /* Update Serial Link options. */
1145 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1148 rval
= qla2x00_set_serdes_params(vha
,
1149 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1150 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1151 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1152 if (rval
!= QLA_SUCCESS
) {
1153 qla_printk(KERN_WARNING
, ha
,
1154 "Unable to update Serial Link options (%x).\n", rval
);
1159 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1161 struct qla_hw_data
*ha
= vha
->hw
;
1162 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1163 struct req_que
*req
= ha
->req_q_map
[0];
1164 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1166 /* Setup ring parameters in initialization control block. */
1167 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1168 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1169 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1170 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1171 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1172 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1173 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1174 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1176 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1177 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1178 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1179 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1180 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1184 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1186 struct qla_hw_data
*ha
= vha
->hw
;
1187 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1188 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1189 struct qla_msix_entry
*msix
;
1190 struct init_cb_24xx
*icb
;
1192 struct req_que
*req
= ha
->req_q_map
[0];
1193 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1195 /* Setup ring parameters in initialization control block. */
1196 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1197 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1198 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1199 icb
->request_q_length
= cpu_to_le16(req
->length
);
1200 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1201 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1202 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1203 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1204 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1207 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1208 icb
->rid
= __constant_cpu_to_le16(rid
);
1209 if (ha
->flags
.msix_enabled
) {
1210 msix
= &ha
->msix_entries
[1];
1211 DEBUG2_17(printk(KERN_INFO
1212 "Reistering vector 0x%x for base que\n", msix
->entry
));
1213 icb
->msix
= cpu_to_le16(msix
->entry
);
1215 /* Use alternate PCI bus number */
1217 icb
->firmware_options_2
|=
1218 __constant_cpu_to_le32(BIT_19
);
1219 /* Use alternate PCI devfn */
1221 icb
->firmware_options_2
|=
1222 __constant_cpu_to_le32(BIT_18
);
1224 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_22
);
1225 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1226 ha
->rsp_q_map
[0]->options
= icb
->firmware_options_2
;
1228 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1229 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1230 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1231 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1233 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1234 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1235 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1236 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1239 RD_REG_DWORD(&ioreg
->hccr
);
1243 * qla2x00_init_rings() - Initializes firmware.
1246 * Beginning of request ring has initialization control block already built
1247 * by nvram config routine.
1249 * Returns 0 on success.
1252 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1255 unsigned long flags
= 0;
1257 struct qla_hw_data
*ha
= vha
->hw
;
1258 struct req_que
*req
= ha
->req_q_map
[0];
1259 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1260 struct mid_init_cb_24xx
*mid_init_cb
=
1261 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1263 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1265 /* Clear outstanding commands array. */
1266 for (cnt
= 0; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1267 req
->outstanding_cmds
[cnt
] = NULL
;
1269 req
->current_outstanding_cmd
= 0;
1271 /* Clear RSCN queue. */
1272 vha
->rscn_in_ptr
= 0;
1273 vha
->rscn_out_ptr
= 0;
1275 /* Initialize firmware. */
1276 req
->ring_ptr
= req
->ring
;
1277 req
->ring_index
= 0;
1278 req
->cnt
= req
->length
;
1279 rsp
->ring_ptr
= rsp
->ring
;
1280 rsp
->ring_index
= 0;
1282 /* Initialize response queue entries */
1283 qla2x00_init_response_q_entries(rsp
);
1285 ha
->isp_ops
->config_rings(vha
);
1287 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1289 /* Update any ISP specific firmware options before initialization. */
1290 ha
->isp_ops
->update_fw_options(vha
);
1292 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1294 if (ha
->flags
.npiv_supported
)
1295 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1297 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1299 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1301 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1304 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1312 * qla2x00_fw_ready() - Waits for firmware ready.
1315 * Returns 0 on success.
1318 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1321 unsigned long wtime
, mtime
, cs84xx_time
;
1322 uint16_t min_wait
; /* Minimum wait time if loop is down */
1323 uint16_t wait_time
; /* Wait time if loop is coming ready */
1325 struct qla_hw_data
*ha
= vha
->hw
;
1329 /* 20 seconds for loop down. */
1333 * Firmware should take at most one RATOV to login, plus 5 seconds for
1334 * our own processing.
1336 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1337 wait_time
= min_wait
;
1340 /* Min wait time if loop down */
1341 mtime
= jiffies
+ (min_wait
* HZ
);
1343 /* wait time before firmware ready */
1344 wtime
= jiffies
+ (wait_time
* HZ
);
1346 /* Wait for ISP to finish LIP */
1347 if (!vha
->flags
.init_done
)
1348 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1350 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1354 rval
= qla2x00_get_firmware_state(vha
, state
);
1355 if (rval
== QLA_SUCCESS
) {
1356 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1357 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1359 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1360 DEBUG16(printk("scsi(%ld): fw_state=%x "
1361 "84xx=%x.\n", vha
->host_no
, state
[0],
1363 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1364 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1365 DEBUG16(printk("scsi(%ld): Sending "
1366 "verify iocb.\n", vha
->host_no
));
1368 cs84xx_time
= jiffies
;
1369 rval
= qla84xx_init_chip(vha
);
1370 if (rval
!= QLA_SUCCESS
)
1373 /* Add time taken to initialize. */
1374 cs84xx_time
= jiffies
- cs84xx_time
;
1375 wtime
+= cs84xx_time
;
1376 mtime
+= cs84xx_time
;
1377 DEBUG16(printk("scsi(%ld): Increasing "
1378 "wait time by %ld. New time %ld\n",
1379 vha
->host_no
, cs84xx_time
, wtime
));
1381 } else if (state
[0] == FSTATE_READY
) {
1382 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1385 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1386 &ha
->login_timeout
, &ha
->r_a_tov
);
1392 rval
= QLA_FUNCTION_FAILED
;
1394 if (atomic_read(&vha
->loop_down_timer
) &&
1395 state
[0] != FSTATE_READY
) {
1396 /* Loop down. Timeout on min_wait for states
1397 * other than Wait for Login.
1399 if (time_after_eq(jiffies
, mtime
)) {
1400 qla_printk(KERN_INFO
, ha
,
1401 "Cable is unplugged...\n");
1403 vha
->device_flags
|= DFLG_NO_CABLE
;
1408 /* Mailbox cmd failed. Timeout on min_wait. */
1409 if (time_after_eq(jiffies
, mtime
))
1413 if (time_after_eq(jiffies
, wtime
))
1416 /* Delay for a while */
1419 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1420 vha
->host_no
, state
[0], jiffies
));
1423 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1424 vha
->host_no
, state
[0], jiffies
));
1427 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1435 * qla2x00_configure_hba
1436 * Setup adapter context.
1439 * ha = adapter state pointer.
1448 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1457 char connect_type
[22];
1458 struct qla_hw_data
*ha
= vha
->hw
;
1460 /* Get host addresses. */
1461 rval
= qla2x00_get_adapter_id(vha
,
1462 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1463 if (rval
!= QLA_SUCCESS
) {
1464 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
1465 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1466 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1467 __func__
, vha
->host_no
));
1469 qla_printk(KERN_WARNING
, ha
,
1470 "ERROR -- Unable to get host loop ID.\n");
1471 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1477 qla_printk(KERN_INFO
, ha
,
1478 "Cannot get topology - retrying.\n");
1479 return (QLA_FUNCTION_FAILED
);
1482 vha
->loop_id
= loop_id
;
1485 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1486 ha
->operating_mode
= LOOP
;
1491 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1493 ha
->current_topology
= ISP_CFG_NL
;
1494 strcpy(connect_type
, "(Loop)");
1498 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1500 ha
->switch_cap
= sw_cap
;
1501 ha
->current_topology
= ISP_CFG_FL
;
1502 strcpy(connect_type
, "(FL_Port)");
1506 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1508 ha
->operating_mode
= P2P
;
1509 ha
->current_topology
= ISP_CFG_N
;
1510 strcpy(connect_type
, "(N_Port-to-N_Port)");
1514 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1516 ha
->switch_cap
= sw_cap
;
1517 ha
->operating_mode
= P2P
;
1518 ha
->current_topology
= ISP_CFG_F
;
1519 strcpy(connect_type
, "(F_Port)");
1523 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1525 vha
->host_no
, topo
));
1526 ha
->current_topology
= ISP_CFG_NL
;
1527 strcpy(connect_type
, "(Loop)");
1531 /* Save Host port and loop ID. */
1532 /* byte order - Big Endian */
1533 vha
->d_id
.b
.domain
= domain
;
1534 vha
->d_id
.b
.area
= area
;
1535 vha
->d_id
.b
.al_pa
= al_pa
;
1537 if (!vha
->flags
.init_done
)
1538 qla_printk(KERN_INFO
, ha
,
1539 "Topology - %s, Host Loop address 0x%x\n",
1540 connect_type
, vha
->loop_id
);
1543 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
1545 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
1552 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
1557 struct qla_hw_data
*ha
= vha
->hw
;
1559 if (memcmp(model
, BINZERO
, len
) != 0) {
1560 strncpy(ha
->model_number
, model
, len
);
1561 st
= en
= ha
->model_number
;
1564 if (*en
!= 0x20 && *en
!= 0x00)
1569 index
= (ha
->pdev
->subsystem_device
& 0xff);
1570 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1571 index
< QLA_MODEL_NAMES
)
1572 strncpy(ha
->model_desc
,
1573 qla2x00_model_name
[index
* 2 + 1],
1574 sizeof(ha
->model_desc
) - 1);
1576 index
= (ha
->pdev
->subsystem_device
& 0xff);
1577 if (ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1578 index
< QLA_MODEL_NAMES
) {
1579 strcpy(ha
->model_number
,
1580 qla2x00_model_name
[index
* 2]);
1581 strncpy(ha
->model_desc
,
1582 qla2x00_model_name
[index
* 2 + 1],
1583 sizeof(ha
->model_desc
) - 1);
1585 strcpy(ha
->model_number
, def
);
1588 if (IS_FWI2_CAPABLE(ha
))
1589 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
1590 sizeof(ha
->model_desc
));
1593 /* On sparc systems, obtain port and node WWN from firmware
1596 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
1599 struct qla_hw_data
*ha
= vha
->hw
;
1600 struct pci_dev
*pdev
= ha
->pdev
;
1601 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1605 val
= of_get_property(dp
, "port-wwn", &len
);
1606 if (val
&& len
>= WWN_SIZE
)
1607 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1609 val
= of_get_property(dp
, "node-wwn", &len
);
1610 if (val
&& len
>= WWN_SIZE
)
1611 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1616 * NVRAM configuration for ISP 2xxx
1619 * ha = adapter block pointer.
1622 * initialization control block in response_ring
1623 * host adapters parameters in host adapter block
1629 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
1634 uint8_t *dptr1
, *dptr2
;
1635 struct qla_hw_data
*ha
= vha
->hw
;
1636 init_cb_t
*icb
= ha
->init_cb
;
1637 nvram_t
*nv
= ha
->nvram
;
1638 uint8_t *ptr
= ha
->nvram
;
1639 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1643 /* Determine NVRAM starting address. */
1644 ha
->nvram_size
= sizeof(nvram_t
);
1646 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1647 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1648 ha
->nvram_base
= 0x80;
1650 /* Get NVRAM data and calculate checksum. */
1651 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1652 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1655 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
1656 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
1658 /* Bad NVRAM data, set defaults parameters. */
1659 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1660 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1661 /* Reset NVRAM data. */
1662 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1663 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1665 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1666 "invalid -- WWPN) defaults.\n");
1669 qla2xxx_hw_event_log(vha
, HW_EVENT_NVRAM_CHKSUM_ERR
, 0,
1670 MSW(chksum
), LSW(chksum
));
1673 * Set default initialization control block.
1675 memset(nv
, 0, ha
->nvram_size
);
1676 nv
->parameter_block_version
= ICB_VERSION
;
1678 if (IS_QLA23XX(ha
)) {
1679 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1680 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1681 nv
->add_firmware_options
[0] = BIT_5
;
1682 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1683 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1684 nv
->special_options
[1] = BIT_7
;
1685 } else if (IS_QLA2200(ha
)) {
1686 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1687 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1688 nv
->add_firmware_options
[0] = BIT_5
;
1689 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1690 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1691 } else if (IS_QLA2100(ha
)) {
1692 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
1693 nv
->firmware_options
[1] = BIT_5
;
1694 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
1697 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
1698 nv
->execution_throttle
= __constant_cpu_to_le16(16);
1699 nv
->retry_count
= 8;
1700 nv
->retry_delay
= 1;
1702 nv
->port_name
[0] = 33;
1703 nv
->port_name
[3] = 224;
1704 nv
->port_name
[4] = 139;
1706 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
1708 nv
->login_timeout
= 4;
1711 * Set default host adapter parameters
1713 nv
->host_p
[1] = BIT_2
;
1714 nv
->reset_delay
= 5;
1715 nv
->port_down_retry_count
= 8;
1716 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
1717 nv
->link_down_timeout
= 60;
1722 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1724 * The SN2 does not provide BIOS emulation which means you can't change
1725 * potentially bogus BIOS settings. Force the use of default settings
1726 * for link rate and frame size. Hope that the rest of the settings
1729 if (ia64_platform_is("sn2")) {
1730 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1732 nv
->special_options
[1] = BIT_7
;
1736 /* Reset Initialization control block */
1737 memset(icb
, 0, ha
->init_cb_size
);
1740 * Setup driver NVRAM options.
1742 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
1743 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
1744 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
1745 nv
->firmware_options
[1] &= ~BIT_4
;
1747 if (IS_QLA23XX(ha
)) {
1748 nv
->firmware_options
[0] |= BIT_2
;
1749 nv
->firmware_options
[0] &= ~BIT_3
;
1750 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
1752 if (IS_QLA2300(ha
)) {
1753 if (ha
->fb_rev
== FPM_2310
) {
1754 strcpy(ha
->model_number
, "QLA2310");
1756 strcpy(ha
->model_number
, "QLA2300");
1759 qla2x00_set_model_info(vha
, nv
->model_number
,
1760 sizeof(nv
->model_number
), "QLA23xx");
1762 } else if (IS_QLA2200(ha
)) {
1763 nv
->firmware_options
[0] |= BIT_2
;
1765 * 'Point-to-point preferred, else loop' is not a safe
1766 * connection mode setting.
1768 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
1770 /* Force 'loop preferred, else point-to-point'. */
1771 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
1772 nv
->add_firmware_options
[0] |= BIT_5
;
1774 strcpy(ha
->model_number
, "QLA22xx");
1775 } else /*if (IS_QLA2100(ha))*/ {
1776 strcpy(ha
->model_number
, "QLA2100");
1780 * Copy over NVRAM RISC parameter block to initialization control block.
1782 dptr1
= (uint8_t *)icb
;
1783 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
1784 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
1786 *dptr1
++ = *dptr2
++;
1788 /* Copy 2nd half. */
1789 dptr1
= (uint8_t *)icb
->add_firmware_options
;
1790 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
1792 *dptr1
++ = *dptr2
++;
1794 /* Use alternate WWN? */
1795 if (nv
->host_p
[1] & BIT_7
) {
1796 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
1797 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
1800 /* Prepare nodename */
1801 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
1803 * Firmware will apply the following mask if the nodename was
1806 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
1807 icb
->node_name
[0] &= 0xF0;
1811 * Set host adapter parameters.
1813 if (nv
->host_p
[0] & BIT_7
)
1814 ql2xextended_error_logging
= 1;
1815 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
1816 /* Always load RISC code on non ISP2[12]00 chips. */
1817 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
1818 ha
->flags
.disable_risc_code_load
= 0;
1819 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
1820 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
1821 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
1822 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
1823 ha
->flags
.disable_serdes
= 0;
1825 ha
->operating_mode
=
1826 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
1828 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
1829 sizeof(ha
->fw_seriallink_options
));
1831 /* save HBA serial number */
1832 ha
->serial0
= icb
->port_name
[5];
1833 ha
->serial1
= icb
->port_name
[6];
1834 ha
->serial2
= icb
->port_name
[7];
1835 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
1836 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
1838 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
1840 ha
->retry_count
= nv
->retry_count
;
1842 /* Set minimum login_timeout to 4 seconds. */
1843 if (nv
->login_timeout
< ql2xlogintimeout
)
1844 nv
->login_timeout
= ql2xlogintimeout
;
1845 if (nv
->login_timeout
< 4)
1846 nv
->login_timeout
= 4;
1847 ha
->login_timeout
= nv
->login_timeout
;
1848 icb
->login_timeout
= nv
->login_timeout
;
1850 /* Set minimum RATOV to 100 tenths of a second. */
1853 ha
->loop_reset_delay
= nv
->reset_delay
;
1855 /* Link Down Timeout = 0:
1857 * When Port Down timer expires we will start returning
1858 * I/O's to OS with "DID_NO_CONNECT".
1860 * Link Down Timeout != 0:
1862 * The driver waits for the link to come up after link down
1863 * before returning I/Os to OS with "DID_NO_CONNECT".
1865 if (nv
->link_down_timeout
== 0) {
1866 ha
->loop_down_abort_time
=
1867 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
1869 ha
->link_down_timeout
= nv
->link_down_timeout
;
1870 ha
->loop_down_abort_time
=
1871 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
1875 * Need enough time to try and get the port back.
1877 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
1878 if (qlport_down_retry
)
1879 ha
->port_down_retry_count
= qlport_down_retry
;
1880 /* Set login_retry_count */
1881 ha
->login_retry_count
= nv
->retry_count
;
1882 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
1883 ha
->port_down_retry_count
> 3)
1884 ha
->login_retry_count
= ha
->port_down_retry_count
;
1885 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
1886 ha
->login_retry_count
= ha
->port_down_retry_count
;
1887 if (ql2xloginretrycount
)
1888 ha
->login_retry_count
= ql2xloginretrycount
;
1890 icb
->lun_enables
= __constant_cpu_to_le16(0);
1891 icb
->command_resource_count
= 0;
1892 icb
->immediate_notify_resource_count
= 0;
1893 icb
->timeout
= __constant_cpu_to_le16(0);
1895 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1897 icb
->firmware_options
[0] &= ~BIT_3
;
1898 icb
->add_firmware_options
[0] &=
1899 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1900 icb
->add_firmware_options
[0] |= BIT_2
;
1901 icb
->response_accumulation_timer
= 3;
1902 icb
->interrupt_delay_timer
= 5;
1904 vha
->flags
.process_response_queue
= 1;
1907 if (!vha
->flags
.init_done
) {
1908 ha
->zio_mode
= icb
->add_firmware_options
[0] &
1909 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1910 ha
->zio_timer
= icb
->interrupt_delay_timer
?
1911 icb
->interrupt_delay_timer
: 2;
1913 icb
->add_firmware_options
[0] &=
1914 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1915 vha
->flags
.process_response_queue
= 0;
1916 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1917 ha
->zio_mode
= QLA_ZIO_MODE_6
;
1919 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1920 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
1921 ha
->zio_timer
* 100));
1922 qla_printk(KERN_INFO
, ha
,
1923 "ZIO mode %d enabled; timer delay (%d us).\n",
1924 ha
->zio_mode
, ha
->zio_timer
* 100);
1926 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
1927 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
1928 vha
->flags
.process_response_queue
= 1;
1933 DEBUG2_3(printk(KERN_WARNING
1934 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
1940 qla2x00_rport_del(void *data
)
1942 fc_port_t
*fcport
= data
;
1943 struct fc_rport
*rport
;
1945 spin_lock_irq(fcport
->vha
->host
->host_lock
);
1946 rport
= fcport
->drport
;
1947 fcport
->drport
= NULL
;
1948 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
1950 fc_remote_port_delete(rport
);
1954 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1956 * @flags: allocation flags
1958 * Returns a pointer to the allocated fcport, or NULL, if none available.
1961 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
1965 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
1969 /* Setup fcport template structure. */
1971 fcport
->vp_idx
= vha
->vp_idx
;
1972 fcport
->port_type
= FCT_UNKNOWN
;
1973 fcport
->loop_id
= FC_NO_LOOP_ID
;
1974 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
1975 fcport
->flags
= FCF_RLC_SUPPORT
;
1976 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
1982 * qla2x00_configure_loop
1983 * Updates Fibre Channel Device Database with what is actually on loop.
1986 * ha = adapter block pointer.
1991 * 2 = database was full and device was not configured.
1994 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
1997 unsigned long flags
, save_flags
;
1998 struct qla_hw_data
*ha
= vha
->hw
;
2001 /* Get Initiator ID */
2002 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2003 rval
= qla2x00_configure_hba(vha
);
2004 if (rval
!= QLA_SUCCESS
) {
2005 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2011 save_flags
= flags
= vha
->dpc_flags
;
2012 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2013 vha
->host_no
, flags
));
2016 * If we have both an RSCN and PORT UPDATE pending then handle them
2017 * both at the same time.
2019 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2020 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2022 /* Determine what we need to do */
2023 if (ha
->current_topology
== ISP_CFG_FL
&&
2024 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2026 vha
->flags
.rscn_queue_overflow
= 1;
2027 set_bit(RSCN_UPDATE
, &flags
);
2029 } else if (ha
->current_topology
== ISP_CFG_F
&&
2030 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2032 vha
->flags
.rscn_queue_overflow
= 1;
2033 set_bit(RSCN_UPDATE
, &flags
);
2034 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2036 } else if (ha
->current_topology
== ISP_CFG_N
) {
2037 clear_bit(RSCN_UPDATE
, &flags
);
2039 } else if (!vha
->flags
.online
||
2040 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2042 vha
->flags
.rscn_queue_overflow
= 1;
2043 set_bit(RSCN_UPDATE
, &flags
);
2044 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2047 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2048 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2049 rval
= QLA_FUNCTION_FAILED
;
2051 rval
= qla2x00_configure_local_loop(vha
);
2054 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2055 if (LOOP_TRANSITION(vha
))
2056 rval
= QLA_FUNCTION_FAILED
;
2058 rval
= qla2x00_configure_fabric(vha
);
2061 if (rval
== QLA_SUCCESS
) {
2062 if (atomic_read(&vha
->loop_down_timer
) ||
2063 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2064 rval
= QLA_FUNCTION_FAILED
;
2066 atomic_set(&vha
->loop_state
, LOOP_READY
);
2068 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2073 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2074 __func__
, vha
->host_no
));
2076 DEBUG3(printk("%s: exiting normally\n", __func__
));
2079 /* Restore state if a resync event occurred during processing */
2080 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2081 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2082 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2083 if (test_bit(RSCN_UPDATE
, &save_flags
))
2084 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2093 * qla2x00_configure_local_loop
2094 * Updates Fibre Channel Device Database with local loop devices.
2097 * ha = adapter block pointer.
2103 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2108 fc_port_t
*fcport
, *new_fcport
;
2114 uint8_t domain
, area
, al_pa
;
2115 struct qla_hw_data
*ha
= vha
->hw
;
2119 entries
= MAX_FIBRE_DEVICES
;
2121 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2122 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2124 /* Get list of logged in devices. */
2125 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2126 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2128 if (rval
!= QLA_SUCCESS
)
2129 goto cleanup_allocation
;
2131 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2132 ha
->host_no
, entries
));
2133 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2134 entries
* sizeof(struct gid_list_info
)));
2136 /* Allocate temporary fcport for any new fcports discovered. */
2137 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2138 if (new_fcport
== NULL
) {
2139 rval
= QLA_MEMORY_ALLOC_FAILED
;
2140 goto cleanup_allocation
;
2142 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2145 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2147 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2148 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2149 fcport
->port_type
!= FCT_BROADCAST
&&
2150 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2152 DEBUG(printk("scsi(%ld): Marking port lost, "
2154 vha
->host_no
, fcport
->loop_id
));
2156 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2157 fcport
->flags
&= ~FCF_FARP_DONE
;
2161 /* Add devices to port list. */
2162 id_iter
= (char *)ha
->gid_list
;
2163 for (index
= 0; index
< entries
; index
++) {
2164 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2165 area
= ((struct gid_list_info
*)id_iter
)->area
;
2166 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2167 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2168 loop_id
= (uint16_t)
2169 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2171 loop_id
= le16_to_cpu(
2172 ((struct gid_list_info
*)id_iter
)->loop_id
);
2173 id_iter
+= ha
->gid_list_info_size
;
2175 /* Bypass reserved domain fields. */
2176 if ((domain
& 0xf0) == 0xf0)
2179 /* Bypass if not same domain and area of adapter. */
2180 if (area
&& domain
&&
2181 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2184 /* Bypass invalid local loop ID. */
2185 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2188 /* Fill in member data. */
2189 new_fcport
->d_id
.b
.domain
= domain
;
2190 new_fcport
->d_id
.b
.area
= area
;
2191 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2192 new_fcport
->loop_id
= loop_id
;
2193 new_fcport
->vp_idx
= vha
->vp_idx
;
2194 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2195 if (rval2
!= QLA_SUCCESS
) {
2196 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2197 "information -- get_port_database=%x, "
2199 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2200 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2202 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2206 /* Check for matching device in port list. */
2209 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2210 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2214 fcport
->flags
&= ~(FCF_FABRIC_DEVICE
|
2215 FCF_PERSISTENT_BOUND
);
2216 fcport
->loop_id
= new_fcport
->loop_id
;
2217 fcport
->port_type
= new_fcport
->port_type
;
2218 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2219 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2227 /* New device, add to fcports list. */
2228 new_fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2230 new_fcport
->vha
= vha
;
2231 new_fcport
->vp_idx
= vha
->vp_idx
;
2233 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2235 /* Allocate a new replacement fcport. */
2236 fcport
= new_fcport
;
2237 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2238 if (new_fcport
== NULL
) {
2239 rval
= QLA_MEMORY_ALLOC_FAILED
;
2240 goto cleanup_allocation
;
2242 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2245 /* Base iIDMA settings on HBA port speed. */
2246 fcport
->fp_speed
= ha
->link_data_rate
;
2248 qla2x00_update_fcport(vha
, fcport
);
2256 if (rval
!= QLA_SUCCESS
) {
2257 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2258 "rval=%x\n", vha
->host_no
, rval
));
2262 vha
->device_flags
|= DFLG_LOCAL_DEVICES
;
2263 vha
->device_flags
&= ~DFLG_RETRY_LOCAL_DEVICES
;
2270 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2272 #define LS_UNKNOWN 2
2273 static char *link_speeds
[5] = { "1", "2", "?", "4", "8" };
2276 struct qla_hw_data
*ha
= vha
->hw
;
2278 if (!IS_IIDMA_CAPABLE(ha
))
2281 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2282 fcport
->fp_speed
> ha
->link_data_rate
)
2285 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2287 if (rval
!= QLA_SUCCESS
) {
2288 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2289 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2290 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2291 fcport
->port_name
[2], fcport
->port_name
[3],
2292 fcport
->port_name
[4], fcport
->port_name
[5],
2293 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2294 fcport
->fp_speed
, mb
[0], mb
[1]));
2296 DEBUG2(qla_printk(KERN_INFO
, ha
,
2297 "iIDMA adjusted to %s GB/s on "
2298 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2299 link_speeds
[fcport
->fp_speed
], fcport
->port_name
[0],
2300 fcport
->port_name
[1], fcport
->port_name
[2],
2301 fcport
->port_name
[3], fcport
->port_name
[4],
2302 fcport
->port_name
[5], fcport
->port_name
[6],
2303 fcport
->port_name
[7]));
2308 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2310 struct fc_rport_identifiers rport_ids
;
2311 struct fc_rport
*rport
;
2312 struct qla_hw_data
*ha
= vha
->hw
;
2315 qla2x00_rport_del(fcport
);
2317 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2318 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2319 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2320 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2321 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2322 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2324 qla_printk(KERN_WARNING
, ha
,
2325 "Unable to allocate fc remote port!\n");
2328 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2329 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2330 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2332 rport
->supported_classes
= fcport
->supported_classes
;
2334 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2335 if (fcport
->port_type
== FCT_INITIATOR
)
2336 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2337 if (fcport
->port_type
== FCT_TARGET
)
2338 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2339 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2343 * qla2x00_update_fcport
2344 * Updates device on list.
2347 * ha = adapter block pointer.
2348 * fcport = port structure pointer.
2358 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2360 struct qla_hw_data
*ha
= vha
->hw
;
2363 fcport
->login_retry
= 0;
2364 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2366 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2368 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2370 qla2x00_iidma_fcport(vha
, fcport
);
2372 atomic_set(&fcport
->state
, FCS_ONLINE
);
2374 qla2x00_reg_remote_port(vha
, fcport
);
2378 * qla2x00_configure_fabric
2379 * Setup SNS devices with loop ID's.
2382 * ha = adapter block pointer.
2389 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2392 fc_port_t
*fcport
, *fcptemp
;
2393 uint16_t next_loopid
;
2394 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2396 LIST_HEAD(new_fcports
);
2397 struct qla_hw_data
*ha
= vha
->hw
;
2398 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2400 /* If FL port exists, then SNS is present */
2401 if (IS_FWI2_CAPABLE(ha
))
2402 loop_id
= NPH_F_PORT
;
2404 loop_id
= SNS_FL_PORT
;
2405 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2406 if (rval
!= QLA_SUCCESS
) {
2407 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2408 "Port\n", vha
->host_no
));
2410 vha
->device_flags
&= ~SWITCH_FOUND
;
2411 return (QLA_SUCCESS
);
2413 vha
->device_flags
|= SWITCH_FOUND
;
2415 /* Mark devices that need re-synchronization. */
2416 rval2
= qla2x00_device_resync(vha
);
2417 if (rval2
== QLA_RSCNS_HANDLED
) {
2418 /* No point doing the scan, just continue. */
2419 return (QLA_SUCCESS
);
2423 if (ql2xfdmienable
&&
2424 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2425 qla2x00_fdmi_register(vha
);
2427 /* Ensure we are logged into the SNS. */
2428 if (IS_FWI2_CAPABLE(ha
))
2431 loop_id
= SIMPLE_NAME_SERVER
;
2432 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2433 0xfc, mb
, BIT_1
| BIT_0
);
2434 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2435 DEBUG2(qla_printk(KERN_INFO
, ha
,
2436 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2437 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2438 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2439 return (QLA_SUCCESS
);
2442 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
2443 if (qla2x00_rft_id(vha
)) {
2445 DEBUG2(printk("scsi(%ld): Register FC-4 "
2446 "TYPE failed.\n", vha
->host_no
));
2448 if (qla2x00_rff_id(vha
)) {
2450 DEBUG2(printk("scsi(%ld): Register FC-4 "
2451 "Features failed.\n", vha
->host_no
));
2453 if (qla2x00_rnn_id(vha
)) {
2455 DEBUG2(printk("scsi(%ld): Register Node Name "
2456 "failed.\n", vha
->host_no
));
2457 } else if (qla2x00_rsnn_nn(vha
)) {
2459 DEBUG2(printk("scsi(%ld): Register Symbolic "
2460 "Node Name failed.\n", vha
->host_no
));
2464 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
2465 if (rval
!= QLA_SUCCESS
)
2469 * Logout all previous fabric devices marked lost, except
2472 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2473 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2476 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2479 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2480 qla2x00_mark_device_lost(vha
, fcport
,
2481 ql2xplogiabsentdevice
, 0);
2482 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2483 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2484 fcport
->port_type
!= FCT_INITIATOR
&&
2485 fcport
->port_type
!= FCT_BROADCAST
) {
2486 ha
->isp_ops
->fabric_logout(vha
,
2488 fcport
->d_id
.b
.domain
,
2489 fcport
->d_id
.b
.area
,
2490 fcport
->d_id
.b
.al_pa
);
2491 fcport
->loop_id
= FC_NO_LOOP_ID
;
2496 /* Starting free loop ID. */
2497 next_loopid
= ha
->min_external_loopid
;
2500 * Scan through our port list and login entries that need to be
2503 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2504 if (atomic_read(&vha
->loop_down_timer
) ||
2505 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2508 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2509 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2512 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2513 fcport
->loop_id
= next_loopid
;
2514 rval
= qla2x00_find_new_loop_id(
2516 if (rval
!= QLA_SUCCESS
) {
2517 /* Ran out of IDs to use */
2521 /* Login and update database */
2522 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2525 /* Exit if out of loop IDs. */
2526 if (rval
!= QLA_SUCCESS
) {
2531 * Login and add the new devices to our port list.
2533 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2534 if (atomic_read(&vha
->loop_down_timer
) ||
2535 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2538 /* Find a new loop ID to use. */
2539 fcport
->loop_id
= next_loopid
;
2540 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
2541 if (rval
!= QLA_SUCCESS
) {
2542 /* Ran out of IDs to use */
2546 /* Login and update database */
2547 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2551 fcport
->vp_idx
= vha
->vp_idx
;
2553 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
2557 /* Free all new device structures not processed. */
2558 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2559 list_del(&fcport
->list
);
2564 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2565 "rval=%d\n", vha
->host_no
, rval
));
2573 * qla2x00_find_all_fabric_devs
2576 * ha = adapter block pointer.
2577 * dev = database device entry pointer.
2586 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
2587 struct list_head
*new_fcports
)
2591 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2596 int first_dev
, last_dev
;
2597 port_id_t wrap
, nxt_d_id
;
2598 struct qla_hw_data
*ha
= vha
->hw
;
2599 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
2603 /* Try GID_PT to get device list, else GAN. */
2604 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
2607 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2608 "on GA_NXT\n", vha
->host_no
));
2610 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
2613 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
2616 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
2619 } else if (ql2xiidmaenable
&&
2620 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
2621 qla2x00_gpsc(vha
, swl
);
2626 /* Allocate temporary fcport for any new fcports discovered. */
2627 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2628 if (new_fcport
== NULL
) {
2630 return (QLA_MEMORY_ALLOC_FAILED
);
2632 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2633 /* Set start port ID scan at adapter ID. */
2637 /* Starting free loop ID. */
2638 loop_id
= ha
->min_external_loopid
;
2639 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
2640 if (qla2x00_is_reserved_id(vha
, loop_id
))
2643 if (atomic_read(&vha
->loop_down_timer
) || LOOP_TRANSITION(vha
))
2648 wrap
.b24
= new_fcport
->d_id
.b24
;
2650 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2651 memcpy(new_fcport
->node_name
,
2652 swl
[swl_idx
].node_name
, WWN_SIZE
);
2653 memcpy(new_fcport
->port_name
,
2654 swl
[swl_idx
].port_name
, WWN_SIZE
);
2655 memcpy(new_fcport
->fabric_port_name
,
2656 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2657 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2659 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2665 /* Send GA_NXT to the switch */
2666 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
2667 if (rval
!= QLA_SUCCESS
) {
2668 qla_printk(KERN_WARNING
, ha
,
2669 "SNS scan failed -- assuming zero-entry "
2671 list_for_each_entry_safe(fcport
, fcptemp
,
2672 new_fcports
, list
) {
2673 list_del(&fcport
->list
);
2681 /* If wrap on switch device list, exit. */
2683 wrap
.b24
= new_fcport
->d_id
.b24
;
2685 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
2686 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2687 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
2688 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
2692 /* Bypass if same physical adapter. */
2693 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
2696 /* Bypass virtual ports of the same host. */
2698 if (ha
->num_vhosts
) {
2699 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
2700 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
2709 /* Bypass if same domain and area of adapter. */
2710 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
2711 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
2715 /* Bypass reserved domain fields. */
2716 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
2719 /* Locate matching device in database. */
2721 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2722 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2728 /* Update port state. */
2729 memcpy(fcport
->fabric_port_name
,
2730 new_fcport
->fabric_port_name
, WWN_SIZE
);
2731 fcport
->fp_speed
= new_fcport
->fp_speed
;
2734 * If address the same and state FCS_ONLINE, nothing
2737 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
2738 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2743 * If device was not a fabric device before.
2745 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2746 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2747 fcport
->loop_id
= FC_NO_LOOP_ID
;
2748 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
2750 fcport
->flags
&= ~FCF_PERSISTENT_BOUND
;
2755 * Port ID changed or device was marked to be updated;
2756 * Log it out if still logged in and mark it for
2759 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2760 fcport
->flags
|= FCF_LOGIN_NEEDED
;
2761 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2762 (fcport
->flags
& FCF_TAPE_PRESENT
) == 0 &&
2763 fcport
->port_type
!= FCT_INITIATOR
&&
2764 fcport
->port_type
!= FCT_BROADCAST
) {
2765 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
2766 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
2767 fcport
->d_id
.b
.al_pa
);
2768 fcport
->loop_id
= FC_NO_LOOP_ID
;
2776 /* If device was not in our fcports list, then add it. */
2777 list_add_tail(&new_fcport
->list
, new_fcports
);
2779 /* Allocate a new replacement fcport. */
2780 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
2781 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2782 if (new_fcport
== NULL
) {
2784 return (QLA_MEMORY_ALLOC_FAILED
);
2786 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2787 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
2793 if (!list_empty(new_fcports
))
2794 vha
->device_flags
|= DFLG_FABRIC_DEVICES
;
2800 * qla2x00_find_new_loop_id
2801 * Scan through our port list and find a new usable loop ID.
2804 * ha: adapter state pointer.
2805 * dev: port structure pointer.
2808 * qla2x00 local function return status code.
2814 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
2819 uint16_t first_loop_id
;
2820 struct qla_hw_data
*ha
= vha
->hw
;
2821 struct scsi_qla_host
*vp
;
2825 /* Save starting loop ID. */
2826 first_loop_id
= dev
->loop_id
;
2829 /* Skip loop ID if already used by adapter. */
2830 if (dev
->loop_id
== vha
->loop_id
)
2833 /* Skip reserved loop IDs. */
2834 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
2837 /* Reset loop ID if passed the end. */
2838 if (dev
->loop_id
> ha
->max_loop_id
) {
2839 /* first loop ID. */
2840 dev
->loop_id
= ha
->min_external_loopid
;
2843 /* Check for loop ID being already in use. */
2846 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
2847 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
2848 if (fcport
->loop_id
== dev
->loop_id
&&
2850 /* ID possibly in use */
2859 /* If not in use then it is free to use. */
2864 /* ID in use. Try next value. */
2867 /* If wrap around. No free ID to use. */
2868 if (dev
->loop_id
== first_loop_id
) {
2869 dev
->loop_id
= FC_NO_LOOP_ID
;
2870 rval
= QLA_FUNCTION_FAILED
;
2879 * qla2x00_device_resync
2880 * Marks devices in the database that needs resynchronization.
2883 * ha = adapter block pointer.
2889 qla2x00_device_resync(scsi_qla_host_t
*vha
)
2894 uint32_t rscn_entry
;
2895 uint8_t rscn_out_iter
;
2899 rval
= QLA_RSCNS_HANDLED
;
2901 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
2902 vha
->flags
.rscn_queue_overflow
) {
2904 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
2905 format
= MSB(MSW(rscn_entry
));
2906 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
2907 d_id
.b
.area
= MSB(LSW(rscn_entry
));
2908 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
2910 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2911 "[%02x/%02x%02x%02x].\n",
2912 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
2913 d_id
.b
.area
, d_id
.b
.al_pa
));
2915 vha
->rscn_out_ptr
++;
2916 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
2917 vha
->rscn_out_ptr
= 0;
2919 /* Skip duplicate entries. */
2920 for (rscn_out_iter
= vha
->rscn_out_ptr
;
2921 !vha
->flags
.rscn_queue_overflow
&&
2922 rscn_out_iter
!= vha
->rscn_in_ptr
;
2923 rscn_out_iter
= (rscn_out_iter
==
2924 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
2926 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
2929 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2930 "entry found at [%d].\n", vha
->host_no
,
2933 vha
->rscn_out_ptr
= rscn_out_iter
;
2936 /* Queue overflow, set switch default case. */
2937 if (vha
->flags
.rscn_queue_overflow
) {
2938 DEBUG(printk("scsi(%ld): device_resync: rscn "
2939 "overflow.\n", vha
->host_no
));
2942 vha
->flags
.rscn_queue_overflow
= 0;
2958 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
2964 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2965 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2966 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
2967 fcport
->port_type
== FCT_BROADCAST
)
2970 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
2972 fcport
->port_type
!= FCT_INITIATOR
) {
2973 qla2x00_mark_device_lost(vha
, fcport
,
2977 fcport
->flags
&= ~FCF_FARP_DONE
;
2984 * qla2x00_fabric_dev_login
2985 * Login fabric target device and update FC port database.
2988 * ha: adapter state pointer.
2989 * fcport: port structure list pointer.
2990 * next_loopid: contains value of a new loop ID that can be used
2991 * by the next login attempt.
2994 * qla2x00 local function return status code.
3000 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3001 uint16_t *next_loopid
)
3006 struct qla_hw_data
*ha
= vha
->hw
;
3011 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3012 if (rval
== QLA_SUCCESS
) {
3013 /* Send an ADISC to tape devices.*/
3015 if (fcport
->flags
& FCF_TAPE_PRESENT
)
3017 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3018 if (rval
!= QLA_SUCCESS
) {
3019 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3020 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3021 fcport
->d_id
.b
.al_pa
);
3022 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3024 qla2x00_update_fcport(vha
, fcport
);
3032 * qla2x00_fabric_login
3033 * Issue fabric login command.
3036 * ha = adapter block pointer.
3037 * device = pointer to FC device type structure.
3040 * 0 - Login successfully
3042 * 2 - Initiator device
3046 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3047 uint16_t *next_loopid
)
3051 uint16_t tmp_loopid
;
3052 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3053 struct qla_hw_data
*ha
= vha
->hw
;
3059 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3060 "for port %02x%02x%02x.\n",
3061 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3062 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3064 /* Login fcport on switch. */
3065 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3066 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3067 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3068 if (mb
[0] == MBS_PORT_ID_USED
) {
3070 * Device has another loop ID. The firmware team
3071 * recommends the driver perform an implicit login with
3072 * the specified ID again. The ID we just used is save
3073 * here so we return with an ID that can be tried by
3077 tmp_loopid
= fcport
->loop_id
;
3078 fcport
->loop_id
= mb
[1];
3080 DEBUG(printk("Fabric Login: port in use - next "
3081 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3082 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3083 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3085 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3090 /* A retry occurred before. */
3091 *next_loopid
= tmp_loopid
;
3094 * No retry occurred before. Just increment the
3095 * ID value for next login.
3097 *next_loopid
= (fcport
->loop_id
+ 1);
3100 if (mb
[1] & BIT_0
) {
3101 fcport
->port_type
= FCT_INITIATOR
;
3103 fcport
->port_type
= FCT_TARGET
;
3104 if (mb
[1] & BIT_1
) {
3105 fcport
->flags
|= FCF_TAPE_PRESENT
;
3110 fcport
->supported_classes
|= FC_COS_CLASS2
;
3112 fcport
->supported_classes
|= FC_COS_CLASS3
;
3116 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3118 * Loop ID already used, try next loop ID.
3121 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3122 if (rval
!= QLA_SUCCESS
) {
3123 /* Ran out of loop IDs to use */
3126 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3128 * Firmware possibly timed out during login. If NO
3129 * retries are left to do then the device is declared
3132 *next_loopid
= fcport
->loop_id
;
3133 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3134 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3135 fcport
->d_id
.b
.al_pa
);
3136 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3142 * unrecoverable / not handled error
3144 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3145 "loop_id=%x jiffies=%lx.\n",
3146 __func__
, vha
->host_no
, mb
[0],
3147 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3148 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3150 *next_loopid
= fcport
->loop_id
;
3151 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3152 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3153 fcport
->d_id
.b
.al_pa
);
3154 fcport
->loop_id
= FC_NO_LOOP_ID
;
3155 fcport
->login_retry
= 0;
3166 * qla2x00_local_device_login
3167 * Issue local device login command.
3170 * ha = adapter block pointer.
3171 * loop_id = loop id of device to login to.
3173 * Returns (Where's the #define!!!!):
3174 * 0 - Login successfully
3179 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3182 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3184 memset(mb
, 0, sizeof(mb
));
3185 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3186 if (rval
== QLA_SUCCESS
) {
3187 /* Interrogate mailbox registers for any errors */
3188 if (mb
[0] == MBS_COMMAND_ERROR
)
3190 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3191 /* device not in PCB table */
3199 * qla2x00_loop_resync
3200 * Resync with fibre channel devices.
3203 * ha = adapter block pointer.
3209 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3211 int rval
= QLA_SUCCESS
;
3213 struct qla_hw_data
*ha
= vha
->hw
;
3214 struct req_que
*req
= ha
->req_q_map
[0];
3215 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3217 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3218 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3219 if (vha
->flags
.online
) {
3220 if (!(rval
= qla2x00_fw_ready(vha
))) {
3221 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3224 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3226 /* Issue a marker after FW becomes ready. */
3227 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3229 vha
->marker_needed
= 0;
3231 /* Remap devices on Loop. */
3232 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3234 qla2x00_configure_loop(vha
);
3236 } while (!atomic_read(&vha
->loop_down_timer
) &&
3237 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3238 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3243 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3244 return (QLA_FUNCTION_FAILED
);
3247 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3253 qla2x00_update_fcports(scsi_qla_host_t
*vha
)
3257 /* Go with deferred removal of rport references. */
3258 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3259 if (fcport
&& fcport
->drport
&&
3260 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
)
3261 qla2x00_rport_del(fcport
);
3266 * Resets ISP and aborts all outstanding commands.
3269 * ha = adapter block pointer.
3275 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3279 struct qla_hw_data
*ha
= vha
->hw
;
3280 struct scsi_qla_host
*vp
;
3281 struct req_que
*req
= ha
->req_q_map
[0];
3283 if (vha
->flags
.online
) {
3284 vha
->flags
.online
= 0;
3285 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3286 ha
->qla_stats
.total_isp_aborts
++;
3288 qla_printk(KERN_INFO
, ha
,
3289 "Performing ISP error recovery - ha= %p.\n", ha
);
3290 ha
->isp_ops
->reset_chip(vha
);
3292 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3293 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3294 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3295 qla2x00_mark_all_devices_lost(vha
, 0);
3296 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3297 qla2x00_mark_all_devices_lost(vp
, 0);
3299 if (!atomic_read(&vha
->loop_down_timer
))
3300 atomic_set(&vha
->loop_down_timer
,
3304 /* Requeue all commands in outstanding command list. */
3305 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3307 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3309 ha
->isp_ops
->nvram_config(vha
);
3311 if (!qla2x00_restart_isp(vha
)) {
3312 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3314 if (!atomic_read(&vha
->loop_down_timer
)) {
3316 * Issue marker command only when we are going
3317 * to start the I/O .
3319 vha
->marker_needed
= 1;
3322 vha
->flags
.online
= 1;
3324 ha
->isp_ops
->enable_intrs(ha
);
3326 ha
->isp_abort_cnt
= 0;
3327 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3330 ha
->flags
.fce_enabled
= 1;
3332 fce_calc_size(ha
->fce_bufs
));
3333 rval
= qla2x00_enable_fce_trace(vha
,
3334 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3337 qla_printk(KERN_WARNING
, ha
,
3338 "Unable to reinitialize FCE "
3340 ha
->flags
.fce_enabled
= 0;
3345 memset(ha
->eft
, 0, EFT_SIZE
);
3346 rval
= qla2x00_enable_eft_trace(vha
,
3347 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3349 qla_printk(KERN_WARNING
, ha
,
3350 "Unable to reinitialize EFT "
3354 } else { /* failed the ISP abort */
3355 vha
->flags
.online
= 1;
3356 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3357 if (ha
->isp_abort_cnt
== 0) {
3358 qla_printk(KERN_WARNING
, ha
,
3359 "ISP error recovery failed - "
3360 "board disabled\n");
3362 * The next call disables the board
3365 ha
->isp_ops
->reset_adapter(vha
);
3366 vha
->flags
.online
= 0;
3367 clear_bit(ISP_ABORT_RETRY
,
3370 } else { /* schedule another ISP abort */
3371 ha
->isp_abort_cnt
--;
3372 DEBUG(printk("qla%ld: ISP abort - "
3373 "retry remaining %d\n",
3374 vha
->host_no
, ha
->isp_abort_cnt
));
3378 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3379 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3380 "- retrying (%d) more times\n",
3381 vha
->host_no
, ha
->isp_abort_cnt
));
3382 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3390 DEBUG(printk(KERN_INFO
3391 "qla2x00_abort_isp(%ld): succeeded.\n",
3393 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3395 qla2x00_vp_abort_isp(vp
);
3398 qla_printk(KERN_INFO
, ha
,
3399 "qla2x00_abort_isp: **** FAILED ****\n");
3406 * qla2x00_restart_isp
3407 * restarts the ISP after a reset
3410 * ha = adapter block pointer.
3416 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
3420 struct qla_hw_data
*ha
= vha
->hw
;
3421 struct req_que
*req
= ha
->req_q_map
[0];
3422 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3424 /* If firmware needs to be loaded */
3425 if (qla2x00_isp_firmware(vha
)) {
3426 vha
->flags
.online
= 0;
3427 status
= ha
->isp_ops
->chip_diag(vha
);
3429 status
= qla2x00_setup_chip(vha
);
3432 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
3433 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3434 /* Initialize the queues in use */
3435 qla25xx_init_queues(ha
);
3437 status
= qla2x00_fw_ready(vha
);
3439 DEBUG(printk("%s(): Start configure loop, "
3440 "status = %d\n", __func__
, status
));
3442 /* Issue a marker after FW becomes ready. */
3443 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
3445 vha
->flags
.online
= 1;
3446 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3449 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3450 qla2x00_configure_loop(vha
);
3452 } while (!atomic_read(&vha
->loop_down_timer
) &&
3453 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3454 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3458 /* if no cable then assume it's good */
3459 if ((vha
->device_flags
& DFLG_NO_CABLE
))
3462 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3470 qla25xx_init_queues(struct qla_hw_data
*ha
)
3472 struct rsp_que
*rsp
= NULL
;
3473 struct req_que
*req
= NULL
;
3474 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3478 for (i
= 1; i
< ha
->max_queues
; i
++) {
3479 rsp
= ha
->rsp_q_map
[i
];
3481 rsp
->options
&= ~BIT_0
;
3482 ret
= qla25xx_init_rsp_que(base_vha
, rsp
, rsp
->options
);
3483 if (ret
!= QLA_SUCCESS
)
3484 DEBUG2_17(printk(KERN_WARNING
3485 "%s Rsp que:%d init failed\n", __func__
,
3488 DEBUG2_17(printk(KERN_INFO
3489 "%s Rsp que:%d inited\n", __func__
,
3492 req
= ha
->req_q_map
[i
];
3494 req
->options
&= ~BIT_0
;
3495 ret
= qla25xx_init_req_que(base_vha
, req
, req
->options
);
3496 if (ret
!= QLA_SUCCESS
)
3497 DEBUG2_17(printk(KERN_WARNING
3498 "%s Req que:%d init failed\n", __func__
,
3501 DEBUG2_17(printk(KERN_WARNING
3502 "%s Rsp que:%d inited\n", __func__
,
3510 * qla2x00_reset_adapter
3514 * ha = adapter block pointer.
3517 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
3519 unsigned long flags
= 0;
3520 struct qla_hw_data
*ha
= vha
->hw
;
3521 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3523 vha
->flags
.online
= 0;
3524 ha
->isp_ops
->disable_intrs(ha
);
3526 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3527 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3528 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3529 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3530 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3531 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3535 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
3537 unsigned long flags
= 0;
3538 struct qla_hw_data
*ha
= vha
->hw
;
3539 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3541 vha
->flags
.online
= 0;
3542 ha
->isp_ops
->disable_intrs(ha
);
3544 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3545 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3546 RD_REG_DWORD(®
->hccr
);
3547 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3548 RD_REG_DWORD(®
->hccr
);
3549 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3552 /* On sparc systems, obtain port and node WWN from firmware
3555 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
3556 struct nvram_24xx
*nv
)
3559 struct qla_hw_data
*ha
= vha
->hw
;
3560 struct pci_dev
*pdev
= ha
->pdev
;
3561 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3565 val
= of_get_property(dp
, "port-wwn", &len
);
3566 if (val
&& len
>= WWN_SIZE
)
3567 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3569 val
= of_get_property(dp
, "node-wwn", &len
);
3570 if (val
&& len
>= WWN_SIZE
)
3571 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3576 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
3579 struct init_cb_24xx
*icb
;
3580 struct nvram_24xx
*nv
;
3582 uint8_t *dptr1
, *dptr2
;
3585 struct qla_hw_data
*ha
= vha
->hw
;
3588 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3591 /* Determine NVRAM starting address. */
3592 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3593 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3594 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3595 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3596 if (PCI_FUNC(ha
->pdev
->devfn
)) {
3597 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3598 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3601 /* Get VPD data into cache */
3602 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
3603 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
3604 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
3606 /* Get NVRAM data into cache and calculate checksum. */
3607 dptr
= (uint32_t *)nv
;
3608 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
3610 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3611 chksum
+= le32_to_cpu(*dptr
++);
3613 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha
->host_no
));
3614 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
3616 /* Bad NVRAM data, set defaults parameters. */
3617 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3618 || nv
->id
[3] != ' ' ||
3619 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3620 /* Reset NVRAM data. */
3621 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
3622 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
3623 le16_to_cpu(nv
->nvram_version
));
3624 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
3625 "invalid -- WWPN) defaults.\n");
3628 * Set default initialization control block.
3630 memset(nv
, 0, ha
->nvram_size
);
3631 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
3632 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
3633 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
3634 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3635 nv
->exchange_count
= __constant_cpu_to_le16(0);
3636 nv
->hard_address
= __constant_cpu_to_le16(124);
3637 nv
->port_name
[0] = 0x21;
3638 nv
->port_name
[1] = 0x00 + PCI_FUNC(ha
->pdev
->devfn
);
3639 nv
->port_name
[2] = 0x00;
3640 nv
->port_name
[3] = 0xe0;
3641 nv
->port_name
[4] = 0x8b;
3642 nv
->port_name
[5] = 0x1c;
3643 nv
->port_name
[6] = 0x55;
3644 nv
->port_name
[7] = 0x86;
3645 nv
->node_name
[0] = 0x20;
3646 nv
->node_name
[1] = 0x00;
3647 nv
->node_name
[2] = 0x00;
3648 nv
->node_name
[3] = 0xe0;
3649 nv
->node_name
[4] = 0x8b;
3650 nv
->node_name
[5] = 0x1c;
3651 nv
->node_name
[6] = 0x55;
3652 nv
->node_name
[7] = 0x86;
3653 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
3654 nv
->login_retry_count
= __constant_cpu_to_le16(8);
3655 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
3656 nv
->login_timeout
= __constant_cpu_to_le16(0);
3657 nv
->firmware_options_1
=
3658 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
3659 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
3660 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
3661 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
3662 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
3663 nv
->efi_parameters
= __constant_cpu_to_le32(0);
3664 nv
->reset_delay
= 5;
3665 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
3666 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
3667 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
3672 /* Reset Initialization control block */
3673 memset(icb
, 0, ha
->init_cb_size
);
3675 /* Copy 1st segment. */
3676 dptr1
= (uint8_t *)icb
;
3677 dptr2
= (uint8_t *)&nv
->version
;
3678 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
3680 *dptr1
++ = *dptr2
++;
3682 icb
->login_retry_count
= nv
->login_retry_count
;
3683 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
3685 /* Copy 2nd segment. */
3686 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
3687 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
3688 cnt
= (uint8_t *)&icb
->reserved_3
-
3689 (uint8_t *)&icb
->interrupt_delay_timer
;
3691 *dptr1
++ = *dptr2
++;
3694 * Setup driver NVRAM options.
3696 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
3699 /* Use alternate WWN? */
3700 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
3701 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
3702 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
3705 /* Prepare nodename */
3706 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
3708 * Firmware will apply the following mask if the nodename was
3711 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
3712 icb
->node_name
[0] &= 0xF0;
3715 /* Set host adapter parameters. */
3716 ha
->flags
.disable_risc_code_load
= 0;
3717 ha
->flags
.enable_lip_reset
= 0;
3718 ha
->flags
.enable_lip_full_login
=
3719 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
3720 ha
->flags
.enable_target_reset
=
3721 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
3722 ha
->flags
.enable_led_scheme
= 0;
3723 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
3725 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
3726 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
3728 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
3729 sizeof(ha
->fw_seriallink_options24
));
3731 /* save HBA serial number */
3732 ha
->serial0
= icb
->port_name
[5];
3733 ha
->serial1
= icb
->port_name
[6];
3734 ha
->serial2
= icb
->port_name
[7];
3735 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
3736 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
3738 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
3740 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
3742 /* Set minimum login_timeout to 4 seconds. */
3743 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
3744 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
3745 if (le16_to_cpu(nv
->login_timeout
) < 4)
3746 nv
->login_timeout
= __constant_cpu_to_le16(4);
3747 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
3748 icb
->login_timeout
= nv
->login_timeout
;
3750 /* Set minimum RATOV to 100 tenths of a second. */
3753 ha
->loop_reset_delay
= nv
->reset_delay
;
3755 /* Link Down Timeout = 0:
3757 * When Port Down timer expires we will start returning
3758 * I/O's to OS with "DID_NO_CONNECT".
3760 * Link Down Timeout != 0:
3762 * The driver waits for the link to come up after link down
3763 * before returning I/Os to OS with "DID_NO_CONNECT".
3765 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
3766 ha
->loop_down_abort_time
=
3767 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
3769 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
3770 ha
->loop_down_abort_time
=
3771 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
3774 /* Need enough time to try and get the port back. */
3775 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
3776 if (qlport_down_retry
)
3777 ha
->port_down_retry_count
= qlport_down_retry
;
3779 /* Set login_retry_count */
3780 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
3781 if (ha
->port_down_retry_count
==
3782 le16_to_cpu(nv
->port_down_retry_count
) &&
3783 ha
->port_down_retry_count
> 3)
3784 ha
->login_retry_count
= ha
->port_down_retry_count
;
3785 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
3786 ha
->login_retry_count
= ha
->port_down_retry_count
;
3787 if (ql2xloginretrycount
)
3788 ha
->login_retry_count
= ql2xloginretrycount
;
3791 if (!vha
->flags
.init_done
) {
3792 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
3793 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3794 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
3795 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
3797 icb
->firmware_options_2
&= __constant_cpu_to_le32(
3798 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
3799 vha
->flags
.process_response_queue
= 0;
3800 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
3801 ha
->zio_mode
= QLA_ZIO_MODE_6
;
3803 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3804 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
3805 ha
->zio_timer
* 100));
3806 qla_printk(KERN_INFO
, ha
,
3807 "ZIO mode %d enabled; timer delay (%d us).\n",
3808 ha
->zio_mode
, ha
->zio_timer
* 100);
3810 icb
->firmware_options_2
|= cpu_to_le32(
3811 (uint32_t)ha
->zio_mode
);
3812 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
3813 vha
->flags
.process_response_queue
= 1;
3817 DEBUG2_3(printk(KERN_WARNING
3818 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
3824 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
3826 int rval
= QLA_SUCCESS
;
3827 int segments
, fragment
;
3829 uint32_t *dcode
, dlen
;
3833 struct qla_hw_data
*ha
= vha
->hw
;
3834 struct req_que
*req
= ha
->req_q_map
[0];
3837 segments
= FA_RISC_CODE_SEGMENTS
;
3838 faddr
= ha
->flt_region_fw
;
3839 dcode
= (uint32_t *)req
->ring
;
3842 /* Validate firmware image by checking version. */
3843 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
3844 for (i
= 0; i
< 4; i
++)
3845 dcode
[i
] = be32_to_cpu(dcode
[i
]);
3846 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
3847 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
3848 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
3850 qla_printk(KERN_WARNING
, ha
,
3851 "Unable to verify integrity of flash firmware image!\n");
3852 qla_printk(KERN_WARNING
, ha
,
3853 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
3854 dcode
[1], dcode
[2], dcode
[3]);
3856 return QLA_FUNCTION_FAILED
;
3859 while (segments
&& rval
== QLA_SUCCESS
) {
3860 /* Read segment's load information. */
3861 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
3863 risc_addr
= be32_to_cpu(dcode
[2]);
3864 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
3865 risc_size
= be32_to_cpu(dcode
[3]);
3868 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3869 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
3870 if (dlen
> risc_size
)
3873 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3874 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3875 vha
->host_no
, risc_addr
, dlen
, faddr
));
3877 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
3878 for (i
= 0; i
< dlen
; i
++)
3879 dcode
[i
] = swab32(dcode
[i
]);
3881 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
3884 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3885 "segment %d of firmware\n", vha
->host_no
,
3887 qla_printk(KERN_WARNING
, ha
,
3888 "[ERROR] Failed to load segment %d of "
3889 "firmware\n", fragment
);
3906 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3909 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
3913 uint16_t *wcode
, *fwcode
;
3914 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
3915 struct fw_blob
*blob
;
3916 struct qla_hw_data
*ha
= vha
->hw
;
3917 struct req_que
*req
= ha
->req_q_map
[0];
3919 /* Load firmware blob. */
3920 blob
= qla2x00_request_firmware(vha
);
3922 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
3923 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
3924 "from: " QLA_FW_URL
".\n");
3925 return QLA_FUNCTION_FAILED
;
3930 wcode
= (uint16_t *)req
->ring
;
3932 fwcode
= (uint16_t *)blob
->fw
->data
;
3935 /* Validate firmware image by checking version. */
3936 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
3937 qla_printk(KERN_WARNING
, ha
,
3938 "Unable to verify integrity of firmware image (%Zd)!\n",
3940 goto fail_fw_integrity
;
3942 for (i
= 0; i
< 4; i
++)
3943 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
3944 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
3945 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
3946 wcode
[2] == 0 && wcode
[3] == 0)) {
3947 qla_printk(KERN_WARNING
, ha
,
3948 "Unable to verify integrity of firmware image!\n");
3949 qla_printk(KERN_WARNING
, ha
,
3950 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
3951 wcode
[1], wcode
[2], wcode
[3]);
3952 goto fail_fw_integrity
;
3956 while (*seg
&& rval
== QLA_SUCCESS
) {
3958 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
3959 risc_size
= be16_to_cpu(fwcode
[3]);
3961 /* Validate firmware image size. */
3962 fwclen
+= risc_size
* sizeof(uint16_t);
3963 if (blob
->fw
->size
< fwclen
) {
3964 qla_printk(KERN_WARNING
, ha
,
3965 "Unable to verify integrity of firmware image "
3966 "(%Zd)!\n", blob
->fw
->size
);
3967 goto fail_fw_integrity
;
3971 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
3972 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
3973 if (wlen
> risc_size
)
3976 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3977 "addr %x, number of words 0x%x.\n", vha
->host_no
,
3980 for (i
= 0; i
< wlen
; i
++)
3981 wcode
[i
] = swab16(fwcode
[i
]);
3983 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
3986 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3987 "segment %d of firmware\n", vha
->host_no
,
3989 qla_printk(KERN_WARNING
, ha
,
3990 "[ERROR] Failed to load segment %d of "
3991 "firmware\n", fragment
);
4007 return QLA_FUNCTION_FAILED
;
4011 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4014 int segments
, fragment
;
4015 uint32_t *dcode
, dlen
;
4019 struct fw_blob
*blob
;
4020 uint32_t *fwcode
, fwclen
;
4021 struct qla_hw_data
*ha
= vha
->hw
;
4022 struct req_que
*req
= ha
->req_q_map
[0];
4024 /* Load firmware blob. */
4025 blob
= qla2x00_request_firmware(vha
);
4027 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4028 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4029 "from: " QLA_FW_URL
".\n");
4031 /* Try to load RISC code from flash. */
4032 qla_printk(KERN_ERR
, ha
, "Attempting to load (potentially "
4033 "outdated) firmware from flash.\n");
4034 return qla24xx_load_risc_flash(vha
, srisc_addr
);
4039 segments
= FA_RISC_CODE_SEGMENTS
;
4040 dcode
= (uint32_t *)req
->ring
;
4042 fwcode
= (uint32_t *)blob
->fw
->data
;
4045 /* Validate firmware image by checking version. */
4046 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4047 qla_printk(KERN_WARNING
, ha
,
4048 "Unable to verify integrity of firmware image (%Zd)!\n",
4050 goto fail_fw_integrity
;
4052 for (i
= 0; i
< 4; i
++)
4053 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4054 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4055 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4056 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4058 qla_printk(KERN_WARNING
, ha
,
4059 "Unable to verify integrity of firmware image!\n");
4060 qla_printk(KERN_WARNING
, ha
,
4061 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4062 dcode
[1], dcode
[2], dcode
[3]);
4063 goto fail_fw_integrity
;
4066 while (segments
&& rval
== QLA_SUCCESS
) {
4067 risc_addr
= be32_to_cpu(fwcode
[2]);
4068 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4069 risc_size
= be32_to_cpu(fwcode
[3]);
4071 /* Validate firmware image size. */
4072 fwclen
+= risc_size
* sizeof(uint32_t);
4073 if (blob
->fw
->size
< fwclen
) {
4074 qla_printk(KERN_WARNING
, ha
,
4075 "Unable to verify integrity of firmware image "
4076 "(%Zd)!\n", blob
->fw
->size
);
4078 goto fail_fw_integrity
;
4082 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4083 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4084 if (dlen
> risc_size
)
4087 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4088 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4091 for (i
= 0; i
< dlen
; i
++)
4092 dcode
[i
] = swab32(fwcode
[i
]);
4094 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4097 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4098 "segment %d of firmware\n", vha
->host_no
,
4100 qla_printk(KERN_WARNING
, ha
,
4101 "[ERROR] Failed to load segment %d of "
4102 "firmware\n", fragment
);
4118 return QLA_FUNCTION_FAILED
;
4122 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4125 struct qla_hw_data
*ha
= vha
->hw
;
4127 if (!IS_FWI2_CAPABLE(ha
))
4129 if (!ha
->fw_major_version
)
4132 ret
= qla2x00_stop_firmware(vha
);
4133 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4134 retries
; retries
--) {
4135 ha
->isp_ops
->reset_chip(vha
);
4136 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4138 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4140 qla_printk(KERN_INFO
, ha
,
4141 "Attempting retry of stop-firmware command...\n");
4142 ret
= qla2x00_stop_firmware(vha
);
4147 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4149 int rval
= QLA_SUCCESS
;
4150 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4151 struct qla_hw_data
*ha
= vha
->hw
;
4152 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4153 struct req_que
*req
= ha
->req_q_map
[0];
4154 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4159 rval
= qla2x00_fw_ready(base_vha
);
4160 if (rval
== QLA_SUCCESS
) {
4161 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4162 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4165 vha
->flags
.management_server_logged_in
= 0;
4167 /* Login to SNS first */
4168 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
4169 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4170 DEBUG15(qla_printk(KERN_INFO
, ha
,
4171 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4172 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4173 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4174 return (QLA_FUNCTION_FAILED
);
4177 atomic_set(&vha
->loop_down_timer
, 0);
4178 atomic_set(&vha
->loop_state
, LOOP_UP
);
4179 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4180 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4181 rval
= qla2x00_loop_resync(base_vha
);
4186 /* 84XX Support **************************************************************/
4188 static LIST_HEAD(qla_cs84xx_list
);
4189 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4191 static struct qla_chip_state_84xx
*
4192 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4194 struct qla_chip_state_84xx
*cs84xx
;
4195 struct qla_hw_data
*ha
= vha
->hw
;
4197 mutex_lock(&qla_cs84xx_mutex
);
4199 /* Find any shared 84xx chip. */
4200 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4201 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4202 kref_get(&cs84xx
->kref
);
4207 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4211 kref_init(&cs84xx
->kref
);
4212 spin_lock_init(&cs84xx
->access_lock
);
4213 mutex_init(&cs84xx
->fw_update_mutex
);
4214 cs84xx
->bus
= ha
->pdev
->bus
;
4216 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4218 mutex_unlock(&qla_cs84xx_mutex
);
4223 __qla84xx_chip_release(struct kref
*kref
)
4225 struct qla_chip_state_84xx
*cs84xx
=
4226 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4228 mutex_lock(&qla_cs84xx_mutex
);
4229 list_del(&cs84xx
->list
);
4230 mutex_unlock(&qla_cs84xx_mutex
);
4235 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4237 struct qla_hw_data
*ha
= vha
->hw
;
4239 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4243 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4247 struct qla_hw_data
*ha
= vha
->hw
;
4249 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4251 rval
= qla84xx_verify_chip(vha
, status
);
4253 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4255 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
: