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/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
21 * QLogic ISP2x00 Hardware Support Function Prototypes.
23 static int qla2x00_isp_firmware(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 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_ctx_sp_timeout(unsigned long __data
)
49 srb_t
*sp
= (srb_t
*)__data
;
51 fc_port_t
*fcport
= sp
->fcport
;
52 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
56 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
57 req
= ha
->req_q_map
[0];
58 req
->outstanding_cmds
[sp
->handle
] = NULL
;
61 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
67 qla2x00_ctx_sp_free(srb_t
*sp
)
69 struct srb_ctx
*ctx
= sp
->ctx
;
72 mempool_free(sp
, sp
->fcport
->vha
->hw
->srb_mempool
);
76 qla2x00_get_ctx_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
, size_t size
,
80 struct qla_hw_data
*ha
= vha
->hw
;
83 sp
= mempool_alloc(ha
->srb_mempool
, GFP_KERNEL
);
86 ctx
= kzalloc(size
, GFP_KERNEL
);
88 mempool_free(sp
, ha
->srb_mempool
);
92 memset(sp
, 0, sizeof(*sp
));
95 ctx
->free
= qla2x00_ctx_sp_free
;
97 init_timer(&ctx
->timer
);
100 ctx
->timer
.expires
= jiffies
+ tmo
* HZ
;
101 ctx
->timer
.data
= (unsigned long)sp
;
102 ctx
->timer
.function
= qla2x00_ctx_sp_timeout
;
103 add_timer(&ctx
->timer
);
108 /* Asynchronous Login/Logout Routines -------------------------------------- */
110 #define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
113 qla2x00_async_logio_timeout(srb_t
*sp
)
115 fc_port_t
*fcport
= sp
->fcport
;
116 struct srb_logio
*lio
= sp
->ctx
;
118 DEBUG2(printk(KERN_WARNING
119 "scsi(%ld:%x): Async-%s timeout.\n",
120 fcport
->vha
->host_no
, sp
->handle
, lio
->ctx
.name
));
122 if (lio
->ctx
.type
== SRB_LOGIN_CMD
)
123 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
127 qla2x00_async_login_ctx_done(srb_t
*sp
)
129 struct srb_logio
*lio
= sp
->ctx
;
131 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
137 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
140 struct qla_hw_data
*ha
= vha
->hw
;
142 struct srb_logio
*lio
;
145 rval
= QLA_FUNCTION_FAILED
;
146 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_logio
),
147 ELS_TMO_2_RATOV(ha
) + 2);
152 lio
->ctx
.type
= SRB_LOGIN_CMD
;
153 lio
->ctx
.name
= "login";
154 lio
->ctx
.timeout
= qla2x00_async_logio_timeout
;
155 lio
->ctx
.done
= qla2x00_async_login_ctx_done
;
156 lio
->flags
|= SRB_LOGIN_COND_PLOGI
;
157 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
158 lio
->flags
|= SRB_LOGIN_RETRIED
;
159 rval
= qla2x00_start_sp(sp
);
160 if (rval
!= QLA_SUCCESS
)
163 DEBUG2(printk(KERN_DEBUG
164 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
165 "retries=%d.\n", fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
166 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
167 fcport
->login_retry
));
171 del_timer_sync(&lio
->ctx
.timer
);
178 qla2x00_async_logout_ctx_done(srb_t
*sp
)
180 struct srb_logio
*lio
= sp
->ctx
;
182 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
188 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
190 struct qla_hw_data
*ha
= vha
->hw
;
192 struct srb_logio
*lio
;
195 rval
= QLA_FUNCTION_FAILED
;
196 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_logio
),
197 ELS_TMO_2_RATOV(ha
) + 2);
202 lio
->ctx
.type
= SRB_LOGOUT_CMD
;
203 lio
->ctx
.name
= "logout";
204 lio
->ctx
.timeout
= qla2x00_async_logio_timeout
;
205 lio
->ctx
.done
= qla2x00_async_logout_ctx_done
;
206 rval
= qla2x00_start_sp(sp
);
207 if (rval
!= QLA_SUCCESS
)
210 DEBUG2(printk(KERN_DEBUG
211 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
212 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
213 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
217 del_timer_sync(&lio
->ctx
.timer
);
224 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
230 case MBS_COMMAND_COMPLETE
:
231 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
232 rval
= qla2x00_get_port_database(vha
, fcport
, BIT_1
);
233 if (rval
!= QLA_SUCCESS
) {
234 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
238 qla2x00_update_fcport(vha
, fcport
);
240 case MBS_COMMAND_ERROR
:
241 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
242 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
244 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
246 case MBS_PORT_ID_USED
:
247 fcport
->loop_id
= data
[1];
248 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
250 case MBS_LOOP_ID_USED
:
252 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
253 if (rval
!= QLA_SUCCESS
) {
254 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
257 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
264 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
267 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
271 /****************************************************************************/
272 /* QLogic ISP2x00 Hardware Support Functions. */
273 /****************************************************************************/
276 * qla2x00_initialize_adapter
280 * ha = adapter block pointer.
286 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
289 struct qla_hw_data
*ha
= vha
->hw
;
290 struct req_que
*req
= ha
->req_q_map
[0];
292 /* Clear adapter flags. */
293 vha
->flags
.online
= 0;
294 ha
->flags
.chip_reset_done
= 0;
295 vha
->flags
.reset_active
= 0;
296 ha
->flags
.pci_channel_io_perm_failure
= 0;
297 ha
->flags
.eeh_busy
= 0;
298 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
299 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
300 vha
->device_flags
= DFLG_NO_CABLE
;
302 vha
->flags
.management_server_logged_in
= 0;
303 vha
->marker_needed
= 0;
304 ha
->isp_abort_cnt
= 0;
305 ha
->beacon_blink_led
= 0;
307 set_bit(0, ha
->req_qid_map
);
308 set_bit(0, ha
->rsp_qid_map
);
310 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
311 rval
= ha
->isp_ops
->pci_config(vha
);
313 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
318 ha
->isp_ops
->reset_chip(vha
);
320 rval
= qla2xxx_get_flash_info(vha
);
322 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
327 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
329 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
331 ha
->isp_ops
->nvram_config(vha
);
333 if (ha
->flags
.disable_serdes
) {
334 /* Mask HBA via NVRAM settings? */
335 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
336 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
337 vha
->port_name
[0], vha
->port_name
[1],
338 vha
->port_name
[2], vha
->port_name
[3],
339 vha
->port_name
[4], vha
->port_name
[5],
340 vha
->port_name
[6], vha
->port_name
[7]);
341 return QLA_FUNCTION_FAILED
;
344 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
346 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
347 rval
= ha
->isp_ops
->chip_diag(vha
);
350 rval
= qla2x00_setup_chip(vha
);
355 if (IS_QLA84XX(ha
)) {
356 ha
->cs84xx
= qla84xx_get_chip(vha
);
358 qla_printk(KERN_ERR
, ha
,
359 "Unable to configure ISP84XX.\n");
360 return QLA_FUNCTION_FAILED
;
363 rval
= qla2x00_init_rings(vha
);
364 ha
->flags
.chip_reset_done
= 1;
366 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
367 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
368 rval
= qla84xx_init_chip(vha
);
369 if (rval
!= QLA_SUCCESS
) {
370 qla_printk(KERN_ERR
, ha
,
371 "Unable to initialize ISP84XX.\n");
372 qla84xx_put_chip(vha
);
376 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
)) {
377 if (qla24xx_read_fcp_prio_cfg(vha
))
378 qla_printk(KERN_ERR
, ha
,
379 "Unable to read FCP priority data.\n");
386 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
389 * Returns 0 on success.
392 qla2100_pci_config(scsi_qla_host_t
*vha
)
396 struct qla_hw_data
*ha
= vha
->hw
;
397 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
399 pci_set_master(ha
->pdev
);
400 pci_try_set_mwi(ha
->pdev
);
402 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
403 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
404 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
406 pci_disable_rom(ha
->pdev
);
408 /* Get PCI bus information. */
409 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
410 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
411 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
417 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
420 * Returns 0 on success.
423 qla2300_pci_config(scsi_qla_host_t
*vha
)
426 unsigned long flags
= 0;
428 struct qla_hw_data
*ha
= vha
->hw
;
429 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
431 pci_set_master(ha
->pdev
);
432 pci_try_set_mwi(ha
->pdev
);
434 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
435 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
437 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
438 w
&= ~PCI_COMMAND_INTX_DISABLE
;
439 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
442 * If this is a 2300 card and not 2312, reset the
443 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
444 * the 2310 also reports itself as a 2300 so we need to get the
445 * fb revision level -- a 6 indicates it really is a 2300 and
448 if (IS_QLA2300(ha
)) {
449 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
452 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
453 for (cnt
= 0; cnt
< 30000; cnt
++) {
454 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
460 /* Select FPM registers. */
461 WRT_REG_WORD(®
->ctrl_status
, 0x20);
462 RD_REG_WORD(®
->ctrl_status
);
464 /* Get the fb rev level */
465 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
467 if (ha
->fb_rev
== FPM_2300
)
468 pci_clear_mwi(ha
->pdev
);
470 /* Deselect FPM registers. */
471 WRT_REG_WORD(®
->ctrl_status
, 0x0);
472 RD_REG_WORD(®
->ctrl_status
);
474 /* Release RISC module. */
475 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
476 for (cnt
= 0; cnt
< 30000; cnt
++) {
477 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
483 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
486 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
488 pci_disable_rom(ha
->pdev
);
490 /* Get PCI bus information. */
491 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
492 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
493 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
499 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
502 * Returns 0 on success.
505 qla24xx_pci_config(scsi_qla_host_t
*vha
)
508 unsigned long flags
= 0;
509 struct qla_hw_data
*ha
= vha
->hw
;
510 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
512 pci_set_master(ha
->pdev
);
513 pci_try_set_mwi(ha
->pdev
);
515 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
516 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
517 w
&= ~PCI_COMMAND_INTX_DISABLE
;
518 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
520 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
522 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
523 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
524 pcix_set_mmrbc(ha
->pdev
, 2048);
526 /* PCIe -- adjust Maximum Read Request Size (2048). */
527 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
528 pcie_set_readrq(ha
->pdev
, 2048);
530 pci_disable_rom(ha
->pdev
);
532 ha
->chip_revision
= ha
->pdev
->revision
;
534 /* Get PCI bus information. */
535 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
536 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
537 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
543 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
546 * Returns 0 on success.
549 qla25xx_pci_config(scsi_qla_host_t
*vha
)
552 struct qla_hw_data
*ha
= vha
->hw
;
554 pci_set_master(ha
->pdev
);
555 pci_try_set_mwi(ha
->pdev
);
557 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
558 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
559 w
&= ~PCI_COMMAND_INTX_DISABLE
;
560 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
562 /* PCIe -- adjust Maximum Read Request Size (2048). */
563 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
564 pcie_set_readrq(ha
->pdev
, 2048);
566 pci_disable_rom(ha
->pdev
);
568 ha
->chip_revision
= ha
->pdev
->revision
;
574 * qla2x00_isp_firmware() - Choose firmware image.
577 * Returns 0 on success.
580 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
583 uint16_t loop_id
, topo
, sw_cap
;
584 uint8_t domain
, area
, al_pa
;
585 struct qla_hw_data
*ha
= vha
->hw
;
587 /* Assume loading risc code */
588 rval
= QLA_FUNCTION_FAILED
;
590 if (ha
->flags
.disable_risc_code_load
) {
591 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
593 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
595 /* Verify checksum of loaded RISC code. */
596 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
597 if (rval
== QLA_SUCCESS
) {
598 /* And, verify we are not in ROM code. */
599 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
600 &area
, &domain
, &topo
, &sw_cap
);
605 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
613 * qla2x00_reset_chip() - Reset ISP chip.
616 * Returns 0 on success.
619 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
621 unsigned long flags
= 0;
622 struct qla_hw_data
*ha
= vha
->hw
;
623 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
627 if (unlikely(pci_channel_offline(ha
->pdev
)))
630 ha
->isp_ops
->disable_intrs(ha
);
632 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
634 /* Turn off master enable */
636 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
637 cmd
&= ~PCI_COMMAND_MASTER
;
638 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
640 if (!IS_QLA2100(ha
)) {
642 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
643 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
644 for (cnt
= 0; cnt
< 30000; cnt
++) {
645 if ((RD_REG_WORD(®
->hccr
) &
646 HCCR_RISC_PAUSE
) != 0)
651 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
655 /* Select FPM registers. */
656 WRT_REG_WORD(®
->ctrl_status
, 0x20);
657 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
659 /* FPM Soft Reset. */
660 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
661 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
663 /* Toggle Fpm Reset. */
664 if (!IS_QLA2200(ha
)) {
665 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
666 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
669 /* Select frame buffer registers. */
670 WRT_REG_WORD(®
->ctrl_status
, 0x10);
671 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
673 /* Reset frame buffer FIFOs. */
674 if (IS_QLA2200(ha
)) {
675 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
676 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
678 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
680 /* Read back fb_cmd until zero or 3 seconds max */
681 for (cnt
= 0; cnt
< 3000; cnt
++) {
682 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
688 /* Select RISC module registers. */
689 WRT_REG_WORD(®
->ctrl_status
, 0);
690 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
692 /* Reset RISC processor. */
693 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
694 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
696 /* Release RISC processor. */
697 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
698 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
701 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
702 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
704 /* Reset ISP chip. */
705 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
707 /* Wait for RISC to recover from reset. */
708 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
710 * It is necessary to for a delay here since the card doesn't
711 * respond to PCI reads during a reset. On some architectures
712 * this will result in an MCA.
715 for (cnt
= 30000; cnt
; cnt
--) {
716 if ((RD_REG_WORD(®
->ctrl_status
) &
717 CSR_ISP_SOFT_RESET
) == 0)
724 /* Reset RISC processor. */
725 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
727 WRT_REG_WORD(®
->semaphore
, 0);
729 /* Release RISC processor. */
730 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
731 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
733 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
734 for (cnt
= 0; cnt
< 30000; cnt
++) {
735 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
743 /* Turn on master enable */
744 cmd
|= PCI_COMMAND_MASTER
;
745 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
747 /* Disable RISC pause on FPM parity error. */
748 if (!IS_QLA2100(ha
)) {
749 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
750 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
753 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
757 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
760 * Returns 0 on success.
763 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
765 unsigned long flags
= 0;
766 struct qla_hw_data
*ha
= vha
->hw
;
767 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
771 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
774 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
775 for (cnt
= 0; cnt
< 30000; cnt
++) {
776 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
782 WRT_REG_DWORD(®
->ctrl_status
,
783 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
784 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
787 /* Wait for firmware to complete NVRAM accesses. */
788 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
789 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
791 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
795 /* Wait for soft-reset to complete. */
796 d2
= RD_REG_DWORD(®
->ctrl_status
);
797 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
799 d2
= RD_REG_DWORD(®
->ctrl_status
);
803 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
804 RD_REG_DWORD(®
->hccr
);
806 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
807 RD_REG_DWORD(®
->hccr
);
809 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
810 RD_REG_DWORD(®
->hccr
);
812 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
813 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
815 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
819 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
821 if (IS_NOPOLLING_TYPE(ha
))
822 ha
->isp_ops
->enable_intrs(ha
);
826 * qla24xx_reset_chip() - Reset ISP24xx chip.
829 * Returns 0 on success.
832 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
834 struct qla_hw_data
*ha
= vha
->hw
;
836 if (pci_channel_offline(ha
->pdev
) &&
837 ha
->flags
.pci_channel_io_perm_failure
) {
841 ha
->isp_ops
->disable_intrs(ha
);
843 /* Perform RISC reset. */
844 qla24xx_reset_risc(vha
);
848 * qla2x00_chip_diag() - Test chip for proper operation.
851 * Returns 0 on success.
854 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
857 struct qla_hw_data
*ha
= vha
->hw
;
858 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
859 unsigned long flags
= 0;
863 struct req_que
*req
= ha
->req_q_map
[0];
865 /* Assume a failed state */
866 rval
= QLA_FUNCTION_FAILED
;
868 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
869 vha
->host_no
, (u_long
)®
->flash_address
));
871 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
873 /* Reset ISP chip. */
874 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
877 * We need to have a delay here since the card will not respond while
878 * in reset causing an MCA on some architectures.
881 data
= qla2x00_debounce_register(®
->ctrl_status
);
882 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
884 data
= RD_REG_WORD(®
->ctrl_status
);
889 goto chip_diag_failed
;
891 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
894 /* Reset RISC processor. */
895 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
896 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
898 /* Workaround for QLA2312 PCI parity error */
899 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
900 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
901 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
903 data
= RD_MAILBOX_REG(ha
, reg
, 0);
910 goto chip_diag_failed
;
912 /* Check product ID of chip */
913 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha
->host_no
));
915 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
916 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
917 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
918 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
919 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
920 mb
[3] != PROD_ID_3
) {
921 qla_printk(KERN_WARNING
, ha
,
922 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
924 goto chip_diag_failed
;
926 ha
->product_id
[0] = mb
[1];
927 ha
->product_id
[1] = mb
[2];
928 ha
->product_id
[2] = mb
[3];
929 ha
->product_id
[3] = mb
[4];
931 /* Adjust fw RISC transfer size */
932 if (req
->length
> 1024)
933 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
935 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
938 if (IS_QLA2200(ha
) &&
939 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
940 /* Limit firmware transfer size with a 2200A */
941 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
944 ha
->device_type
|= DT_ISP2200A
;
945 ha
->fw_transfer_size
= 128;
948 /* Wrap Incoming Mailboxes Test. */
949 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
951 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
952 rval
= qla2x00_mbx_reg_test(vha
);
954 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
956 qla_printk(KERN_WARNING
, ha
,
957 "Failed mailbox send register test\n");
960 /* Flag a successful rval */
963 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
967 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
968 "****\n", vha
->host_no
));
970 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
976 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
979 * Returns 0 on success.
982 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
985 struct qla_hw_data
*ha
= vha
->hw
;
986 struct req_que
*req
= ha
->req_q_map
[0];
991 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
993 rval
= qla2x00_mbx_reg_test(vha
);
995 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
997 qla_printk(KERN_WARNING
, ha
,
998 "Failed mailbox send register test\n");
1000 /* Flag a successful rval */
1008 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1011 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1012 eft_size
, fce_size
, mq_size
;
1015 struct qla_hw_data
*ha
= vha
->hw
;
1016 struct req_que
*req
= ha
->req_q_map
[0];
1017 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1020 qla_printk(KERN_WARNING
, ha
,
1021 "Firmware dump previously allocated.\n");
1026 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1027 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1028 fixed_size
= sizeof(struct qla2100_fw_dump
);
1029 } else if (IS_QLA23XX(ha
)) {
1030 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1031 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1033 } else if (IS_FWI2_CAPABLE(ha
)) {
1035 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1036 else if (IS_QLA25XX(ha
))
1037 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1039 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1040 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1043 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1044 /* Allocate memory for Fibre Channel Event Buffer. */
1045 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1048 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1051 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1052 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
1056 memset(tc
, 0, FCE_SIZE
);
1057 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1058 ha
->fce_mb
, &ha
->fce_bufs
);
1060 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1061 "FCE (%d).\n", rval
);
1062 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1064 ha
->flags
.fce_enabled
= 0;
1068 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
1071 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1072 ha
->flags
.fce_enabled
= 1;
1073 ha
->fce_dma
= tc_dma
;
1076 /* Allocate memory for Extended Trace Buffer. */
1077 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1080 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1081 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
1085 memset(tc
, 0, EFT_SIZE
);
1086 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1088 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1089 "EFT (%d).\n", rval
);
1090 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1095 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
1098 eft_size
= EFT_SIZE
;
1099 ha
->eft_dma
= tc_dma
;
1103 req_q_size
= req
->length
* sizeof(request_t
);
1104 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1106 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1107 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1108 ha
->chain_offset
= dump_size
;
1109 dump_size
+= mq_size
+ fce_size
;
1111 ha
->fw_dump
= vmalloc(dump_size
);
1113 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
1114 "firmware dump!!!\n", dump_size
/ 1024);
1117 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1124 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
1127 ha
->fw_dump_len
= dump_size
;
1128 ha
->fw_dump
->signature
[0] = 'Q';
1129 ha
->fw_dump
->signature
[1] = 'L';
1130 ha
->fw_dump
->signature
[2] = 'G';
1131 ha
->fw_dump
->signature
[3] = 'C';
1132 ha
->fw_dump
->version
= __constant_htonl(1);
1134 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1135 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1136 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1137 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1139 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1140 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1141 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1143 ha
->fw_dump
->header_size
=
1144 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1148 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1150 #define MPS_MASK 0xe0
1154 struct qla_hw_data
*ha
= vha
->hw
;
1156 if (!IS_QLA81XX(vha
->hw
))
1159 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1160 if (rval
!= QLA_SUCCESS
) {
1161 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1162 "Sync-MPI: Unable to acquire semaphore.\n"));
1166 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1167 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1168 if (rval
!= QLA_SUCCESS
) {
1169 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1170 "Sync-MPI: Unable to read sync.\n"));
1175 if (dc
== (dw
& MPS_MASK
))
1180 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1181 if (rval
!= QLA_SUCCESS
) {
1182 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1183 "Sync-MPI: Unable to gain sync.\n"));
1187 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1188 if (rval
!= QLA_SUCCESS
) {
1189 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1190 "Sync-MPI: Unable to release semaphore.\n"));
1198 * qla2x00_setup_chip() - Load and start RISC firmware.
1201 * Returns 0 on success.
1204 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1207 uint32_t srisc_address
= 0;
1208 struct qla_hw_data
*ha
= vha
->hw
;
1209 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1210 unsigned long flags
;
1211 uint16_t fw_major_version
;
1213 if (IS_QLA82XX(ha
)) {
1214 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1215 if (rval
== QLA_SUCCESS
)
1216 goto enable_82xx_npiv
;
1219 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1220 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1221 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1222 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1223 RD_REG_WORD(®
->hccr
);
1224 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1227 qla81xx_mpi_sync(vha
);
1229 /* Load firmware sequences */
1230 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1231 if (rval
== QLA_SUCCESS
) {
1232 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1233 "code.\n", vha
->host_no
));
1235 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1236 if (rval
== QLA_SUCCESS
) {
1237 /* Start firmware execution. */
1238 DEBUG(printk("scsi(%ld): Checksum OK, start "
1239 "firmware.\n", vha
->host_no
));
1241 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1242 /* Retrieve firmware information. */
1243 if (rval
== QLA_SUCCESS
) {
1245 fw_major_version
= ha
->fw_major_version
;
1246 rval
= qla2x00_get_fw_version(vha
,
1247 &ha
->fw_major_version
,
1248 &ha
->fw_minor_version
,
1249 &ha
->fw_subminor_version
,
1250 &ha
->fw_attributes
, &ha
->fw_memory_size
,
1251 ha
->mpi_version
, &ha
->mpi_capabilities
,
1253 if (rval
!= QLA_SUCCESS
)
1255 ha
->flags
.npiv_supported
= 0;
1256 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1257 (ha
->fw_attributes
& BIT_2
)) {
1258 ha
->flags
.npiv_supported
= 1;
1259 if ((!ha
->max_npiv_vports
) ||
1260 ((ha
->max_npiv_vports
+ 1) %
1261 MIN_MULTI_ID_FABRIC
))
1262 ha
->max_npiv_vports
=
1263 MIN_MULTI_ID_FABRIC
- 1;
1265 qla2x00_get_resource_cnts(vha
, NULL
,
1266 &ha
->fw_xcb_count
, NULL
, NULL
,
1267 &ha
->max_npiv_vports
, NULL
);
1269 if (!fw_major_version
&& ql2xallocfwdump
) {
1270 if (!IS_QLA82XX(ha
))
1271 qla2x00_alloc_fw_dump(vha
);
1275 DEBUG2(printk(KERN_INFO
1276 "scsi(%ld): ISP Firmware failed checksum.\n",
1281 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1282 /* Enable proper parity. */
1283 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1286 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1288 /* SRAM, Instruction RAM and GP RAM parity */
1289 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1290 RD_REG_WORD(®
->hccr
);
1291 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1294 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1297 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1298 if (rval
== QLA_SUCCESS
) {
1299 ha
->flags
.fac_supported
= 1;
1300 ha
->fdt_block_size
= size
<< 2;
1302 qla_printk(KERN_ERR
, ha
,
1303 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1304 ha
->fw_major_version
, ha
->fw_minor_version
,
1305 ha
->fw_subminor_version
);
1310 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1318 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1321 * Beginning of request ring has initialization control block already built
1322 * by nvram config routine.
1324 * Returns 0 on success.
1327 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1332 rsp
->ring_ptr
= rsp
->ring
;
1333 rsp
->ring_index
= 0;
1334 rsp
->status_srb
= NULL
;
1335 pkt
= rsp
->ring_ptr
;
1336 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1337 pkt
->signature
= RESPONSE_PROCESSED
;
1343 * qla2x00_update_fw_options() - Read and process firmware options.
1346 * Returns 0 on success.
1349 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1351 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1352 struct qla_hw_data
*ha
= vha
->hw
;
1354 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1355 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1357 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1360 /* Serial Link options. */
1361 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1363 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1364 sizeof(ha
->fw_seriallink_options
)));
1366 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1367 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1368 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1371 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1372 emphasis
= (ha
->fw_seriallink_options
[2] &
1373 (BIT_4
| BIT_3
)) >> 3;
1374 tx_sens
= ha
->fw_seriallink_options
[0] &
1375 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1376 rx_sens
= (ha
->fw_seriallink_options
[0] &
1377 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1378 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1379 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1382 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1383 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1384 ha
->fw_options
[10] |= BIT_5
|
1385 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1386 (tx_sens
& (BIT_1
| BIT_0
));
1389 swing
= (ha
->fw_seriallink_options
[2] &
1390 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1391 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1392 tx_sens
= ha
->fw_seriallink_options
[1] &
1393 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1394 rx_sens
= (ha
->fw_seriallink_options
[1] &
1395 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1396 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1397 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1400 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1401 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1402 ha
->fw_options
[11] |= BIT_5
|
1403 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1404 (tx_sens
& (BIT_1
| BIT_0
));
1408 /* Return command IOCBs without waiting for an ABTS to complete. */
1409 ha
->fw_options
[3] |= BIT_13
;
1412 if (ha
->flags
.enable_led_scheme
)
1413 ha
->fw_options
[2] |= BIT_12
;
1415 /* Detect ISP6312. */
1417 ha
->fw_options
[2] |= BIT_13
;
1419 /* Update firmware options. */
1420 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1424 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1427 struct qla_hw_data
*ha
= vha
->hw
;
1432 /* Update Serial Link options. */
1433 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1436 rval
= qla2x00_set_serdes_params(vha
,
1437 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1438 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1439 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1440 if (rval
!= QLA_SUCCESS
) {
1441 qla_printk(KERN_WARNING
, ha
,
1442 "Unable to update Serial Link options (%x).\n", rval
);
1447 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1449 struct qla_hw_data
*ha
= vha
->hw
;
1450 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1451 struct req_que
*req
= ha
->req_q_map
[0];
1452 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1454 /* Setup ring parameters in initialization control block. */
1455 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1456 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1457 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1458 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1459 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1460 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1461 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1462 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1464 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1465 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1466 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1467 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1468 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1472 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1474 struct qla_hw_data
*ha
= vha
->hw
;
1475 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1476 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1477 struct qla_msix_entry
*msix
;
1478 struct init_cb_24xx
*icb
;
1480 struct req_que
*req
= ha
->req_q_map
[0];
1481 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1483 /* Setup ring parameters in initialization control block. */
1484 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1485 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1486 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1487 icb
->request_q_length
= cpu_to_le16(req
->length
);
1488 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1489 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1490 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1491 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1492 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1495 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1496 icb
->rid
= __constant_cpu_to_le16(rid
);
1497 if (ha
->flags
.msix_enabled
) {
1498 msix
= &ha
->msix_entries
[1];
1499 DEBUG2_17(printk(KERN_INFO
1500 "Registering vector 0x%x for base que\n", msix
->entry
));
1501 icb
->msix
= cpu_to_le16(msix
->entry
);
1503 /* Use alternate PCI bus number */
1505 icb
->firmware_options_2
|=
1506 __constant_cpu_to_le32(BIT_19
);
1507 /* Use alternate PCI devfn */
1509 icb
->firmware_options_2
|=
1510 __constant_cpu_to_le32(BIT_18
);
1512 /* Use Disable MSIX Handshake mode for capable adapters */
1513 if (IS_MSIX_NACK_CAPABLE(ha
)) {
1514 icb
->firmware_options_2
&=
1515 __constant_cpu_to_le32(~BIT_22
);
1516 ha
->flags
.disable_msix_handshake
= 1;
1517 qla_printk(KERN_INFO
, ha
,
1518 "MSIX Handshake Disable Mode turned on\n");
1520 icb
->firmware_options_2
|=
1521 __constant_cpu_to_le32(BIT_22
);
1523 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1525 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1526 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1527 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1528 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1530 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1531 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1532 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1533 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1536 RD_REG_DWORD(&ioreg
->hccr
);
1540 * qla2x00_init_rings() - Initializes firmware.
1543 * Beginning of request ring has initialization control block already built
1544 * by nvram config routine.
1546 * Returns 0 on success.
1549 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1552 unsigned long flags
= 0;
1554 struct qla_hw_data
*ha
= vha
->hw
;
1555 struct req_que
*req
;
1556 struct rsp_que
*rsp
;
1557 struct scsi_qla_host
*vp
;
1558 struct mid_init_cb_24xx
*mid_init_cb
=
1559 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1561 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1563 /* Clear outstanding commands array. */
1564 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1565 req
= ha
->req_q_map
[que
];
1568 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1569 req
->outstanding_cmds
[cnt
] = NULL
;
1571 req
->current_outstanding_cmd
= 1;
1573 /* Initialize firmware. */
1574 req
->ring_ptr
= req
->ring
;
1575 req
->ring_index
= 0;
1576 req
->cnt
= req
->length
;
1579 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1580 rsp
= ha
->rsp_q_map
[que
];
1583 /* Initialize response queue entries */
1584 qla2x00_init_response_q_entries(rsp
);
1587 /* Clear RSCN queue. */
1588 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
1589 vp
->rscn_in_ptr
= 0;
1590 vp
->rscn_out_ptr
= 0;
1592 ha
->isp_ops
->config_rings(vha
);
1594 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1596 /* Update any ISP specific firmware options before initialization. */
1597 ha
->isp_ops
->update_fw_options(vha
);
1599 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1601 if (ha
->flags
.npiv_supported
) {
1602 if (ha
->operating_mode
== LOOP
)
1603 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1604 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1607 if (IS_FWI2_CAPABLE(ha
)) {
1608 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1609 mid_init_cb
->init_cb
.execution_throttle
=
1610 cpu_to_le16(ha
->fw_xcb_count
);
1613 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1615 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1618 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1626 * qla2x00_fw_ready() - Waits for firmware ready.
1629 * Returns 0 on success.
1632 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1635 unsigned long wtime
, mtime
, cs84xx_time
;
1636 uint16_t min_wait
; /* Minimum wait time if loop is down */
1637 uint16_t wait_time
; /* Wait time if loop is coming ready */
1639 struct qla_hw_data
*ha
= vha
->hw
;
1643 /* 20 seconds for loop down. */
1647 * Firmware should take at most one RATOV to login, plus 5 seconds for
1648 * our own processing.
1650 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1651 wait_time
= min_wait
;
1654 /* Min wait time if loop down */
1655 mtime
= jiffies
+ (min_wait
* HZ
);
1657 /* wait time before firmware ready */
1658 wtime
= jiffies
+ (wait_time
* HZ
);
1660 /* Wait for ISP to finish LIP */
1661 if (!vha
->flags
.init_done
)
1662 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1664 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1668 rval
= qla2x00_get_firmware_state(vha
, state
);
1669 if (rval
== QLA_SUCCESS
) {
1670 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1671 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1673 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1674 DEBUG16(printk("scsi(%ld): fw_state=%x "
1675 "84xx=%x.\n", vha
->host_no
, state
[0],
1677 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1678 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1679 DEBUG16(printk("scsi(%ld): Sending "
1680 "verify iocb.\n", vha
->host_no
));
1682 cs84xx_time
= jiffies
;
1683 rval
= qla84xx_init_chip(vha
);
1684 if (rval
!= QLA_SUCCESS
)
1687 /* Add time taken to initialize. */
1688 cs84xx_time
= jiffies
- cs84xx_time
;
1689 wtime
+= cs84xx_time
;
1690 mtime
+= cs84xx_time
;
1691 DEBUG16(printk("scsi(%ld): Increasing "
1692 "wait time by %ld. New time %ld\n",
1693 vha
->host_no
, cs84xx_time
, wtime
));
1695 } else if (state
[0] == FSTATE_READY
) {
1696 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1699 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1700 &ha
->login_timeout
, &ha
->r_a_tov
);
1706 rval
= QLA_FUNCTION_FAILED
;
1708 if (atomic_read(&vha
->loop_down_timer
) &&
1709 state
[0] != FSTATE_READY
) {
1710 /* Loop down. Timeout on min_wait for states
1711 * other than Wait for Login.
1713 if (time_after_eq(jiffies
, mtime
)) {
1714 qla_printk(KERN_INFO
, ha
,
1715 "Cable is unplugged...\n");
1717 vha
->device_flags
|= DFLG_NO_CABLE
;
1722 /* Mailbox cmd failed. Timeout on min_wait. */
1723 if (time_after_eq(jiffies
, mtime
))
1727 if (time_after_eq(jiffies
, wtime
))
1730 /* Delay for a while */
1733 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1734 vha
->host_no
, state
[0], jiffies
));
1737 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1738 vha
->host_no
, state
[0], state
[1], state
[2], state
[3], state
[4],
1742 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1750 * qla2x00_configure_hba
1751 * Setup adapter context.
1754 * ha = adapter state pointer.
1763 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1772 char connect_type
[22];
1773 struct qla_hw_data
*ha
= vha
->hw
;
1775 /* Get host addresses. */
1776 rval
= qla2x00_get_adapter_id(vha
,
1777 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1778 if (rval
!= QLA_SUCCESS
) {
1779 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
1780 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1781 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1782 __func__
, vha
->host_no
));
1784 qla_printk(KERN_WARNING
, ha
,
1785 "ERROR -- Unable to get host loop ID.\n");
1786 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1792 qla_printk(KERN_INFO
, ha
,
1793 "Cannot get topology - retrying.\n");
1794 return (QLA_FUNCTION_FAILED
);
1797 vha
->loop_id
= loop_id
;
1800 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
1801 ha
->operating_mode
= LOOP
;
1806 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1808 ha
->current_topology
= ISP_CFG_NL
;
1809 strcpy(connect_type
, "(Loop)");
1813 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1815 ha
->switch_cap
= sw_cap
;
1816 ha
->current_topology
= ISP_CFG_FL
;
1817 strcpy(connect_type
, "(FL_Port)");
1821 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1823 ha
->operating_mode
= P2P
;
1824 ha
->current_topology
= ISP_CFG_N
;
1825 strcpy(connect_type
, "(N_Port-to-N_Port)");
1829 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1831 ha
->switch_cap
= sw_cap
;
1832 ha
->operating_mode
= P2P
;
1833 ha
->current_topology
= ISP_CFG_F
;
1834 strcpy(connect_type
, "(F_Port)");
1838 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1840 vha
->host_no
, topo
));
1841 ha
->current_topology
= ISP_CFG_NL
;
1842 strcpy(connect_type
, "(Loop)");
1846 /* Save Host port and loop ID. */
1847 /* byte order - Big Endian */
1848 vha
->d_id
.b
.domain
= domain
;
1849 vha
->d_id
.b
.area
= area
;
1850 vha
->d_id
.b
.al_pa
= al_pa
;
1852 if (!vha
->flags
.init_done
)
1853 qla_printk(KERN_INFO
, ha
,
1854 "Topology - %s, Host Loop address 0x%x\n",
1855 connect_type
, vha
->loop_id
);
1858 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
1860 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
1867 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
1872 struct qla_hw_data
*ha
= vha
->hw
;
1873 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
1874 !IS_QLA8XXX_TYPE(ha
);
1876 if (memcmp(model
, BINZERO
, len
) != 0) {
1877 strncpy(ha
->model_number
, model
, len
);
1878 st
= en
= ha
->model_number
;
1881 if (*en
!= 0x20 && *en
!= 0x00)
1886 index
= (ha
->pdev
->subsystem_device
& 0xff);
1888 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1889 index
< QLA_MODEL_NAMES
)
1890 strncpy(ha
->model_desc
,
1891 qla2x00_model_name
[index
* 2 + 1],
1892 sizeof(ha
->model_desc
) - 1);
1894 index
= (ha
->pdev
->subsystem_device
& 0xff);
1896 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
1897 index
< QLA_MODEL_NAMES
) {
1898 strcpy(ha
->model_number
,
1899 qla2x00_model_name
[index
* 2]);
1900 strncpy(ha
->model_desc
,
1901 qla2x00_model_name
[index
* 2 + 1],
1902 sizeof(ha
->model_desc
) - 1);
1904 strcpy(ha
->model_number
, def
);
1907 if (IS_FWI2_CAPABLE(ha
))
1908 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
1909 sizeof(ha
->model_desc
));
1912 /* On sparc systems, obtain port and node WWN from firmware
1915 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
1918 struct qla_hw_data
*ha
= vha
->hw
;
1919 struct pci_dev
*pdev
= ha
->pdev
;
1920 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
1924 val
= of_get_property(dp
, "port-wwn", &len
);
1925 if (val
&& len
>= WWN_SIZE
)
1926 memcpy(nv
->port_name
, val
, WWN_SIZE
);
1928 val
= of_get_property(dp
, "node-wwn", &len
);
1929 if (val
&& len
>= WWN_SIZE
)
1930 memcpy(nv
->node_name
, val
, WWN_SIZE
);
1935 * NVRAM configuration for ISP 2xxx
1938 * ha = adapter block pointer.
1941 * initialization control block in response_ring
1942 * host adapters parameters in host adapter block
1948 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
1953 uint8_t *dptr1
, *dptr2
;
1954 struct qla_hw_data
*ha
= vha
->hw
;
1955 init_cb_t
*icb
= ha
->init_cb
;
1956 nvram_t
*nv
= ha
->nvram
;
1957 uint8_t *ptr
= ha
->nvram
;
1958 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1962 /* Determine NVRAM starting address. */
1963 ha
->nvram_size
= sizeof(nvram_t
);
1965 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
1966 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
1967 ha
->nvram_base
= 0x80;
1969 /* Get NVRAM data and calculate checksum. */
1970 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
1971 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
1974 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
1975 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
1977 /* Bad NVRAM data, set defaults parameters. */
1978 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
1979 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
1980 /* Reset NVRAM data. */
1981 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
1982 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
1984 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
1985 "invalid -- WWPN) defaults.\n");
1988 * Set default initialization control block.
1990 memset(nv
, 0, ha
->nvram_size
);
1991 nv
->parameter_block_version
= ICB_VERSION
;
1993 if (IS_QLA23XX(ha
)) {
1994 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
1995 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
1996 nv
->add_firmware_options
[0] = BIT_5
;
1997 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
1998 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
1999 nv
->special_options
[1] = BIT_7
;
2000 } else if (IS_QLA2200(ha
)) {
2001 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2002 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2003 nv
->add_firmware_options
[0] = BIT_5
;
2004 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2005 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2006 } else if (IS_QLA2100(ha
)) {
2007 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2008 nv
->firmware_options
[1] = BIT_5
;
2009 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2012 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2013 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2014 nv
->retry_count
= 8;
2015 nv
->retry_delay
= 1;
2017 nv
->port_name
[0] = 33;
2018 nv
->port_name
[3] = 224;
2019 nv
->port_name
[4] = 139;
2021 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2023 nv
->login_timeout
= 4;
2026 * Set default host adapter parameters
2028 nv
->host_p
[1] = BIT_2
;
2029 nv
->reset_delay
= 5;
2030 nv
->port_down_retry_count
= 8;
2031 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2032 nv
->link_down_timeout
= 60;
2037 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2039 * The SN2 does not provide BIOS emulation which means you can't change
2040 * potentially bogus BIOS settings. Force the use of default settings
2041 * for link rate and frame size. Hope that the rest of the settings
2044 if (ia64_platform_is("sn2")) {
2045 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2047 nv
->special_options
[1] = BIT_7
;
2051 /* Reset Initialization control block */
2052 memset(icb
, 0, ha
->init_cb_size
);
2055 * Setup driver NVRAM options.
2057 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2058 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2059 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2060 nv
->firmware_options
[1] &= ~BIT_4
;
2062 if (IS_QLA23XX(ha
)) {
2063 nv
->firmware_options
[0] |= BIT_2
;
2064 nv
->firmware_options
[0] &= ~BIT_3
;
2065 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2067 if (IS_QLA2300(ha
)) {
2068 if (ha
->fb_rev
== FPM_2310
) {
2069 strcpy(ha
->model_number
, "QLA2310");
2071 strcpy(ha
->model_number
, "QLA2300");
2074 qla2x00_set_model_info(vha
, nv
->model_number
,
2075 sizeof(nv
->model_number
), "QLA23xx");
2077 } else if (IS_QLA2200(ha
)) {
2078 nv
->firmware_options
[0] |= BIT_2
;
2080 * 'Point-to-point preferred, else loop' is not a safe
2081 * connection mode setting.
2083 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2085 /* Force 'loop preferred, else point-to-point'. */
2086 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2087 nv
->add_firmware_options
[0] |= BIT_5
;
2089 strcpy(ha
->model_number
, "QLA22xx");
2090 } else /*if (IS_QLA2100(ha))*/ {
2091 strcpy(ha
->model_number
, "QLA2100");
2095 * Copy over NVRAM RISC parameter block to initialization control block.
2097 dptr1
= (uint8_t *)icb
;
2098 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2099 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2101 *dptr1
++ = *dptr2
++;
2103 /* Copy 2nd half. */
2104 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2105 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2107 *dptr1
++ = *dptr2
++;
2109 /* Use alternate WWN? */
2110 if (nv
->host_p
[1] & BIT_7
) {
2111 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2112 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2115 /* Prepare nodename */
2116 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2118 * Firmware will apply the following mask if the nodename was
2121 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2122 icb
->node_name
[0] &= 0xF0;
2126 * Set host adapter parameters.
2128 if (nv
->host_p
[0] & BIT_7
)
2129 ql2xextended_error_logging
= 1;
2130 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2131 /* Always load RISC code on non ISP2[12]00 chips. */
2132 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2133 ha
->flags
.disable_risc_code_load
= 0;
2134 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2135 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2136 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2137 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2138 ha
->flags
.disable_serdes
= 0;
2140 ha
->operating_mode
=
2141 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2143 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2144 sizeof(ha
->fw_seriallink_options
));
2146 /* save HBA serial number */
2147 ha
->serial0
= icb
->port_name
[5];
2148 ha
->serial1
= icb
->port_name
[6];
2149 ha
->serial2
= icb
->port_name
[7];
2150 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2151 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2153 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2155 ha
->retry_count
= nv
->retry_count
;
2157 /* Set minimum login_timeout to 4 seconds. */
2158 if (nv
->login_timeout
< ql2xlogintimeout
)
2159 nv
->login_timeout
= ql2xlogintimeout
;
2160 if (nv
->login_timeout
< 4)
2161 nv
->login_timeout
= 4;
2162 ha
->login_timeout
= nv
->login_timeout
;
2163 icb
->login_timeout
= nv
->login_timeout
;
2165 /* Set minimum RATOV to 100 tenths of a second. */
2168 ha
->loop_reset_delay
= nv
->reset_delay
;
2170 /* Link Down Timeout = 0:
2172 * When Port Down timer expires we will start returning
2173 * I/O's to OS with "DID_NO_CONNECT".
2175 * Link Down Timeout != 0:
2177 * The driver waits for the link to come up after link down
2178 * before returning I/Os to OS with "DID_NO_CONNECT".
2180 if (nv
->link_down_timeout
== 0) {
2181 ha
->loop_down_abort_time
=
2182 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2184 ha
->link_down_timeout
= nv
->link_down_timeout
;
2185 ha
->loop_down_abort_time
=
2186 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2190 * Need enough time to try and get the port back.
2192 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2193 if (qlport_down_retry
)
2194 ha
->port_down_retry_count
= qlport_down_retry
;
2195 /* Set login_retry_count */
2196 ha
->login_retry_count
= nv
->retry_count
;
2197 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2198 ha
->port_down_retry_count
> 3)
2199 ha
->login_retry_count
= ha
->port_down_retry_count
;
2200 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2201 ha
->login_retry_count
= ha
->port_down_retry_count
;
2202 if (ql2xloginretrycount
)
2203 ha
->login_retry_count
= ql2xloginretrycount
;
2205 icb
->lun_enables
= __constant_cpu_to_le16(0);
2206 icb
->command_resource_count
= 0;
2207 icb
->immediate_notify_resource_count
= 0;
2208 icb
->timeout
= __constant_cpu_to_le16(0);
2210 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2212 icb
->firmware_options
[0] &= ~BIT_3
;
2213 icb
->add_firmware_options
[0] &=
2214 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2215 icb
->add_firmware_options
[0] |= BIT_2
;
2216 icb
->response_accumulation_timer
= 3;
2217 icb
->interrupt_delay_timer
= 5;
2219 vha
->flags
.process_response_queue
= 1;
2222 if (!vha
->flags
.init_done
) {
2223 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2224 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2225 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2226 icb
->interrupt_delay_timer
: 2;
2228 icb
->add_firmware_options
[0] &=
2229 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2230 vha
->flags
.process_response_queue
= 0;
2231 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2232 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2234 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2235 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
2236 ha
->zio_timer
* 100));
2237 qla_printk(KERN_INFO
, ha
,
2238 "ZIO mode %d enabled; timer delay (%d us).\n",
2239 ha
->zio_mode
, ha
->zio_timer
* 100);
2241 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2242 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2243 vha
->flags
.process_response_queue
= 1;
2248 DEBUG2_3(printk(KERN_WARNING
2249 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
2255 qla2x00_rport_del(void *data
)
2257 fc_port_t
*fcport
= data
;
2258 struct fc_rport
*rport
;
2260 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2261 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2262 fcport
->drport
= NULL
;
2263 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2265 fc_remote_port_delete(rport
);
2269 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2271 * @flags: allocation flags
2273 * Returns a pointer to the allocated fcport, or NULL, if none available.
2276 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2280 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2284 /* Setup fcport template structure. */
2286 fcport
->vp_idx
= vha
->vp_idx
;
2287 fcport
->port_type
= FCT_UNKNOWN
;
2288 fcport
->loop_id
= FC_NO_LOOP_ID
;
2289 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
2290 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2296 * qla2x00_configure_loop
2297 * Updates Fibre Channel Device Database with what is actually on loop.
2300 * ha = adapter block pointer.
2305 * 2 = database was full and device was not configured.
2308 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2311 unsigned long flags
, save_flags
;
2312 struct qla_hw_data
*ha
= vha
->hw
;
2315 /* Get Initiator ID */
2316 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2317 rval
= qla2x00_configure_hba(vha
);
2318 if (rval
!= QLA_SUCCESS
) {
2319 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2325 save_flags
= flags
= vha
->dpc_flags
;
2326 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2327 vha
->host_no
, flags
));
2330 * If we have both an RSCN and PORT UPDATE pending then handle them
2331 * both at the same time.
2333 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2334 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2336 qla2x00_get_data_rate(vha
);
2338 /* Determine what we need to do */
2339 if (ha
->current_topology
== ISP_CFG_FL
&&
2340 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2342 vha
->flags
.rscn_queue_overflow
= 1;
2343 set_bit(RSCN_UPDATE
, &flags
);
2345 } else if (ha
->current_topology
== ISP_CFG_F
&&
2346 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2348 vha
->flags
.rscn_queue_overflow
= 1;
2349 set_bit(RSCN_UPDATE
, &flags
);
2350 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2352 } else if (ha
->current_topology
== ISP_CFG_N
) {
2353 clear_bit(RSCN_UPDATE
, &flags
);
2355 } else if (!vha
->flags
.online
||
2356 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2358 vha
->flags
.rscn_queue_overflow
= 1;
2359 set_bit(RSCN_UPDATE
, &flags
);
2360 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2363 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2364 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2365 rval
= QLA_FUNCTION_FAILED
;
2367 rval
= qla2x00_configure_local_loop(vha
);
2370 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2371 if (LOOP_TRANSITION(vha
))
2372 rval
= QLA_FUNCTION_FAILED
;
2374 rval
= qla2x00_configure_fabric(vha
);
2377 if (rval
== QLA_SUCCESS
) {
2378 if (atomic_read(&vha
->loop_down_timer
) ||
2379 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2380 rval
= QLA_FUNCTION_FAILED
;
2382 atomic_set(&vha
->loop_state
, LOOP_READY
);
2384 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2389 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2390 __func__
, vha
->host_no
));
2392 DEBUG3(printk("%s: exiting normally\n", __func__
));
2395 /* Restore state if a resync event occurred during processing */
2396 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2397 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2398 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2399 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2400 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2401 vha
->flags
.rscn_queue_overflow
= 1;
2411 * qla2x00_configure_local_loop
2412 * Updates Fibre Channel Device Database with local loop devices.
2415 * ha = adapter block pointer.
2421 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2426 fc_port_t
*fcport
, *new_fcport
;
2432 uint8_t domain
, area
, al_pa
;
2433 struct qla_hw_data
*ha
= vha
->hw
;
2437 entries
= MAX_FIBRE_DEVICES
;
2439 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2440 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2442 /* Get list of logged in devices. */
2443 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2444 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2446 if (rval
!= QLA_SUCCESS
)
2447 goto cleanup_allocation
;
2449 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2450 vha
->host_no
, entries
));
2451 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2452 entries
* sizeof(struct gid_list_info
)));
2454 /* Allocate temporary fcport for any new fcports discovered. */
2455 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2456 if (new_fcport
== NULL
) {
2457 rval
= QLA_MEMORY_ALLOC_FAILED
;
2458 goto cleanup_allocation
;
2460 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2463 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2465 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2466 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2467 fcport
->port_type
!= FCT_BROADCAST
&&
2468 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2470 DEBUG(printk("scsi(%ld): Marking port lost, "
2472 vha
->host_no
, fcport
->loop_id
));
2474 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2478 /* Add devices to port list. */
2479 id_iter
= (char *)ha
->gid_list
;
2480 for (index
= 0; index
< entries
; index
++) {
2481 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2482 area
= ((struct gid_list_info
*)id_iter
)->area
;
2483 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2484 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2485 loop_id
= (uint16_t)
2486 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2488 loop_id
= le16_to_cpu(
2489 ((struct gid_list_info
*)id_iter
)->loop_id
);
2490 id_iter
+= ha
->gid_list_info_size
;
2492 /* Bypass reserved domain fields. */
2493 if ((domain
& 0xf0) == 0xf0)
2496 /* Bypass if not same domain and area of adapter. */
2497 if (area
&& domain
&&
2498 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2501 /* Bypass invalid local loop ID. */
2502 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2505 /* Fill in member data. */
2506 new_fcport
->d_id
.b
.domain
= domain
;
2507 new_fcport
->d_id
.b
.area
= area
;
2508 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2509 new_fcport
->loop_id
= loop_id
;
2510 new_fcport
->vp_idx
= vha
->vp_idx
;
2511 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2512 if (rval2
!= QLA_SUCCESS
) {
2513 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2514 "information -- get_port_database=%x, "
2516 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2517 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2519 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2523 /* Check for matching device in port list. */
2526 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2527 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2531 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2532 fcport
->loop_id
= new_fcport
->loop_id
;
2533 fcport
->port_type
= new_fcport
->port_type
;
2534 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2535 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2543 /* New device, add to fcports list. */
2545 new_fcport
->vha
= vha
;
2546 new_fcport
->vp_idx
= vha
->vp_idx
;
2548 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2550 /* Allocate a new replacement fcport. */
2551 fcport
= new_fcport
;
2552 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2553 if (new_fcport
== NULL
) {
2554 rval
= QLA_MEMORY_ALLOC_FAILED
;
2555 goto cleanup_allocation
;
2557 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2560 /* Base iIDMA settings on HBA port speed. */
2561 fcport
->fp_speed
= ha
->link_data_rate
;
2563 qla2x00_update_fcport(vha
, fcport
);
2571 if (rval
!= QLA_SUCCESS
) {
2572 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2573 "rval=%x\n", vha
->host_no
, rval
));
2580 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2582 #define LS_UNKNOWN 2
2583 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
2587 struct qla_hw_data
*ha
= vha
->hw
;
2589 if (!IS_IIDMA_CAPABLE(ha
))
2592 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2593 fcport
->fp_speed
> ha
->link_data_rate
)
2596 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2598 if (rval
!= QLA_SUCCESS
) {
2599 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2600 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2601 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2602 fcport
->port_name
[2], fcport
->port_name
[3],
2603 fcport
->port_name
[4], fcport
->port_name
[5],
2604 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2605 fcport
->fp_speed
, mb
[0], mb
[1]));
2607 link_speed
= link_speeds
[LS_UNKNOWN
];
2608 if (fcport
->fp_speed
< 5)
2609 link_speed
= link_speeds
[fcport
->fp_speed
];
2610 else if (fcport
->fp_speed
== 0x13)
2611 link_speed
= link_speeds
[5];
2612 DEBUG2(qla_printk(KERN_INFO
, ha
,
2613 "iIDMA adjusted to %s GB/s on "
2614 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2615 link_speed
, fcport
->port_name
[0],
2616 fcport
->port_name
[1], fcport
->port_name
[2],
2617 fcport
->port_name
[3], fcport
->port_name
[4],
2618 fcport
->port_name
[5], fcport
->port_name
[6],
2619 fcport
->port_name
[7]));
2624 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2626 struct fc_rport_identifiers rport_ids
;
2627 struct fc_rport
*rport
;
2628 struct qla_hw_data
*ha
= vha
->hw
;
2630 qla2x00_rport_del(fcport
);
2632 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2633 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2634 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2635 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2636 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2637 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2639 qla_printk(KERN_WARNING
, ha
,
2640 "Unable to allocate fc remote port!\n");
2643 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2644 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2645 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2647 rport
->supported_classes
= fcport
->supported_classes
;
2649 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2650 if (fcport
->port_type
== FCT_INITIATOR
)
2651 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2652 if (fcport
->port_type
== FCT_TARGET
)
2653 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2654 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2658 * qla2x00_update_fcport
2659 * Updates device on list.
2662 * ha = adapter block pointer.
2663 * fcport = port structure pointer.
2673 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2675 struct qla_hw_data
*ha
= vha
->hw
;
2678 fcport
->login_retry
= 0;
2679 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2681 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2683 fcport
->flags
&= ~FCF_LOGIN_NEEDED
;
2685 qla2x00_iidma_fcport(vha
, fcport
);
2687 atomic_set(&fcport
->state
, FCS_ONLINE
);
2689 qla2x00_reg_remote_port(vha
, fcport
);
2693 * qla2x00_configure_fabric
2694 * Setup SNS devices with loop ID's.
2697 * ha = adapter block pointer.
2704 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2707 fc_port_t
*fcport
, *fcptemp
;
2708 uint16_t next_loopid
;
2709 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2711 LIST_HEAD(new_fcports
);
2712 struct qla_hw_data
*ha
= vha
->hw
;
2713 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2715 /* If FL port exists, then SNS is present */
2716 if (IS_FWI2_CAPABLE(ha
))
2717 loop_id
= NPH_F_PORT
;
2719 loop_id
= SNS_FL_PORT
;
2720 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2721 if (rval
!= QLA_SUCCESS
) {
2722 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2723 "Port\n", vha
->host_no
));
2725 vha
->device_flags
&= ~SWITCH_FOUND
;
2726 return (QLA_SUCCESS
);
2728 vha
->device_flags
|= SWITCH_FOUND
;
2730 /* Mark devices that need re-synchronization. */
2731 rval2
= qla2x00_device_resync(vha
);
2732 if (rval2
== QLA_RSCNS_HANDLED
) {
2733 /* No point doing the scan, just continue. */
2734 return (QLA_SUCCESS
);
2738 if (ql2xfdmienable
&&
2739 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2740 qla2x00_fdmi_register(vha
);
2742 /* Ensure we are logged into the SNS. */
2743 if (IS_FWI2_CAPABLE(ha
))
2746 loop_id
= SIMPLE_NAME_SERVER
;
2747 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2748 0xfc, mb
, BIT_1
| BIT_0
);
2749 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2750 DEBUG2(qla_printk(KERN_INFO
, ha
,
2751 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2752 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2753 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2754 return (QLA_SUCCESS
);
2757 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
2758 if (qla2x00_rft_id(vha
)) {
2760 DEBUG2(printk("scsi(%ld): Register FC-4 "
2761 "TYPE failed.\n", vha
->host_no
));
2763 if (qla2x00_rff_id(vha
)) {
2765 DEBUG2(printk("scsi(%ld): Register FC-4 "
2766 "Features failed.\n", vha
->host_no
));
2768 if (qla2x00_rnn_id(vha
)) {
2770 DEBUG2(printk("scsi(%ld): Register Node Name "
2771 "failed.\n", vha
->host_no
));
2772 } else if (qla2x00_rsnn_nn(vha
)) {
2774 DEBUG2(printk("scsi(%ld): Register Symbolic "
2775 "Node Name failed.\n", vha
->host_no
));
2779 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
2780 if (rval
!= QLA_SUCCESS
)
2784 * Logout all previous fabric devices marked lost, except
2787 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2788 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2791 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
2794 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
2795 qla2x00_mark_device_lost(vha
, fcport
,
2796 ql2xplogiabsentdevice
, 0);
2797 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
2798 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
2799 fcport
->port_type
!= FCT_INITIATOR
&&
2800 fcport
->port_type
!= FCT_BROADCAST
) {
2801 ha
->isp_ops
->fabric_logout(vha
,
2803 fcport
->d_id
.b
.domain
,
2804 fcport
->d_id
.b
.area
,
2805 fcport
->d_id
.b
.al_pa
);
2806 fcport
->loop_id
= FC_NO_LOOP_ID
;
2811 /* Starting free loop ID. */
2812 next_loopid
= ha
->min_external_loopid
;
2815 * Scan through our port list and login entries that need to be
2818 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2819 if (atomic_read(&vha
->loop_down_timer
) ||
2820 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2823 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
2824 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
2827 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
2828 fcport
->loop_id
= next_loopid
;
2829 rval
= qla2x00_find_new_loop_id(
2831 if (rval
!= QLA_SUCCESS
) {
2832 /* Ran out of IDs to use */
2836 /* Login and update database */
2837 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2840 /* Exit if out of loop IDs. */
2841 if (rval
!= QLA_SUCCESS
) {
2846 * Login and add the new devices to our port list.
2848 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2849 if (atomic_read(&vha
->loop_down_timer
) ||
2850 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2853 /* Find a new loop ID to use. */
2854 fcport
->loop_id
= next_loopid
;
2855 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
2856 if (rval
!= QLA_SUCCESS
) {
2857 /* Ran out of IDs to use */
2861 /* Login and update database */
2862 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
2866 fcport
->vp_idx
= vha
->vp_idx
;
2868 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
2872 /* Free all new device structures not processed. */
2873 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
2874 list_del(&fcport
->list
);
2879 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2880 "rval=%d\n", vha
->host_no
, rval
));
2888 * qla2x00_find_all_fabric_devs
2891 * ha = adapter block pointer.
2892 * dev = database device entry pointer.
2901 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
2902 struct list_head
*new_fcports
)
2906 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
2911 int first_dev
, last_dev
;
2912 port_id_t wrap
, nxt_d_id
;
2913 struct qla_hw_data
*ha
= vha
->hw
;
2914 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
2915 struct scsi_qla_host
*tvp
;
2919 /* Try GID_PT to get device list, else GAN. */
2920 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
2923 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2924 "on GA_NXT\n", vha
->host_no
));
2926 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
2929 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
2932 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
2935 } else if (ql2xiidmaenable
&&
2936 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
2937 qla2x00_gpsc(vha
, swl
);
2942 /* Allocate temporary fcport for any new fcports discovered. */
2943 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2944 if (new_fcport
== NULL
) {
2946 return (QLA_MEMORY_ALLOC_FAILED
);
2948 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
2949 /* Set start port ID scan at adapter ID. */
2953 /* Starting free loop ID. */
2954 loop_id
= ha
->min_external_loopid
;
2955 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
2956 if (qla2x00_is_reserved_id(vha
, loop_id
))
2959 if (atomic_read(&vha
->loop_down_timer
) ||
2960 LOOP_TRANSITION(vha
)) {
2961 atomic_set(&vha
->loop_down_timer
, 0);
2962 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2963 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2969 wrap
.b24
= new_fcport
->d_id
.b24
;
2971 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
2972 memcpy(new_fcport
->node_name
,
2973 swl
[swl_idx
].node_name
, WWN_SIZE
);
2974 memcpy(new_fcport
->port_name
,
2975 swl
[swl_idx
].port_name
, WWN_SIZE
);
2976 memcpy(new_fcport
->fabric_port_name
,
2977 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
2978 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
2980 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
2986 /* Send GA_NXT to the switch */
2987 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
2988 if (rval
!= QLA_SUCCESS
) {
2989 qla_printk(KERN_WARNING
, ha
,
2990 "SNS scan failed -- assuming zero-entry "
2992 list_for_each_entry_safe(fcport
, fcptemp
,
2993 new_fcports
, list
) {
2994 list_del(&fcport
->list
);
3002 /* If wrap on switch device list, exit. */
3004 wrap
.b24
= new_fcport
->d_id
.b24
;
3006 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3007 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
3008 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
3009 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
3013 /* Bypass if same physical adapter. */
3014 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3017 /* Bypass virtual ports of the same host. */
3019 if (ha
->num_vhosts
) {
3020 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3021 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3030 /* Bypass if same domain and area of adapter. */
3031 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3032 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3036 /* Bypass reserved domain fields. */
3037 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3040 /* Locate matching device in database. */
3042 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3043 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3049 /* Update port state. */
3050 memcpy(fcport
->fabric_port_name
,
3051 new_fcport
->fabric_port_name
, WWN_SIZE
);
3052 fcport
->fp_speed
= new_fcport
->fp_speed
;
3055 * If address the same and state FCS_ONLINE, nothing
3058 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3059 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3064 * If device was not a fabric device before.
3066 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3067 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3068 fcport
->loop_id
= FC_NO_LOOP_ID
;
3069 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3075 * Port ID changed or device was marked to be updated;
3076 * Log it out if still logged in and mark it for
3079 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3080 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3081 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3082 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3083 fcport
->port_type
!= FCT_INITIATOR
&&
3084 fcport
->port_type
!= FCT_BROADCAST
) {
3085 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3086 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3087 fcport
->d_id
.b
.al_pa
);
3088 fcport
->loop_id
= FC_NO_LOOP_ID
;
3096 /* If device was not in our fcports list, then add it. */
3097 list_add_tail(&new_fcport
->list
, new_fcports
);
3099 /* Allocate a new replacement fcport. */
3100 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3101 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3102 if (new_fcport
== NULL
) {
3104 return (QLA_MEMORY_ALLOC_FAILED
);
3106 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3107 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3117 * qla2x00_find_new_loop_id
3118 * Scan through our port list and find a new usable loop ID.
3121 * ha: adapter state pointer.
3122 * dev: port structure pointer.
3125 * qla2x00 local function return status code.
3131 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3136 uint16_t first_loop_id
;
3137 struct qla_hw_data
*ha
= vha
->hw
;
3138 struct scsi_qla_host
*vp
;
3139 struct scsi_qla_host
*tvp
;
3143 /* Save starting loop ID. */
3144 first_loop_id
= dev
->loop_id
;
3147 /* Skip loop ID if already used by adapter. */
3148 if (dev
->loop_id
== vha
->loop_id
)
3151 /* Skip reserved loop IDs. */
3152 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3155 /* Reset loop ID if passed the end. */
3156 if (dev
->loop_id
> ha
->max_loop_id
) {
3157 /* first loop ID. */
3158 dev
->loop_id
= ha
->min_external_loopid
;
3161 /* Check for loop ID being already in use. */
3164 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3165 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3166 if (fcport
->loop_id
== dev
->loop_id
&&
3168 /* ID possibly in use */
3177 /* If not in use then it is free to use. */
3182 /* ID in use. Try next value. */
3185 /* If wrap around. No free ID to use. */
3186 if (dev
->loop_id
== first_loop_id
) {
3187 dev
->loop_id
= FC_NO_LOOP_ID
;
3188 rval
= QLA_FUNCTION_FAILED
;
3197 * qla2x00_device_resync
3198 * Marks devices in the database that needs resynchronization.
3201 * ha = adapter block pointer.
3207 qla2x00_device_resync(scsi_qla_host_t
*vha
)
3212 uint32_t rscn_entry
;
3213 uint8_t rscn_out_iter
;
3217 rval
= QLA_RSCNS_HANDLED
;
3219 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
3220 vha
->flags
.rscn_queue_overflow
) {
3222 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
3223 format
= MSB(MSW(rscn_entry
));
3224 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
3225 d_id
.b
.area
= MSB(LSW(rscn_entry
));
3226 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
3228 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3229 "[%02x/%02x%02x%02x].\n",
3230 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
3231 d_id
.b
.area
, d_id
.b
.al_pa
));
3233 vha
->rscn_out_ptr
++;
3234 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
3235 vha
->rscn_out_ptr
= 0;
3237 /* Skip duplicate entries. */
3238 for (rscn_out_iter
= vha
->rscn_out_ptr
;
3239 !vha
->flags
.rscn_queue_overflow
&&
3240 rscn_out_iter
!= vha
->rscn_in_ptr
;
3241 rscn_out_iter
= (rscn_out_iter
==
3242 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
3244 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
3247 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3248 "entry found at [%d].\n", vha
->host_no
,
3251 vha
->rscn_out_ptr
= rscn_out_iter
;
3254 /* Queue overflow, set switch default case. */
3255 if (vha
->flags
.rscn_queue_overflow
) {
3256 DEBUG(printk("scsi(%ld): device_resync: rscn "
3257 "overflow.\n", vha
->host_no
));
3260 vha
->flags
.rscn_queue_overflow
= 0;
3276 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
3282 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3283 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3284 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
3285 fcport
->port_type
== FCT_BROADCAST
)
3288 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3290 fcport
->port_type
!= FCT_INITIATOR
) {
3291 qla2x00_mark_device_lost(vha
, fcport
,
3301 * qla2x00_fabric_dev_login
3302 * Login fabric target device and update FC port database.
3305 * ha: adapter state pointer.
3306 * fcport: port structure list pointer.
3307 * next_loopid: contains value of a new loop ID that can be used
3308 * by the next login attempt.
3311 * qla2x00 local function return status code.
3317 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3318 uint16_t *next_loopid
)
3323 struct qla_hw_data
*ha
= vha
->hw
;
3328 if (IS_ALOGIO_CAPABLE(ha
)) {
3329 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3334 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3335 if (rval
== QLA_SUCCESS
) {
3336 /* Send an ADISC to FCP2 devices.*/
3338 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3340 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3341 if (rval
!= QLA_SUCCESS
) {
3342 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3343 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3344 fcport
->d_id
.b
.al_pa
);
3345 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3347 qla2x00_update_fcport(vha
, fcport
);
3355 * qla2x00_fabric_login
3356 * Issue fabric login command.
3359 * ha = adapter block pointer.
3360 * device = pointer to FC device type structure.
3363 * 0 - Login successfully
3365 * 2 - Initiator device
3369 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3370 uint16_t *next_loopid
)
3374 uint16_t tmp_loopid
;
3375 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3376 struct qla_hw_data
*ha
= vha
->hw
;
3382 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3383 "for port %02x%02x%02x.\n",
3384 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3385 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3387 /* Login fcport on switch. */
3388 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3389 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3390 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3391 if (mb
[0] == MBS_PORT_ID_USED
) {
3393 * Device has another loop ID. The firmware team
3394 * recommends the driver perform an implicit login with
3395 * the specified ID again. The ID we just used is save
3396 * here so we return with an ID that can be tried by
3400 tmp_loopid
= fcport
->loop_id
;
3401 fcport
->loop_id
= mb
[1];
3403 DEBUG(printk("Fabric Login: port in use - next "
3404 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3405 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3406 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3408 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3413 /* A retry occurred before. */
3414 *next_loopid
= tmp_loopid
;
3417 * No retry occurred before. Just increment the
3418 * ID value for next login.
3420 *next_loopid
= (fcport
->loop_id
+ 1);
3423 if (mb
[1] & BIT_0
) {
3424 fcport
->port_type
= FCT_INITIATOR
;
3426 fcport
->port_type
= FCT_TARGET
;
3427 if (mb
[1] & BIT_1
) {
3428 fcport
->flags
|= FCF_FCP2_DEVICE
;
3433 fcport
->supported_classes
|= FC_COS_CLASS2
;
3435 fcport
->supported_classes
|= FC_COS_CLASS3
;
3439 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3441 * Loop ID already used, try next loop ID.
3444 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3445 if (rval
!= QLA_SUCCESS
) {
3446 /* Ran out of loop IDs to use */
3449 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3451 * Firmware possibly timed out during login. If NO
3452 * retries are left to do then the device is declared
3455 *next_loopid
= fcport
->loop_id
;
3456 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3457 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3458 fcport
->d_id
.b
.al_pa
);
3459 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3465 * unrecoverable / not handled error
3467 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3468 "loop_id=%x jiffies=%lx.\n",
3469 __func__
, vha
->host_no
, mb
[0],
3470 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3471 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3473 *next_loopid
= fcport
->loop_id
;
3474 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3475 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3476 fcport
->d_id
.b
.al_pa
);
3477 fcport
->loop_id
= FC_NO_LOOP_ID
;
3478 fcport
->login_retry
= 0;
3489 * qla2x00_local_device_login
3490 * Issue local device login command.
3493 * ha = adapter block pointer.
3494 * loop_id = loop id of device to login to.
3496 * Returns (Where's the #define!!!!):
3497 * 0 - Login successfully
3502 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3505 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3507 memset(mb
, 0, sizeof(mb
));
3508 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3509 if (rval
== QLA_SUCCESS
) {
3510 /* Interrogate mailbox registers for any errors */
3511 if (mb
[0] == MBS_COMMAND_ERROR
)
3513 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3514 /* device not in PCB table */
3522 * qla2x00_loop_resync
3523 * Resync with fibre channel devices.
3526 * ha = adapter block pointer.
3532 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3534 int rval
= QLA_SUCCESS
;
3536 struct req_que
*req
;
3537 struct rsp_que
*rsp
;
3539 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3540 req
= vha
->hw
->req_q_map
[0];
3545 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3546 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3547 if (vha
->flags
.online
) {
3548 if (!(rval
= qla2x00_fw_ready(vha
))) {
3549 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3552 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3554 /* Issue a marker after FW becomes ready. */
3555 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3557 vha
->marker_needed
= 0;
3559 /* Remap devices on Loop. */
3560 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3562 qla2x00_configure_loop(vha
);
3564 } while (!atomic_read(&vha
->loop_down_timer
) &&
3565 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3566 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3571 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3572 return (QLA_FUNCTION_FAILED
);
3575 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3581 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3584 struct scsi_qla_host
*tvp
, *vha
;
3586 /* Go with deferred removal of rport references. */
3587 list_for_each_entry_safe(vha
, tvp
, &base_vha
->hw
->vp_list
, list
)
3588 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3589 if (fcport
&& fcport
->drport
&&
3590 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
)
3591 qla2x00_rport_del(fcport
);
3595 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3597 struct qla_hw_data
*ha
= vha
->hw
;
3598 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3599 struct scsi_qla_host
*tvp
;
3601 vha
->flags
.online
= 0;
3602 ha
->flags
.chip_reset_done
= 0;
3603 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3604 ha
->qla_stats
.total_isp_aborts
++;
3606 qla_printk(KERN_INFO
, ha
,
3607 "Performing ISP error recovery - ha= %p.\n", ha
);
3609 /* Chip reset does not apply to 82XX */
3610 if (!IS_QLA82XX(ha
))
3611 ha
->isp_ops
->reset_chip(vha
);
3613 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3614 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3615 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3616 qla2x00_mark_all_devices_lost(vha
, 0);
3617 list_for_each_entry_safe(vp
, tvp
, &base_vha
->hw
->vp_list
, list
)
3618 qla2x00_mark_all_devices_lost(vp
, 0);
3620 if (!atomic_read(&vha
->loop_down_timer
))
3621 atomic_set(&vha
->loop_down_timer
,
3625 /* Make sure for ISP 82XX IO DMA is complete */
3627 qla82xx_wait_for_pending_commands(vha
);
3629 /* Requeue all commands in outstanding command list. */
3630 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3635 * Resets ISP and aborts all outstanding commands.
3638 * ha = adapter block pointer.
3644 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3648 struct qla_hw_data
*ha
= vha
->hw
;
3649 struct scsi_qla_host
*vp
;
3650 struct scsi_qla_host
*tvp
;
3651 struct req_que
*req
= ha
->req_q_map
[0];
3653 if (vha
->flags
.online
) {
3654 qla2x00_abort_isp_cleanup(vha
);
3656 if (unlikely(pci_channel_offline(ha
->pdev
) &&
3657 ha
->flags
.pci_channel_io_perm_failure
)) {
3658 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3663 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3665 ha
->isp_ops
->nvram_config(vha
);
3667 if (!qla2x00_restart_isp(vha
)) {
3668 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3670 if (!atomic_read(&vha
->loop_down_timer
)) {
3672 * Issue marker command only when we are going
3673 * to start the I/O .
3675 vha
->marker_needed
= 1;
3678 vha
->flags
.online
= 1;
3680 ha
->isp_ops
->enable_intrs(ha
);
3682 ha
->isp_abort_cnt
= 0;
3683 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3686 qla2x00_get_fw_version(vha
,
3687 &ha
->fw_major_version
,
3688 &ha
->fw_minor_version
,
3689 &ha
->fw_subminor_version
,
3690 &ha
->fw_attributes
, &ha
->fw_memory_size
,
3691 ha
->mpi_version
, &ha
->mpi_capabilities
,
3695 ha
->flags
.fce_enabled
= 1;
3697 fce_calc_size(ha
->fce_bufs
));
3698 rval
= qla2x00_enable_fce_trace(vha
,
3699 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3702 qla_printk(KERN_WARNING
, ha
,
3703 "Unable to reinitialize FCE "
3705 ha
->flags
.fce_enabled
= 0;
3710 memset(ha
->eft
, 0, EFT_SIZE
);
3711 rval
= qla2x00_enable_eft_trace(vha
,
3712 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3714 qla_printk(KERN_WARNING
, ha
,
3715 "Unable to reinitialize EFT "
3719 } else { /* failed the ISP abort */
3720 vha
->flags
.online
= 1;
3721 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3722 if (ha
->isp_abort_cnt
== 0) {
3723 qla_printk(KERN_WARNING
, ha
,
3724 "ISP error recovery failed - "
3725 "board disabled\n");
3727 * The next call disables the board
3730 ha
->isp_ops
->reset_adapter(vha
);
3731 vha
->flags
.online
= 0;
3732 clear_bit(ISP_ABORT_RETRY
,
3735 } else { /* schedule another ISP abort */
3736 ha
->isp_abort_cnt
--;
3737 DEBUG(printk("qla%ld: ISP abort - "
3738 "retry remaining %d\n",
3739 vha
->host_no
, ha
->isp_abort_cnt
));
3743 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3744 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3745 "- retrying (%d) more times\n",
3746 vha
->host_no
, ha
->isp_abort_cnt
));
3747 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3755 DEBUG(printk(KERN_INFO
3756 "qla2x00_abort_isp(%ld): succeeded.\n",
3758 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3760 qla2x00_vp_abort_isp(vp
);
3763 qla_printk(KERN_INFO
, ha
,
3764 "qla2x00_abort_isp: **** FAILED ****\n");
3771 * qla2x00_restart_isp
3772 * restarts the ISP after a reset
3775 * ha = adapter block pointer.
3781 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
3785 struct qla_hw_data
*ha
= vha
->hw
;
3786 struct req_que
*req
= ha
->req_q_map
[0];
3787 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3789 /* If firmware needs to be loaded */
3790 if (qla2x00_isp_firmware(vha
)) {
3791 vha
->flags
.online
= 0;
3792 status
= ha
->isp_ops
->chip_diag(vha
);
3794 status
= qla2x00_setup_chip(vha
);
3797 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
3798 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3799 ha
->flags
.chip_reset_done
= 1;
3800 /* Initialize the queues in use */
3801 qla25xx_init_queues(ha
);
3803 status
= qla2x00_fw_ready(vha
);
3805 DEBUG(printk("%s(): Start configure loop, "
3806 "status = %d\n", __func__
, status
));
3808 /* Issue a marker after FW becomes ready. */
3809 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
3811 vha
->flags
.online
= 1;
3812 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3815 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3816 qla2x00_configure_loop(vha
);
3818 } while (!atomic_read(&vha
->loop_down_timer
) &&
3819 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3820 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3824 /* if no cable then assume it's good */
3825 if ((vha
->device_flags
& DFLG_NO_CABLE
))
3828 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3836 qla25xx_init_queues(struct qla_hw_data
*ha
)
3838 struct rsp_que
*rsp
= NULL
;
3839 struct req_que
*req
= NULL
;
3840 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3844 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
3845 rsp
= ha
->rsp_q_map
[i
];
3847 rsp
->options
&= ~BIT_0
;
3848 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
3849 if (ret
!= QLA_SUCCESS
)
3850 DEBUG2_17(printk(KERN_WARNING
3851 "%s Rsp que:%d init failed\n", __func__
,
3854 DEBUG2_17(printk(KERN_INFO
3855 "%s Rsp que:%d inited\n", __func__
,
3859 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
3860 req
= ha
->req_q_map
[i
];
3862 /* Clear outstanding commands array. */
3863 req
->options
&= ~BIT_0
;
3864 ret
= qla25xx_init_req_que(base_vha
, req
);
3865 if (ret
!= QLA_SUCCESS
)
3866 DEBUG2_17(printk(KERN_WARNING
3867 "%s Req que:%d init failed\n", __func__
,
3870 DEBUG2_17(printk(KERN_WARNING
3871 "%s Req que:%d inited\n", __func__
,
3879 * qla2x00_reset_adapter
3883 * ha = adapter block pointer.
3886 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
3888 unsigned long flags
= 0;
3889 struct qla_hw_data
*ha
= vha
->hw
;
3890 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3892 vha
->flags
.online
= 0;
3893 ha
->isp_ops
->disable_intrs(ha
);
3895 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3896 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3897 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3898 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3899 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
3900 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3904 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
3906 unsigned long flags
= 0;
3907 struct qla_hw_data
*ha
= vha
->hw
;
3908 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
3913 vha
->flags
.online
= 0;
3914 ha
->isp_ops
->disable_intrs(ha
);
3916 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3917 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
3918 RD_REG_DWORD(®
->hccr
);
3919 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
3920 RD_REG_DWORD(®
->hccr
);
3921 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3923 if (IS_NOPOLLING_TYPE(ha
))
3924 ha
->isp_ops
->enable_intrs(ha
);
3927 /* On sparc systems, obtain port and node WWN from firmware
3930 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
3931 struct nvram_24xx
*nv
)
3934 struct qla_hw_data
*ha
= vha
->hw
;
3935 struct pci_dev
*pdev
= ha
->pdev
;
3936 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
3940 val
= of_get_property(dp
, "port-wwn", &len
);
3941 if (val
&& len
>= WWN_SIZE
)
3942 memcpy(nv
->port_name
, val
, WWN_SIZE
);
3944 val
= of_get_property(dp
, "node-wwn", &len
);
3945 if (val
&& len
>= WWN_SIZE
)
3946 memcpy(nv
->node_name
, val
, WWN_SIZE
);
3951 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
3954 struct init_cb_24xx
*icb
;
3955 struct nvram_24xx
*nv
;
3957 uint8_t *dptr1
, *dptr2
;
3960 struct qla_hw_data
*ha
= vha
->hw
;
3963 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3966 /* Determine NVRAM starting address. */
3967 if (ha
->flags
.port0
) {
3968 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
3969 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
3971 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
3972 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
3974 ha
->nvram_size
= sizeof(struct nvram_24xx
);
3975 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
3977 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
3979 /* Get VPD data into cache */
3980 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
3981 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
3982 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
3984 /* Get NVRAM data into cache and calculate checksum. */
3985 dptr
= (uint32_t *)nv
;
3986 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
3988 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
3989 chksum
+= le32_to_cpu(*dptr
++);
3991 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
3992 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
3994 /* Bad NVRAM data, set defaults parameters. */
3995 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
3996 || nv
->id
[3] != ' ' ||
3997 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
3998 /* Reset NVRAM data. */
3999 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4000 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4001 le16_to_cpu(nv
->nvram_version
));
4002 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4003 "invalid -- WWPN) defaults.\n");
4006 * Set default initialization control block.
4008 memset(nv
, 0, ha
->nvram_size
);
4009 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4010 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4011 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4012 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4013 nv
->exchange_count
= __constant_cpu_to_le16(0);
4014 nv
->hard_address
= __constant_cpu_to_le16(124);
4015 nv
->port_name
[0] = 0x21;
4016 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4017 nv
->port_name
[2] = 0x00;
4018 nv
->port_name
[3] = 0xe0;
4019 nv
->port_name
[4] = 0x8b;
4020 nv
->port_name
[5] = 0x1c;
4021 nv
->port_name
[6] = 0x55;
4022 nv
->port_name
[7] = 0x86;
4023 nv
->node_name
[0] = 0x20;
4024 nv
->node_name
[1] = 0x00;
4025 nv
->node_name
[2] = 0x00;
4026 nv
->node_name
[3] = 0xe0;
4027 nv
->node_name
[4] = 0x8b;
4028 nv
->node_name
[5] = 0x1c;
4029 nv
->node_name
[6] = 0x55;
4030 nv
->node_name
[7] = 0x86;
4031 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4032 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4033 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4034 nv
->login_timeout
= __constant_cpu_to_le16(0);
4035 nv
->firmware_options_1
=
4036 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4037 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4038 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4039 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4040 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4041 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4042 nv
->reset_delay
= 5;
4043 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4044 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4045 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4050 /* Reset Initialization control block */
4051 memset(icb
, 0, ha
->init_cb_size
);
4053 /* Copy 1st segment. */
4054 dptr1
= (uint8_t *)icb
;
4055 dptr2
= (uint8_t *)&nv
->version
;
4056 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4058 *dptr1
++ = *dptr2
++;
4060 icb
->login_retry_count
= nv
->login_retry_count
;
4061 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4063 /* Copy 2nd segment. */
4064 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4065 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4066 cnt
= (uint8_t *)&icb
->reserved_3
-
4067 (uint8_t *)&icb
->interrupt_delay_timer
;
4069 *dptr1
++ = *dptr2
++;
4072 * Setup driver NVRAM options.
4074 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4077 /* Use alternate WWN? */
4078 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4079 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4080 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4083 /* Prepare nodename */
4084 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4086 * Firmware will apply the following mask if the nodename was
4089 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4090 icb
->node_name
[0] &= 0xF0;
4093 /* Set host adapter parameters. */
4094 ha
->flags
.disable_risc_code_load
= 0;
4095 ha
->flags
.enable_lip_reset
= 0;
4096 ha
->flags
.enable_lip_full_login
=
4097 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4098 ha
->flags
.enable_target_reset
=
4099 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4100 ha
->flags
.enable_led_scheme
= 0;
4101 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4103 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4104 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4106 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4107 sizeof(ha
->fw_seriallink_options24
));
4109 /* save HBA serial number */
4110 ha
->serial0
= icb
->port_name
[5];
4111 ha
->serial1
= icb
->port_name
[6];
4112 ha
->serial2
= icb
->port_name
[7];
4113 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4114 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4116 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4118 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4120 /* Set minimum login_timeout to 4 seconds. */
4121 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4122 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4123 if (le16_to_cpu(nv
->login_timeout
) < 4)
4124 nv
->login_timeout
= __constant_cpu_to_le16(4);
4125 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4126 icb
->login_timeout
= nv
->login_timeout
;
4128 /* Set minimum RATOV to 100 tenths of a second. */
4131 ha
->loop_reset_delay
= nv
->reset_delay
;
4133 /* Link Down Timeout = 0:
4135 * When Port Down timer expires we will start returning
4136 * I/O's to OS with "DID_NO_CONNECT".
4138 * Link Down Timeout != 0:
4140 * The driver waits for the link to come up after link down
4141 * before returning I/Os to OS with "DID_NO_CONNECT".
4143 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4144 ha
->loop_down_abort_time
=
4145 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4147 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4148 ha
->loop_down_abort_time
=
4149 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4152 /* Need enough time to try and get the port back. */
4153 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4154 if (qlport_down_retry
)
4155 ha
->port_down_retry_count
= qlport_down_retry
;
4157 /* Set login_retry_count */
4158 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4159 if (ha
->port_down_retry_count
==
4160 le16_to_cpu(nv
->port_down_retry_count
) &&
4161 ha
->port_down_retry_count
> 3)
4162 ha
->login_retry_count
= ha
->port_down_retry_count
;
4163 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4164 ha
->login_retry_count
= ha
->port_down_retry_count
;
4165 if (ql2xloginretrycount
)
4166 ha
->login_retry_count
= ql2xloginretrycount
;
4169 if (!vha
->flags
.init_done
) {
4170 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4171 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4172 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4173 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4175 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4176 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4177 vha
->flags
.process_response_queue
= 0;
4178 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4179 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4181 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4182 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4183 ha
->zio_timer
* 100));
4184 qla_printk(KERN_INFO
, ha
,
4185 "ZIO mode %d enabled; timer delay (%d us).\n",
4186 ha
->zio_mode
, ha
->zio_timer
* 100);
4188 icb
->firmware_options_2
|= cpu_to_le32(
4189 (uint32_t)ha
->zio_mode
);
4190 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4191 vha
->flags
.process_response_queue
= 1;
4195 DEBUG2_3(printk(KERN_WARNING
4196 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4202 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4205 int rval
= QLA_SUCCESS
;
4206 int segments
, fragment
;
4207 uint32_t *dcode
, dlen
;
4211 struct qla_hw_data
*ha
= vha
->hw
;
4212 struct req_que
*req
= ha
->req_q_map
[0];
4214 qla_printk(KERN_INFO
, ha
,
4215 "FW: Loading from flash (%x)...\n", faddr
);
4219 segments
= FA_RISC_CODE_SEGMENTS
;
4220 dcode
= (uint32_t *)req
->ring
;
4223 /* Validate firmware image by checking version. */
4224 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4225 for (i
= 0; i
< 4; i
++)
4226 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4227 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4228 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4229 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4231 qla_printk(KERN_WARNING
, ha
,
4232 "Unable to verify integrity of flash firmware image!\n");
4233 qla_printk(KERN_WARNING
, ha
,
4234 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4235 dcode
[1], dcode
[2], dcode
[3]);
4237 return QLA_FUNCTION_FAILED
;
4240 while (segments
&& rval
== QLA_SUCCESS
) {
4241 /* Read segment's load information. */
4242 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4244 risc_addr
= be32_to_cpu(dcode
[2]);
4245 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4246 risc_size
= be32_to_cpu(dcode
[3]);
4249 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4250 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4251 if (dlen
> risc_size
)
4254 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4255 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4256 vha
->host_no
, risc_addr
, dlen
, faddr
));
4258 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4259 for (i
= 0; i
< dlen
; i
++)
4260 dcode
[i
] = swab32(dcode
[i
]);
4262 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4265 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4266 "segment %d of firmware\n", vha
->host_no
,
4268 qla_printk(KERN_WARNING
, ha
,
4269 "[ERROR] Failed to load segment %d of "
4270 "firmware\n", fragment
);
4287 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4290 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4294 uint16_t *wcode
, *fwcode
;
4295 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4296 struct fw_blob
*blob
;
4297 struct qla_hw_data
*ha
= vha
->hw
;
4298 struct req_que
*req
= ha
->req_q_map
[0];
4300 /* Load firmware blob. */
4301 blob
= qla2x00_request_firmware(vha
);
4303 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4304 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4305 "from: " QLA_FW_URL
".\n");
4306 return QLA_FUNCTION_FAILED
;
4311 wcode
= (uint16_t *)req
->ring
;
4313 fwcode
= (uint16_t *)blob
->fw
->data
;
4316 /* Validate firmware image by checking version. */
4317 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4318 qla_printk(KERN_WARNING
, ha
,
4319 "Unable to verify integrity of firmware image (%Zd)!\n",
4321 goto fail_fw_integrity
;
4323 for (i
= 0; i
< 4; i
++)
4324 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4325 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4326 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4327 wcode
[2] == 0 && wcode
[3] == 0)) {
4328 qla_printk(KERN_WARNING
, ha
,
4329 "Unable to verify integrity of firmware image!\n");
4330 qla_printk(KERN_WARNING
, ha
,
4331 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
4332 wcode
[1], wcode
[2], wcode
[3]);
4333 goto fail_fw_integrity
;
4337 while (*seg
&& rval
== QLA_SUCCESS
) {
4339 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4340 risc_size
= be16_to_cpu(fwcode
[3]);
4342 /* Validate firmware image size. */
4343 fwclen
+= risc_size
* sizeof(uint16_t);
4344 if (blob
->fw
->size
< fwclen
) {
4345 qla_printk(KERN_WARNING
, ha
,
4346 "Unable to verify integrity of firmware image "
4347 "(%Zd)!\n", blob
->fw
->size
);
4348 goto fail_fw_integrity
;
4352 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4353 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4354 if (wlen
> risc_size
)
4357 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4358 "addr %x, number of words 0x%x.\n", vha
->host_no
,
4361 for (i
= 0; i
< wlen
; i
++)
4362 wcode
[i
] = swab16(fwcode
[i
]);
4364 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4367 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4368 "segment %d of firmware\n", vha
->host_no
,
4370 qla_printk(KERN_WARNING
, ha
,
4371 "[ERROR] Failed to load segment %d of "
4372 "firmware\n", fragment
);
4388 return QLA_FUNCTION_FAILED
;
4392 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4395 int segments
, fragment
;
4396 uint32_t *dcode
, dlen
;
4400 struct fw_blob
*blob
;
4401 uint32_t *fwcode
, fwclen
;
4402 struct qla_hw_data
*ha
= vha
->hw
;
4403 struct req_que
*req
= ha
->req_q_map
[0];
4405 /* Load firmware blob. */
4406 blob
= qla2x00_request_firmware(vha
);
4408 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4409 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4410 "from: " QLA_FW_URL
".\n");
4412 return QLA_FUNCTION_FAILED
;
4415 qla_printk(KERN_INFO
, ha
,
4416 "FW: Loading via request-firmware...\n");
4420 segments
= FA_RISC_CODE_SEGMENTS
;
4421 dcode
= (uint32_t *)req
->ring
;
4423 fwcode
= (uint32_t *)blob
->fw
->data
;
4426 /* Validate firmware image by checking version. */
4427 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4428 qla_printk(KERN_WARNING
, ha
,
4429 "Unable to verify integrity of firmware image (%Zd)!\n",
4431 goto fail_fw_integrity
;
4433 for (i
= 0; i
< 4; i
++)
4434 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4435 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4436 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4437 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4439 qla_printk(KERN_WARNING
, ha
,
4440 "Unable to verify integrity of firmware image!\n");
4441 qla_printk(KERN_WARNING
, ha
,
4442 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4443 dcode
[1], dcode
[2], dcode
[3]);
4444 goto fail_fw_integrity
;
4447 while (segments
&& rval
== QLA_SUCCESS
) {
4448 risc_addr
= be32_to_cpu(fwcode
[2]);
4449 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4450 risc_size
= be32_to_cpu(fwcode
[3]);
4452 /* Validate firmware image size. */
4453 fwclen
+= risc_size
* sizeof(uint32_t);
4454 if (blob
->fw
->size
< fwclen
) {
4455 qla_printk(KERN_WARNING
, ha
,
4456 "Unable to verify integrity of firmware image "
4457 "(%Zd)!\n", blob
->fw
->size
);
4459 goto fail_fw_integrity
;
4463 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4464 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4465 if (dlen
> risc_size
)
4468 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4469 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4472 for (i
= 0; i
< dlen
; i
++)
4473 dcode
[i
] = swab32(fwcode
[i
]);
4475 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4478 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4479 "segment %d of firmware\n", vha
->host_no
,
4481 qla_printk(KERN_WARNING
, ha
,
4482 "[ERROR] Failed to load segment %d of "
4483 "firmware\n", fragment
);
4499 return QLA_FUNCTION_FAILED
;
4503 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4507 if (ql2xfwloadbin
== 1)
4508 return qla81xx_load_risc(vha
, srisc_addr
);
4512 * 1) Firmware via request-firmware interface (.bin file).
4513 * 2) Firmware residing in flash.
4515 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4516 if (rval
== QLA_SUCCESS
)
4519 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4520 vha
->hw
->flt_region_fw
);
4524 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4527 struct qla_hw_data
*ha
= vha
->hw
;
4529 if (ql2xfwloadbin
== 2)
4534 * 1) Firmware residing in flash.
4535 * 2) Firmware via request-firmware interface (.bin file).
4536 * 3) Golden-Firmware residing in flash -- limited operation.
4538 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4539 if (rval
== QLA_SUCCESS
)
4543 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4544 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4547 qla_printk(KERN_ERR
, ha
,
4548 "FW: Attempting to fallback to golden firmware...\n");
4549 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4550 if (rval
!= QLA_SUCCESS
)
4553 qla_printk(KERN_ERR
, ha
,
4554 "FW: Please update operational firmware...\n");
4555 ha
->flags
.running_gold_fw
= 1;
4561 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4564 struct qla_hw_data
*ha
= vha
->hw
;
4566 if (ha
->flags
.pci_channel_io_perm_failure
)
4568 if (!IS_FWI2_CAPABLE(ha
))
4570 if (!ha
->fw_major_version
)
4573 ret
= qla2x00_stop_firmware(vha
);
4574 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4575 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4576 ha
->isp_ops
->reset_chip(vha
);
4577 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4579 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4581 qla_printk(KERN_INFO
, ha
,
4582 "Attempting retry of stop-firmware command...\n");
4583 ret
= qla2x00_stop_firmware(vha
);
4588 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4590 int rval
= QLA_SUCCESS
;
4591 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4592 struct qla_hw_data
*ha
= vha
->hw
;
4593 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4594 struct req_que
*req
;
4595 struct rsp_que
*rsp
;
4600 rval
= qla2x00_fw_ready(base_vha
);
4601 if (ha
->flags
.cpu_affinity_enabled
)
4602 req
= ha
->req_q_map
[0];
4607 if (rval
== QLA_SUCCESS
) {
4608 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4609 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4612 vha
->flags
.management_server_logged_in
= 0;
4614 /* Login to SNS first */
4615 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
4616 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4617 DEBUG15(qla_printk(KERN_INFO
, ha
,
4618 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4619 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4620 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4621 return (QLA_FUNCTION_FAILED
);
4624 atomic_set(&vha
->loop_down_timer
, 0);
4625 atomic_set(&vha
->loop_state
, LOOP_UP
);
4626 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4627 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4628 rval
= qla2x00_loop_resync(base_vha
);
4633 /* 84XX Support **************************************************************/
4635 static LIST_HEAD(qla_cs84xx_list
);
4636 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4638 static struct qla_chip_state_84xx
*
4639 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4641 struct qla_chip_state_84xx
*cs84xx
;
4642 struct qla_hw_data
*ha
= vha
->hw
;
4644 mutex_lock(&qla_cs84xx_mutex
);
4646 /* Find any shared 84xx chip. */
4647 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4648 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4649 kref_get(&cs84xx
->kref
);
4654 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4658 kref_init(&cs84xx
->kref
);
4659 spin_lock_init(&cs84xx
->access_lock
);
4660 mutex_init(&cs84xx
->fw_update_mutex
);
4661 cs84xx
->bus
= ha
->pdev
->bus
;
4663 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4665 mutex_unlock(&qla_cs84xx_mutex
);
4670 __qla84xx_chip_release(struct kref
*kref
)
4672 struct qla_chip_state_84xx
*cs84xx
=
4673 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4675 mutex_lock(&qla_cs84xx_mutex
);
4676 list_del(&cs84xx
->list
);
4677 mutex_unlock(&qla_cs84xx_mutex
);
4682 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4684 struct qla_hw_data
*ha
= vha
->hw
;
4686 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4690 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4694 struct qla_hw_data
*ha
= vha
->hw
;
4696 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4698 rval
= qla84xx_verify_chip(vha
, status
);
4700 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4702 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
4706 /* 81XX Support **************************************************************/
4709 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
4712 struct init_cb_81xx
*icb
;
4713 struct nvram_81xx
*nv
;
4715 uint8_t *dptr1
, *dptr2
;
4718 struct qla_hw_data
*ha
= vha
->hw
;
4721 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
4724 /* Determine NVRAM starting address. */
4725 ha
->nvram_size
= sizeof(struct nvram_81xx
);
4726 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4728 /* Get VPD data into cache */
4729 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4730 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
4733 /* Get NVRAM data into cache and calculate checksum. */
4734 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
4736 dptr
= (uint32_t *)nv
;
4737 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4738 chksum
+= le32_to_cpu(*dptr
++);
4740 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
4741 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
4743 /* Bad NVRAM data, set defaults parameters. */
4744 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4745 || nv
->id
[3] != ' ' ||
4746 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4747 /* Reset NVRAM data. */
4748 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4749 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4750 le16_to_cpu(nv
->nvram_version
));
4751 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4752 "invalid -- WWPN) defaults.\n");
4755 * Set default initialization control block.
4757 memset(nv
, 0, ha
->nvram_size
);
4758 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4759 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4760 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4761 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4762 nv
->exchange_count
= __constant_cpu_to_le16(0);
4763 nv
->port_name
[0] = 0x21;
4764 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4765 nv
->port_name
[2] = 0x00;
4766 nv
->port_name
[3] = 0xe0;
4767 nv
->port_name
[4] = 0x8b;
4768 nv
->port_name
[5] = 0x1c;
4769 nv
->port_name
[6] = 0x55;
4770 nv
->port_name
[7] = 0x86;
4771 nv
->node_name
[0] = 0x20;
4772 nv
->node_name
[1] = 0x00;
4773 nv
->node_name
[2] = 0x00;
4774 nv
->node_name
[3] = 0xe0;
4775 nv
->node_name
[4] = 0x8b;
4776 nv
->node_name
[5] = 0x1c;
4777 nv
->node_name
[6] = 0x55;
4778 nv
->node_name
[7] = 0x86;
4779 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4780 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4781 nv
->login_timeout
= __constant_cpu_to_le16(0);
4782 nv
->firmware_options_1
=
4783 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4784 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4785 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4786 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4787 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4788 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4789 nv
->reset_delay
= 5;
4790 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4791 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4792 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4793 nv
->enode_mac
[0] = 0x00;
4794 nv
->enode_mac
[1] = 0x02;
4795 nv
->enode_mac
[2] = 0x03;
4796 nv
->enode_mac
[3] = 0x04;
4797 nv
->enode_mac
[4] = 0x05;
4798 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
4803 /* Reset Initialization control block */
4804 memset(icb
, 0, sizeof(struct init_cb_81xx
));
4806 /* Copy 1st segment. */
4807 dptr1
= (uint8_t *)icb
;
4808 dptr2
= (uint8_t *)&nv
->version
;
4809 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4811 *dptr1
++ = *dptr2
++;
4813 icb
->login_retry_count
= nv
->login_retry_count
;
4815 /* Copy 2nd segment. */
4816 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4817 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4818 cnt
= (uint8_t *)&icb
->reserved_5
-
4819 (uint8_t *)&icb
->interrupt_delay_timer
;
4821 *dptr1
++ = *dptr2
++;
4823 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
4824 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4825 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
4826 icb
->enode_mac
[0] = 0x01;
4827 icb
->enode_mac
[1] = 0x02;
4828 icb
->enode_mac
[2] = 0x03;
4829 icb
->enode_mac
[3] = 0x04;
4830 icb
->enode_mac
[4] = 0x05;
4831 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
4834 /* Use extended-initialization control block. */
4835 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
4838 * Setup driver NVRAM options.
4840 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4843 /* Use alternate WWN? */
4844 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4845 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4846 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4849 /* Prepare nodename */
4850 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4852 * Firmware will apply the following mask if the nodename was
4855 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4856 icb
->node_name
[0] &= 0xF0;
4859 /* Set host adapter parameters. */
4860 ha
->flags
.disable_risc_code_load
= 0;
4861 ha
->flags
.enable_lip_reset
= 0;
4862 ha
->flags
.enable_lip_full_login
=
4863 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4864 ha
->flags
.enable_target_reset
=
4865 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4866 ha
->flags
.enable_led_scheme
= 0;
4867 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4869 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4870 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4872 /* save HBA serial number */
4873 ha
->serial0
= icb
->port_name
[5];
4874 ha
->serial1
= icb
->port_name
[6];
4875 ha
->serial2
= icb
->port_name
[7];
4876 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4877 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4879 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4881 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4883 /* Set minimum login_timeout to 4 seconds. */
4884 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4885 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4886 if (le16_to_cpu(nv
->login_timeout
) < 4)
4887 nv
->login_timeout
= __constant_cpu_to_le16(4);
4888 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4889 icb
->login_timeout
= nv
->login_timeout
;
4891 /* Set minimum RATOV to 100 tenths of a second. */
4894 ha
->loop_reset_delay
= nv
->reset_delay
;
4896 /* Link Down Timeout = 0:
4898 * When Port Down timer expires we will start returning
4899 * I/O's to OS with "DID_NO_CONNECT".
4901 * Link Down Timeout != 0:
4903 * The driver waits for the link to come up after link down
4904 * before returning I/Os to OS with "DID_NO_CONNECT".
4906 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4907 ha
->loop_down_abort_time
=
4908 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4910 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4911 ha
->loop_down_abort_time
=
4912 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4915 /* Need enough time to try and get the port back. */
4916 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4917 if (qlport_down_retry
)
4918 ha
->port_down_retry_count
= qlport_down_retry
;
4920 /* Set login_retry_count */
4921 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4922 if (ha
->port_down_retry_count
==
4923 le16_to_cpu(nv
->port_down_retry_count
) &&
4924 ha
->port_down_retry_count
> 3)
4925 ha
->login_retry_count
= ha
->port_down_retry_count
;
4926 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4927 ha
->login_retry_count
= ha
->port_down_retry_count
;
4928 if (ql2xloginretrycount
)
4929 ha
->login_retry_count
= ql2xloginretrycount
;
4932 if (!vha
->flags
.init_done
) {
4933 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4934 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4935 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4936 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4938 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4939 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4940 vha
->flags
.process_response_queue
= 0;
4941 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4942 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4944 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4945 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4946 ha
->zio_timer
* 100));
4947 qla_printk(KERN_INFO
, ha
,
4948 "ZIO mode %d enabled; timer delay (%d us).\n",
4949 ha
->zio_mode
, ha
->zio_timer
* 100);
4951 icb
->firmware_options_2
|= cpu_to_le32(
4952 (uint32_t)ha
->zio_mode
);
4953 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4954 vha
->flags
.process_response_queue
= 1;
4958 DEBUG2_3(printk(KERN_WARNING
4959 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4965 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
4969 struct qla_hw_data
*ha
= vha
->hw
;
4970 struct req_que
*req
= ha
->req_q_map
[0];
4971 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4972 struct scsi_qla_host
*vp
;
4973 struct scsi_qla_host
*tvp
;
4975 status
= qla2x00_init_rings(vha
);
4977 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4978 ha
->flags
.chip_reset_done
= 1;
4980 status
= qla2x00_fw_ready(vha
);
4982 qla_printk(KERN_INFO
, ha
,
4983 "%s(): Start configure loop, "
4984 "status = %d\n", __func__
, status
);
4986 /* Issue a marker after FW becomes ready. */
4987 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4989 vha
->flags
.online
= 1;
4990 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4993 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4994 qla2x00_configure_loop(vha
);
4996 } while (!atomic_read(&vha
->loop_down_timer
) &&
4997 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
4999 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5002 /* if no cable then assume it's good */
5003 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5006 qla_printk(KERN_INFO
, ha
,
5007 "%s(): Configure loop done, status = 0x%x\n",
5012 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5014 if (!atomic_read(&vha
->loop_down_timer
)) {
5016 * Issue marker command only when we are going
5017 * to start the I/O .
5019 vha
->marker_needed
= 1;
5022 vha
->flags
.online
= 1;
5024 ha
->isp_ops
->enable_intrs(ha
);
5026 ha
->isp_abort_cnt
= 0;
5027 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5030 ha
->flags
.fce_enabled
= 1;
5032 fce_calc_size(ha
->fce_bufs
));
5033 rval
= qla2x00_enable_fce_trace(vha
,
5034 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5037 qla_printk(KERN_WARNING
, ha
,
5038 "Unable to reinitialize FCE "
5040 ha
->flags
.fce_enabled
= 0;
5045 memset(ha
->eft
, 0, EFT_SIZE
);
5046 rval
= qla2x00_enable_eft_trace(vha
,
5047 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5049 qla_printk(KERN_WARNING
, ha
,
5050 "Unable to reinitialize EFT "
5054 } else { /* failed the ISP abort */
5055 vha
->flags
.online
= 1;
5056 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
5057 if (ha
->isp_abort_cnt
== 0) {
5058 qla_printk(KERN_WARNING
, ha
,
5059 "ISP error recovery failed - "
5060 "board disabled\n");
5062 * The next call disables the board
5065 ha
->isp_ops
->reset_adapter(vha
);
5066 vha
->flags
.online
= 0;
5067 clear_bit(ISP_ABORT_RETRY
,
5070 } else { /* schedule another ISP abort */
5071 ha
->isp_abort_cnt
--;
5072 qla_printk(KERN_INFO
, ha
,
5073 "qla%ld: ISP abort - "
5074 "retry remaining %d\n",
5075 vha
->host_no
, ha
->isp_abort_cnt
);
5079 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
5080 qla_printk(KERN_INFO
, ha
,
5081 "(%ld): ISP error recovery "
5082 "- retrying (%d) more times\n",
5083 vha
->host_no
, ha
->isp_abort_cnt
);
5084 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5090 DEBUG(printk(KERN_INFO
5091 "qla82xx_restart_isp(%ld): succeeded.\n",
5093 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
5095 qla2x00_vp_abort_isp(vp
);
5098 qla_printk(KERN_INFO
, ha
,
5099 "qla82xx_restart_isp: **** FAILED ****\n");
5106 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5108 struct qla_hw_data
*ha
= vha
->hw
;
5113 /* Enable ETS Burst. */
5114 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5115 ha
->fw_options
[2] |= BIT_9
;
5116 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5120 * qla24xx_get_fcp_prio
5121 * Gets the fcp cmd priority value for the logged in port.
5122 * Looks for a match of the port descriptors within
5123 * each of the fcp prio config entries. If a match is found,
5124 * the tag (priority) value is returned.
5127 * ha = adapter block po
5128 * fcport = port structure pointer.
5131 * non-zero (if found)
5138 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5141 uint8_t pid_match
, wwn_match
;
5143 uint32_t pid1
, pid2
;
5144 uint64_t wwn1
, wwn2
;
5145 struct qla_fcp_prio_entry
*pri_entry
;
5146 struct qla_hw_data
*ha
= vha
->hw
;
5148 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5152 entries
= ha
->fcp_prio_cfg
->num_entries
;
5153 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5155 for (i
= 0; i
< entries
; i
++) {
5156 pid_match
= wwn_match
= 0;
5158 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5163 /* check source pid for a match */
5164 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5165 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5166 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5167 if (pid1
== INVALID_PORT_ID
)
5169 else if (pid1
== pid2
)
5173 /* check destination pid for a match */
5174 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5175 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5176 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5177 if (pid1
== INVALID_PORT_ID
)
5179 else if (pid1
== pid2
)
5183 /* check source WWN for a match */
5184 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5185 wwn1
= wwn_to_u64(vha
->port_name
);
5186 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5187 if (wwn2
== (uint64_t)-1)
5189 else if (wwn1
== wwn2
)
5193 /* check destination WWN for a match */
5194 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5195 wwn1
= wwn_to_u64(fcport
->port_name
);
5196 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5197 if (wwn2
== (uint64_t)-1)
5199 else if (wwn1
== wwn2
)
5203 if (pid_match
== 2 || wwn_match
== 2) {
5204 /* Found a matching entry */
5205 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5206 priority
= pri_entry
->tag
;
5217 * qla24xx_update_fcport_fcp_prio
5218 * Activates fcp priority for the logged in fc port
5221 * ha = adapter block pointer.
5222 * fcp = port structure pointer.
5225 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5231 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
5237 if (atomic_read(&fcport
->state
) == FCS_UNCONFIGURED
||
5238 fcport
->port_type
!= FCT_TARGET
||
5239 fcport
->loop_id
== FC_NO_LOOP_ID
)
5240 return QLA_FUNCTION_FAILED
;
5242 priority
= qla24xx_get_fcp_prio(ha
, fcport
);
5243 ret
= qla24xx_set_fcp_prio(ha
, fcport
->loop_id
, priority
, mb
);
5244 if (ret
== QLA_SUCCESS
)
5245 fcport
->fcp_prio
= priority
;
5247 DEBUG2(printk(KERN_WARNING
5248 "scsi(%ld): Unable to activate fcp priority, "
5249 " ret=0x%x\n", ha
->host_no
, ret
));
5255 * qla24xx_update_all_fcp_prio
5256 * Activates fcp priority for all the logged in ports
5259 * ha = adapter block pointer.
5262 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5268 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5273 ret
= QLA_FUNCTION_FAILED
;
5274 /* We need to set priority for all logged in ports */
5275 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5276 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);