2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 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 struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
39 static int qla84xx_init_chip(scsi_qla_host_t
*);
40 static int qla25xx_init_queues(struct qla_hw_data
*);
42 /* SRB Extensions ---------------------------------------------------------- */
45 qla2x00_ctx_sp_timeout(unsigned long __data
)
47 srb_t
*sp
= (srb_t
*)__data
;
49 struct srb_iocb
*iocb
;
50 fc_port_t
*fcport
= sp
->fcport
;
51 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
55 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
56 req
= ha
->req_q_map
[0];
57 req
->outstanding_cmds
[sp
->handle
] = NULL
;
59 iocb
= ctx
->u
.iocb_cmd
;
62 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
66 qla2x00_ctx_sp_free(srb_t
*sp
)
68 struct srb_ctx
*ctx
= sp
->ctx
;
69 struct srb_iocb
*iocb
= ctx
->u
.iocb_cmd
;
70 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
72 del_timer(&iocb
->timer
);
75 mempool_free(sp
, sp
->fcport
->vha
->hw
->srb_mempool
);
77 QLA_VHA_MARK_NOT_BUSY(vha
);
81 qla2x00_get_ctx_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
, size_t size
,
85 struct qla_hw_data
*ha
= vha
->hw
;
87 struct srb_iocb
*iocb
;
90 QLA_VHA_MARK_BUSY(vha
, bail
);
94 sp
= mempool_alloc(ha
->srb_mempool
, GFP_KERNEL
);
97 ctx
= kzalloc(size
, GFP_KERNEL
);
99 mempool_free(sp
, ha
->srb_mempool
);
103 iocb
= kzalloc(sizeof(struct srb_iocb
), GFP_KERNEL
);
105 mempool_free(sp
, ha
->srb_mempool
);
111 memset(sp
, 0, sizeof(*sp
));
114 ctx
->u
.iocb_cmd
= iocb
;
115 iocb
->free
= qla2x00_ctx_sp_free
;
117 init_timer(&iocb
->timer
);
120 iocb
->timer
.expires
= jiffies
+ tmo
* HZ
;
121 iocb
->timer
.data
= (unsigned long)sp
;
122 iocb
->timer
.function
= qla2x00_ctx_sp_timeout
;
123 add_timer(&iocb
->timer
);
126 QLA_VHA_MARK_NOT_BUSY(vha
);
130 /* Asynchronous Login/Logout Routines -------------------------------------- */
132 static inline unsigned long
133 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
136 struct qla_hw_data
*ha
= vha
->hw
;
138 /* Firmware should use switch negotiated r_a_tov for timeout. */
139 tmo
= ha
->r_a_tov
/ 10 * 2;
140 if (!IS_FWI2_CAPABLE(ha
)) {
142 * Except for earlier ISPs where the timeout is seeded from the
143 * initialization control block.
145 tmo
= ha
->login_timeout
;
151 qla2x00_async_iocb_timeout(srb_t
*sp
)
153 fc_port_t
*fcport
= sp
->fcport
;
154 struct srb_ctx
*ctx
= sp
->ctx
;
156 DEBUG2(printk(KERN_WARNING
157 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
158 fcport
->vha
->host_no
, sp
->handle
,
159 ctx
->name
, fcport
->d_id
.b
.domain
,
160 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
162 fcport
->flags
&= ~FCF_ASYNC_SENT
;
163 if (ctx
->type
== SRB_LOGIN_CMD
) {
164 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
165 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
166 /* Retry as needed. */
167 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
168 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
169 QLA_LOGIO_LOGIN_RETRIED
: 0;
170 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
,
176 qla2x00_async_login_ctx_done(srb_t
*sp
)
178 struct srb_ctx
*ctx
= sp
->ctx
;
179 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
181 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
187 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
192 struct srb_iocb
*lio
;
195 rval
= QLA_FUNCTION_FAILED
;
196 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
197 qla2x00_get_async_timeout(vha
) + 2);
202 ctx
->type
= SRB_LOGIN_CMD
;
204 lio
= ctx
->u
.iocb_cmd
;
205 lio
->timeout
= qla2x00_async_iocb_timeout
;
206 lio
->done
= qla2x00_async_login_ctx_done
;
207 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
208 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
209 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
210 rval
= qla2x00_start_sp(sp
);
211 if (rval
!= QLA_SUCCESS
)
214 DEBUG2(printk(KERN_DEBUG
215 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
216 "retries=%d.\n", fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
217 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
218 fcport
->login_retry
));
228 qla2x00_async_logout_ctx_done(srb_t
*sp
)
230 struct srb_ctx
*ctx
= sp
->ctx
;
231 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
233 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
239 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
243 struct srb_iocb
*lio
;
246 rval
= QLA_FUNCTION_FAILED
;
247 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
248 qla2x00_get_async_timeout(vha
) + 2);
253 ctx
->type
= SRB_LOGOUT_CMD
;
254 ctx
->name
= "logout";
255 lio
= ctx
->u
.iocb_cmd
;
256 lio
->timeout
= qla2x00_async_iocb_timeout
;
257 lio
->done
= qla2x00_async_logout_ctx_done
;
258 rval
= qla2x00_start_sp(sp
);
259 if (rval
!= QLA_SUCCESS
)
262 DEBUG2(printk(KERN_DEBUG
263 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
264 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
265 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
275 qla2x00_async_adisc_ctx_done(srb_t
*sp
)
277 struct srb_ctx
*ctx
= sp
->ctx
;
278 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
280 qla2x00_post_async_adisc_done_work(sp
->fcport
->vha
, sp
->fcport
,
286 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
291 struct srb_iocb
*lio
;
294 rval
= QLA_FUNCTION_FAILED
;
295 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
296 qla2x00_get_async_timeout(vha
) + 2);
301 ctx
->type
= SRB_ADISC_CMD
;
303 lio
= ctx
->u
.iocb_cmd
;
304 lio
->timeout
= qla2x00_async_iocb_timeout
;
305 lio
->done
= qla2x00_async_adisc_ctx_done
;
306 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
307 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
308 rval
= qla2x00_start_sp(sp
);
309 if (rval
!= QLA_SUCCESS
)
312 DEBUG2(printk(KERN_DEBUG
313 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
314 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
315 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
326 qla2x00_async_tm_cmd_ctx_done(srb_t
*sp
)
328 struct srb_ctx
*ctx
= sp
->ctx
;
329 struct srb_iocb
*iocb
= (struct srb_iocb
*)ctx
->u
.iocb_cmd
;
331 qla2x00_async_tm_cmd_done(sp
->fcport
->vha
, sp
->fcport
, iocb
);
336 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
339 struct scsi_qla_host
*vha
= fcport
->vha
;
342 struct srb_iocb
*tcf
;
345 rval
= QLA_FUNCTION_FAILED
;
346 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
347 qla2x00_get_async_timeout(vha
) + 2);
352 ctx
->type
= SRB_TM_CMD
;
354 tcf
= ctx
->u
.iocb_cmd
;
355 tcf
->u
.tmf
.flags
= flags
;
356 tcf
->u
.tmf
.lun
= lun
;
357 tcf
->u
.tmf
.data
= tag
;
358 tcf
->timeout
= qla2x00_async_iocb_timeout
;
359 tcf
->done
= qla2x00_async_tm_cmd_ctx_done
;
361 rval
= qla2x00_start_sp(sp
);
362 if (rval
!= QLA_SUCCESS
)
365 DEBUG2(printk(KERN_DEBUG
366 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
367 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
368 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
379 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
385 case MBS_COMMAND_COMPLETE
:
387 * Driver must validate login state - If PRLI not complete,
388 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
391 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
392 if (rval
!= QLA_SUCCESS
) {
393 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
394 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
397 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
398 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
401 qla2x00_update_fcport(vha
, fcport
);
403 case MBS_COMMAND_ERROR
:
404 fcport
->flags
&= ~FCF_ASYNC_SENT
;
405 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
406 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
408 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
410 case MBS_PORT_ID_USED
:
411 fcport
->loop_id
= data
[1];
412 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
413 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
415 case MBS_LOOP_ID_USED
:
417 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
418 if (rval
!= QLA_SUCCESS
) {
419 fcport
->flags
&= ~FCF_ASYNC_SENT
;
420 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
423 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
430 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
433 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
438 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
441 if (data
[0] == MBS_COMMAND_COMPLETE
) {
442 qla2x00_update_fcport(vha
, fcport
);
448 fcport
->flags
&= ~FCF_ASYNC_SENT
;
449 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
450 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
452 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
458 qla2x00_async_tm_cmd_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
459 struct srb_iocb
*iocb
)
465 flags
= iocb
->u
.tmf
.flags
;
466 lun
= (uint16_t)iocb
->u
.tmf
.lun
;
468 /* Issue Marker IOCB */
469 rval
= qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
470 vha
->hw
->rsp_q_map
[0], fcport
->loop_id
, lun
,
471 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
473 if ((rval
!= QLA_SUCCESS
) || iocb
->u
.tmf
.data
) {
474 DEBUG2_3_11(printk(KERN_WARNING
475 "%s(%ld): TM IOCB failed (%x).\n",
476 __func__
, vha
->host_no
, rval
));
482 /****************************************************************************/
483 /* QLogic ISP2x00 Hardware Support Functions. */
484 /****************************************************************************/
487 * qla2x00_initialize_adapter
491 * ha = adapter block pointer.
497 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
500 struct qla_hw_data
*ha
= vha
->hw
;
501 struct req_que
*req
= ha
->req_q_map
[0];
503 /* Clear adapter flags. */
504 vha
->flags
.online
= 0;
505 ha
->flags
.chip_reset_done
= 0;
506 vha
->flags
.reset_active
= 0;
507 ha
->flags
.pci_channel_io_perm_failure
= 0;
508 ha
->flags
.eeh_busy
= 0;
509 ha
->flags
.thermal_supported
= 1;
510 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
511 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
512 vha
->device_flags
= DFLG_NO_CABLE
;
514 vha
->flags
.management_server_logged_in
= 0;
515 vha
->marker_needed
= 0;
516 ha
->isp_abort_cnt
= 0;
517 ha
->beacon_blink_led
= 0;
519 set_bit(0, ha
->req_qid_map
);
520 set_bit(0, ha
->rsp_qid_map
);
522 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
523 rval
= ha
->isp_ops
->pci_config(vha
);
525 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
530 ha
->isp_ops
->reset_chip(vha
);
532 rval
= qla2xxx_get_flash_info(vha
);
534 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
539 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
541 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
543 ha
->isp_ops
->nvram_config(vha
);
545 if (ha
->flags
.disable_serdes
) {
546 /* Mask HBA via NVRAM settings? */
547 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
548 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
549 vha
->port_name
[0], vha
->port_name
[1],
550 vha
->port_name
[2], vha
->port_name
[3],
551 vha
->port_name
[4], vha
->port_name
[5],
552 vha
->port_name
[6], vha
->port_name
[7]);
553 return QLA_FUNCTION_FAILED
;
556 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
558 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
559 rval
= ha
->isp_ops
->chip_diag(vha
);
562 rval
= qla2x00_setup_chip(vha
);
567 if (IS_QLA84XX(ha
)) {
568 ha
->cs84xx
= qla84xx_get_chip(vha
);
570 qla_printk(KERN_ERR
, ha
,
571 "Unable to configure ISP84XX.\n");
572 return QLA_FUNCTION_FAILED
;
575 rval
= qla2x00_init_rings(vha
);
576 ha
->flags
.chip_reset_done
= 1;
578 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
579 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
580 rval
= qla84xx_init_chip(vha
);
581 if (rval
!= QLA_SUCCESS
) {
582 qla_printk(KERN_ERR
, ha
,
583 "Unable to initialize ISP84XX.\n");
584 qla84xx_put_chip(vha
);
588 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
589 qla24xx_read_fcp_prio_cfg(vha
);
595 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
598 * Returns 0 on success.
601 qla2100_pci_config(scsi_qla_host_t
*vha
)
605 struct qla_hw_data
*ha
= vha
->hw
;
606 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
608 pci_set_master(ha
->pdev
);
609 pci_try_set_mwi(ha
->pdev
);
611 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
612 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
613 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
615 pci_disable_rom(ha
->pdev
);
617 /* Get PCI bus information. */
618 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
619 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
620 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
626 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
629 * Returns 0 on success.
632 qla2300_pci_config(scsi_qla_host_t
*vha
)
635 unsigned long flags
= 0;
637 struct qla_hw_data
*ha
= vha
->hw
;
638 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
640 pci_set_master(ha
->pdev
);
641 pci_try_set_mwi(ha
->pdev
);
643 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
644 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
646 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
647 w
&= ~PCI_COMMAND_INTX_DISABLE
;
648 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
651 * If this is a 2300 card and not 2312, reset the
652 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
653 * the 2310 also reports itself as a 2300 so we need to get the
654 * fb revision level -- a 6 indicates it really is a 2300 and
657 if (IS_QLA2300(ha
)) {
658 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
661 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
662 for (cnt
= 0; cnt
< 30000; cnt
++) {
663 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
669 /* Select FPM registers. */
670 WRT_REG_WORD(®
->ctrl_status
, 0x20);
671 RD_REG_WORD(®
->ctrl_status
);
673 /* Get the fb rev level */
674 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
676 if (ha
->fb_rev
== FPM_2300
)
677 pci_clear_mwi(ha
->pdev
);
679 /* Deselect FPM registers. */
680 WRT_REG_WORD(®
->ctrl_status
, 0x0);
681 RD_REG_WORD(®
->ctrl_status
);
683 /* Release RISC module. */
684 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
685 for (cnt
= 0; cnt
< 30000; cnt
++) {
686 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
692 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
695 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
697 pci_disable_rom(ha
->pdev
);
699 /* Get PCI bus information. */
700 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
701 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
702 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
708 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
711 * Returns 0 on success.
714 qla24xx_pci_config(scsi_qla_host_t
*vha
)
717 unsigned long flags
= 0;
718 struct qla_hw_data
*ha
= vha
->hw
;
719 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
721 pci_set_master(ha
->pdev
);
722 pci_try_set_mwi(ha
->pdev
);
724 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
725 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
726 w
&= ~PCI_COMMAND_INTX_DISABLE
;
727 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
729 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
731 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
732 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
733 pcix_set_mmrbc(ha
->pdev
, 2048);
735 /* PCIe -- adjust Maximum Read Request Size (2048). */
736 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
737 pcie_set_readrq(ha
->pdev
, 2048);
739 pci_disable_rom(ha
->pdev
);
741 ha
->chip_revision
= ha
->pdev
->revision
;
743 /* Get PCI bus information. */
744 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
745 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
746 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
752 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
755 * Returns 0 on success.
758 qla25xx_pci_config(scsi_qla_host_t
*vha
)
761 struct qla_hw_data
*ha
= vha
->hw
;
763 pci_set_master(ha
->pdev
);
764 pci_try_set_mwi(ha
->pdev
);
766 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
767 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
768 w
&= ~PCI_COMMAND_INTX_DISABLE
;
769 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
771 /* PCIe -- adjust Maximum Read Request Size (2048). */
772 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
773 pcie_set_readrq(ha
->pdev
, 2048);
775 pci_disable_rom(ha
->pdev
);
777 ha
->chip_revision
= ha
->pdev
->revision
;
783 * qla2x00_isp_firmware() - Choose firmware image.
786 * Returns 0 on success.
789 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
792 uint16_t loop_id
, topo
, sw_cap
;
793 uint8_t domain
, area
, al_pa
;
794 struct qla_hw_data
*ha
= vha
->hw
;
796 /* Assume loading risc code */
797 rval
= QLA_FUNCTION_FAILED
;
799 if (ha
->flags
.disable_risc_code_load
) {
800 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
802 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
804 /* Verify checksum of loaded RISC code. */
805 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
806 if (rval
== QLA_SUCCESS
) {
807 /* And, verify we are not in ROM code. */
808 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
809 &area
, &domain
, &topo
, &sw_cap
);
814 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
822 * qla2x00_reset_chip() - Reset ISP chip.
825 * Returns 0 on success.
828 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
830 unsigned long flags
= 0;
831 struct qla_hw_data
*ha
= vha
->hw
;
832 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
836 if (unlikely(pci_channel_offline(ha
->pdev
)))
839 ha
->isp_ops
->disable_intrs(ha
);
841 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
843 /* Turn off master enable */
845 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
846 cmd
&= ~PCI_COMMAND_MASTER
;
847 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
849 if (!IS_QLA2100(ha
)) {
851 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
852 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
853 for (cnt
= 0; cnt
< 30000; cnt
++) {
854 if ((RD_REG_WORD(®
->hccr
) &
855 HCCR_RISC_PAUSE
) != 0)
860 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
864 /* Select FPM registers. */
865 WRT_REG_WORD(®
->ctrl_status
, 0x20);
866 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
868 /* FPM Soft Reset. */
869 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
870 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
872 /* Toggle Fpm Reset. */
873 if (!IS_QLA2200(ha
)) {
874 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
875 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
878 /* Select frame buffer registers. */
879 WRT_REG_WORD(®
->ctrl_status
, 0x10);
880 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
882 /* Reset frame buffer FIFOs. */
883 if (IS_QLA2200(ha
)) {
884 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
885 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
887 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
889 /* Read back fb_cmd until zero or 3 seconds max */
890 for (cnt
= 0; cnt
< 3000; cnt
++) {
891 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
897 /* Select RISC module registers. */
898 WRT_REG_WORD(®
->ctrl_status
, 0);
899 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
901 /* Reset RISC processor. */
902 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
903 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
905 /* Release RISC processor. */
906 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
907 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
910 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
911 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
913 /* Reset ISP chip. */
914 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
916 /* Wait for RISC to recover from reset. */
917 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
919 * It is necessary to for a delay here since the card doesn't
920 * respond to PCI reads during a reset. On some architectures
921 * this will result in an MCA.
924 for (cnt
= 30000; cnt
; cnt
--) {
925 if ((RD_REG_WORD(®
->ctrl_status
) &
926 CSR_ISP_SOFT_RESET
) == 0)
933 /* Reset RISC processor. */
934 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
936 WRT_REG_WORD(®
->semaphore
, 0);
938 /* Release RISC processor. */
939 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
940 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
942 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
943 for (cnt
= 0; cnt
< 30000; cnt
++) {
944 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
952 /* Turn on master enable */
953 cmd
|= PCI_COMMAND_MASTER
;
954 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
956 /* Disable RISC pause on FPM parity error. */
957 if (!IS_QLA2100(ha
)) {
958 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
959 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
962 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
966 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
968 * Returns 0 on success.
971 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
973 uint16_t mb
[4] = {0x1010, 0, 1, 0};
975 return qla81xx_write_mpi_register(vha
, mb
);
979 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
982 * Returns 0 on success.
985 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
987 unsigned long flags
= 0;
988 struct qla_hw_data
*ha
= vha
->hw
;
989 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
992 static int abts_cnt
; /* ISP abort retry counts */
994 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
997 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
998 for (cnt
= 0; cnt
< 30000; cnt
++) {
999 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
1005 WRT_REG_DWORD(®
->ctrl_status
,
1006 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
1007 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1010 /* Wait for firmware to complete NVRAM accesses. */
1011 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1012 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
1014 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1018 /* Wait for soft-reset to complete. */
1019 d2
= RD_REG_DWORD(®
->ctrl_status
);
1020 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
1022 d2
= RD_REG_DWORD(®
->ctrl_status
);
1026 /* If required, do an MPI FW reset now */
1027 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
1028 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
1029 if (++abts_cnt
< 5) {
1030 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1031 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
1034 * We exhausted the ISP abort retries. We have to
1035 * set the board offline.
1038 vha
->flags
.online
= 0;
1043 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
1044 RD_REG_DWORD(®
->hccr
);
1046 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
1047 RD_REG_DWORD(®
->hccr
);
1049 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1050 RD_REG_DWORD(®
->hccr
);
1052 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1053 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1055 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1059 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1061 if (IS_NOPOLLING_TYPE(ha
))
1062 ha
->isp_ops
->enable_intrs(ha
);
1066 * qla24xx_reset_chip() - Reset ISP24xx chip.
1069 * Returns 0 on success.
1072 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1074 struct qla_hw_data
*ha
= vha
->hw
;
1076 if (pci_channel_offline(ha
->pdev
) &&
1077 ha
->flags
.pci_channel_io_perm_failure
) {
1081 ha
->isp_ops
->disable_intrs(ha
);
1083 /* Perform RISC reset. */
1084 qla24xx_reset_risc(vha
);
1088 * qla2x00_chip_diag() - Test chip for proper operation.
1091 * Returns 0 on success.
1094 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1097 struct qla_hw_data
*ha
= vha
->hw
;
1098 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1099 unsigned long flags
= 0;
1103 struct req_que
*req
= ha
->req_q_map
[0];
1105 /* Assume a failed state */
1106 rval
= QLA_FUNCTION_FAILED
;
1108 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
1109 vha
->host_no
, (u_long
)®
->flash_address
));
1111 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1113 /* Reset ISP chip. */
1114 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1117 * We need to have a delay here since the card will not respond while
1118 * in reset causing an MCA on some architectures.
1121 data
= qla2x00_debounce_register(®
->ctrl_status
);
1122 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1124 data
= RD_REG_WORD(®
->ctrl_status
);
1129 goto chip_diag_failed
;
1131 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
1134 /* Reset RISC processor. */
1135 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1136 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1138 /* Workaround for QLA2312 PCI parity error */
1139 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1140 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1141 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1143 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1150 goto chip_diag_failed
;
1152 /* Check product ID of chip */
1153 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha
->host_no
));
1155 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1156 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1157 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1158 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1159 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1160 mb
[3] != PROD_ID_3
) {
1161 qla_printk(KERN_WARNING
, ha
,
1162 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
1164 goto chip_diag_failed
;
1166 ha
->product_id
[0] = mb
[1];
1167 ha
->product_id
[1] = mb
[2];
1168 ha
->product_id
[2] = mb
[3];
1169 ha
->product_id
[3] = mb
[4];
1171 /* Adjust fw RISC transfer size */
1172 if (req
->length
> 1024)
1173 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1175 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1178 if (IS_QLA2200(ha
) &&
1179 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1180 /* Limit firmware transfer size with a 2200A */
1181 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
1184 ha
->device_type
|= DT_ISP2200A
;
1185 ha
->fw_transfer_size
= 128;
1188 /* Wrap Incoming Mailboxes Test. */
1189 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1191 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
1192 rval
= qla2x00_mbx_reg_test(vha
);
1194 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1196 qla_printk(KERN_WARNING
, ha
,
1197 "Failed mailbox send register test\n");
1200 /* Flag a successful rval */
1203 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1207 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
1208 "****\n", vha
->host_no
));
1210 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1216 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1219 * Returns 0 on success.
1222 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1225 struct qla_hw_data
*ha
= vha
->hw
;
1226 struct req_que
*req
= ha
->req_q_map
[0];
1231 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1233 rval
= qla2x00_mbx_reg_test(vha
);
1235 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1237 qla_printk(KERN_WARNING
, ha
,
1238 "Failed mailbox send register test\n");
1240 /* Flag a successful rval */
1248 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1251 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1252 eft_size
, fce_size
, mq_size
;
1255 struct qla_hw_data
*ha
= vha
->hw
;
1256 struct req_que
*req
= ha
->req_q_map
[0];
1257 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1260 qla_printk(KERN_WARNING
, ha
,
1261 "Firmware dump previously allocated.\n");
1266 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1267 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1268 fixed_size
= sizeof(struct qla2100_fw_dump
);
1269 } else if (IS_QLA23XX(ha
)) {
1270 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1271 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1273 } else if (IS_FWI2_CAPABLE(ha
)) {
1275 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1276 else if (IS_QLA25XX(ha
))
1277 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1279 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1280 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1283 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1284 /* Allocate memory for Fibre Channel Event Buffer. */
1285 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1288 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1291 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1292 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
1296 memset(tc
, 0, FCE_SIZE
);
1297 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1298 ha
->fce_mb
, &ha
->fce_bufs
);
1300 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1301 "FCE (%d).\n", rval
);
1302 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1304 ha
->flags
.fce_enabled
= 0;
1308 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
1311 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1312 ha
->flags
.fce_enabled
= 1;
1313 ha
->fce_dma
= tc_dma
;
1316 /* Allocate memory for Extended Trace Buffer. */
1317 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1320 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1321 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
1325 memset(tc
, 0, EFT_SIZE
);
1326 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1328 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1329 "EFT (%d).\n", rval
);
1330 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1335 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
1338 eft_size
= EFT_SIZE
;
1339 ha
->eft_dma
= tc_dma
;
1343 req_q_size
= req
->length
* sizeof(request_t
);
1344 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1346 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1347 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1348 ha
->chain_offset
= dump_size
;
1349 dump_size
+= mq_size
+ fce_size
;
1351 ha
->fw_dump
= vmalloc(dump_size
);
1353 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
1354 "firmware dump!!!\n", dump_size
/ 1024);
1357 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1364 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1371 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
1374 ha
->fw_dump_len
= dump_size
;
1375 ha
->fw_dump
->signature
[0] = 'Q';
1376 ha
->fw_dump
->signature
[1] = 'L';
1377 ha
->fw_dump
->signature
[2] = 'G';
1378 ha
->fw_dump
->signature
[3] = 'C';
1379 ha
->fw_dump
->version
= __constant_htonl(1);
1381 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1382 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1383 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1384 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1386 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1387 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1388 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1390 ha
->fw_dump
->header_size
=
1391 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1395 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1397 #define MPS_MASK 0xe0
1401 struct qla_hw_data
*ha
= vha
->hw
;
1403 if (!IS_QLA81XX(vha
->hw
))
1406 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1407 if (rval
!= QLA_SUCCESS
) {
1408 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1409 "Sync-MPI: Unable to acquire semaphore.\n"));
1413 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1414 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1415 if (rval
!= QLA_SUCCESS
) {
1416 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1417 "Sync-MPI: Unable to read sync.\n"));
1422 if (dc
== (dw
& MPS_MASK
))
1427 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1428 if (rval
!= QLA_SUCCESS
) {
1429 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1430 "Sync-MPI: Unable to gain sync.\n"));
1434 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1435 if (rval
!= QLA_SUCCESS
) {
1436 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1437 "Sync-MPI: Unable to release semaphore.\n"));
1445 * qla2x00_setup_chip() - Load and start RISC firmware.
1448 * Returns 0 on success.
1451 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1454 uint32_t srisc_address
= 0;
1455 struct qla_hw_data
*ha
= vha
->hw
;
1456 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1457 unsigned long flags
;
1458 uint16_t fw_major_version
;
1460 if (IS_QLA82XX(ha
)) {
1461 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1462 if (rval
== QLA_SUCCESS
) {
1463 qla2x00_stop_firmware(vha
);
1464 goto enable_82xx_npiv
;
1469 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1470 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1471 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1472 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1473 RD_REG_WORD(®
->hccr
);
1474 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1477 qla81xx_mpi_sync(vha
);
1479 /* Load firmware sequences */
1480 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1481 if (rval
== QLA_SUCCESS
) {
1482 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1483 "code.\n", vha
->host_no
));
1485 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1486 if (rval
== QLA_SUCCESS
) {
1487 /* Start firmware execution. */
1488 DEBUG(printk("scsi(%ld): Checksum OK, start "
1489 "firmware.\n", vha
->host_no
));
1491 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1492 /* Retrieve firmware information. */
1493 if (rval
== QLA_SUCCESS
) {
1495 fw_major_version
= ha
->fw_major_version
;
1496 rval
= qla2x00_get_fw_version(vha
,
1497 &ha
->fw_major_version
,
1498 &ha
->fw_minor_version
,
1499 &ha
->fw_subminor_version
,
1500 &ha
->fw_attributes
, &ha
->fw_memory_size
,
1501 ha
->mpi_version
, &ha
->mpi_capabilities
,
1503 if (rval
!= QLA_SUCCESS
)
1505 ha
->flags
.npiv_supported
= 0;
1506 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1507 (ha
->fw_attributes
& BIT_2
)) {
1508 ha
->flags
.npiv_supported
= 1;
1509 if ((!ha
->max_npiv_vports
) ||
1510 ((ha
->max_npiv_vports
+ 1) %
1511 MIN_MULTI_ID_FABRIC
))
1512 ha
->max_npiv_vports
=
1513 MIN_MULTI_ID_FABRIC
- 1;
1515 qla2x00_get_resource_cnts(vha
, NULL
,
1516 &ha
->fw_xcb_count
, NULL
, NULL
,
1517 &ha
->max_npiv_vports
, NULL
);
1519 if (!fw_major_version
&& ql2xallocfwdump
) {
1520 if (!IS_QLA82XX(ha
))
1521 qla2x00_alloc_fw_dump(vha
);
1525 DEBUG2(printk(KERN_INFO
1526 "scsi(%ld): ISP Firmware failed checksum.\n",
1531 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1532 /* Enable proper parity. */
1533 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1536 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1538 /* SRAM, Instruction RAM and GP RAM parity */
1539 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1540 RD_REG_WORD(®
->hccr
);
1541 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1544 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1547 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1548 if (rval
== QLA_SUCCESS
) {
1549 ha
->flags
.fac_supported
= 1;
1550 ha
->fdt_block_size
= size
<< 2;
1552 qla_printk(KERN_ERR
, ha
,
1553 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1554 ha
->fw_major_version
, ha
->fw_minor_version
,
1555 ha
->fw_subminor_version
);
1560 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1568 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1571 * Beginning of request ring has initialization control block already built
1572 * by nvram config routine.
1574 * Returns 0 on success.
1577 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1582 rsp
->ring_ptr
= rsp
->ring
;
1583 rsp
->ring_index
= 0;
1584 rsp
->status_srb
= NULL
;
1585 pkt
= rsp
->ring_ptr
;
1586 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1587 pkt
->signature
= RESPONSE_PROCESSED
;
1593 * qla2x00_update_fw_options() - Read and process firmware options.
1596 * Returns 0 on success.
1599 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1601 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1602 struct qla_hw_data
*ha
= vha
->hw
;
1604 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1605 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1607 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1610 /* Serial Link options. */
1611 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1613 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1614 sizeof(ha
->fw_seriallink_options
)));
1616 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1617 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1618 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1621 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1622 emphasis
= (ha
->fw_seriallink_options
[2] &
1623 (BIT_4
| BIT_3
)) >> 3;
1624 tx_sens
= ha
->fw_seriallink_options
[0] &
1625 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1626 rx_sens
= (ha
->fw_seriallink_options
[0] &
1627 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1628 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1629 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1632 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1633 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1634 ha
->fw_options
[10] |= BIT_5
|
1635 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1636 (tx_sens
& (BIT_1
| BIT_0
));
1639 swing
= (ha
->fw_seriallink_options
[2] &
1640 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1641 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1642 tx_sens
= ha
->fw_seriallink_options
[1] &
1643 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1644 rx_sens
= (ha
->fw_seriallink_options
[1] &
1645 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1646 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1647 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1650 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1651 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1652 ha
->fw_options
[11] |= BIT_5
|
1653 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1654 (tx_sens
& (BIT_1
| BIT_0
));
1658 /* Return command IOCBs without waiting for an ABTS to complete. */
1659 ha
->fw_options
[3] |= BIT_13
;
1662 if (ha
->flags
.enable_led_scheme
)
1663 ha
->fw_options
[2] |= BIT_12
;
1665 /* Detect ISP6312. */
1667 ha
->fw_options
[2] |= BIT_13
;
1669 /* Update firmware options. */
1670 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1674 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1677 struct qla_hw_data
*ha
= vha
->hw
;
1682 /* Update Serial Link options. */
1683 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1686 rval
= qla2x00_set_serdes_params(vha
,
1687 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1688 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1689 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1690 if (rval
!= QLA_SUCCESS
) {
1691 qla_printk(KERN_WARNING
, ha
,
1692 "Unable to update Serial Link options (%x).\n", rval
);
1697 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1699 struct qla_hw_data
*ha
= vha
->hw
;
1700 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1701 struct req_que
*req
= ha
->req_q_map
[0];
1702 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1704 /* Setup ring parameters in initialization control block. */
1705 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1706 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1707 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1708 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1709 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1710 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1711 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1712 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1714 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1715 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1716 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1717 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1718 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1722 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1724 struct qla_hw_data
*ha
= vha
->hw
;
1725 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1726 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1727 struct qla_msix_entry
*msix
;
1728 struct init_cb_24xx
*icb
;
1730 struct req_que
*req
= ha
->req_q_map
[0];
1731 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1733 /* Setup ring parameters in initialization control block. */
1734 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1735 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1736 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1737 icb
->request_q_length
= cpu_to_le16(req
->length
);
1738 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1739 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1740 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1741 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1742 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1745 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1746 icb
->rid
= __constant_cpu_to_le16(rid
);
1747 if (ha
->flags
.msix_enabled
) {
1748 msix
= &ha
->msix_entries
[1];
1749 DEBUG2_17(printk(KERN_INFO
1750 "Registering vector 0x%x for base que\n", msix
->entry
));
1751 icb
->msix
= cpu_to_le16(msix
->entry
);
1753 /* Use alternate PCI bus number */
1755 icb
->firmware_options_2
|=
1756 __constant_cpu_to_le32(BIT_19
);
1757 /* Use alternate PCI devfn */
1759 icb
->firmware_options_2
|=
1760 __constant_cpu_to_le32(BIT_18
);
1762 /* Use Disable MSIX Handshake mode for capable adapters */
1763 if (IS_MSIX_NACK_CAPABLE(ha
)) {
1764 icb
->firmware_options_2
&=
1765 __constant_cpu_to_le32(~BIT_22
);
1766 ha
->flags
.disable_msix_handshake
= 1;
1767 qla_printk(KERN_INFO
, ha
,
1768 "MSIX Handshake Disable Mode turned on\n");
1770 icb
->firmware_options_2
|=
1771 __constant_cpu_to_le32(BIT_22
);
1773 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1775 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1776 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1777 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1778 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1780 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1781 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1782 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1783 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1786 RD_REG_DWORD(&ioreg
->hccr
);
1790 * qla2x00_init_rings() - Initializes firmware.
1793 * Beginning of request ring has initialization control block already built
1794 * by nvram config routine.
1796 * Returns 0 on success.
1799 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1802 unsigned long flags
= 0;
1804 struct qla_hw_data
*ha
= vha
->hw
;
1805 struct req_que
*req
;
1806 struct rsp_que
*rsp
;
1807 struct scsi_qla_host
*vp
;
1808 struct mid_init_cb_24xx
*mid_init_cb
=
1809 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1811 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1813 /* Clear outstanding commands array. */
1814 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1815 req
= ha
->req_q_map
[que
];
1818 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1819 req
->outstanding_cmds
[cnt
] = NULL
;
1821 req
->current_outstanding_cmd
= 1;
1823 /* Initialize firmware. */
1824 req
->ring_ptr
= req
->ring
;
1825 req
->ring_index
= 0;
1826 req
->cnt
= req
->length
;
1829 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1830 rsp
= ha
->rsp_q_map
[que
];
1833 /* Initialize response queue entries */
1834 qla2x00_init_response_q_entries(rsp
);
1837 spin_lock(&ha
->vport_slock
);
1838 /* Clear RSCN queue. */
1839 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
1840 vp
->rscn_in_ptr
= 0;
1841 vp
->rscn_out_ptr
= 0;
1844 spin_unlock(&ha
->vport_slock
);
1846 ha
->isp_ops
->config_rings(vha
);
1848 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1850 /* Update any ISP specific firmware options before initialization. */
1851 ha
->isp_ops
->update_fw_options(vha
);
1853 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1855 if (ha
->flags
.npiv_supported
) {
1856 if (ha
->operating_mode
== LOOP
)
1857 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1858 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1861 if (IS_FWI2_CAPABLE(ha
)) {
1862 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1863 mid_init_cb
->init_cb
.execution_throttle
=
1864 cpu_to_le16(ha
->fw_xcb_count
);
1867 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1869 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1872 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1880 * qla2x00_fw_ready() - Waits for firmware ready.
1883 * Returns 0 on success.
1886 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1889 unsigned long wtime
, mtime
, cs84xx_time
;
1890 uint16_t min_wait
; /* Minimum wait time if loop is down */
1891 uint16_t wait_time
; /* Wait time if loop is coming ready */
1893 struct qla_hw_data
*ha
= vha
->hw
;
1897 /* 20 seconds for loop down. */
1901 * Firmware should take at most one RATOV to login, plus 5 seconds for
1902 * our own processing.
1904 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1905 wait_time
= min_wait
;
1908 /* Min wait time if loop down */
1909 mtime
= jiffies
+ (min_wait
* HZ
);
1911 /* wait time before firmware ready */
1912 wtime
= jiffies
+ (wait_time
* HZ
);
1914 /* Wait for ISP to finish LIP */
1915 if (!vha
->flags
.init_done
)
1916 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1918 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1922 rval
= qla2x00_get_firmware_state(vha
, state
);
1923 if (rval
== QLA_SUCCESS
) {
1924 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1925 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1927 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1928 DEBUG16(printk("scsi(%ld): fw_state=%x "
1929 "84xx=%x.\n", vha
->host_no
, state
[0],
1931 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1932 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1933 DEBUG16(printk("scsi(%ld): Sending "
1934 "verify iocb.\n", vha
->host_no
));
1936 cs84xx_time
= jiffies
;
1937 rval
= qla84xx_init_chip(vha
);
1938 if (rval
!= QLA_SUCCESS
)
1941 /* Add time taken to initialize. */
1942 cs84xx_time
= jiffies
- cs84xx_time
;
1943 wtime
+= cs84xx_time
;
1944 mtime
+= cs84xx_time
;
1945 DEBUG16(printk("scsi(%ld): Increasing "
1946 "wait time by %ld. New time %ld\n",
1947 vha
->host_no
, cs84xx_time
, wtime
));
1949 } else if (state
[0] == FSTATE_READY
) {
1950 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1953 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1954 &ha
->login_timeout
, &ha
->r_a_tov
);
1960 rval
= QLA_FUNCTION_FAILED
;
1962 if (atomic_read(&vha
->loop_down_timer
) &&
1963 state
[0] != FSTATE_READY
) {
1964 /* Loop down. Timeout on min_wait for states
1965 * other than Wait for Login.
1967 if (time_after_eq(jiffies
, mtime
)) {
1968 qla_printk(KERN_INFO
, ha
,
1969 "Cable is unplugged...\n");
1971 vha
->device_flags
|= DFLG_NO_CABLE
;
1976 /* Mailbox cmd failed. Timeout on min_wait. */
1977 if (time_after_eq(jiffies
, mtime
) ||
1978 ha
->flags
.isp82xx_fw_hung
)
1982 if (time_after_eq(jiffies
, wtime
))
1985 /* Delay for a while */
1988 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1989 vha
->host_no
, state
[0], jiffies
));
1992 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1993 vha
->host_no
, state
[0], state
[1], state
[2], state
[3], state
[4],
1997 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
2005 * qla2x00_configure_hba
2006 * Setup adapter context.
2009 * ha = adapter state pointer.
2018 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
2027 char connect_type
[22];
2028 struct qla_hw_data
*ha
= vha
->hw
;
2030 /* Get host addresses. */
2031 rval
= qla2x00_get_adapter_id(vha
,
2032 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
2033 if (rval
!= QLA_SUCCESS
) {
2034 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
2035 IS_QLA8XXX_TYPE(ha
) ||
2036 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
2037 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
2038 __func__
, vha
->host_no
));
2040 qla_printk(KERN_WARNING
, ha
,
2041 "ERROR -- Unable to get host loop ID.\n");
2042 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2048 qla_printk(KERN_INFO
, ha
,
2049 "Cannot get topology - retrying.\n");
2050 return (QLA_FUNCTION_FAILED
);
2053 vha
->loop_id
= loop_id
;
2056 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2057 ha
->operating_mode
= LOOP
;
2062 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
2064 ha
->current_topology
= ISP_CFG_NL
;
2065 strcpy(connect_type
, "(Loop)");
2069 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
2071 ha
->switch_cap
= sw_cap
;
2072 ha
->current_topology
= ISP_CFG_FL
;
2073 strcpy(connect_type
, "(FL_Port)");
2077 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
2079 ha
->operating_mode
= P2P
;
2080 ha
->current_topology
= ISP_CFG_N
;
2081 strcpy(connect_type
, "(N_Port-to-N_Port)");
2085 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
2087 ha
->switch_cap
= sw_cap
;
2088 ha
->operating_mode
= P2P
;
2089 ha
->current_topology
= ISP_CFG_F
;
2090 strcpy(connect_type
, "(F_Port)");
2094 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2096 vha
->host_no
, topo
));
2097 ha
->current_topology
= ISP_CFG_NL
;
2098 strcpy(connect_type
, "(Loop)");
2102 /* Save Host port and loop ID. */
2103 /* byte order - Big Endian */
2104 vha
->d_id
.b
.domain
= domain
;
2105 vha
->d_id
.b
.area
= area
;
2106 vha
->d_id
.b
.al_pa
= al_pa
;
2108 if (!vha
->flags
.init_done
)
2109 qla_printk(KERN_INFO
, ha
,
2110 "Topology - %s, Host Loop address 0x%x\n",
2111 connect_type
, vha
->loop_id
);
2114 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
2116 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
2123 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2128 struct qla_hw_data
*ha
= vha
->hw
;
2129 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2130 !IS_QLA8XXX_TYPE(ha
);
2132 if (memcmp(model
, BINZERO
, len
) != 0) {
2133 strncpy(ha
->model_number
, model
, len
);
2134 st
= en
= ha
->model_number
;
2137 if (*en
!= 0x20 && *en
!= 0x00)
2142 index
= (ha
->pdev
->subsystem_device
& 0xff);
2144 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2145 index
< QLA_MODEL_NAMES
)
2146 strncpy(ha
->model_desc
,
2147 qla2x00_model_name
[index
* 2 + 1],
2148 sizeof(ha
->model_desc
) - 1);
2150 index
= (ha
->pdev
->subsystem_device
& 0xff);
2152 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2153 index
< QLA_MODEL_NAMES
) {
2154 strcpy(ha
->model_number
,
2155 qla2x00_model_name
[index
* 2]);
2156 strncpy(ha
->model_desc
,
2157 qla2x00_model_name
[index
* 2 + 1],
2158 sizeof(ha
->model_desc
) - 1);
2160 strcpy(ha
->model_number
, def
);
2163 if (IS_FWI2_CAPABLE(ha
))
2164 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2165 sizeof(ha
->model_desc
));
2168 /* On sparc systems, obtain port and node WWN from firmware
2171 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2174 struct qla_hw_data
*ha
= vha
->hw
;
2175 struct pci_dev
*pdev
= ha
->pdev
;
2176 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2180 val
= of_get_property(dp
, "port-wwn", &len
);
2181 if (val
&& len
>= WWN_SIZE
)
2182 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2184 val
= of_get_property(dp
, "node-wwn", &len
);
2185 if (val
&& len
>= WWN_SIZE
)
2186 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2191 * NVRAM configuration for ISP 2xxx
2194 * ha = adapter block pointer.
2197 * initialization control block in response_ring
2198 * host adapters parameters in host adapter block
2204 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2209 uint8_t *dptr1
, *dptr2
;
2210 struct qla_hw_data
*ha
= vha
->hw
;
2211 init_cb_t
*icb
= ha
->init_cb
;
2212 nvram_t
*nv
= ha
->nvram
;
2213 uint8_t *ptr
= ha
->nvram
;
2214 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2218 /* Determine NVRAM starting address. */
2219 ha
->nvram_size
= sizeof(nvram_t
);
2221 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2222 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2223 ha
->nvram_base
= 0x80;
2225 /* Get NVRAM data and calculate checksum. */
2226 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2227 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2230 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
2231 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
2233 /* Bad NVRAM data, set defaults parameters. */
2234 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2235 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2236 /* Reset NVRAM data. */
2237 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
2238 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
2240 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
2241 "invalid -- WWPN) defaults.\n");
2244 * Set default initialization control block.
2246 memset(nv
, 0, ha
->nvram_size
);
2247 nv
->parameter_block_version
= ICB_VERSION
;
2249 if (IS_QLA23XX(ha
)) {
2250 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2251 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2252 nv
->add_firmware_options
[0] = BIT_5
;
2253 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2254 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2255 nv
->special_options
[1] = BIT_7
;
2256 } else if (IS_QLA2200(ha
)) {
2257 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2258 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2259 nv
->add_firmware_options
[0] = BIT_5
;
2260 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2261 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2262 } else if (IS_QLA2100(ha
)) {
2263 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2264 nv
->firmware_options
[1] = BIT_5
;
2265 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2268 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2269 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2270 nv
->retry_count
= 8;
2271 nv
->retry_delay
= 1;
2273 nv
->port_name
[0] = 33;
2274 nv
->port_name
[3] = 224;
2275 nv
->port_name
[4] = 139;
2277 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2279 nv
->login_timeout
= 4;
2282 * Set default host adapter parameters
2284 nv
->host_p
[1] = BIT_2
;
2285 nv
->reset_delay
= 5;
2286 nv
->port_down_retry_count
= 8;
2287 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2288 nv
->link_down_timeout
= 60;
2293 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2295 * The SN2 does not provide BIOS emulation which means you can't change
2296 * potentially bogus BIOS settings. Force the use of default settings
2297 * for link rate and frame size. Hope that the rest of the settings
2300 if (ia64_platform_is("sn2")) {
2301 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2303 nv
->special_options
[1] = BIT_7
;
2307 /* Reset Initialization control block */
2308 memset(icb
, 0, ha
->init_cb_size
);
2311 * Setup driver NVRAM options.
2313 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2314 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2315 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2316 nv
->firmware_options
[1] &= ~BIT_4
;
2318 if (IS_QLA23XX(ha
)) {
2319 nv
->firmware_options
[0] |= BIT_2
;
2320 nv
->firmware_options
[0] &= ~BIT_3
;
2321 nv
->firmware_options
[0] &= ~BIT_6
;
2322 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2324 if (IS_QLA2300(ha
)) {
2325 if (ha
->fb_rev
== FPM_2310
) {
2326 strcpy(ha
->model_number
, "QLA2310");
2328 strcpy(ha
->model_number
, "QLA2300");
2331 qla2x00_set_model_info(vha
, nv
->model_number
,
2332 sizeof(nv
->model_number
), "QLA23xx");
2334 } else if (IS_QLA2200(ha
)) {
2335 nv
->firmware_options
[0] |= BIT_2
;
2337 * 'Point-to-point preferred, else loop' is not a safe
2338 * connection mode setting.
2340 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2342 /* Force 'loop preferred, else point-to-point'. */
2343 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2344 nv
->add_firmware_options
[0] |= BIT_5
;
2346 strcpy(ha
->model_number
, "QLA22xx");
2347 } else /*if (IS_QLA2100(ha))*/ {
2348 strcpy(ha
->model_number
, "QLA2100");
2352 * Copy over NVRAM RISC parameter block to initialization control block.
2354 dptr1
= (uint8_t *)icb
;
2355 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2356 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2358 *dptr1
++ = *dptr2
++;
2360 /* Copy 2nd half. */
2361 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2362 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2364 *dptr1
++ = *dptr2
++;
2366 /* Use alternate WWN? */
2367 if (nv
->host_p
[1] & BIT_7
) {
2368 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2369 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2372 /* Prepare nodename */
2373 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2375 * Firmware will apply the following mask if the nodename was
2378 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2379 icb
->node_name
[0] &= 0xF0;
2383 * Set host adapter parameters.
2387 * BIT_7 in the host-parameters section allows for modification to
2388 * internal driver logging.
2390 if (nv
->host_p
[0] & BIT_7
)
2391 ql2xextended_error_logging
= 0x7fffffff;
2392 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2393 /* Always load RISC code on non ISP2[12]00 chips. */
2394 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2395 ha
->flags
.disable_risc_code_load
= 0;
2396 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2397 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2398 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2399 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2400 ha
->flags
.disable_serdes
= 0;
2402 ha
->operating_mode
=
2403 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2405 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2406 sizeof(ha
->fw_seriallink_options
));
2408 /* save HBA serial number */
2409 ha
->serial0
= icb
->port_name
[5];
2410 ha
->serial1
= icb
->port_name
[6];
2411 ha
->serial2
= icb
->port_name
[7];
2412 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2413 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2415 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2417 ha
->retry_count
= nv
->retry_count
;
2419 /* Set minimum login_timeout to 4 seconds. */
2420 if (nv
->login_timeout
!= ql2xlogintimeout
)
2421 nv
->login_timeout
= ql2xlogintimeout
;
2422 if (nv
->login_timeout
< 4)
2423 nv
->login_timeout
= 4;
2424 ha
->login_timeout
= nv
->login_timeout
;
2425 icb
->login_timeout
= nv
->login_timeout
;
2427 /* Set minimum RATOV to 100 tenths of a second. */
2430 ha
->loop_reset_delay
= nv
->reset_delay
;
2432 /* Link Down Timeout = 0:
2434 * When Port Down timer expires we will start returning
2435 * I/O's to OS with "DID_NO_CONNECT".
2437 * Link Down Timeout != 0:
2439 * The driver waits for the link to come up after link down
2440 * before returning I/Os to OS with "DID_NO_CONNECT".
2442 if (nv
->link_down_timeout
== 0) {
2443 ha
->loop_down_abort_time
=
2444 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2446 ha
->link_down_timeout
= nv
->link_down_timeout
;
2447 ha
->loop_down_abort_time
=
2448 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2452 * Need enough time to try and get the port back.
2454 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2455 if (qlport_down_retry
)
2456 ha
->port_down_retry_count
= qlport_down_retry
;
2457 /* Set login_retry_count */
2458 ha
->login_retry_count
= nv
->retry_count
;
2459 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2460 ha
->port_down_retry_count
> 3)
2461 ha
->login_retry_count
= ha
->port_down_retry_count
;
2462 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2463 ha
->login_retry_count
= ha
->port_down_retry_count
;
2464 if (ql2xloginretrycount
)
2465 ha
->login_retry_count
= ql2xloginretrycount
;
2467 icb
->lun_enables
= __constant_cpu_to_le16(0);
2468 icb
->command_resource_count
= 0;
2469 icb
->immediate_notify_resource_count
= 0;
2470 icb
->timeout
= __constant_cpu_to_le16(0);
2472 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2474 icb
->firmware_options
[0] &= ~BIT_3
;
2475 icb
->add_firmware_options
[0] &=
2476 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2477 icb
->add_firmware_options
[0] |= BIT_2
;
2478 icb
->response_accumulation_timer
= 3;
2479 icb
->interrupt_delay_timer
= 5;
2481 vha
->flags
.process_response_queue
= 1;
2484 if (!vha
->flags
.init_done
) {
2485 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2486 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2487 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2488 icb
->interrupt_delay_timer
: 2;
2490 icb
->add_firmware_options
[0] &=
2491 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2492 vha
->flags
.process_response_queue
= 0;
2493 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2494 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2496 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2497 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
2498 ha
->zio_timer
* 100));
2499 qla_printk(KERN_INFO
, ha
,
2500 "ZIO mode %d enabled; timer delay (%d us).\n",
2501 ha
->zio_mode
, ha
->zio_timer
* 100);
2503 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2504 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2505 vha
->flags
.process_response_queue
= 1;
2510 DEBUG2_3(printk(KERN_WARNING
2511 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
2517 qla2x00_rport_del(void *data
)
2519 fc_port_t
*fcport
= data
;
2520 struct fc_rport
*rport
;
2521 unsigned long flags
;
2523 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2524 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2525 fcport
->drport
= NULL
;
2526 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2528 fc_remote_port_delete(rport
);
2532 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2534 * @flags: allocation flags
2536 * Returns a pointer to the allocated fcport, or NULL, if none available.
2539 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2543 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2547 /* Setup fcport template structure. */
2549 fcport
->vp_idx
= vha
->vp_idx
;
2550 fcport
->port_type
= FCT_UNKNOWN
;
2551 fcport
->loop_id
= FC_NO_LOOP_ID
;
2552 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
2553 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2559 * qla2x00_configure_loop
2560 * Updates Fibre Channel Device Database with what is actually on loop.
2563 * ha = adapter block pointer.
2568 * 2 = database was full and device was not configured.
2571 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2574 unsigned long flags
, save_flags
;
2575 struct qla_hw_data
*ha
= vha
->hw
;
2578 /* Get Initiator ID */
2579 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2580 rval
= qla2x00_configure_hba(vha
);
2581 if (rval
!= QLA_SUCCESS
) {
2582 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2588 save_flags
= flags
= vha
->dpc_flags
;
2589 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2590 vha
->host_no
, flags
));
2593 * If we have both an RSCN and PORT UPDATE pending then handle them
2594 * both at the same time.
2596 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2597 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2599 qla2x00_get_data_rate(vha
);
2601 /* Determine what we need to do */
2602 if (ha
->current_topology
== ISP_CFG_FL
&&
2603 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2605 vha
->flags
.rscn_queue_overflow
= 1;
2606 set_bit(RSCN_UPDATE
, &flags
);
2608 } else if (ha
->current_topology
== ISP_CFG_F
&&
2609 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2611 vha
->flags
.rscn_queue_overflow
= 1;
2612 set_bit(RSCN_UPDATE
, &flags
);
2613 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2615 } else if (ha
->current_topology
== ISP_CFG_N
) {
2616 clear_bit(RSCN_UPDATE
, &flags
);
2618 } else if (!vha
->flags
.online
||
2619 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2621 vha
->flags
.rscn_queue_overflow
= 1;
2622 set_bit(RSCN_UPDATE
, &flags
);
2623 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2626 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2627 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2628 rval
= QLA_FUNCTION_FAILED
;
2630 rval
= qla2x00_configure_local_loop(vha
);
2633 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2634 if (LOOP_TRANSITION(vha
))
2635 rval
= QLA_FUNCTION_FAILED
;
2637 rval
= qla2x00_configure_fabric(vha
);
2640 if (rval
== QLA_SUCCESS
) {
2641 if (atomic_read(&vha
->loop_down_timer
) ||
2642 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2643 rval
= QLA_FUNCTION_FAILED
;
2645 atomic_set(&vha
->loop_state
, LOOP_READY
);
2647 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2652 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2653 __func__
, vha
->host_no
));
2655 DEBUG3(printk("%s: exiting normally\n", __func__
));
2658 /* Restore state if a resync event occurred during processing */
2659 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2660 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2661 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2662 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2663 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2664 if (!IS_ALOGIO_CAPABLE(ha
))
2665 vha
->flags
.rscn_queue_overflow
= 1;
2675 * qla2x00_configure_local_loop
2676 * Updates Fibre Channel Device Database with local loop devices.
2679 * ha = adapter block pointer.
2685 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2690 fc_port_t
*fcport
, *new_fcport
;
2696 uint8_t domain
, area
, al_pa
;
2697 struct qla_hw_data
*ha
= vha
->hw
;
2701 entries
= MAX_FIBRE_DEVICES
;
2703 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2704 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2706 /* Get list of logged in devices. */
2707 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2708 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2710 if (rval
!= QLA_SUCCESS
)
2711 goto cleanup_allocation
;
2713 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2714 vha
->host_no
, entries
));
2715 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2716 entries
* sizeof(struct gid_list_info
)));
2718 /* Allocate temporary fcport for any new fcports discovered. */
2719 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2720 if (new_fcport
== NULL
) {
2721 rval
= QLA_MEMORY_ALLOC_FAILED
;
2722 goto cleanup_allocation
;
2724 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2727 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2729 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2730 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2731 fcport
->port_type
!= FCT_BROADCAST
&&
2732 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2734 DEBUG(printk("scsi(%ld): Marking port lost, "
2736 vha
->host_no
, fcport
->loop_id
));
2738 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2742 /* Add devices to port list. */
2743 id_iter
= (char *)ha
->gid_list
;
2744 for (index
= 0; index
< entries
; index
++) {
2745 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2746 area
= ((struct gid_list_info
*)id_iter
)->area
;
2747 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2748 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2749 loop_id
= (uint16_t)
2750 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2752 loop_id
= le16_to_cpu(
2753 ((struct gid_list_info
*)id_iter
)->loop_id
);
2754 id_iter
+= ha
->gid_list_info_size
;
2756 /* Bypass reserved domain fields. */
2757 if ((domain
& 0xf0) == 0xf0)
2760 /* Bypass if not same domain and area of adapter. */
2761 if (area
&& domain
&&
2762 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2765 /* Bypass invalid local loop ID. */
2766 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2769 /* Fill in member data. */
2770 new_fcport
->d_id
.b
.domain
= domain
;
2771 new_fcport
->d_id
.b
.area
= area
;
2772 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2773 new_fcport
->loop_id
= loop_id
;
2774 new_fcport
->vp_idx
= vha
->vp_idx
;
2775 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2776 if (rval2
!= QLA_SUCCESS
) {
2777 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2778 "information -- get_port_database=%x, "
2780 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2781 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2783 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2787 /* Check for matching device in port list. */
2790 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2791 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2795 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2796 fcport
->loop_id
= new_fcport
->loop_id
;
2797 fcport
->port_type
= new_fcport
->port_type
;
2798 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2799 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2807 /* New device, add to fcports list. */
2809 new_fcport
->vha
= vha
;
2810 new_fcport
->vp_idx
= vha
->vp_idx
;
2812 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2814 /* Allocate a new replacement fcport. */
2815 fcport
= new_fcport
;
2816 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2817 if (new_fcport
== NULL
) {
2818 rval
= QLA_MEMORY_ALLOC_FAILED
;
2819 goto cleanup_allocation
;
2821 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2824 /* Base iIDMA settings on HBA port speed. */
2825 fcport
->fp_speed
= ha
->link_data_rate
;
2827 qla2x00_update_fcport(vha
, fcport
);
2835 if (rval
!= QLA_SUCCESS
) {
2836 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2837 "rval=%x\n", vha
->host_no
, rval
));
2844 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2846 #define LS_UNKNOWN 2
2847 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
2851 struct qla_hw_data
*ha
= vha
->hw
;
2853 if (!IS_IIDMA_CAPABLE(ha
))
2856 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
2859 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2860 fcport
->fp_speed
> ha
->link_data_rate
)
2863 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2865 if (rval
!= QLA_SUCCESS
) {
2866 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2867 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2868 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2869 fcport
->port_name
[2], fcport
->port_name
[3],
2870 fcport
->port_name
[4], fcport
->port_name
[5],
2871 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2872 fcport
->fp_speed
, mb
[0], mb
[1]));
2874 link_speed
= link_speeds
[LS_UNKNOWN
];
2875 if (fcport
->fp_speed
< 5)
2876 link_speed
= link_speeds
[fcport
->fp_speed
];
2877 else if (fcport
->fp_speed
== 0x13)
2878 link_speed
= link_speeds
[5];
2879 DEBUG2(qla_printk(KERN_INFO
, ha
,
2880 "iIDMA adjusted to %s GB/s on "
2881 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2882 link_speed
, fcport
->port_name
[0],
2883 fcport
->port_name
[1], fcport
->port_name
[2],
2884 fcport
->port_name
[3], fcport
->port_name
[4],
2885 fcport
->port_name
[5], fcport
->port_name
[6],
2886 fcport
->port_name
[7]));
2891 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2893 struct fc_rport_identifiers rport_ids
;
2894 struct fc_rport
*rport
;
2895 struct qla_hw_data
*ha
= vha
->hw
;
2896 unsigned long flags
;
2898 qla2x00_rport_del(fcport
);
2900 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2901 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2902 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2903 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2904 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2905 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2907 qla_printk(KERN_WARNING
, ha
,
2908 "Unable to allocate fc remote port!\n");
2911 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2912 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2913 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2915 rport
->supported_classes
= fcport
->supported_classes
;
2917 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2918 if (fcport
->port_type
== FCT_INITIATOR
)
2919 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2920 if (fcport
->port_type
== FCT_TARGET
)
2921 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2922 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2926 * qla2x00_update_fcport
2927 * Updates device on list.
2930 * ha = adapter block pointer.
2931 * fcport = port structure pointer.
2941 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2944 fcport
->login_retry
= 0;
2945 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
2947 qla2x00_iidma_fcport(vha
, fcport
);
2948 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
2949 qla2x00_reg_remote_port(vha
, fcport
);
2950 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
2954 * qla2x00_configure_fabric
2955 * Setup SNS devices with loop ID's.
2958 * ha = adapter block pointer.
2965 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2968 fc_port_t
*fcport
, *fcptemp
;
2969 uint16_t next_loopid
;
2970 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2972 LIST_HEAD(new_fcports
);
2973 struct qla_hw_data
*ha
= vha
->hw
;
2974 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2976 /* If FL port exists, then SNS is present */
2977 if (IS_FWI2_CAPABLE(ha
))
2978 loop_id
= NPH_F_PORT
;
2980 loop_id
= SNS_FL_PORT
;
2981 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2982 if (rval
!= QLA_SUCCESS
) {
2983 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2984 "Port\n", vha
->host_no
));
2986 vha
->device_flags
&= ~SWITCH_FOUND
;
2987 return (QLA_SUCCESS
);
2989 vha
->device_flags
|= SWITCH_FOUND
;
2991 /* Mark devices that need re-synchronization. */
2992 rval2
= qla2x00_device_resync(vha
);
2993 if (rval2
== QLA_RSCNS_HANDLED
) {
2994 /* No point doing the scan, just continue. */
2995 return (QLA_SUCCESS
);
2999 if (ql2xfdmienable
&&
3000 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
3001 qla2x00_fdmi_register(vha
);
3003 /* Ensure we are logged into the SNS. */
3004 if (IS_FWI2_CAPABLE(ha
))
3007 loop_id
= SIMPLE_NAME_SERVER
;
3008 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
3009 0xfc, mb
, BIT_1
| BIT_0
);
3010 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
3011 DEBUG2(qla_printk(KERN_INFO
, ha
,
3012 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
3013 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
3014 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
3015 return (QLA_SUCCESS
);
3018 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
3019 if (qla2x00_rft_id(vha
)) {
3021 DEBUG2(printk("scsi(%ld): Register FC-4 "
3022 "TYPE failed.\n", vha
->host_no
));
3024 if (qla2x00_rff_id(vha
)) {
3026 DEBUG2(printk("scsi(%ld): Register FC-4 "
3027 "Features failed.\n", vha
->host_no
));
3029 if (qla2x00_rnn_id(vha
)) {
3031 DEBUG2(printk("scsi(%ld): Register Node Name "
3032 "failed.\n", vha
->host_no
));
3033 } else if (qla2x00_rsnn_nn(vha
)) {
3035 DEBUG2(printk("scsi(%ld): Register Symbolic "
3036 "Node Name failed.\n", vha
->host_no
));
3040 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
3041 if (rval
!= QLA_SUCCESS
)
3045 * Logout all previous fabric devices marked lost, except
3048 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3049 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3052 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3055 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
3056 qla2x00_mark_device_lost(vha
, fcport
,
3057 ql2xplogiabsentdevice
, 0);
3058 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3059 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3060 fcport
->port_type
!= FCT_INITIATOR
&&
3061 fcport
->port_type
!= FCT_BROADCAST
) {
3062 ha
->isp_ops
->fabric_logout(vha
,
3064 fcport
->d_id
.b
.domain
,
3065 fcport
->d_id
.b
.area
,
3066 fcport
->d_id
.b
.al_pa
);
3067 fcport
->loop_id
= FC_NO_LOOP_ID
;
3072 /* Starting free loop ID. */
3073 next_loopid
= ha
->min_external_loopid
;
3076 * Scan through our port list and login entries that need to be
3079 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3080 if (atomic_read(&vha
->loop_down_timer
) ||
3081 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3084 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3085 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
3088 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3089 fcport
->loop_id
= next_loopid
;
3090 rval
= qla2x00_find_new_loop_id(
3092 if (rval
!= QLA_SUCCESS
) {
3093 /* Ran out of IDs to use */
3097 /* Login and update database */
3098 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3101 /* Exit if out of loop IDs. */
3102 if (rval
!= QLA_SUCCESS
) {
3107 * Login and add the new devices to our port list.
3109 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3110 if (atomic_read(&vha
->loop_down_timer
) ||
3111 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3114 /* Find a new loop ID to use. */
3115 fcport
->loop_id
= next_loopid
;
3116 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
3117 if (rval
!= QLA_SUCCESS
) {
3118 /* Ran out of IDs to use */
3122 /* Login and update database */
3123 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3127 fcport
->vp_idx
= vha
->vp_idx
;
3129 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
3133 /* Free all new device structures not processed. */
3134 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3135 list_del(&fcport
->list
);
3140 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
3141 "rval=%d\n", vha
->host_no
, rval
));
3148 * qla2x00_find_all_fabric_devs
3151 * ha = adapter block pointer.
3152 * dev = database device entry pointer.
3161 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3162 struct list_head
*new_fcports
)
3166 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3171 int first_dev
, last_dev
;
3172 port_id_t wrap
= {}, nxt_d_id
;
3173 struct qla_hw_data
*ha
= vha
->hw
;
3174 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3175 struct scsi_qla_host
*tvp
;
3179 /* Try GID_PT to get device list, else GAN. */
3180 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
3183 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
3184 "on GA_NXT\n", vha
->host_no
));
3186 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3189 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3192 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3195 } else if (ql2xiidmaenable
&&
3196 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3197 qla2x00_gpsc(vha
, swl
);
3200 /* If other queries succeeded probe for FC-4 type */
3202 qla2x00_gff_id(vha
, swl
);
3206 /* Allocate temporary fcport for any new fcports discovered. */
3207 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3208 if (new_fcport
== NULL
) {
3210 return (QLA_MEMORY_ALLOC_FAILED
);
3212 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3213 /* Set start port ID scan at adapter ID. */
3217 /* Starting free loop ID. */
3218 loop_id
= ha
->min_external_loopid
;
3219 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3220 if (qla2x00_is_reserved_id(vha
, loop_id
))
3223 if (ha
->current_topology
== ISP_CFG_FL
&&
3224 (atomic_read(&vha
->loop_down_timer
) ||
3225 LOOP_TRANSITION(vha
))) {
3226 atomic_set(&vha
->loop_down_timer
, 0);
3227 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3228 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3234 wrap
.b24
= new_fcport
->d_id
.b24
;
3236 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3237 memcpy(new_fcport
->node_name
,
3238 swl
[swl_idx
].node_name
, WWN_SIZE
);
3239 memcpy(new_fcport
->port_name
,
3240 swl
[swl_idx
].port_name
, WWN_SIZE
);
3241 memcpy(new_fcport
->fabric_port_name
,
3242 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3243 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3244 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3246 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3252 /* Send GA_NXT to the switch */
3253 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3254 if (rval
!= QLA_SUCCESS
) {
3255 qla_printk(KERN_WARNING
, ha
,
3256 "SNS scan failed -- assuming zero-entry "
3258 list_for_each_entry_safe(fcport
, fcptemp
,
3259 new_fcports
, list
) {
3260 list_del(&fcport
->list
);
3268 /* If wrap on switch device list, exit. */
3270 wrap
.b24
= new_fcport
->d_id
.b24
;
3272 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3273 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
3274 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
3275 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
3279 /* Bypass if same physical adapter. */
3280 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3283 /* Bypass virtual ports of the same host. */
3285 if (ha
->num_vhosts
) {
3286 unsigned long flags
;
3288 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3289 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3290 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3295 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3301 /* Bypass if same domain and area of adapter. */
3302 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3303 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3307 /* Bypass reserved domain fields. */
3308 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3311 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3312 if (ql2xgffidenable
&&
3313 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3314 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3317 /* Locate matching device in database. */
3319 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3320 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3326 /* Update port state. */
3327 memcpy(fcport
->fabric_port_name
,
3328 new_fcport
->fabric_port_name
, WWN_SIZE
);
3329 fcport
->fp_speed
= new_fcport
->fp_speed
;
3332 * If address the same and state FCS_ONLINE, nothing
3335 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3336 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3341 * If device was not a fabric device before.
3343 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3344 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3345 fcport
->loop_id
= FC_NO_LOOP_ID
;
3346 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3352 * Port ID changed or device was marked to be updated;
3353 * Log it out if still logged in and mark it for
3356 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3357 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3358 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3359 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3360 fcport
->port_type
!= FCT_INITIATOR
&&
3361 fcport
->port_type
!= FCT_BROADCAST
) {
3362 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3363 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3364 fcport
->d_id
.b
.al_pa
);
3365 fcport
->loop_id
= FC_NO_LOOP_ID
;
3373 /* If device was not in our fcports list, then add it. */
3374 list_add_tail(&new_fcport
->list
, new_fcports
);
3376 /* Allocate a new replacement fcport. */
3377 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3378 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3379 if (new_fcport
== NULL
) {
3381 return (QLA_MEMORY_ALLOC_FAILED
);
3383 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3384 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3394 * qla2x00_find_new_loop_id
3395 * Scan through our port list and find a new usable loop ID.
3398 * ha: adapter state pointer.
3399 * dev: port structure pointer.
3402 * qla2x00 local function return status code.
3408 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3413 uint16_t first_loop_id
;
3414 struct qla_hw_data
*ha
= vha
->hw
;
3415 struct scsi_qla_host
*vp
;
3416 struct scsi_qla_host
*tvp
;
3417 unsigned long flags
= 0;
3421 /* Save starting loop ID. */
3422 first_loop_id
= dev
->loop_id
;
3425 /* Skip loop ID if already used by adapter. */
3426 if (dev
->loop_id
== vha
->loop_id
)
3429 /* Skip reserved loop IDs. */
3430 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3433 /* Reset loop ID if passed the end. */
3434 if (dev
->loop_id
> ha
->max_loop_id
) {
3435 /* first loop ID. */
3436 dev
->loop_id
= ha
->min_external_loopid
;
3439 /* Check for loop ID being already in use. */
3443 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3444 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3445 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3446 if (fcport
->loop_id
== dev
->loop_id
&&
3448 /* ID possibly in use */
3456 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3458 /* If not in use then it is free to use. */
3463 /* ID in use. Try next value. */
3466 /* If wrap around. No free ID to use. */
3467 if (dev
->loop_id
== first_loop_id
) {
3468 dev
->loop_id
= FC_NO_LOOP_ID
;
3469 rval
= QLA_FUNCTION_FAILED
;
3478 * qla2x00_device_resync
3479 * Marks devices in the database that needs resynchronization.
3482 * ha = adapter block pointer.
3488 qla2x00_device_resync(scsi_qla_host_t
*vha
)
3493 uint32_t rscn_entry
;
3494 uint8_t rscn_out_iter
;
3496 port_id_t d_id
= {};
3498 rval
= QLA_RSCNS_HANDLED
;
3500 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
3501 vha
->flags
.rscn_queue_overflow
) {
3503 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
3504 format
= MSB(MSW(rscn_entry
));
3505 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
3506 d_id
.b
.area
= MSB(LSW(rscn_entry
));
3507 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
3509 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3510 "[%02x/%02x%02x%02x].\n",
3511 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
3512 d_id
.b
.area
, d_id
.b
.al_pa
));
3514 vha
->rscn_out_ptr
++;
3515 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
3516 vha
->rscn_out_ptr
= 0;
3518 /* Skip duplicate entries. */
3519 for (rscn_out_iter
= vha
->rscn_out_ptr
;
3520 !vha
->flags
.rscn_queue_overflow
&&
3521 rscn_out_iter
!= vha
->rscn_in_ptr
;
3522 rscn_out_iter
= (rscn_out_iter
==
3523 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
3525 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
3528 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3529 "entry found at [%d].\n", vha
->host_no
,
3532 vha
->rscn_out_ptr
= rscn_out_iter
;
3535 /* Queue overflow, set switch default case. */
3536 if (vha
->flags
.rscn_queue_overflow
) {
3537 DEBUG(printk("scsi(%ld): device_resync: rscn "
3538 "overflow.\n", vha
->host_no
));
3541 vha
->flags
.rscn_queue_overflow
= 0;
3557 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
3563 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3564 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3565 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
3566 fcport
->port_type
== FCT_BROADCAST
)
3569 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3571 fcport
->port_type
!= FCT_INITIATOR
) {
3572 qla2x00_mark_device_lost(vha
, fcport
,
3582 * qla2x00_fabric_dev_login
3583 * Login fabric target device and update FC port database.
3586 * ha: adapter state pointer.
3587 * fcport: port structure list pointer.
3588 * next_loopid: contains value of a new loop ID that can be used
3589 * by the next login attempt.
3592 * qla2x00 local function return status code.
3598 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3599 uint16_t *next_loopid
)
3604 struct qla_hw_data
*ha
= vha
->hw
;
3609 if (IS_ALOGIO_CAPABLE(ha
)) {
3610 if (fcport
->flags
& FCF_ASYNC_SENT
)
3612 fcport
->flags
|= FCF_ASYNC_SENT
;
3613 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3618 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3619 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3620 if (rval
== QLA_SUCCESS
) {
3621 /* Send an ADISC to FCP2 devices.*/
3623 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3625 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3626 if (rval
!= QLA_SUCCESS
) {
3627 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3628 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3629 fcport
->d_id
.b
.al_pa
);
3630 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3632 qla2x00_update_fcport(vha
, fcport
);
3640 * qla2x00_fabric_login
3641 * Issue fabric login command.
3644 * ha = adapter block pointer.
3645 * device = pointer to FC device type structure.
3648 * 0 - Login successfully
3650 * 2 - Initiator device
3654 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3655 uint16_t *next_loopid
)
3659 uint16_t tmp_loopid
;
3660 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3661 struct qla_hw_data
*ha
= vha
->hw
;
3667 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3668 "for port %02x%02x%02x.\n",
3669 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3670 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3672 /* Login fcport on switch. */
3673 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3674 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3675 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3676 if (mb
[0] == MBS_PORT_ID_USED
) {
3678 * Device has another loop ID. The firmware team
3679 * recommends the driver perform an implicit login with
3680 * the specified ID again. The ID we just used is save
3681 * here so we return with an ID that can be tried by
3685 tmp_loopid
= fcport
->loop_id
;
3686 fcport
->loop_id
= mb
[1];
3688 DEBUG(printk("Fabric Login: port in use - next "
3689 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3690 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3691 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3693 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3698 /* A retry occurred before. */
3699 *next_loopid
= tmp_loopid
;
3702 * No retry occurred before. Just increment the
3703 * ID value for next login.
3705 *next_loopid
= (fcport
->loop_id
+ 1);
3708 if (mb
[1] & BIT_0
) {
3709 fcport
->port_type
= FCT_INITIATOR
;
3711 fcport
->port_type
= FCT_TARGET
;
3712 if (mb
[1] & BIT_1
) {
3713 fcport
->flags
|= FCF_FCP2_DEVICE
;
3718 fcport
->supported_classes
|= FC_COS_CLASS2
;
3720 fcport
->supported_classes
|= FC_COS_CLASS3
;
3724 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3726 * Loop ID already used, try next loop ID.
3729 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3730 if (rval
!= QLA_SUCCESS
) {
3731 /* Ran out of loop IDs to use */
3734 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3736 * Firmware possibly timed out during login. If NO
3737 * retries are left to do then the device is declared
3740 *next_loopid
= fcport
->loop_id
;
3741 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3742 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3743 fcport
->d_id
.b
.al_pa
);
3744 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3750 * unrecoverable / not handled error
3752 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3753 "loop_id=%x jiffies=%lx.\n",
3754 __func__
, vha
->host_no
, mb
[0],
3755 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3756 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3758 *next_loopid
= fcport
->loop_id
;
3759 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3760 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3761 fcport
->d_id
.b
.al_pa
);
3762 fcport
->loop_id
= FC_NO_LOOP_ID
;
3763 fcport
->login_retry
= 0;
3774 * qla2x00_local_device_login
3775 * Issue local device login command.
3778 * ha = adapter block pointer.
3779 * loop_id = loop id of device to login to.
3781 * Returns (Where's the #define!!!!):
3782 * 0 - Login successfully
3787 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3790 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3792 memset(mb
, 0, sizeof(mb
));
3793 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3794 if (rval
== QLA_SUCCESS
) {
3795 /* Interrogate mailbox registers for any errors */
3796 if (mb
[0] == MBS_COMMAND_ERROR
)
3798 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3799 /* device not in PCB table */
3807 * qla2x00_loop_resync
3808 * Resync with fibre channel devices.
3811 * ha = adapter block pointer.
3817 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3819 int rval
= QLA_SUCCESS
;
3821 struct req_que
*req
;
3822 struct rsp_que
*rsp
;
3824 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3825 req
= vha
->hw
->req_q_map
[0];
3830 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3831 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3832 if (vha
->flags
.online
) {
3833 if (!(rval
= qla2x00_fw_ready(vha
))) {
3834 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3837 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3839 /* Issue a marker after FW becomes ready. */
3840 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3842 vha
->marker_needed
= 0;
3844 /* Remap devices on Loop. */
3845 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3847 qla2x00_configure_loop(vha
);
3849 } while (!atomic_read(&vha
->loop_down_timer
) &&
3850 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3851 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3856 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3857 return (QLA_FUNCTION_FAILED
);
3860 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3866 * qla2x00_perform_loop_resync
3867 * Description: This function will set the appropriate flags and call
3868 * qla2x00_loop_resync. If successful loop will be resynced
3869 * Arguments : scsi_qla_host_t pointer
3870 * returm : Success or Failure
3873 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
3877 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
3878 /*Configure the flags so that resync happens properly*/
3879 atomic_set(&ha
->loop_down_timer
, 0);
3880 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
3881 atomic_set(&ha
->loop_state
, LOOP_UP
);
3882 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
3883 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
3884 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3886 rval
= qla2x00_loop_resync(ha
);
3888 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
3890 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
3897 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3900 struct scsi_qla_host
*vha
;
3901 struct qla_hw_data
*ha
= base_vha
->hw
;
3902 unsigned long flags
;
3904 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3905 /* Go with deferred removal of rport references. */
3906 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3907 atomic_inc(&vha
->vref_count
);
3908 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3909 if (fcport
->drport
&&
3910 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3911 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3913 qla2x00_rport_del(fcport
);
3915 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3918 atomic_dec(&vha
->vref_count
);
3920 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3924 * qla82xx_quiescent_state_cleanup
3925 * Description: This function will block the new I/Os
3926 * Its not aborting any I/Os as context
3927 * is not destroyed during quiescence
3928 * Arguments: scsi_qla_host_t
3932 qla82xx_quiescent_state_cleanup(scsi_qla_host_t
*vha
)
3934 struct qla_hw_data
*ha
= vha
->hw
;
3935 struct scsi_qla_host
*vp
;
3937 qla_printk(KERN_INFO
, ha
,
3938 "Performing ISP error recovery - ha= %p.\n", ha
);
3940 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3941 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3942 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3943 qla2x00_mark_all_devices_lost(vha
, 0);
3944 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3945 qla2x00_mark_all_devices_lost(vha
, 0);
3947 if (!atomic_read(&vha
->loop_down_timer
))
3948 atomic_set(&vha
->loop_down_timer
,
3951 /* Wait for pending cmds to complete */
3952 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
3956 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3958 struct qla_hw_data
*ha
= vha
->hw
;
3959 struct scsi_qla_host
*vp
;
3960 unsigned long flags
;
3963 /* For ISP82XX, driver waits for completion of the commands.
3964 * online flag should be set.
3966 if (!IS_QLA82XX(ha
))
3967 vha
->flags
.online
= 0;
3968 ha
->flags
.chip_reset_done
= 0;
3969 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3970 ha
->qla_stats
.total_isp_aborts
++;
3972 qla_printk(KERN_INFO
, ha
,
3973 "Performing ISP error recovery - ha= %p.\n", ha
);
3975 /* For ISP82XX, reset_chip is just disabling interrupts.
3976 * Driver waits for the completion of the commands.
3977 * the interrupts need to be enabled.
3979 if (!IS_QLA82XX(ha
))
3980 ha
->isp_ops
->reset_chip(vha
);
3982 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3983 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3984 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3985 qla2x00_mark_all_devices_lost(vha
, 0);
3987 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3988 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3989 atomic_inc(&vp
->vref_count
);
3990 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3992 qla2x00_mark_all_devices_lost(vp
, 0);
3994 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3995 atomic_dec(&vp
->vref_count
);
3997 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3999 if (!atomic_read(&vha
->loop_down_timer
))
4000 atomic_set(&vha
->loop_down_timer
,
4004 /* Clear all async request states across all VPs. */
4005 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
4006 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4007 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4008 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4009 atomic_inc(&vp
->vref_count
);
4010 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4012 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
4013 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4015 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4016 atomic_dec(&vp
->vref_count
);
4018 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4020 if (!ha
->flags
.eeh_busy
) {
4021 /* Make sure for ISP 82XX IO DMA is complete */
4022 if (IS_QLA82XX(ha
)) {
4023 qla82xx_chip_reset_cleanup(vha
);
4025 /* Done waiting for pending commands.
4026 * Reset the online flag.
4028 vha
->flags
.online
= 0;
4031 /* Requeue all commands in outstanding command list. */
4032 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
4038 * Resets ISP and aborts all outstanding commands.
4041 * ha = adapter block pointer.
4047 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
4051 struct qla_hw_data
*ha
= vha
->hw
;
4052 struct scsi_qla_host
*vp
;
4053 struct req_que
*req
= ha
->req_q_map
[0];
4054 unsigned long flags
;
4056 if (vha
->flags
.online
) {
4057 qla2x00_abort_isp_cleanup(vha
);
4059 if (unlikely(pci_channel_offline(ha
->pdev
) &&
4060 ha
->flags
.pci_channel_io_perm_failure
)) {
4061 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4066 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
4068 ha
->isp_ops
->nvram_config(vha
);
4070 if (!qla2x00_restart_isp(vha
)) {
4071 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4073 if (!atomic_read(&vha
->loop_down_timer
)) {
4075 * Issue marker command only when we are going
4076 * to start the I/O .
4078 vha
->marker_needed
= 1;
4081 vha
->flags
.online
= 1;
4083 ha
->isp_ops
->enable_intrs(ha
);
4085 ha
->isp_abort_cnt
= 0;
4086 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4089 qla2x00_get_fw_version(vha
,
4090 &ha
->fw_major_version
,
4091 &ha
->fw_minor_version
,
4092 &ha
->fw_subminor_version
,
4093 &ha
->fw_attributes
, &ha
->fw_memory_size
,
4094 ha
->mpi_version
, &ha
->mpi_capabilities
,
4098 ha
->flags
.fce_enabled
= 1;
4100 fce_calc_size(ha
->fce_bufs
));
4101 rval
= qla2x00_enable_fce_trace(vha
,
4102 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
4105 qla_printk(KERN_WARNING
, ha
,
4106 "Unable to reinitialize FCE "
4108 ha
->flags
.fce_enabled
= 0;
4113 memset(ha
->eft
, 0, EFT_SIZE
);
4114 rval
= qla2x00_enable_eft_trace(vha
,
4115 ha
->eft_dma
, EFT_NUM_BUFFERS
);
4117 qla_printk(KERN_WARNING
, ha
,
4118 "Unable to reinitialize EFT "
4122 } else { /* failed the ISP abort */
4123 vha
->flags
.online
= 1;
4124 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
4125 if (ha
->isp_abort_cnt
== 0) {
4126 qla_printk(KERN_WARNING
, ha
,
4127 "ISP error recovery failed - "
4128 "board disabled\n");
4130 * The next call disables the board
4133 ha
->isp_ops
->reset_adapter(vha
);
4134 vha
->flags
.online
= 0;
4135 clear_bit(ISP_ABORT_RETRY
,
4138 } else { /* schedule another ISP abort */
4139 ha
->isp_abort_cnt
--;
4140 DEBUG(printk("qla%ld: ISP abort - "
4141 "retry remaining %d\n",
4142 vha
->host_no
, ha
->isp_abort_cnt
));
4146 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
4147 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4148 "- retrying (%d) more times\n",
4149 vha
->host_no
, ha
->isp_abort_cnt
));
4150 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4158 DEBUG(printk(KERN_INFO
4159 "qla2x00_abort_isp(%ld): succeeded.\n",
4162 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4163 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4165 atomic_inc(&vp
->vref_count
);
4166 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4168 qla2x00_vp_abort_isp(vp
);
4170 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4171 atomic_dec(&vp
->vref_count
);
4174 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4177 qla_printk(KERN_INFO
, ha
,
4178 "qla2x00_abort_isp: **** FAILED ****\n");
4185 * qla2x00_restart_isp
4186 * restarts the ISP after a reset
4189 * ha = adapter block pointer.
4195 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4199 struct qla_hw_data
*ha
= vha
->hw
;
4200 struct req_que
*req
= ha
->req_q_map
[0];
4201 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4203 /* If firmware needs to be loaded */
4204 if (qla2x00_isp_firmware(vha
)) {
4205 vha
->flags
.online
= 0;
4206 status
= ha
->isp_ops
->chip_diag(vha
);
4208 status
= qla2x00_setup_chip(vha
);
4211 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4212 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4213 ha
->flags
.chip_reset_done
= 1;
4214 /* Initialize the queues in use */
4215 qla25xx_init_queues(ha
);
4217 status
= qla2x00_fw_ready(vha
);
4219 DEBUG(printk("%s(): Start configure loop, "
4220 "status = %d\n", __func__
, status
));
4222 /* Issue a marker after FW becomes ready. */
4223 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4225 vha
->flags
.online
= 1;
4226 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4229 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4230 qla2x00_configure_loop(vha
);
4232 } while (!atomic_read(&vha
->loop_down_timer
) &&
4233 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4234 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4238 /* if no cable then assume it's good */
4239 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4242 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4250 qla25xx_init_queues(struct qla_hw_data
*ha
)
4252 struct rsp_que
*rsp
= NULL
;
4253 struct req_que
*req
= NULL
;
4254 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4258 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4259 rsp
= ha
->rsp_q_map
[i
];
4261 rsp
->options
&= ~BIT_0
;
4262 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4263 if (ret
!= QLA_SUCCESS
)
4264 DEBUG2_17(printk(KERN_WARNING
4265 "%s Rsp que:%d init failed\n", __func__
,
4268 DEBUG2_17(printk(KERN_INFO
4269 "%s Rsp que:%d inited\n", __func__
,
4273 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4274 req
= ha
->req_q_map
[i
];
4276 /* Clear outstanding commands array. */
4277 req
->options
&= ~BIT_0
;
4278 ret
= qla25xx_init_req_que(base_vha
, req
);
4279 if (ret
!= QLA_SUCCESS
)
4280 DEBUG2_17(printk(KERN_WARNING
4281 "%s Req que:%d init failed\n", __func__
,
4284 DEBUG2_17(printk(KERN_WARNING
4285 "%s Req que:%d inited\n", __func__
,
4293 * qla2x00_reset_adapter
4297 * ha = adapter block pointer.
4300 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4302 unsigned long flags
= 0;
4303 struct qla_hw_data
*ha
= vha
->hw
;
4304 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4306 vha
->flags
.online
= 0;
4307 ha
->isp_ops
->disable_intrs(ha
);
4309 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4310 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4311 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4312 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4313 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4314 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4318 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4320 unsigned long flags
= 0;
4321 struct qla_hw_data
*ha
= vha
->hw
;
4322 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4327 vha
->flags
.online
= 0;
4328 ha
->isp_ops
->disable_intrs(ha
);
4330 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4331 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4332 RD_REG_DWORD(®
->hccr
);
4333 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4334 RD_REG_DWORD(®
->hccr
);
4335 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4337 if (IS_NOPOLLING_TYPE(ha
))
4338 ha
->isp_ops
->enable_intrs(ha
);
4341 /* On sparc systems, obtain port and node WWN from firmware
4344 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4345 struct nvram_24xx
*nv
)
4348 struct qla_hw_data
*ha
= vha
->hw
;
4349 struct pci_dev
*pdev
= ha
->pdev
;
4350 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4354 val
= of_get_property(dp
, "port-wwn", &len
);
4355 if (val
&& len
>= WWN_SIZE
)
4356 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4358 val
= of_get_property(dp
, "node-wwn", &len
);
4359 if (val
&& len
>= WWN_SIZE
)
4360 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4365 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4368 struct init_cb_24xx
*icb
;
4369 struct nvram_24xx
*nv
;
4371 uint8_t *dptr1
, *dptr2
;
4374 struct qla_hw_data
*ha
= vha
->hw
;
4377 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4380 /* Determine NVRAM starting address. */
4381 if (ha
->flags
.port0
) {
4382 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4383 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4385 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4386 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4388 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4389 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4391 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4393 /* Get VPD data into cache */
4394 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4395 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4396 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4398 /* Get NVRAM data into cache and calculate checksum. */
4399 dptr
= (uint32_t *)nv
;
4400 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4402 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4403 chksum
+= le32_to_cpu(*dptr
++);
4405 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
4406 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
4408 /* Bad NVRAM data, set defaults parameters. */
4409 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4410 || nv
->id
[3] != ' ' ||
4411 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4412 /* Reset NVRAM data. */
4413 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4414 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4415 le16_to_cpu(nv
->nvram_version
));
4416 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4417 "invalid -- WWPN) defaults.\n");
4420 * Set default initialization control block.
4422 memset(nv
, 0, ha
->nvram_size
);
4423 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4424 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4425 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4426 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4427 nv
->exchange_count
= __constant_cpu_to_le16(0);
4428 nv
->hard_address
= __constant_cpu_to_le16(124);
4429 nv
->port_name
[0] = 0x21;
4430 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4431 nv
->port_name
[2] = 0x00;
4432 nv
->port_name
[3] = 0xe0;
4433 nv
->port_name
[4] = 0x8b;
4434 nv
->port_name
[5] = 0x1c;
4435 nv
->port_name
[6] = 0x55;
4436 nv
->port_name
[7] = 0x86;
4437 nv
->node_name
[0] = 0x20;
4438 nv
->node_name
[1] = 0x00;
4439 nv
->node_name
[2] = 0x00;
4440 nv
->node_name
[3] = 0xe0;
4441 nv
->node_name
[4] = 0x8b;
4442 nv
->node_name
[5] = 0x1c;
4443 nv
->node_name
[6] = 0x55;
4444 nv
->node_name
[7] = 0x86;
4445 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4446 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4447 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4448 nv
->login_timeout
= __constant_cpu_to_le16(0);
4449 nv
->firmware_options_1
=
4450 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4451 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4452 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4453 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4454 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4455 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4456 nv
->reset_delay
= 5;
4457 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4458 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4459 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4464 /* Reset Initialization control block */
4465 memset(icb
, 0, ha
->init_cb_size
);
4467 /* Copy 1st segment. */
4468 dptr1
= (uint8_t *)icb
;
4469 dptr2
= (uint8_t *)&nv
->version
;
4470 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4472 *dptr1
++ = *dptr2
++;
4474 icb
->login_retry_count
= nv
->login_retry_count
;
4475 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4477 /* Copy 2nd segment. */
4478 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4479 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4480 cnt
= (uint8_t *)&icb
->reserved_3
-
4481 (uint8_t *)&icb
->interrupt_delay_timer
;
4483 *dptr1
++ = *dptr2
++;
4486 * Setup driver NVRAM options.
4488 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4491 /* Use alternate WWN? */
4492 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4493 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4494 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4497 /* Prepare nodename */
4498 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4500 * Firmware will apply the following mask if the nodename was
4503 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4504 icb
->node_name
[0] &= 0xF0;
4507 /* Set host adapter parameters. */
4508 ha
->flags
.disable_risc_code_load
= 0;
4509 ha
->flags
.enable_lip_reset
= 0;
4510 ha
->flags
.enable_lip_full_login
=
4511 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4512 ha
->flags
.enable_target_reset
=
4513 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4514 ha
->flags
.enable_led_scheme
= 0;
4515 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4517 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4518 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4520 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4521 sizeof(ha
->fw_seriallink_options24
));
4523 /* save HBA serial number */
4524 ha
->serial0
= icb
->port_name
[5];
4525 ha
->serial1
= icb
->port_name
[6];
4526 ha
->serial2
= icb
->port_name
[7];
4527 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4528 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4530 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4532 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4534 /* Set minimum login_timeout to 4 seconds. */
4535 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4536 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4537 if (le16_to_cpu(nv
->login_timeout
) < 4)
4538 nv
->login_timeout
= __constant_cpu_to_le16(4);
4539 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4540 icb
->login_timeout
= nv
->login_timeout
;
4542 /* Set minimum RATOV to 100 tenths of a second. */
4545 ha
->loop_reset_delay
= nv
->reset_delay
;
4547 /* Link Down Timeout = 0:
4549 * When Port Down timer expires we will start returning
4550 * I/O's to OS with "DID_NO_CONNECT".
4552 * Link Down Timeout != 0:
4554 * The driver waits for the link to come up after link down
4555 * before returning I/Os to OS with "DID_NO_CONNECT".
4557 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4558 ha
->loop_down_abort_time
=
4559 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4561 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4562 ha
->loop_down_abort_time
=
4563 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4566 /* Need enough time to try and get the port back. */
4567 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4568 if (qlport_down_retry
)
4569 ha
->port_down_retry_count
= qlport_down_retry
;
4571 /* Set login_retry_count */
4572 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4573 if (ha
->port_down_retry_count
==
4574 le16_to_cpu(nv
->port_down_retry_count
) &&
4575 ha
->port_down_retry_count
> 3)
4576 ha
->login_retry_count
= ha
->port_down_retry_count
;
4577 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4578 ha
->login_retry_count
= ha
->port_down_retry_count
;
4579 if (ql2xloginretrycount
)
4580 ha
->login_retry_count
= ql2xloginretrycount
;
4583 if (!vha
->flags
.init_done
) {
4584 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4585 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4586 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4587 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4589 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4590 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4591 vha
->flags
.process_response_queue
= 0;
4592 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4593 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4595 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4596 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4597 ha
->zio_timer
* 100));
4598 qla_printk(KERN_INFO
, ha
,
4599 "ZIO mode %d enabled; timer delay (%d us).\n",
4600 ha
->zio_mode
, ha
->zio_timer
* 100);
4602 icb
->firmware_options_2
|= cpu_to_le32(
4603 (uint32_t)ha
->zio_mode
);
4604 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4605 vha
->flags
.process_response_queue
= 1;
4609 DEBUG2_3(printk(KERN_WARNING
4610 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4616 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4619 int rval
= QLA_SUCCESS
;
4620 int segments
, fragment
;
4621 uint32_t *dcode
, dlen
;
4625 struct qla_hw_data
*ha
= vha
->hw
;
4626 struct req_que
*req
= ha
->req_q_map
[0];
4628 qla_printk(KERN_INFO
, ha
,
4629 "FW: Loading from flash (%x)...\n", faddr
);
4633 segments
= FA_RISC_CODE_SEGMENTS
;
4634 dcode
= (uint32_t *)req
->ring
;
4637 /* Validate firmware image by checking version. */
4638 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4639 for (i
= 0; i
< 4; i
++)
4640 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4641 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4642 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4643 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4645 qla_printk(KERN_WARNING
, ha
,
4646 "Unable to verify integrity of flash firmware image!\n");
4647 qla_printk(KERN_WARNING
, ha
,
4648 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4649 dcode
[1], dcode
[2], dcode
[3]);
4651 return QLA_FUNCTION_FAILED
;
4654 while (segments
&& rval
== QLA_SUCCESS
) {
4655 /* Read segment's load information. */
4656 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4658 risc_addr
= be32_to_cpu(dcode
[2]);
4659 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4660 risc_size
= be32_to_cpu(dcode
[3]);
4663 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4664 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4665 if (dlen
> risc_size
)
4668 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4669 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4670 vha
->host_no
, risc_addr
, dlen
, faddr
));
4672 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4673 for (i
= 0; i
< dlen
; i
++)
4674 dcode
[i
] = swab32(dcode
[i
]);
4676 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4679 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4680 "segment %d of firmware\n", vha
->host_no
,
4682 qla_printk(KERN_WARNING
, ha
,
4683 "[ERROR] Failed to load segment %d of "
4684 "firmware\n", fragment
);
4701 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4704 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4708 uint16_t *wcode
, *fwcode
;
4709 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4710 struct fw_blob
*blob
;
4711 struct qla_hw_data
*ha
= vha
->hw
;
4712 struct req_que
*req
= ha
->req_q_map
[0];
4714 /* Load firmware blob. */
4715 blob
= qla2x00_request_firmware(vha
);
4717 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4718 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4719 "from: " QLA_FW_URL
".\n");
4720 return QLA_FUNCTION_FAILED
;
4725 wcode
= (uint16_t *)req
->ring
;
4727 fwcode
= (uint16_t *)blob
->fw
->data
;
4730 /* Validate firmware image by checking version. */
4731 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4732 qla_printk(KERN_WARNING
, ha
,
4733 "Unable to verify integrity of firmware image (%Zd)!\n",
4735 goto fail_fw_integrity
;
4737 for (i
= 0; i
< 4; i
++)
4738 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4739 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4740 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4741 wcode
[2] == 0 && wcode
[3] == 0)) {
4742 qla_printk(KERN_WARNING
, ha
,
4743 "Unable to verify integrity of firmware image!\n");
4744 qla_printk(KERN_WARNING
, ha
,
4745 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
4746 wcode
[1], wcode
[2], wcode
[3]);
4747 goto fail_fw_integrity
;
4751 while (*seg
&& rval
== QLA_SUCCESS
) {
4753 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4754 risc_size
= be16_to_cpu(fwcode
[3]);
4756 /* Validate firmware image size. */
4757 fwclen
+= risc_size
* sizeof(uint16_t);
4758 if (blob
->fw
->size
< fwclen
) {
4759 qla_printk(KERN_WARNING
, ha
,
4760 "Unable to verify integrity of firmware image "
4761 "(%Zd)!\n", blob
->fw
->size
);
4762 goto fail_fw_integrity
;
4766 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4767 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4768 if (wlen
> risc_size
)
4771 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4772 "addr %x, number of words 0x%x.\n", vha
->host_no
,
4775 for (i
= 0; i
< wlen
; i
++)
4776 wcode
[i
] = swab16(fwcode
[i
]);
4778 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4781 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4782 "segment %d of firmware\n", vha
->host_no
,
4784 qla_printk(KERN_WARNING
, ha
,
4785 "[ERROR] Failed to load segment %d of "
4786 "firmware\n", fragment
);
4802 return QLA_FUNCTION_FAILED
;
4806 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4809 int segments
, fragment
;
4810 uint32_t *dcode
, dlen
;
4814 struct fw_blob
*blob
;
4815 uint32_t *fwcode
, fwclen
;
4816 struct qla_hw_data
*ha
= vha
->hw
;
4817 struct req_que
*req
= ha
->req_q_map
[0];
4819 /* Load firmware blob. */
4820 blob
= qla2x00_request_firmware(vha
);
4822 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4823 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4824 "from: " QLA_FW_URL
".\n");
4826 return QLA_FUNCTION_FAILED
;
4829 qla_printk(KERN_INFO
, ha
,
4830 "FW: Loading via request-firmware...\n");
4834 segments
= FA_RISC_CODE_SEGMENTS
;
4835 dcode
= (uint32_t *)req
->ring
;
4837 fwcode
= (uint32_t *)blob
->fw
->data
;
4840 /* Validate firmware image by checking version. */
4841 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4842 qla_printk(KERN_WARNING
, ha
,
4843 "Unable to verify integrity of firmware image (%Zd)!\n",
4845 goto fail_fw_integrity
;
4847 for (i
= 0; i
< 4; i
++)
4848 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4849 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4850 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4851 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4853 qla_printk(KERN_WARNING
, ha
,
4854 "Unable to verify integrity of firmware image!\n");
4855 qla_printk(KERN_WARNING
, ha
,
4856 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4857 dcode
[1], dcode
[2], dcode
[3]);
4858 goto fail_fw_integrity
;
4861 while (segments
&& rval
== QLA_SUCCESS
) {
4862 risc_addr
= be32_to_cpu(fwcode
[2]);
4863 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4864 risc_size
= be32_to_cpu(fwcode
[3]);
4866 /* Validate firmware image size. */
4867 fwclen
+= risc_size
* sizeof(uint32_t);
4868 if (blob
->fw
->size
< fwclen
) {
4869 qla_printk(KERN_WARNING
, ha
,
4870 "Unable to verify integrity of firmware image "
4871 "(%Zd)!\n", blob
->fw
->size
);
4873 goto fail_fw_integrity
;
4877 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4878 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4879 if (dlen
> risc_size
)
4882 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4883 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4886 for (i
= 0; i
< dlen
; i
++)
4887 dcode
[i
] = swab32(fwcode
[i
]);
4889 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4892 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4893 "segment %d of firmware\n", vha
->host_no
,
4895 qla_printk(KERN_WARNING
, ha
,
4896 "[ERROR] Failed to load segment %d of "
4897 "firmware\n", fragment
);
4913 return QLA_FUNCTION_FAILED
;
4917 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4921 if (ql2xfwloadbin
== 1)
4922 return qla81xx_load_risc(vha
, srisc_addr
);
4926 * 1) Firmware via request-firmware interface (.bin file).
4927 * 2) Firmware residing in flash.
4929 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4930 if (rval
== QLA_SUCCESS
)
4933 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4934 vha
->hw
->flt_region_fw
);
4938 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4941 struct qla_hw_data
*ha
= vha
->hw
;
4943 if (ql2xfwloadbin
== 2)
4948 * 1) Firmware residing in flash.
4949 * 2) Firmware via request-firmware interface (.bin file).
4950 * 3) Golden-Firmware residing in flash -- limited operation.
4952 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4953 if (rval
== QLA_SUCCESS
)
4957 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4958 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4961 qla_printk(KERN_ERR
, ha
,
4962 "FW: Attempting to fallback to golden firmware...\n");
4963 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4964 if (rval
!= QLA_SUCCESS
)
4967 qla_printk(KERN_ERR
, ha
,
4968 "FW: Please update operational firmware...\n");
4969 ha
->flags
.running_gold_fw
= 1;
4975 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4978 struct qla_hw_data
*ha
= vha
->hw
;
4980 if (ha
->flags
.pci_channel_io_perm_failure
)
4982 if (!IS_FWI2_CAPABLE(ha
))
4984 if (!ha
->fw_major_version
)
4987 ret
= qla2x00_stop_firmware(vha
);
4988 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4989 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4990 ha
->isp_ops
->reset_chip(vha
);
4991 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4993 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4995 qla_printk(KERN_INFO
, ha
,
4996 "Attempting retry of stop-firmware command...\n");
4997 ret
= qla2x00_stop_firmware(vha
);
5002 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
5004 int rval
= QLA_SUCCESS
;
5005 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5006 struct qla_hw_data
*ha
= vha
->hw
;
5007 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5008 struct req_que
*req
;
5009 struct rsp_que
*rsp
;
5014 rval
= qla2x00_fw_ready(base_vha
);
5015 if (ha
->flags
.cpu_affinity_enabled
)
5016 req
= ha
->req_q_map
[0];
5021 if (rval
== QLA_SUCCESS
) {
5022 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5023 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5026 vha
->flags
.management_server_logged_in
= 0;
5028 /* Login to SNS first */
5029 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
5030 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
5031 DEBUG15(qla_printk(KERN_INFO
, ha
,
5032 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5033 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
5034 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
5035 return (QLA_FUNCTION_FAILED
);
5038 atomic_set(&vha
->loop_down_timer
, 0);
5039 atomic_set(&vha
->loop_state
, LOOP_UP
);
5040 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5041 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5042 rval
= qla2x00_loop_resync(base_vha
);
5047 /* 84XX Support **************************************************************/
5049 static LIST_HEAD(qla_cs84xx_list
);
5050 static DEFINE_MUTEX(qla_cs84xx_mutex
);
5052 static struct qla_chip_state_84xx
*
5053 qla84xx_get_chip(struct scsi_qla_host
*vha
)
5055 struct qla_chip_state_84xx
*cs84xx
;
5056 struct qla_hw_data
*ha
= vha
->hw
;
5058 mutex_lock(&qla_cs84xx_mutex
);
5060 /* Find any shared 84xx chip. */
5061 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
5062 if (cs84xx
->bus
== ha
->pdev
->bus
) {
5063 kref_get(&cs84xx
->kref
);
5068 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
5072 kref_init(&cs84xx
->kref
);
5073 spin_lock_init(&cs84xx
->access_lock
);
5074 mutex_init(&cs84xx
->fw_update_mutex
);
5075 cs84xx
->bus
= ha
->pdev
->bus
;
5077 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
5079 mutex_unlock(&qla_cs84xx_mutex
);
5084 __qla84xx_chip_release(struct kref
*kref
)
5086 struct qla_chip_state_84xx
*cs84xx
=
5087 container_of(kref
, struct qla_chip_state_84xx
, kref
);
5089 mutex_lock(&qla_cs84xx_mutex
);
5090 list_del(&cs84xx
->list
);
5091 mutex_unlock(&qla_cs84xx_mutex
);
5096 qla84xx_put_chip(struct scsi_qla_host
*vha
)
5098 struct qla_hw_data
*ha
= vha
->hw
;
5100 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
5104 qla84xx_init_chip(scsi_qla_host_t
*vha
)
5108 struct qla_hw_data
*ha
= vha
->hw
;
5110 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
5112 rval
= qla84xx_verify_chip(vha
, status
);
5114 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
5116 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
5120 /* 81XX Support **************************************************************/
5123 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
5126 struct init_cb_81xx
*icb
;
5127 struct nvram_81xx
*nv
;
5129 uint8_t *dptr1
, *dptr2
;
5132 struct qla_hw_data
*ha
= vha
->hw
;
5135 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
5138 /* Determine NVRAM starting address. */
5139 ha
->nvram_size
= sizeof(struct nvram_81xx
);
5140 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
5142 /* Get VPD data into cache */
5143 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
5144 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
5147 /* Get NVRAM data into cache and calculate checksum. */
5148 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
5150 dptr
= (uint32_t *)nv
;
5151 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
5152 chksum
+= le32_to_cpu(*dptr
++);
5154 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
5155 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
5157 /* Bad NVRAM data, set defaults parameters. */
5158 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
5159 || nv
->id
[3] != ' ' ||
5160 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
5161 /* Reset NVRAM data. */
5162 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
5163 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
5164 le16_to_cpu(nv
->nvram_version
));
5165 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
5166 "invalid -- WWPN) defaults.\n");
5169 * Set default initialization control block.
5171 memset(nv
, 0, ha
->nvram_size
);
5172 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5173 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5174 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5175 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5176 nv
->exchange_count
= __constant_cpu_to_le16(0);
5177 nv
->port_name
[0] = 0x21;
5178 nv
->port_name
[1] = 0x00 + ha
->port_no
;
5179 nv
->port_name
[2] = 0x00;
5180 nv
->port_name
[3] = 0xe0;
5181 nv
->port_name
[4] = 0x8b;
5182 nv
->port_name
[5] = 0x1c;
5183 nv
->port_name
[6] = 0x55;
5184 nv
->port_name
[7] = 0x86;
5185 nv
->node_name
[0] = 0x20;
5186 nv
->node_name
[1] = 0x00;
5187 nv
->node_name
[2] = 0x00;
5188 nv
->node_name
[3] = 0xe0;
5189 nv
->node_name
[4] = 0x8b;
5190 nv
->node_name
[5] = 0x1c;
5191 nv
->node_name
[6] = 0x55;
5192 nv
->node_name
[7] = 0x86;
5193 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5194 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5195 nv
->login_timeout
= __constant_cpu_to_le16(0);
5196 nv
->firmware_options_1
=
5197 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5198 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5199 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5200 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5201 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5202 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5203 nv
->reset_delay
= 5;
5204 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5205 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5206 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
5207 nv
->enode_mac
[0] = 0x00;
5208 nv
->enode_mac
[1] = 0x02;
5209 nv
->enode_mac
[2] = 0x03;
5210 nv
->enode_mac
[3] = 0x04;
5211 nv
->enode_mac
[4] = 0x05;
5212 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5217 /* Reset Initialization control block */
5218 memset(icb
, 0, ha
->init_cb_size
);
5220 /* Copy 1st segment. */
5221 dptr1
= (uint8_t *)icb
;
5222 dptr2
= (uint8_t *)&nv
->version
;
5223 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5225 *dptr1
++ = *dptr2
++;
5227 icb
->login_retry_count
= nv
->login_retry_count
;
5229 /* Copy 2nd segment. */
5230 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5231 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5232 cnt
= (uint8_t *)&icb
->reserved_5
-
5233 (uint8_t *)&icb
->interrupt_delay_timer
;
5235 *dptr1
++ = *dptr2
++;
5237 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5238 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5239 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5240 icb
->enode_mac
[0] = 0x01;
5241 icb
->enode_mac
[1] = 0x02;
5242 icb
->enode_mac
[2] = 0x03;
5243 icb
->enode_mac
[3] = 0x04;
5244 icb
->enode_mac
[4] = 0x05;
5245 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5248 /* Use extended-initialization control block. */
5249 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5252 * Setup driver NVRAM options.
5254 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5257 /* Use alternate WWN? */
5258 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5259 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5260 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5263 /* Prepare nodename */
5264 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5266 * Firmware will apply the following mask if the nodename was
5269 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5270 icb
->node_name
[0] &= 0xF0;
5273 /* Set host adapter parameters. */
5274 ha
->flags
.disable_risc_code_load
= 0;
5275 ha
->flags
.enable_lip_reset
= 0;
5276 ha
->flags
.enable_lip_full_login
=
5277 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5278 ha
->flags
.enable_target_reset
=
5279 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5280 ha
->flags
.enable_led_scheme
= 0;
5281 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5283 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5284 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5286 /* save HBA serial number */
5287 ha
->serial0
= icb
->port_name
[5];
5288 ha
->serial1
= icb
->port_name
[6];
5289 ha
->serial2
= icb
->port_name
[7];
5290 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5291 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5293 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5295 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5297 /* Set minimum login_timeout to 4 seconds. */
5298 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5299 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5300 if (le16_to_cpu(nv
->login_timeout
) < 4)
5301 nv
->login_timeout
= __constant_cpu_to_le16(4);
5302 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5303 icb
->login_timeout
= nv
->login_timeout
;
5305 /* Set minimum RATOV to 100 tenths of a second. */
5308 ha
->loop_reset_delay
= nv
->reset_delay
;
5310 /* Link Down Timeout = 0:
5312 * When Port Down timer expires we will start returning
5313 * I/O's to OS with "DID_NO_CONNECT".
5315 * Link Down Timeout != 0:
5317 * The driver waits for the link to come up after link down
5318 * before returning I/Os to OS with "DID_NO_CONNECT".
5320 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5321 ha
->loop_down_abort_time
=
5322 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5324 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5325 ha
->loop_down_abort_time
=
5326 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5329 /* Need enough time to try and get the port back. */
5330 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5331 if (qlport_down_retry
)
5332 ha
->port_down_retry_count
= qlport_down_retry
;
5334 /* Set login_retry_count */
5335 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5336 if (ha
->port_down_retry_count
==
5337 le16_to_cpu(nv
->port_down_retry_count
) &&
5338 ha
->port_down_retry_count
> 3)
5339 ha
->login_retry_count
= ha
->port_down_retry_count
;
5340 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5341 ha
->login_retry_count
= ha
->port_down_retry_count
;
5342 if (ql2xloginretrycount
)
5343 ha
->login_retry_count
= ql2xloginretrycount
;
5346 if (!vha
->flags
.init_done
) {
5347 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5348 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5349 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5350 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5352 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5353 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5354 vha
->flags
.process_response_queue
= 0;
5355 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5356 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5358 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5359 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
5360 ha
->zio_timer
* 100));
5361 qla_printk(KERN_INFO
, ha
,
5362 "ZIO mode %d enabled; timer delay (%d us).\n",
5363 ha
->zio_mode
, ha
->zio_timer
* 100);
5365 icb
->firmware_options_2
|= cpu_to_le32(
5366 (uint32_t)ha
->zio_mode
);
5367 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5368 vha
->flags
.process_response_queue
= 1;
5372 DEBUG2_3(printk(KERN_WARNING
5373 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
5379 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5383 struct qla_hw_data
*ha
= vha
->hw
;
5384 struct req_que
*req
= ha
->req_q_map
[0];
5385 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5386 struct scsi_qla_host
*vp
;
5387 unsigned long flags
;
5389 status
= qla2x00_init_rings(vha
);
5391 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5392 ha
->flags
.chip_reset_done
= 1;
5394 status
= qla2x00_fw_ready(vha
);
5396 qla_printk(KERN_INFO
, ha
,
5397 "%s(): Start configure loop, "
5398 "status = %d\n", __func__
, status
);
5400 /* Issue a marker after FW becomes ready. */
5401 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5403 vha
->flags
.online
= 1;
5404 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5407 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5408 qla2x00_configure_loop(vha
);
5410 } while (!atomic_read(&vha
->loop_down_timer
) &&
5411 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5413 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5416 /* if no cable then assume it's good */
5417 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5420 qla_printk(KERN_INFO
, ha
,
5421 "%s(): Configure loop done, status = 0x%x\n",
5426 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5428 if (!atomic_read(&vha
->loop_down_timer
)) {
5430 * Issue marker command only when we are going
5431 * to start the I/O .
5433 vha
->marker_needed
= 1;
5436 vha
->flags
.online
= 1;
5438 ha
->isp_ops
->enable_intrs(ha
);
5440 ha
->isp_abort_cnt
= 0;
5441 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5443 /* Update the firmware version */
5444 qla2x00_get_fw_version(vha
, &ha
->fw_major_version
,
5445 &ha
->fw_minor_version
, &ha
->fw_subminor_version
,
5446 &ha
->fw_attributes
, &ha
->fw_memory_size
,
5447 ha
->mpi_version
, &ha
->mpi_capabilities
,
5451 ha
->flags
.fce_enabled
= 1;
5453 fce_calc_size(ha
->fce_bufs
));
5454 rval
= qla2x00_enable_fce_trace(vha
,
5455 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5458 qla_printk(KERN_WARNING
, ha
,
5459 "Unable to reinitialize FCE "
5461 ha
->flags
.fce_enabled
= 0;
5466 memset(ha
->eft
, 0, EFT_SIZE
);
5467 rval
= qla2x00_enable_eft_trace(vha
,
5468 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5470 qla_printk(KERN_WARNING
, ha
,
5471 "Unable to reinitialize EFT "
5478 DEBUG(printk(KERN_INFO
5479 "qla82xx_restart_isp(%ld): succeeded.\n",
5482 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5483 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5485 atomic_inc(&vp
->vref_count
);
5486 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5488 qla2x00_vp_abort_isp(vp
);
5490 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5491 atomic_dec(&vp
->vref_count
);
5494 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5497 qla_printk(KERN_INFO
, ha
,
5498 "qla82xx_restart_isp: **** FAILED ****\n");
5505 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5507 struct qla_hw_data
*ha
= vha
->hw
;
5512 /* Enable ETS Burst. */
5513 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5514 ha
->fw_options
[2] |= BIT_9
;
5515 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5519 * qla24xx_get_fcp_prio
5520 * Gets the fcp cmd priority value for the logged in port.
5521 * Looks for a match of the port descriptors within
5522 * each of the fcp prio config entries. If a match is found,
5523 * the tag (priority) value is returned.
5526 * vha = scsi host structure pointer.
5527 * fcport = port structure pointer.
5530 * non-zero (if found)
5537 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5540 uint8_t pid_match
, wwn_match
;
5542 uint32_t pid1
, pid2
;
5543 uint64_t wwn1
, wwn2
;
5544 struct qla_fcp_prio_entry
*pri_entry
;
5545 struct qla_hw_data
*ha
= vha
->hw
;
5547 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5551 entries
= ha
->fcp_prio_cfg
->num_entries
;
5552 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5554 for (i
= 0; i
< entries
; i
++) {
5555 pid_match
= wwn_match
= 0;
5557 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5562 /* check source pid for a match */
5563 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5564 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5565 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5566 if (pid1
== INVALID_PORT_ID
)
5568 else if (pid1
== pid2
)
5572 /* check destination pid for a match */
5573 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5574 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5575 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5576 if (pid1
== INVALID_PORT_ID
)
5578 else if (pid1
== pid2
)
5582 /* check source WWN for a match */
5583 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5584 wwn1
= wwn_to_u64(vha
->port_name
);
5585 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5586 if (wwn2
== (uint64_t)-1)
5588 else if (wwn1
== wwn2
)
5592 /* check destination WWN for a match */
5593 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5594 wwn1
= wwn_to_u64(fcport
->port_name
);
5595 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5596 if (wwn2
== (uint64_t)-1)
5598 else if (wwn1
== wwn2
)
5602 if (pid_match
== 2 || wwn_match
== 2) {
5603 /* Found a matching entry */
5604 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5605 priority
= pri_entry
->tag
;
5616 * qla24xx_update_fcport_fcp_prio
5617 * Activates fcp priority for the logged in fc port
5620 * vha = scsi host structure pointer.
5621 * fcp = port structure pointer.
5624 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5630 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5636 if (fcport
->port_type
!= FCT_TARGET
||
5637 fcport
->loop_id
== FC_NO_LOOP_ID
)
5638 return QLA_FUNCTION_FAILED
;
5640 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
5642 return QLA_FUNCTION_FAILED
;
5644 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
5645 if (ret
== QLA_SUCCESS
)
5646 fcport
->fcp_prio
= priority
;
5648 DEBUG2(printk(KERN_WARNING
5649 "scsi(%ld): Unable to activate fcp priority, "
5650 " ret=0x%x\n", vha
->host_no
, ret
));
5656 * qla24xx_update_all_fcp_prio
5657 * Activates fcp priority for all the logged in ports
5660 * ha = adapter block pointer.
5663 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5669 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5674 ret
= QLA_FUNCTION_FAILED
;
5675 /* We need to set priority for all logged in ports */
5676 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5677 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);