2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
21 * QLogic ISP2x00 Hardware Support Function Prototypes.
23 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
24 static int qla2x00_setup_chip(scsi_qla_host_t
*);
25 static int qla2x00_init_rings(scsi_qla_host_t
*);
26 static int qla2x00_fw_ready(scsi_qla_host_t
*);
27 static int qla2x00_configure_hba(scsi_qla_host_t
*);
28 static int qla2x00_configure_loop(scsi_qla_host_t
*);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
30 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
32 static int qla2x00_device_resync(scsi_qla_host_t
*);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
36 static int qla2x00_restart_isp(scsi_qla_host_t
*);
38 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*, fc_port_t
*);
40 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
41 static int qla84xx_init_chip(scsi_qla_host_t
*);
42 static int qla25xx_init_queues(struct qla_hw_data
*);
44 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_ctx_sp_timeout(unsigned long __data
)
49 srb_t
*sp
= (srb_t
*)__data
;
51 struct srb_iocb
*iocb
;
52 fc_port_t
*fcport
= sp
->fcport
;
53 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
57 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
58 req
= ha
->req_q_map
[0];
59 req
->outstanding_cmds
[sp
->handle
] = NULL
;
61 iocb
= ctx
->u
.iocb_cmd
;
64 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
68 qla2x00_ctx_sp_free(srb_t
*sp
)
70 struct srb_ctx
*ctx
= sp
->ctx
;
71 struct srb_iocb
*iocb
= ctx
->u
.iocb_cmd
;
72 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
74 del_timer(&iocb
->timer
);
77 mempool_free(sp
, sp
->fcport
->vha
->hw
->srb_mempool
);
79 QLA_VHA_MARK_NOT_BUSY(vha
);
83 qla2x00_get_ctx_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
, size_t size
,
87 struct qla_hw_data
*ha
= vha
->hw
;
89 struct srb_iocb
*iocb
;
92 QLA_VHA_MARK_BUSY(vha
, bail
);
96 sp
= mempool_alloc(ha
->srb_mempool
, GFP_KERNEL
);
99 ctx
= kzalloc(size
, GFP_KERNEL
);
101 mempool_free(sp
, ha
->srb_mempool
);
105 iocb
= kzalloc(sizeof(struct srb_iocb
), GFP_KERNEL
);
107 mempool_free(sp
, ha
->srb_mempool
);
113 memset(sp
, 0, sizeof(*sp
));
116 ctx
->u
.iocb_cmd
= iocb
;
117 iocb
->free
= qla2x00_ctx_sp_free
;
119 init_timer(&iocb
->timer
);
122 iocb
->timer
.expires
= jiffies
+ tmo
* HZ
;
123 iocb
->timer
.data
= (unsigned long)sp
;
124 iocb
->timer
.function
= qla2x00_ctx_sp_timeout
;
125 add_timer(&iocb
->timer
);
128 QLA_VHA_MARK_NOT_BUSY(vha
);
132 /* Asynchronous Login/Logout Routines -------------------------------------- */
134 static inline unsigned long
135 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
138 struct qla_hw_data
*ha
= vha
->hw
;
140 /* Firmware should use switch negotiated r_a_tov for timeout. */
141 tmo
= ha
->r_a_tov
/ 10 * 2;
142 if (!IS_FWI2_CAPABLE(ha
)) {
144 * Except for earlier ISPs where the timeout is seeded from the
145 * initialization control block.
147 tmo
= ha
->login_timeout
;
153 qla2x00_async_iocb_timeout(srb_t
*sp
)
155 fc_port_t
*fcport
= sp
->fcport
;
156 struct srb_ctx
*ctx
= sp
->ctx
;
158 DEBUG2(printk(KERN_WARNING
159 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
160 fcport
->vha
->host_no
, sp
->handle
,
161 ctx
->name
, fcport
->d_id
.b
.domain
,
162 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
164 fcport
->flags
&= ~FCF_ASYNC_SENT
;
165 if (ctx
->type
== SRB_LOGIN_CMD
) {
166 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
167 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
168 /* Retry as needed. */
169 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
170 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
171 QLA_LOGIO_LOGIN_RETRIED
: 0;
172 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
,
178 qla2x00_async_login_ctx_done(srb_t
*sp
)
180 struct srb_ctx
*ctx
= sp
->ctx
;
181 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
183 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
189 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
194 struct srb_iocb
*lio
;
197 rval
= QLA_FUNCTION_FAILED
;
198 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
199 qla2x00_get_async_timeout(vha
) + 2);
204 ctx
->type
= SRB_LOGIN_CMD
;
206 lio
= ctx
->u
.iocb_cmd
;
207 lio
->timeout
= qla2x00_async_iocb_timeout
;
208 lio
->done
= qla2x00_async_login_ctx_done
;
209 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
210 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
211 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
212 rval
= qla2x00_start_sp(sp
);
213 if (rval
!= QLA_SUCCESS
)
216 DEBUG2(printk(KERN_DEBUG
217 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
218 "retries=%d.\n", fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
219 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
220 fcport
->login_retry
));
230 qla2x00_async_logout_ctx_done(srb_t
*sp
)
232 struct srb_ctx
*ctx
= sp
->ctx
;
233 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
235 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
241 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
245 struct srb_iocb
*lio
;
248 rval
= QLA_FUNCTION_FAILED
;
249 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
250 qla2x00_get_async_timeout(vha
) + 2);
255 ctx
->type
= SRB_LOGOUT_CMD
;
256 ctx
->name
= "logout";
257 lio
= ctx
->u
.iocb_cmd
;
258 lio
->timeout
= qla2x00_async_iocb_timeout
;
259 lio
->done
= qla2x00_async_logout_ctx_done
;
260 rval
= qla2x00_start_sp(sp
);
261 if (rval
!= QLA_SUCCESS
)
264 DEBUG2(printk(KERN_DEBUG
265 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
266 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
267 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
277 qla2x00_async_adisc_ctx_done(srb_t
*sp
)
279 struct srb_ctx
*ctx
= sp
->ctx
;
280 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
282 qla2x00_post_async_adisc_done_work(sp
->fcport
->vha
, sp
->fcport
,
288 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
293 struct srb_iocb
*lio
;
296 rval
= QLA_FUNCTION_FAILED
;
297 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
298 qla2x00_get_async_timeout(vha
) + 2);
303 ctx
->type
= SRB_ADISC_CMD
;
305 lio
= ctx
->u
.iocb_cmd
;
306 lio
->timeout
= qla2x00_async_iocb_timeout
;
307 lio
->done
= qla2x00_async_adisc_ctx_done
;
308 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
309 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
310 rval
= qla2x00_start_sp(sp
);
311 if (rval
!= QLA_SUCCESS
)
314 DEBUG2(printk(KERN_DEBUG
315 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
316 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
317 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
328 qla2x00_async_tm_cmd_ctx_done(srb_t
*sp
)
330 struct srb_ctx
*ctx
= sp
->ctx
;
331 struct srb_iocb
*iocb
= (struct srb_iocb
*)ctx
->u
.iocb_cmd
;
333 qla2x00_async_tm_cmd_done(sp
->fcport
->vha
, sp
->fcport
, iocb
);
338 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
341 struct scsi_qla_host
*vha
= fcport
->vha
;
344 struct srb_iocb
*tcf
;
347 rval
= QLA_FUNCTION_FAILED
;
348 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
349 qla2x00_get_async_timeout(vha
) + 2);
354 ctx
->type
= SRB_TM_CMD
;
356 tcf
= ctx
->u
.iocb_cmd
;
357 tcf
->u
.tmf
.flags
= flags
;
358 tcf
->u
.tmf
.lun
= lun
;
359 tcf
->u
.tmf
.data
= tag
;
360 tcf
->timeout
= qla2x00_async_iocb_timeout
;
361 tcf
->done
= qla2x00_async_tm_cmd_ctx_done
;
363 rval
= qla2x00_start_sp(sp
);
364 if (rval
!= QLA_SUCCESS
)
367 DEBUG2(printk(KERN_DEBUG
368 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
369 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
370 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
381 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
387 case MBS_COMMAND_COMPLETE
:
388 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
389 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
392 qla2x00_update_fcport(vha
, fcport
);
394 case MBS_COMMAND_ERROR
:
395 fcport
->flags
&= ~FCF_ASYNC_SENT
;
396 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
397 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
399 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
401 case MBS_PORT_ID_USED
:
402 fcport
->loop_id
= data
[1];
403 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
404 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
406 case MBS_LOOP_ID_USED
:
408 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
409 if (rval
!= QLA_SUCCESS
) {
410 fcport
->flags
&= ~FCF_ASYNC_SENT
;
411 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
414 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
421 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
424 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
429 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
432 if (data
[0] == MBS_COMMAND_COMPLETE
) {
433 qla2x00_update_fcport(vha
, fcport
);
439 fcport
->flags
&= ~FCF_ASYNC_SENT
;
440 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
441 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
443 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
449 qla2x00_async_tm_cmd_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
450 struct srb_iocb
*iocb
)
456 flags
= iocb
->u
.tmf
.flags
;
457 lun
= (uint16_t)iocb
->u
.tmf
.lun
;
459 /* Issue Marker IOCB */
460 rval
= qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
461 vha
->hw
->rsp_q_map
[0], fcport
->loop_id
, lun
,
462 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
464 if ((rval
!= QLA_SUCCESS
) || iocb
->u
.tmf
.data
) {
465 DEBUG2_3_11(printk(KERN_WARNING
466 "%s(%ld): TM IOCB failed (%x).\n",
467 __func__
, vha
->host_no
, rval
));
473 /****************************************************************************/
474 /* QLogic ISP2x00 Hardware Support Functions. */
475 /****************************************************************************/
478 * qla2x00_initialize_adapter
482 * ha = adapter block pointer.
488 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
491 struct qla_hw_data
*ha
= vha
->hw
;
492 struct req_que
*req
= ha
->req_q_map
[0];
494 /* Clear adapter flags. */
495 vha
->flags
.online
= 0;
496 ha
->flags
.chip_reset_done
= 0;
497 vha
->flags
.reset_active
= 0;
498 ha
->flags
.pci_channel_io_perm_failure
= 0;
499 ha
->flags
.eeh_busy
= 0;
500 ha
->flags
.thermal_supported
= 1;
501 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
502 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
503 vha
->device_flags
= DFLG_NO_CABLE
;
505 vha
->flags
.management_server_logged_in
= 0;
506 vha
->marker_needed
= 0;
507 ha
->isp_abort_cnt
= 0;
508 ha
->beacon_blink_led
= 0;
510 set_bit(0, ha
->req_qid_map
);
511 set_bit(0, ha
->rsp_qid_map
);
513 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
514 rval
= ha
->isp_ops
->pci_config(vha
);
516 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
521 ha
->isp_ops
->reset_chip(vha
);
523 rval
= qla2xxx_get_flash_info(vha
);
525 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
530 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
532 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
534 ha
->isp_ops
->nvram_config(vha
);
536 if (ha
->flags
.disable_serdes
) {
537 /* Mask HBA via NVRAM settings? */
538 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
539 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
540 vha
->port_name
[0], vha
->port_name
[1],
541 vha
->port_name
[2], vha
->port_name
[3],
542 vha
->port_name
[4], vha
->port_name
[5],
543 vha
->port_name
[6], vha
->port_name
[7]);
544 return QLA_FUNCTION_FAILED
;
547 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
549 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
550 rval
= ha
->isp_ops
->chip_diag(vha
);
553 rval
= qla2x00_setup_chip(vha
);
558 if (IS_QLA84XX(ha
)) {
559 ha
->cs84xx
= qla84xx_get_chip(vha
);
561 qla_printk(KERN_ERR
, ha
,
562 "Unable to configure ISP84XX.\n");
563 return QLA_FUNCTION_FAILED
;
566 rval
= qla2x00_init_rings(vha
);
567 ha
->flags
.chip_reset_done
= 1;
569 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
570 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
571 rval
= qla84xx_init_chip(vha
);
572 if (rval
!= QLA_SUCCESS
) {
573 qla_printk(KERN_ERR
, ha
,
574 "Unable to initialize ISP84XX.\n");
575 qla84xx_put_chip(vha
);
579 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
580 qla24xx_read_fcp_prio_cfg(vha
);
586 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
589 * Returns 0 on success.
592 qla2100_pci_config(scsi_qla_host_t
*vha
)
596 struct qla_hw_data
*ha
= vha
->hw
;
597 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
599 pci_set_master(ha
->pdev
);
600 pci_try_set_mwi(ha
->pdev
);
602 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
603 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
604 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
606 pci_disable_rom(ha
->pdev
);
608 /* Get PCI bus information. */
609 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
610 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
611 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
617 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
620 * Returns 0 on success.
623 qla2300_pci_config(scsi_qla_host_t
*vha
)
626 unsigned long flags
= 0;
628 struct qla_hw_data
*ha
= vha
->hw
;
629 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
631 pci_set_master(ha
->pdev
);
632 pci_try_set_mwi(ha
->pdev
);
634 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
635 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
637 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
638 w
&= ~PCI_COMMAND_INTX_DISABLE
;
639 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
642 * If this is a 2300 card and not 2312, reset the
643 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
644 * the 2310 also reports itself as a 2300 so we need to get the
645 * fb revision level -- a 6 indicates it really is a 2300 and
648 if (IS_QLA2300(ha
)) {
649 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
652 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
653 for (cnt
= 0; cnt
< 30000; cnt
++) {
654 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
660 /* Select FPM registers. */
661 WRT_REG_WORD(®
->ctrl_status
, 0x20);
662 RD_REG_WORD(®
->ctrl_status
);
664 /* Get the fb rev level */
665 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
667 if (ha
->fb_rev
== FPM_2300
)
668 pci_clear_mwi(ha
->pdev
);
670 /* Deselect FPM registers. */
671 WRT_REG_WORD(®
->ctrl_status
, 0x0);
672 RD_REG_WORD(®
->ctrl_status
);
674 /* Release RISC module. */
675 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
676 for (cnt
= 0; cnt
< 30000; cnt
++) {
677 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
683 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
686 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
688 pci_disable_rom(ha
->pdev
);
690 /* Get PCI bus information. */
691 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
692 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
693 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
699 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
702 * Returns 0 on success.
705 qla24xx_pci_config(scsi_qla_host_t
*vha
)
708 unsigned long flags
= 0;
709 struct qla_hw_data
*ha
= vha
->hw
;
710 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
712 pci_set_master(ha
->pdev
);
713 pci_try_set_mwi(ha
->pdev
);
715 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
716 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
717 w
&= ~PCI_COMMAND_INTX_DISABLE
;
718 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
720 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
722 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
723 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
724 pcix_set_mmrbc(ha
->pdev
, 2048);
726 /* PCIe -- adjust Maximum Read Request Size (2048). */
727 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
728 pcie_set_readrq(ha
->pdev
, 2048);
730 pci_disable_rom(ha
->pdev
);
732 ha
->chip_revision
= ha
->pdev
->revision
;
734 /* Get PCI bus information. */
735 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
736 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
737 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
743 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
746 * Returns 0 on success.
749 qla25xx_pci_config(scsi_qla_host_t
*vha
)
752 struct qla_hw_data
*ha
= vha
->hw
;
754 pci_set_master(ha
->pdev
);
755 pci_try_set_mwi(ha
->pdev
);
757 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
758 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
759 w
&= ~PCI_COMMAND_INTX_DISABLE
;
760 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
762 /* PCIe -- adjust Maximum Read Request Size (2048). */
763 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
764 pcie_set_readrq(ha
->pdev
, 2048);
766 pci_disable_rom(ha
->pdev
);
768 ha
->chip_revision
= ha
->pdev
->revision
;
774 * qla2x00_isp_firmware() - Choose firmware image.
777 * Returns 0 on success.
780 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
783 uint16_t loop_id
, topo
, sw_cap
;
784 uint8_t domain
, area
, al_pa
;
785 struct qla_hw_data
*ha
= vha
->hw
;
787 /* Assume loading risc code */
788 rval
= QLA_FUNCTION_FAILED
;
790 if (ha
->flags
.disable_risc_code_load
) {
791 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
793 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
795 /* Verify checksum of loaded RISC code. */
796 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
797 if (rval
== QLA_SUCCESS
) {
798 /* And, verify we are not in ROM code. */
799 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
800 &area
, &domain
, &topo
, &sw_cap
);
805 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
813 * qla2x00_reset_chip() - Reset ISP chip.
816 * Returns 0 on success.
819 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
821 unsigned long flags
= 0;
822 struct qla_hw_data
*ha
= vha
->hw
;
823 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
827 if (unlikely(pci_channel_offline(ha
->pdev
)))
830 ha
->isp_ops
->disable_intrs(ha
);
832 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
834 /* Turn off master enable */
836 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
837 cmd
&= ~PCI_COMMAND_MASTER
;
838 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
840 if (!IS_QLA2100(ha
)) {
842 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
843 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
844 for (cnt
= 0; cnt
< 30000; cnt
++) {
845 if ((RD_REG_WORD(®
->hccr
) &
846 HCCR_RISC_PAUSE
) != 0)
851 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
855 /* Select FPM registers. */
856 WRT_REG_WORD(®
->ctrl_status
, 0x20);
857 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
859 /* FPM Soft Reset. */
860 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
861 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
863 /* Toggle Fpm Reset. */
864 if (!IS_QLA2200(ha
)) {
865 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
866 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
869 /* Select frame buffer registers. */
870 WRT_REG_WORD(®
->ctrl_status
, 0x10);
871 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
873 /* Reset frame buffer FIFOs. */
874 if (IS_QLA2200(ha
)) {
875 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
876 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
878 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
880 /* Read back fb_cmd until zero or 3 seconds max */
881 for (cnt
= 0; cnt
< 3000; cnt
++) {
882 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
888 /* Select RISC module registers. */
889 WRT_REG_WORD(®
->ctrl_status
, 0);
890 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
892 /* Reset RISC processor. */
893 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
894 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
896 /* Release RISC processor. */
897 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
898 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
901 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
902 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
904 /* Reset ISP chip. */
905 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
907 /* Wait for RISC to recover from reset. */
908 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
910 * It is necessary to for a delay here since the card doesn't
911 * respond to PCI reads during a reset. On some architectures
912 * this will result in an MCA.
915 for (cnt
= 30000; cnt
; cnt
--) {
916 if ((RD_REG_WORD(®
->ctrl_status
) &
917 CSR_ISP_SOFT_RESET
) == 0)
924 /* Reset RISC processor. */
925 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
927 WRT_REG_WORD(®
->semaphore
, 0);
929 /* Release RISC processor. */
930 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
931 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
933 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
934 for (cnt
= 0; cnt
< 30000; cnt
++) {
935 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
943 /* Turn on master enable */
944 cmd
|= PCI_COMMAND_MASTER
;
945 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
947 /* Disable RISC pause on FPM parity error. */
948 if (!IS_QLA2100(ha
)) {
949 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
950 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
953 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
957 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
959 * Returns 0 on success.
962 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
964 uint16_t mb
[4] = {0x1010, 0, 1, 0};
966 return qla81xx_write_mpi_register(vha
, mb
);
970 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
973 * Returns 0 on success.
976 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
978 unsigned long flags
= 0;
979 struct qla_hw_data
*ha
= vha
->hw
;
980 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
983 static int abts_cnt
; /* ISP abort retry counts */
985 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
988 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
989 for (cnt
= 0; cnt
< 30000; cnt
++) {
990 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
996 WRT_REG_DWORD(®
->ctrl_status
,
997 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
998 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1001 /* Wait for firmware to complete NVRAM accesses. */
1002 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1003 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
1005 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1009 /* Wait for soft-reset to complete. */
1010 d2
= RD_REG_DWORD(®
->ctrl_status
);
1011 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
1013 d2
= RD_REG_DWORD(®
->ctrl_status
);
1017 /* If required, do an MPI FW reset now */
1018 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
1019 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
1020 if (++abts_cnt
< 5) {
1021 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1022 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
1025 * We exhausted the ISP abort retries. We have to
1026 * set the board offline.
1029 vha
->flags
.online
= 0;
1034 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
1035 RD_REG_DWORD(®
->hccr
);
1037 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
1038 RD_REG_DWORD(®
->hccr
);
1040 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1041 RD_REG_DWORD(®
->hccr
);
1043 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1044 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1046 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1050 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1052 if (IS_NOPOLLING_TYPE(ha
))
1053 ha
->isp_ops
->enable_intrs(ha
);
1057 * qla24xx_reset_chip() - Reset ISP24xx chip.
1060 * Returns 0 on success.
1063 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1065 struct qla_hw_data
*ha
= vha
->hw
;
1067 if (pci_channel_offline(ha
->pdev
) &&
1068 ha
->flags
.pci_channel_io_perm_failure
) {
1072 ha
->isp_ops
->disable_intrs(ha
);
1074 /* Perform RISC reset. */
1075 qla24xx_reset_risc(vha
);
1079 * qla2x00_chip_diag() - Test chip for proper operation.
1082 * Returns 0 on success.
1085 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1088 struct qla_hw_data
*ha
= vha
->hw
;
1089 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1090 unsigned long flags
= 0;
1094 struct req_que
*req
= ha
->req_q_map
[0];
1096 /* Assume a failed state */
1097 rval
= QLA_FUNCTION_FAILED
;
1099 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
1100 vha
->host_no
, (u_long
)®
->flash_address
));
1102 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1104 /* Reset ISP chip. */
1105 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1108 * We need to have a delay here since the card will not respond while
1109 * in reset causing an MCA on some architectures.
1112 data
= qla2x00_debounce_register(®
->ctrl_status
);
1113 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1115 data
= RD_REG_WORD(®
->ctrl_status
);
1120 goto chip_diag_failed
;
1122 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
1125 /* Reset RISC processor. */
1126 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1127 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1129 /* Workaround for QLA2312 PCI parity error */
1130 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1131 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1132 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1134 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1141 goto chip_diag_failed
;
1143 /* Check product ID of chip */
1144 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha
->host_no
));
1146 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1147 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1148 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1149 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1150 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1151 mb
[3] != PROD_ID_3
) {
1152 qla_printk(KERN_WARNING
, ha
,
1153 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
1155 goto chip_diag_failed
;
1157 ha
->product_id
[0] = mb
[1];
1158 ha
->product_id
[1] = mb
[2];
1159 ha
->product_id
[2] = mb
[3];
1160 ha
->product_id
[3] = mb
[4];
1162 /* Adjust fw RISC transfer size */
1163 if (req
->length
> 1024)
1164 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1166 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1169 if (IS_QLA2200(ha
) &&
1170 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1171 /* Limit firmware transfer size with a 2200A */
1172 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
1175 ha
->device_type
|= DT_ISP2200A
;
1176 ha
->fw_transfer_size
= 128;
1179 /* Wrap Incoming Mailboxes Test. */
1180 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1182 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
1183 rval
= qla2x00_mbx_reg_test(vha
);
1185 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1187 qla_printk(KERN_WARNING
, ha
,
1188 "Failed mailbox send register test\n");
1191 /* Flag a successful rval */
1194 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1198 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
1199 "****\n", vha
->host_no
));
1201 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1207 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1210 * Returns 0 on success.
1213 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1216 struct qla_hw_data
*ha
= vha
->hw
;
1217 struct req_que
*req
= ha
->req_q_map
[0];
1222 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1224 rval
= qla2x00_mbx_reg_test(vha
);
1226 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1228 qla_printk(KERN_WARNING
, ha
,
1229 "Failed mailbox send register test\n");
1231 /* Flag a successful rval */
1239 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1242 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1243 eft_size
, fce_size
, mq_size
;
1246 struct qla_hw_data
*ha
= vha
->hw
;
1247 struct req_que
*req
= ha
->req_q_map
[0];
1248 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1251 qla_printk(KERN_WARNING
, ha
,
1252 "Firmware dump previously allocated.\n");
1257 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1258 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1259 fixed_size
= sizeof(struct qla2100_fw_dump
);
1260 } else if (IS_QLA23XX(ha
)) {
1261 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1262 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1264 } else if (IS_FWI2_CAPABLE(ha
)) {
1266 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1267 else if (IS_QLA25XX(ha
))
1268 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1270 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1271 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1274 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1275 /* Allocate memory for Fibre Channel Event Buffer. */
1276 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1279 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1282 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1283 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
1287 memset(tc
, 0, FCE_SIZE
);
1288 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1289 ha
->fce_mb
, &ha
->fce_bufs
);
1291 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1292 "FCE (%d).\n", rval
);
1293 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1295 ha
->flags
.fce_enabled
= 0;
1299 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
1302 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1303 ha
->flags
.fce_enabled
= 1;
1304 ha
->fce_dma
= tc_dma
;
1307 /* Allocate memory for Extended Trace Buffer. */
1308 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1311 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1312 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
1316 memset(tc
, 0, EFT_SIZE
);
1317 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1319 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1320 "EFT (%d).\n", rval
);
1321 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1326 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
1329 eft_size
= EFT_SIZE
;
1330 ha
->eft_dma
= tc_dma
;
1334 req_q_size
= req
->length
* sizeof(request_t
);
1335 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1337 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1338 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1339 ha
->chain_offset
= dump_size
;
1340 dump_size
+= mq_size
+ fce_size
;
1342 ha
->fw_dump
= vmalloc(dump_size
);
1344 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
1345 "firmware dump!!!\n", dump_size
/ 1024);
1348 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1355 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1362 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
1365 ha
->fw_dump_len
= dump_size
;
1366 ha
->fw_dump
->signature
[0] = 'Q';
1367 ha
->fw_dump
->signature
[1] = 'L';
1368 ha
->fw_dump
->signature
[2] = 'G';
1369 ha
->fw_dump
->signature
[3] = 'C';
1370 ha
->fw_dump
->version
= __constant_htonl(1);
1372 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1373 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1374 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1375 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1377 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1378 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1379 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1381 ha
->fw_dump
->header_size
=
1382 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1386 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1388 #define MPS_MASK 0xe0
1392 struct qla_hw_data
*ha
= vha
->hw
;
1394 if (!IS_QLA81XX(vha
->hw
))
1397 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1398 if (rval
!= QLA_SUCCESS
) {
1399 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1400 "Sync-MPI: Unable to acquire semaphore.\n"));
1404 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1405 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1406 if (rval
!= QLA_SUCCESS
) {
1407 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1408 "Sync-MPI: Unable to read sync.\n"));
1413 if (dc
== (dw
& MPS_MASK
))
1418 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1419 if (rval
!= QLA_SUCCESS
) {
1420 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1421 "Sync-MPI: Unable to gain sync.\n"));
1425 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1426 if (rval
!= QLA_SUCCESS
) {
1427 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1428 "Sync-MPI: Unable to release semaphore.\n"));
1436 * qla2x00_setup_chip() - Load and start RISC firmware.
1439 * Returns 0 on success.
1442 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1445 uint32_t srisc_address
= 0;
1446 struct qla_hw_data
*ha
= vha
->hw
;
1447 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1448 unsigned long flags
;
1449 uint16_t fw_major_version
;
1451 if (IS_QLA82XX(ha
)) {
1452 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1453 if (rval
== QLA_SUCCESS
) {
1454 qla2x00_stop_firmware(vha
);
1455 goto enable_82xx_npiv
;
1460 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1461 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1462 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1463 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1464 RD_REG_WORD(®
->hccr
);
1465 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1468 qla81xx_mpi_sync(vha
);
1470 /* Load firmware sequences */
1471 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1472 if (rval
== QLA_SUCCESS
) {
1473 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1474 "code.\n", vha
->host_no
));
1476 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1477 if (rval
== QLA_SUCCESS
) {
1478 /* Start firmware execution. */
1479 DEBUG(printk("scsi(%ld): Checksum OK, start "
1480 "firmware.\n", vha
->host_no
));
1482 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1483 /* Retrieve firmware information. */
1484 if (rval
== QLA_SUCCESS
) {
1486 fw_major_version
= ha
->fw_major_version
;
1487 rval
= qla2x00_get_fw_version(vha
,
1488 &ha
->fw_major_version
,
1489 &ha
->fw_minor_version
,
1490 &ha
->fw_subminor_version
,
1491 &ha
->fw_attributes
, &ha
->fw_memory_size
,
1492 ha
->mpi_version
, &ha
->mpi_capabilities
,
1494 if (rval
!= QLA_SUCCESS
)
1496 ha
->flags
.npiv_supported
= 0;
1497 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1498 (ha
->fw_attributes
& BIT_2
)) {
1499 ha
->flags
.npiv_supported
= 1;
1500 if ((!ha
->max_npiv_vports
) ||
1501 ((ha
->max_npiv_vports
+ 1) %
1502 MIN_MULTI_ID_FABRIC
))
1503 ha
->max_npiv_vports
=
1504 MIN_MULTI_ID_FABRIC
- 1;
1506 qla2x00_get_resource_cnts(vha
, NULL
,
1507 &ha
->fw_xcb_count
, NULL
, NULL
,
1508 &ha
->max_npiv_vports
, NULL
);
1510 if (!fw_major_version
&& ql2xallocfwdump
) {
1511 if (!IS_QLA82XX(ha
))
1512 qla2x00_alloc_fw_dump(vha
);
1516 DEBUG2(printk(KERN_INFO
1517 "scsi(%ld): ISP Firmware failed checksum.\n",
1522 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1523 /* Enable proper parity. */
1524 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1527 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1529 /* SRAM, Instruction RAM and GP RAM parity */
1530 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1531 RD_REG_WORD(®
->hccr
);
1532 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1535 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1538 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1539 if (rval
== QLA_SUCCESS
) {
1540 ha
->flags
.fac_supported
= 1;
1541 ha
->fdt_block_size
= size
<< 2;
1543 qla_printk(KERN_ERR
, ha
,
1544 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1545 ha
->fw_major_version
, ha
->fw_minor_version
,
1546 ha
->fw_subminor_version
);
1551 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1559 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1562 * Beginning of request ring has initialization control block already built
1563 * by nvram config routine.
1565 * Returns 0 on success.
1568 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1573 rsp
->ring_ptr
= rsp
->ring
;
1574 rsp
->ring_index
= 0;
1575 rsp
->status_srb
= NULL
;
1576 pkt
= rsp
->ring_ptr
;
1577 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1578 pkt
->signature
= RESPONSE_PROCESSED
;
1584 * qla2x00_update_fw_options() - Read and process firmware options.
1587 * Returns 0 on success.
1590 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1592 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1593 struct qla_hw_data
*ha
= vha
->hw
;
1595 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1596 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1598 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1601 /* Serial Link options. */
1602 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1604 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1605 sizeof(ha
->fw_seriallink_options
)));
1607 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1608 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1609 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1612 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1613 emphasis
= (ha
->fw_seriallink_options
[2] &
1614 (BIT_4
| BIT_3
)) >> 3;
1615 tx_sens
= ha
->fw_seriallink_options
[0] &
1616 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1617 rx_sens
= (ha
->fw_seriallink_options
[0] &
1618 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1619 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1620 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1623 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1624 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1625 ha
->fw_options
[10] |= BIT_5
|
1626 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1627 (tx_sens
& (BIT_1
| BIT_0
));
1630 swing
= (ha
->fw_seriallink_options
[2] &
1631 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1632 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1633 tx_sens
= ha
->fw_seriallink_options
[1] &
1634 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1635 rx_sens
= (ha
->fw_seriallink_options
[1] &
1636 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1637 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1638 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1641 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1642 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1643 ha
->fw_options
[11] |= BIT_5
|
1644 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1645 (tx_sens
& (BIT_1
| BIT_0
));
1649 /* Return command IOCBs without waiting for an ABTS to complete. */
1650 ha
->fw_options
[3] |= BIT_13
;
1653 if (ha
->flags
.enable_led_scheme
)
1654 ha
->fw_options
[2] |= BIT_12
;
1656 /* Detect ISP6312. */
1658 ha
->fw_options
[2] |= BIT_13
;
1660 /* Update firmware options. */
1661 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1665 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1668 struct qla_hw_data
*ha
= vha
->hw
;
1673 /* Update Serial Link options. */
1674 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1677 rval
= qla2x00_set_serdes_params(vha
,
1678 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1679 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1680 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1681 if (rval
!= QLA_SUCCESS
) {
1682 qla_printk(KERN_WARNING
, ha
,
1683 "Unable to update Serial Link options (%x).\n", rval
);
1688 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1690 struct qla_hw_data
*ha
= vha
->hw
;
1691 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1692 struct req_que
*req
= ha
->req_q_map
[0];
1693 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1695 /* Setup ring parameters in initialization control block. */
1696 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1697 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1698 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1699 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1700 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1701 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1702 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1703 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1705 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1706 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1707 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1708 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1709 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1713 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1715 struct qla_hw_data
*ha
= vha
->hw
;
1716 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1717 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1718 struct qla_msix_entry
*msix
;
1719 struct init_cb_24xx
*icb
;
1721 struct req_que
*req
= ha
->req_q_map
[0];
1722 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1724 /* Setup ring parameters in initialization control block. */
1725 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1726 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1727 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1728 icb
->request_q_length
= cpu_to_le16(req
->length
);
1729 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1730 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1731 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1732 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1733 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1736 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1737 icb
->rid
= __constant_cpu_to_le16(rid
);
1738 if (ha
->flags
.msix_enabled
) {
1739 msix
= &ha
->msix_entries
[1];
1740 DEBUG2_17(printk(KERN_INFO
1741 "Registering vector 0x%x for base que\n", msix
->entry
));
1742 icb
->msix
= cpu_to_le16(msix
->entry
);
1744 /* Use alternate PCI bus number */
1746 icb
->firmware_options_2
|=
1747 __constant_cpu_to_le32(BIT_19
);
1748 /* Use alternate PCI devfn */
1750 icb
->firmware_options_2
|=
1751 __constant_cpu_to_le32(BIT_18
);
1753 /* Use Disable MSIX Handshake mode for capable adapters */
1754 if (IS_MSIX_NACK_CAPABLE(ha
)) {
1755 icb
->firmware_options_2
&=
1756 __constant_cpu_to_le32(~BIT_22
);
1757 ha
->flags
.disable_msix_handshake
= 1;
1758 qla_printk(KERN_INFO
, ha
,
1759 "MSIX Handshake Disable Mode turned on\n");
1761 icb
->firmware_options_2
|=
1762 __constant_cpu_to_le32(BIT_22
);
1764 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1766 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1767 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1768 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1769 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1771 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1772 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1773 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1774 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1777 RD_REG_DWORD(&ioreg
->hccr
);
1781 * qla2x00_init_rings() - Initializes firmware.
1784 * Beginning of request ring has initialization control block already built
1785 * by nvram config routine.
1787 * Returns 0 on success.
1790 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1793 unsigned long flags
= 0;
1795 struct qla_hw_data
*ha
= vha
->hw
;
1796 struct req_que
*req
;
1797 struct rsp_que
*rsp
;
1798 struct scsi_qla_host
*vp
;
1799 struct mid_init_cb_24xx
*mid_init_cb
=
1800 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1802 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1804 /* Clear outstanding commands array. */
1805 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1806 req
= ha
->req_q_map
[que
];
1809 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1810 req
->outstanding_cmds
[cnt
] = NULL
;
1812 req
->current_outstanding_cmd
= 1;
1814 /* Initialize firmware. */
1815 req
->ring_ptr
= req
->ring
;
1816 req
->ring_index
= 0;
1817 req
->cnt
= req
->length
;
1820 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1821 rsp
= ha
->rsp_q_map
[que
];
1824 /* Initialize response queue entries */
1825 qla2x00_init_response_q_entries(rsp
);
1828 spin_lock(&ha
->vport_slock
);
1829 /* Clear RSCN queue. */
1830 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
1831 vp
->rscn_in_ptr
= 0;
1832 vp
->rscn_out_ptr
= 0;
1835 spin_unlock(&ha
->vport_slock
);
1837 ha
->isp_ops
->config_rings(vha
);
1839 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1841 /* Update any ISP specific firmware options before initialization. */
1842 ha
->isp_ops
->update_fw_options(vha
);
1844 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1846 if (ha
->flags
.npiv_supported
) {
1847 if (ha
->operating_mode
== LOOP
)
1848 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1849 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1852 if (IS_FWI2_CAPABLE(ha
)) {
1853 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1854 mid_init_cb
->init_cb
.execution_throttle
=
1855 cpu_to_le16(ha
->fw_xcb_count
);
1858 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1860 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1863 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1871 * qla2x00_fw_ready() - Waits for firmware ready.
1874 * Returns 0 on success.
1877 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1880 unsigned long wtime
, mtime
, cs84xx_time
;
1881 uint16_t min_wait
; /* Minimum wait time if loop is down */
1882 uint16_t wait_time
; /* Wait time if loop is coming ready */
1884 struct qla_hw_data
*ha
= vha
->hw
;
1888 /* 20 seconds for loop down. */
1892 * Firmware should take at most one RATOV to login, plus 5 seconds for
1893 * our own processing.
1895 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1896 wait_time
= min_wait
;
1899 /* Min wait time if loop down */
1900 mtime
= jiffies
+ (min_wait
* HZ
);
1902 /* wait time before firmware ready */
1903 wtime
= jiffies
+ (wait_time
* HZ
);
1905 /* Wait for ISP to finish LIP */
1906 if (!vha
->flags
.init_done
)
1907 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1909 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1913 rval
= qla2x00_get_firmware_state(vha
, state
);
1914 if (rval
== QLA_SUCCESS
) {
1915 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1916 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1918 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1919 DEBUG16(printk("scsi(%ld): fw_state=%x "
1920 "84xx=%x.\n", vha
->host_no
, state
[0],
1922 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1923 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1924 DEBUG16(printk("scsi(%ld): Sending "
1925 "verify iocb.\n", vha
->host_no
));
1927 cs84xx_time
= jiffies
;
1928 rval
= qla84xx_init_chip(vha
);
1929 if (rval
!= QLA_SUCCESS
)
1932 /* Add time taken to initialize. */
1933 cs84xx_time
= jiffies
- cs84xx_time
;
1934 wtime
+= cs84xx_time
;
1935 mtime
+= cs84xx_time
;
1936 DEBUG16(printk("scsi(%ld): Increasing "
1937 "wait time by %ld. New time %ld\n",
1938 vha
->host_no
, cs84xx_time
, wtime
));
1940 } else if (state
[0] == FSTATE_READY
) {
1941 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1944 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1945 &ha
->login_timeout
, &ha
->r_a_tov
);
1951 rval
= QLA_FUNCTION_FAILED
;
1953 if (atomic_read(&vha
->loop_down_timer
) &&
1954 state
[0] != FSTATE_READY
) {
1955 /* Loop down. Timeout on min_wait for states
1956 * other than Wait for Login.
1958 if (time_after_eq(jiffies
, mtime
)) {
1959 qla_printk(KERN_INFO
, ha
,
1960 "Cable is unplugged...\n");
1962 vha
->device_flags
|= DFLG_NO_CABLE
;
1967 /* Mailbox cmd failed. Timeout on min_wait. */
1968 if (time_after_eq(jiffies
, mtime
) ||
1969 ha
->flags
.isp82xx_fw_hung
)
1973 if (time_after_eq(jiffies
, wtime
))
1976 /* Delay for a while */
1979 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1980 vha
->host_no
, state
[0], jiffies
));
1983 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1984 vha
->host_no
, state
[0], state
[1], state
[2], state
[3], state
[4],
1988 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1996 * qla2x00_configure_hba
1997 * Setup adapter context.
2000 * ha = adapter state pointer.
2009 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
2018 char connect_type
[22];
2019 struct qla_hw_data
*ha
= vha
->hw
;
2021 /* Get host addresses. */
2022 rval
= qla2x00_get_adapter_id(vha
,
2023 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
2024 if (rval
!= QLA_SUCCESS
) {
2025 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
2026 IS_QLA8XXX_TYPE(ha
) ||
2027 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
2028 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
2029 __func__
, vha
->host_no
));
2031 qla_printk(KERN_WARNING
, ha
,
2032 "ERROR -- Unable to get host loop ID.\n");
2033 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2039 qla_printk(KERN_INFO
, ha
,
2040 "Cannot get topology - retrying.\n");
2041 return (QLA_FUNCTION_FAILED
);
2044 vha
->loop_id
= loop_id
;
2047 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2048 ha
->operating_mode
= LOOP
;
2053 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
2055 ha
->current_topology
= ISP_CFG_NL
;
2056 strcpy(connect_type
, "(Loop)");
2060 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
2062 ha
->switch_cap
= sw_cap
;
2063 ha
->current_topology
= ISP_CFG_FL
;
2064 strcpy(connect_type
, "(FL_Port)");
2068 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
2070 ha
->operating_mode
= P2P
;
2071 ha
->current_topology
= ISP_CFG_N
;
2072 strcpy(connect_type
, "(N_Port-to-N_Port)");
2076 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
2078 ha
->switch_cap
= sw_cap
;
2079 ha
->operating_mode
= P2P
;
2080 ha
->current_topology
= ISP_CFG_F
;
2081 strcpy(connect_type
, "(F_Port)");
2085 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2087 vha
->host_no
, topo
));
2088 ha
->current_topology
= ISP_CFG_NL
;
2089 strcpy(connect_type
, "(Loop)");
2093 /* Save Host port and loop ID. */
2094 /* byte order - Big Endian */
2095 vha
->d_id
.b
.domain
= domain
;
2096 vha
->d_id
.b
.area
= area
;
2097 vha
->d_id
.b
.al_pa
= al_pa
;
2099 if (!vha
->flags
.init_done
)
2100 qla_printk(KERN_INFO
, ha
,
2101 "Topology - %s, Host Loop address 0x%x\n",
2102 connect_type
, vha
->loop_id
);
2105 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
2107 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
2114 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2119 struct qla_hw_data
*ha
= vha
->hw
;
2120 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2121 !IS_QLA8XXX_TYPE(ha
);
2123 if (memcmp(model
, BINZERO
, len
) != 0) {
2124 strncpy(ha
->model_number
, model
, len
);
2125 st
= en
= ha
->model_number
;
2128 if (*en
!= 0x20 && *en
!= 0x00)
2133 index
= (ha
->pdev
->subsystem_device
& 0xff);
2135 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2136 index
< QLA_MODEL_NAMES
)
2137 strncpy(ha
->model_desc
,
2138 qla2x00_model_name
[index
* 2 + 1],
2139 sizeof(ha
->model_desc
) - 1);
2141 index
= (ha
->pdev
->subsystem_device
& 0xff);
2143 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2144 index
< QLA_MODEL_NAMES
) {
2145 strcpy(ha
->model_number
,
2146 qla2x00_model_name
[index
* 2]);
2147 strncpy(ha
->model_desc
,
2148 qla2x00_model_name
[index
* 2 + 1],
2149 sizeof(ha
->model_desc
) - 1);
2151 strcpy(ha
->model_number
, def
);
2154 if (IS_FWI2_CAPABLE(ha
))
2155 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2156 sizeof(ha
->model_desc
));
2159 /* On sparc systems, obtain port and node WWN from firmware
2162 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2165 struct qla_hw_data
*ha
= vha
->hw
;
2166 struct pci_dev
*pdev
= ha
->pdev
;
2167 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2171 val
= of_get_property(dp
, "port-wwn", &len
);
2172 if (val
&& len
>= WWN_SIZE
)
2173 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2175 val
= of_get_property(dp
, "node-wwn", &len
);
2176 if (val
&& len
>= WWN_SIZE
)
2177 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2182 * NVRAM configuration for ISP 2xxx
2185 * ha = adapter block pointer.
2188 * initialization control block in response_ring
2189 * host adapters parameters in host adapter block
2195 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2200 uint8_t *dptr1
, *dptr2
;
2201 struct qla_hw_data
*ha
= vha
->hw
;
2202 init_cb_t
*icb
= ha
->init_cb
;
2203 nvram_t
*nv
= ha
->nvram
;
2204 uint8_t *ptr
= ha
->nvram
;
2205 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2209 /* Determine NVRAM starting address. */
2210 ha
->nvram_size
= sizeof(nvram_t
);
2212 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2213 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2214 ha
->nvram_base
= 0x80;
2216 /* Get NVRAM data and calculate checksum. */
2217 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2218 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2221 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
2222 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
2224 /* Bad NVRAM data, set defaults parameters. */
2225 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2226 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2227 /* Reset NVRAM data. */
2228 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
2229 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
2231 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
2232 "invalid -- WWPN) defaults.\n");
2235 * Set default initialization control block.
2237 memset(nv
, 0, ha
->nvram_size
);
2238 nv
->parameter_block_version
= ICB_VERSION
;
2240 if (IS_QLA23XX(ha
)) {
2241 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2242 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2243 nv
->add_firmware_options
[0] = BIT_5
;
2244 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2245 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2246 nv
->special_options
[1] = BIT_7
;
2247 } else if (IS_QLA2200(ha
)) {
2248 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2249 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2250 nv
->add_firmware_options
[0] = BIT_5
;
2251 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2252 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2253 } else if (IS_QLA2100(ha
)) {
2254 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2255 nv
->firmware_options
[1] = BIT_5
;
2256 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2259 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2260 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2261 nv
->retry_count
= 8;
2262 nv
->retry_delay
= 1;
2264 nv
->port_name
[0] = 33;
2265 nv
->port_name
[3] = 224;
2266 nv
->port_name
[4] = 139;
2268 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2270 nv
->login_timeout
= 4;
2273 * Set default host adapter parameters
2275 nv
->host_p
[1] = BIT_2
;
2276 nv
->reset_delay
= 5;
2277 nv
->port_down_retry_count
= 8;
2278 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2279 nv
->link_down_timeout
= 60;
2284 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2286 * The SN2 does not provide BIOS emulation which means you can't change
2287 * potentially bogus BIOS settings. Force the use of default settings
2288 * for link rate and frame size. Hope that the rest of the settings
2291 if (ia64_platform_is("sn2")) {
2292 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2294 nv
->special_options
[1] = BIT_7
;
2298 /* Reset Initialization control block */
2299 memset(icb
, 0, ha
->init_cb_size
);
2302 * Setup driver NVRAM options.
2304 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2305 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2306 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2307 nv
->firmware_options
[1] &= ~BIT_4
;
2309 if (IS_QLA23XX(ha
)) {
2310 nv
->firmware_options
[0] |= BIT_2
;
2311 nv
->firmware_options
[0] &= ~BIT_3
;
2312 nv
->firmware_options
[0] &= ~BIT_6
;
2313 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2315 if (IS_QLA2300(ha
)) {
2316 if (ha
->fb_rev
== FPM_2310
) {
2317 strcpy(ha
->model_number
, "QLA2310");
2319 strcpy(ha
->model_number
, "QLA2300");
2322 qla2x00_set_model_info(vha
, nv
->model_number
,
2323 sizeof(nv
->model_number
), "QLA23xx");
2325 } else if (IS_QLA2200(ha
)) {
2326 nv
->firmware_options
[0] |= BIT_2
;
2328 * 'Point-to-point preferred, else loop' is not a safe
2329 * connection mode setting.
2331 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2333 /* Force 'loop preferred, else point-to-point'. */
2334 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2335 nv
->add_firmware_options
[0] |= BIT_5
;
2337 strcpy(ha
->model_number
, "QLA22xx");
2338 } else /*if (IS_QLA2100(ha))*/ {
2339 strcpy(ha
->model_number
, "QLA2100");
2343 * Copy over NVRAM RISC parameter block to initialization control block.
2345 dptr1
= (uint8_t *)icb
;
2346 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2347 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2349 *dptr1
++ = *dptr2
++;
2351 /* Copy 2nd half. */
2352 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2353 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2355 *dptr1
++ = *dptr2
++;
2357 /* Use alternate WWN? */
2358 if (nv
->host_p
[1] & BIT_7
) {
2359 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2360 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2363 /* Prepare nodename */
2364 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2366 * Firmware will apply the following mask if the nodename was
2369 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2370 icb
->node_name
[0] &= 0xF0;
2374 * Set host adapter parameters.
2376 if (nv
->host_p
[0] & BIT_7
)
2377 ql2xextended_error_logging
= 1;
2378 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2379 /* Always load RISC code on non ISP2[12]00 chips. */
2380 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2381 ha
->flags
.disable_risc_code_load
= 0;
2382 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2383 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2384 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2385 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2386 ha
->flags
.disable_serdes
= 0;
2388 ha
->operating_mode
=
2389 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2391 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2392 sizeof(ha
->fw_seriallink_options
));
2394 /* save HBA serial number */
2395 ha
->serial0
= icb
->port_name
[5];
2396 ha
->serial1
= icb
->port_name
[6];
2397 ha
->serial2
= icb
->port_name
[7];
2398 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2399 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2401 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2403 ha
->retry_count
= nv
->retry_count
;
2405 /* Set minimum login_timeout to 4 seconds. */
2406 if (nv
->login_timeout
!= ql2xlogintimeout
)
2407 nv
->login_timeout
= ql2xlogintimeout
;
2408 if (nv
->login_timeout
< 4)
2409 nv
->login_timeout
= 4;
2410 ha
->login_timeout
= nv
->login_timeout
;
2411 icb
->login_timeout
= nv
->login_timeout
;
2413 /* Set minimum RATOV to 100 tenths of a second. */
2416 ha
->loop_reset_delay
= nv
->reset_delay
;
2418 /* Link Down Timeout = 0:
2420 * When Port Down timer expires we will start returning
2421 * I/O's to OS with "DID_NO_CONNECT".
2423 * Link Down Timeout != 0:
2425 * The driver waits for the link to come up after link down
2426 * before returning I/Os to OS with "DID_NO_CONNECT".
2428 if (nv
->link_down_timeout
== 0) {
2429 ha
->loop_down_abort_time
=
2430 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2432 ha
->link_down_timeout
= nv
->link_down_timeout
;
2433 ha
->loop_down_abort_time
=
2434 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2438 * Need enough time to try and get the port back.
2440 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2441 if (qlport_down_retry
)
2442 ha
->port_down_retry_count
= qlport_down_retry
;
2443 /* Set login_retry_count */
2444 ha
->login_retry_count
= nv
->retry_count
;
2445 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2446 ha
->port_down_retry_count
> 3)
2447 ha
->login_retry_count
= ha
->port_down_retry_count
;
2448 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2449 ha
->login_retry_count
= ha
->port_down_retry_count
;
2450 if (ql2xloginretrycount
)
2451 ha
->login_retry_count
= ql2xloginretrycount
;
2453 icb
->lun_enables
= __constant_cpu_to_le16(0);
2454 icb
->command_resource_count
= 0;
2455 icb
->immediate_notify_resource_count
= 0;
2456 icb
->timeout
= __constant_cpu_to_le16(0);
2458 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2460 icb
->firmware_options
[0] &= ~BIT_3
;
2461 icb
->add_firmware_options
[0] &=
2462 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2463 icb
->add_firmware_options
[0] |= BIT_2
;
2464 icb
->response_accumulation_timer
= 3;
2465 icb
->interrupt_delay_timer
= 5;
2467 vha
->flags
.process_response_queue
= 1;
2470 if (!vha
->flags
.init_done
) {
2471 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2472 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2473 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2474 icb
->interrupt_delay_timer
: 2;
2476 icb
->add_firmware_options
[0] &=
2477 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2478 vha
->flags
.process_response_queue
= 0;
2479 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2480 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2482 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2483 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
2484 ha
->zio_timer
* 100));
2485 qla_printk(KERN_INFO
, ha
,
2486 "ZIO mode %d enabled; timer delay (%d us).\n",
2487 ha
->zio_mode
, ha
->zio_timer
* 100);
2489 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2490 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2491 vha
->flags
.process_response_queue
= 1;
2496 DEBUG2_3(printk(KERN_WARNING
2497 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
2503 qla2x00_rport_del(void *data
)
2505 fc_port_t
*fcport
= data
;
2506 struct fc_rport
*rport
;
2507 unsigned long flags
;
2509 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2510 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2511 fcport
->drport
= NULL
;
2512 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2514 fc_remote_port_delete(rport
);
2518 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2520 * @flags: allocation flags
2522 * Returns a pointer to the allocated fcport, or NULL, if none available.
2525 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2529 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2533 /* Setup fcport template structure. */
2535 fcport
->vp_idx
= vha
->vp_idx
;
2536 fcport
->port_type
= FCT_UNKNOWN
;
2537 fcport
->loop_id
= FC_NO_LOOP_ID
;
2538 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
2539 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2545 * qla2x00_configure_loop
2546 * Updates Fibre Channel Device Database with what is actually on loop.
2549 * ha = adapter block pointer.
2554 * 2 = database was full and device was not configured.
2557 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2560 unsigned long flags
, save_flags
;
2561 struct qla_hw_data
*ha
= vha
->hw
;
2564 /* Get Initiator ID */
2565 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2566 rval
= qla2x00_configure_hba(vha
);
2567 if (rval
!= QLA_SUCCESS
) {
2568 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2574 save_flags
= flags
= vha
->dpc_flags
;
2575 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2576 vha
->host_no
, flags
));
2579 * If we have both an RSCN and PORT UPDATE pending then handle them
2580 * both at the same time.
2582 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2583 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2585 qla2x00_get_data_rate(vha
);
2587 /* Determine what we need to do */
2588 if (ha
->current_topology
== ISP_CFG_FL
&&
2589 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2591 vha
->flags
.rscn_queue_overflow
= 1;
2592 set_bit(RSCN_UPDATE
, &flags
);
2594 } else if (ha
->current_topology
== ISP_CFG_F
&&
2595 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2597 vha
->flags
.rscn_queue_overflow
= 1;
2598 set_bit(RSCN_UPDATE
, &flags
);
2599 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2601 } else if (ha
->current_topology
== ISP_CFG_N
) {
2602 clear_bit(RSCN_UPDATE
, &flags
);
2604 } else if (!vha
->flags
.online
||
2605 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2607 vha
->flags
.rscn_queue_overflow
= 1;
2608 set_bit(RSCN_UPDATE
, &flags
);
2609 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2612 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2613 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2614 rval
= QLA_FUNCTION_FAILED
;
2616 rval
= qla2x00_configure_local_loop(vha
);
2619 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2620 if (LOOP_TRANSITION(vha
))
2621 rval
= QLA_FUNCTION_FAILED
;
2623 rval
= qla2x00_configure_fabric(vha
);
2626 if (rval
== QLA_SUCCESS
) {
2627 if (atomic_read(&vha
->loop_down_timer
) ||
2628 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2629 rval
= QLA_FUNCTION_FAILED
;
2631 atomic_set(&vha
->loop_state
, LOOP_READY
);
2633 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2638 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2639 __func__
, vha
->host_no
));
2641 DEBUG3(printk("%s: exiting normally\n", __func__
));
2644 /* Restore state if a resync event occurred during processing */
2645 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2646 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2647 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2648 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2649 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2650 if (!IS_ALOGIO_CAPABLE(ha
))
2651 vha
->flags
.rscn_queue_overflow
= 1;
2661 * qla2x00_configure_local_loop
2662 * Updates Fibre Channel Device Database with local loop devices.
2665 * ha = adapter block pointer.
2671 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2676 fc_port_t
*fcport
, *new_fcport
;
2682 uint8_t domain
, area
, al_pa
;
2683 struct qla_hw_data
*ha
= vha
->hw
;
2687 entries
= MAX_FIBRE_DEVICES
;
2689 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2690 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2692 /* Get list of logged in devices. */
2693 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2694 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2696 if (rval
!= QLA_SUCCESS
)
2697 goto cleanup_allocation
;
2699 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2700 vha
->host_no
, entries
));
2701 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2702 entries
* sizeof(struct gid_list_info
)));
2704 /* Allocate temporary fcport for any new fcports discovered. */
2705 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2706 if (new_fcport
== NULL
) {
2707 rval
= QLA_MEMORY_ALLOC_FAILED
;
2708 goto cleanup_allocation
;
2710 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2713 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2715 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2716 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2717 fcport
->port_type
!= FCT_BROADCAST
&&
2718 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2720 DEBUG(printk("scsi(%ld): Marking port lost, "
2722 vha
->host_no
, fcport
->loop_id
));
2724 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2728 /* Add devices to port list. */
2729 id_iter
= (char *)ha
->gid_list
;
2730 for (index
= 0; index
< entries
; index
++) {
2731 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2732 area
= ((struct gid_list_info
*)id_iter
)->area
;
2733 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2734 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2735 loop_id
= (uint16_t)
2736 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2738 loop_id
= le16_to_cpu(
2739 ((struct gid_list_info
*)id_iter
)->loop_id
);
2740 id_iter
+= ha
->gid_list_info_size
;
2742 /* Bypass reserved domain fields. */
2743 if ((domain
& 0xf0) == 0xf0)
2746 /* Bypass if not same domain and area of adapter. */
2747 if (area
&& domain
&&
2748 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2751 /* Bypass invalid local loop ID. */
2752 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2755 /* Fill in member data. */
2756 new_fcport
->d_id
.b
.domain
= domain
;
2757 new_fcport
->d_id
.b
.area
= area
;
2758 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2759 new_fcport
->loop_id
= loop_id
;
2760 new_fcport
->vp_idx
= vha
->vp_idx
;
2761 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2762 if (rval2
!= QLA_SUCCESS
) {
2763 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2764 "information -- get_port_database=%x, "
2766 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2767 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2769 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2773 /* Check for matching device in port list. */
2776 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2777 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2781 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2782 fcport
->loop_id
= new_fcport
->loop_id
;
2783 fcport
->port_type
= new_fcport
->port_type
;
2784 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2785 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2793 /* New device, add to fcports list. */
2795 new_fcport
->vha
= vha
;
2796 new_fcport
->vp_idx
= vha
->vp_idx
;
2798 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2800 /* Allocate a new replacement fcport. */
2801 fcport
= new_fcport
;
2802 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2803 if (new_fcport
== NULL
) {
2804 rval
= QLA_MEMORY_ALLOC_FAILED
;
2805 goto cleanup_allocation
;
2807 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2810 /* Base iIDMA settings on HBA port speed. */
2811 fcport
->fp_speed
= ha
->link_data_rate
;
2813 qla2x00_update_fcport(vha
, fcport
);
2821 if (rval
!= QLA_SUCCESS
) {
2822 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2823 "rval=%x\n", vha
->host_no
, rval
));
2830 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2832 #define LS_UNKNOWN 2
2833 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
2837 struct qla_hw_data
*ha
= vha
->hw
;
2839 if (!IS_IIDMA_CAPABLE(ha
))
2842 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
2845 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2846 fcport
->fp_speed
> ha
->link_data_rate
)
2849 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2851 if (rval
!= QLA_SUCCESS
) {
2852 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2853 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2854 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2855 fcport
->port_name
[2], fcport
->port_name
[3],
2856 fcport
->port_name
[4], fcport
->port_name
[5],
2857 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2858 fcport
->fp_speed
, mb
[0], mb
[1]));
2860 link_speed
= link_speeds
[LS_UNKNOWN
];
2861 if (fcport
->fp_speed
< 5)
2862 link_speed
= link_speeds
[fcport
->fp_speed
];
2863 else if (fcport
->fp_speed
== 0x13)
2864 link_speed
= link_speeds
[5];
2865 DEBUG2(qla_printk(KERN_INFO
, ha
,
2866 "iIDMA adjusted to %s GB/s on "
2867 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2868 link_speed
, fcport
->port_name
[0],
2869 fcport
->port_name
[1], fcport
->port_name
[2],
2870 fcport
->port_name
[3], fcport
->port_name
[4],
2871 fcport
->port_name
[5], fcport
->port_name
[6],
2872 fcport
->port_name
[7]));
2877 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2879 struct fc_rport_identifiers rport_ids
;
2880 struct fc_rport
*rport
;
2881 struct qla_hw_data
*ha
= vha
->hw
;
2882 unsigned long flags
;
2884 qla2x00_rport_del(fcport
);
2886 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2887 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2888 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2889 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2890 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2891 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2893 qla_printk(KERN_WARNING
, ha
,
2894 "Unable to allocate fc remote port!\n");
2897 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2898 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2899 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2901 rport
->supported_classes
= fcport
->supported_classes
;
2903 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2904 if (fcport
->port_type
== FCT_INITIATOR
)
2905 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2906 if (fcport
->port_type
== FCT_TARGET
)
2907 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2908 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2912 * qla2x00_update_fcport
2913 * Updates device on list.
2916 * ha = adapter block pointer.
2917 * fcport = port structure pointer.
2927 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2930 fcport
->login_retry
= 0;
2931 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
2933 qla2x00_iidma_fcport(vha
, fcport
);
2934 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
2935 qla2x00_reg_remote_port(vha
, fcport
);
2936 atomic_set(&fcport
->state
, FCS_ONLINE
);
2940 * qla2x00_configure_fabric
2941 * Setup SNS devices with loop ID's.
2944 * ha = adapter block pointer.
2951 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2954 fc_port_t
*fcport
, *fcptemp
;
2955 uint16_t next_loopid
;
2956 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2958 LIST_HEAD(new_fcports
);
2959 struct qla_hw_data
*ha
= vha
->hw
;
2960 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2962 /* If FL port exists, then SNS is present */
2963 if (IS_FWI2_CAPABLE(ha
))
2964 loop_id
= NPH_F_PORT
;
2966 loop_id
= SNS_FL_PORT
;
2967 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2968 if (rval
!= QLA_SUCCESS
) {
2969 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2970 "Port\n", vha
->host_no
));
2972 vha
->device_flags
&= ~SWITCH_FOUND
;
2973 return (QLA_SUCCESS
);
2975 vha
->device_flags
|= SWITCH_FOUND
;
2977 /* Mark devices that need re-synchronization. */
2978 rval2
= qla2x00_device_resync(vha
);
2979 if (rval2
== QLA_RSCNS_HANDLED
) {
2980 /* No point doing the scan, just continue. */
2981 return (QLA_SUCCESS
);
2985 if (ql2xfdmienable
&&
2986 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2987 qla2x00_fdmi_register(vha
);
2989 /* Ensure we are logged into the SNS. */
2990 if (IS_FWI2_CAPABLE(ha
))
2993 loop_id
= SIMPLE_NAME_SERVER
;
2994 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2995 0xfc, mb
, BIT_1
| BIT_0
);
2996 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2997 DEBUG2(qla_printk(KERN_INFO
, ha
,
2998 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2999 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
3000 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
3001 return (QLA_SUCCESS
);
3004 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
3005 if (qla2x00_rft_id(vha
)) {
3007 DEBUG2(printk("scsi(%ld): Register FC-4 "
3008 "TYPE failed.\n", vha
->host_no
));
3010 if (qla2x00_rff_id(vha
)) {
3012 DEBUG2(printk("scsi(%ld): Register FC-4 "
3013 "Features failed.\n", vha
->host_no
));
3015 if (qla2x00_rnn_id(vha
)) {
3017 DEBUG2(printk("scsi(%ld): Register Node Name "
3018 "failed.\n", vha
->host_no
));
3019 } else if (qla2x00_rsnn_nn(vha
)) {
3021 DEBUG2(printk("scsi(%ld): Register Symbolic "
3022 "Node Name failed.\n", vha
->host_no
));
3026 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
3027 if (rval
!= QLA_SUCCESS
)
3031 * Logout all previous fabric devices marked lost, except
3034 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3035 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3038 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3041 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
3042 qla2x00_mark_device_lost(vha
, fcport
,
3043 ql2xplogiabsentdevice
, 0);
3044 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3045 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3046 fcport
->port_type
!= FCT_INITIATOR
&&
3047 fcport
->port_type
!= FCT_BROADCAST
) {
3048 ha
->isp_ops
->fabric_logout(vha
,
3050 fcport
->d_id
.b
.domain
,
3051 fcport
->d_id
.b
.area
,
3052 fcport
->d_id
.b
.al_pa
);
3053 fcport
->loop_id
= FC_NO_LOOP_ID
;
3058 /* Starting free loop ID. */
3059 next_loopid
= ha
->min_external_loopid
;
3062 * Scan through our port list and login entries that need to be
3065 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3066 if (atomic_read(&vha
->loop_down_timer
) ||
3067 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3070 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3071 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
3074 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3075 fcport
->loop_id
= next_loopid
;
3076 rval
= qla2x00_find_new_loop_id(
3078 if (rval
!= QLA_SUCCESS
) {
3079 /* Ran out of IDs to use */
3083 /* Login and update database */
3084 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3087 /* Exit if out of loop IDs. */
3088 if (rval
!= QLA_SUCCESS
) {
3093 * Login and add the new devices to our port list.
3095 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3096 if (atomic_read(&vha
->loop_down_timer
) ||
3097 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3100 /* Find a new loop ID to use. */
3101 fcport
->loop_id
= next_loopid
;
3102 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
3103 if (rval
!= QLA_SUCCESS
) {
3104 /* Ran out of IDs to use */
3108 /* Login and update database */
3109 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3113 fcport
->vp_idx
= vha
->vp_idx
;
3115 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
3119 /* Free all new device structures not processed. */
3120 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3121 list_del(&fcport
->list
);
3126 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
3127 "rval=%d\n", vha
->host_no
, rval
));
3134 * qla2x00_find_all_fabric_devs
3137 * ha = adapter block pointer.
3138 * dev = database device entry pointer.
3147 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3148 struct list_head
*new_fcports
)
3152 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3157 int first_dev
, last_dev
;
3158 port_id_t wrap
= {}, nxt_d_id
;
3159 struct qla_hw_data
*ha
= vha
->hw
;
3160 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3161 struct scsi_qla_host
*tvp
;
3165 /* Try GID_PT to get device list, else GAN. */
3166 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
3169 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
3170 "on GA_NXT\n", vha
->host_no
));
3172 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3175 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3178 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3181 } else if (ql2xiidmaenable
&&
3182 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3183 qla2x00_gpsc(vha
, swl
);
3186 /* If other queries succeeded probe for FC-4 type */
3188 qla2x00_gff_id(vha
, swl
);
3192 /* Allocate temporary fcport for any new fcports discovered. */
3193 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3194 if (new_fcport
== NULL
) {
3196 return (QLA_MEMORY_ALLOC_FAILED
);
3198 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3199 /* Set start port ID scan at adapter ID. */
3203 /* Starting free loop ID. */
3204 loop_id
= ha
->min_external_loopid
;
3205 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3206 if (qla2x00_is_reserved_id(vha
, loop_id
))
3209 if (ha
->current_topology
== ISP_CFG_FL
&&
3210 (atomic_read(&vha
->loop_down_timer
) ||
3211 LOOP_TRANSITION(vha
))) {
3212 atomic_set(&vha
->loop_down_timer
, 0);
3213 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3214 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3220 wrap
.b24
= new_fcport
->d_id
.b24
;
3222 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3223 memcpy(new_fcport
->node_name
,
3224 swl
[swl_idx
].node_name
, WWN_SIZE
);
3225 memcpy(new_fcport
->port_name
,
3226 swl
[swl_idx
].port_name
, WWN_SIZE
);
3227 memcpy(new_fcport
->fabric_port_name
,
3228 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3229 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3230 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3232 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3238 /* Send GA_NXT to the switch */
3239 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3240 if (rval
!= QLA_SUCCESS
) {
3241 qla_printk(KERN_WARNING
, ha
,
3242 "SNS scan failed -- assuming zero-entry "
3244 list_for_each_entry_safe(fcport
, fcptemp
,
3245 new_fcports
, list
) {
3246 list_del(&fcport
->list
);
3254 /* If wrap on switch device list, exit. */
3256 wrap
.b24
= new_fcport
->d_id
.b24
;
3258 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3259 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
3260 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
3261 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
3265 /* Bypass if same physical adapter. */
3266 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3269 /* Bypass virtual ports of the same host. */
3271 if (ha
->num_vhosts
) {
3272 unsigned long flags
;
3274 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3275 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3276 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3281 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3287 /* Bypass if same domain and area of adapter. */
3288 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3289 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3293 /* Bypass reserved domain fields. */
3294 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3297 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3298 if (ql2xgffidenable
&&
3299 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3300 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3303 /* Locate matching device in database. */
3305 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3306 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3312 /* Update port state. */
3313 memcpy(fcport
->fabric_port_name
,
3314 new_fcport
->fabric_port_name
, WWN_SIZE
);
3315 fcport
->fp_speed
= new_fcport
->fp_speed
;
3318 * If address the same and state FCS_ONLINE, nothing
3321 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3322 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3327 * If device was not a fabric device before.
3329 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3330 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3331 fcport
->loop_id
= FC_NO_LOOP_ID
;
3332 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3338 * Port ID changed or device was marked to be updated;
3339 * Log it out if still logged in and mark it for
3342 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3343 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3344 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3345 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3346 fcport
->port_type
!= FCT_INITIATOR
&&
3347 fcport
->port_type
!= FCT_BROADCAST
) {
3348 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3349 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3350 fcport
->d_id
.b
.al_pa
);
3351 fcport
->loop_id
= FC_NO_LOOP_ID
;
3359 /* If device was not in our fcports list, then add it. */
3360 list_add_tail(&new_fcport
->list
, new_fcports
);
3362 /* Allocate a new replacement fcport. */
3363 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3364 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3365 if (new_fcport
== NULL
) {
3367 return (QLA_MEMORY_ALLOC_FAILED
);
3369 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3370 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3380 * qla2x00_find_new_loop_id
3381 * Scan through our port list and find a new usable loop ID.
3384 * ha: adapter state pointer.
3385 * dev: port structure pointer.
3388 * qla2x00 local function return status code.
3394 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3399 uint16_t first_loop_id
;
3400 struct qla_hw_data
*ha
= vha
->hw
;
3401 struct scsi_qla_host
*vp
;
3402 struct scsi_qla_host
*tvp
;
3403 unsigned long flags
= 0;
3407 /* Save starting loop ID. */
3408 first_loop_id
= dev
->loop_id
;
3411 /* Skip loop ID if already used by adapter. */
3412 if (dev
->loop_id
== vha
->loop_id
)
3415 /* Skip reserved loop IDs. */
3416 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3419 /* Reset loop ID if passed the end. */
3420 if (dev
->loop_id
> ha
->max_loop_id
) {
3421 /* first loop ID. */
3422 dev
->loop_id
= ha
->min_external_loopid
;
3425 /* Check for loop ID being already in use. */
3429 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3430 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3431 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3432 if (fcport
->loop_id
== dev
->loop_id
&&
3434 /* ID possibly in use */
3442 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3444 /* If not in use then it is free to use. */
3449 /* ID in use. Try next value. */
3452 /* If wrap around. No free ID to use. */
3453 if (dev
->loop_id
== first_loop_id
) {
3454 dev
->loop_id
= FC_NO_LOOP_ID
;
3455 rval
= QLA_FUNCTION_FAILED
;
3464 * qla2x00_device_resync
3465 * Marks devices in the database that needs resynchronization.
3468 * ha = adapter block pointer.
3474 qla2x00_device_resync(scsi_qla_host_t
*vha
)
3479 uint32_t rscn_entry
;
3480 uint8_t rscn_out_iter
;
3482 port_id_t d_id
= {};
3484 rval
= QLA_RSCNS_HANDLED
;
3486 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
3487 vha
->flags
.rscn_queue_overflow
) {
3489 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
3490 format
= MSB(MSW(rscn_entry
));
3491 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
3492 d_id
.b
.area
= MSB(LSW(rscn_entry
));
3493 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
3495 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3496 "[%02x/%02x%02x%02x].\n",
3497 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
3498 d_id
.b
.area
, d_id
.b
.al_pa
));
3500 vha
->rscn_out_ptr
++;
3501 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
3502 vha
->rscn_out_ptr
= 0;
3504 /* Skip duplicate entries. */
3505 for (rscn_out_iter
= vha
->rscn_out_ptr
;
3506 !vha
->flags
.rscn_queue_overflow
&&
3507 rscn_out_iter
!= vha
->rscn_in_ptr
;
3508 rscn_out_iter
= (rscn_out_iter
==
3509 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
3511 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
3514 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3515 "entry found at [%d].\n", vha
->host_no
,
3518 vha
->rscn_out_ptr
= rscn_out_iter
;
3521 /* Queue overflow, set switch default case. */
3522 if (vha
->flags
.rscn_queue_overflow
) {
3523 DEBUG(printk("scsi(%ld): device_resync: rscn "
3524 "overflow.\n", vha
->host_no
));
3527 vha
->flags
.rscn_queue_overflow
= 0;
3543 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
3549 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3550 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3551 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
3552 fcport
->port_type
== FCT_BROADCAST
)
3555 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3557 fcport
->port_type
!= FCT_INITIATOR
) {
3558 qla2x00_mark_device_lost(vha
, fcport
,
3568 * qla2x00_fabric_dev_login
3569 * Login fabric target device and update FC port database.
3572 * ha: adapter state pointer.
3573 * fcport: port structure list pointer.
3574 * next_loopid: contains value of a new loop ID that can be used
3575 * by the next login attempt.
3578 * qla2x00 local function return status code.
3584 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3585 uint16_t *next_loopid
)
3590 struct qla_hw_data
*ha
= vha
->hw
;
3595 if (IS_ALOGIO_CAPABLE(ha
)) {
3596 if (fcport
->flags
& FCF_ASYNC_SENT
)
3598 fcport
->flags
|= FCF_ASYNC_SENT
;
3599 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3604 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3605 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3606 if (rval
== QLA_SUCCESS
) {
3607 /* Send an ADISC to FCP2 devices.*/
3609 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3611 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3612 if (rval
!= QLA_SUCCESS
) {
3613 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3614 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3615 fcport
->d_id
.b
.al_pa
);
3616 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3618 qla2x00_update_fcport(vha
, fcport
);
3626 * qla2x00_fabric_login
3627 * Issue fabric login command.
3630 * ha = adapter block pointer.
3631 * device = pointer to FC device type structure.
3634 * 0 - Login successfully
3636 * 2 - Initiator device
3640 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3641 uint16_t *next_loopid
)
3645 uint16_t tmp_loopid
;
3646 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3647 struct qla_hw_data
*ha
= vha
->hw
;
3653 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3654 "for port %02x%02x%02x.\n",
3655 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3656 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3658 /* Login fcport on switch. */
3659 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3660 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3661 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3662 if (mb
[0] == MBS_PORT_ID_USED
) {
3664 * Device has another loop ID. The firmware team
3665 * recommends the driver perform an implicit login with
3666 * the specified ID again. The ID we just used is save
3667 * here so we return with an ID that can be tried by
3671 tmp_loopid
= fcport
->loop_id
;
3672 fcport
->loop_id
= mb
[1];
3674 DEBUG(printk("Fabric Login: port in use - next "
3675 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3676 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3677 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3679 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3684 /* A retry occurred before. */
3685 *next_loopid
= tmp_loopid
;
3688 * No retry occurred before. Just increment the
3689 * ID value for next login.
3691 *next_loopid
= (fcport
->loop_id
+ 1);
3694 if (mb
[1] & BIT_0
) {
3695 fcport
->port_type
= FCT_INITIATOR
;
3697 fcport
->port_type
= FCT_TARGET
;
3698 if (mb
[1] & BIT_1
) {
3699 fcport
->flags
|= FCF_FCP2_DEVICE
;
3704 fcport
->supported_classes
|= FC_COS_CLASS2
;
3706 fcport
->supported_classes
|= FC_COS_CLASS3
;
3710 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3712 * Loop ID already used, try next loop ID.
3715 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3716 if (rval
!= QLA_SUCCESS
) {
3717 /* Ran out of loop IDs to use */
3720 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3722 * Firmware possibly timed out during login. If NO
3723 * retries are left to do then the device is declared
3726 *next_loopid
= fcport
->loop_id
;
3727 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3728 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3729 fcport
->d_id
.b
.al_pa
);
3730 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3736 * unrecoverable / not handled error
3738 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3739 "loop_id=%x jiffies=%lx.\n",
3740 __func__
, vha
->host_no
, mb
[0],
3741 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3742 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3744 *next_loopid
= fcport
->loop_id
;
3745 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3746 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3747 fcport
->d_id
.b
.al_pa
);
3748 fcport
->loop_id
= FC_NO_LOOP_ID
;
3749 fcport
->login_retry
= 0;
3760 * qla2x00_local_device_login
3761 * Issue local device login command.
3764 * ha = adapter block pointer.
3765 * loop_id = loop id of device to login to.
3767 * Returns (Where's the #define!!!!):
3768 * 0 - Login successfully
3773 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3776 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3778 memset(mb
, 0, sizeof(mb
));
3779 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3780 if (rval
== QLA_SUCCESS
) {
3781 /* Interrogate mailbox registers for any errors */
3782 if (mb
[0] == MBS_COMMAND_ERROR
)
3784 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3785 /* device not in PCB table */
3793 * qla2x00_loop_resync
3794 * Resync with fibre channel devices.
3797 * ha = adapter block pointer.
3803 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3805 int rval
= QLA_SUCCESS
;
3807 struct req_que
*req
;
3808 struct rsp_que
*rsp
;
3810 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3811 req
= vha
->hw
->req_q_map
[0];
3816 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3817 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3818 if (vha
->flags
.online
) {
3819 if (!(rval
= qla2x00_fw_ready(vha
))) {
3820 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3823 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3825 /* Issue a marker after FW becomes ready. */
3826 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3828 vha
->marker_needed
= 0;
3830 /* Remap devices on Loop. */
3831 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3833 qla2x00_configure_loop(vha
);
3835 } while (!atomic_read(&vha
->loop_down_timer
) &&
3836 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3837 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3842 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3843 return (QLA_FUNCTION_FAILED
);
3846 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3852 * qla2x00_perform_loop_resync
3853 * Description: This function will set the appropriate flags and call
3854 * qla2x00_loop_resync. If successful loop will be resynced
3855 * Arguments : scsi_qla_host_t pointer
3856 * returm : Success or Failure
3859 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
3863 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
3864 /*Configure the flags so that resync happens properly*/
3865 atomic_set(&ha
->loop_down_timer
, 0);
3866 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
3867 atomic_set(&ha
->loop_state
, LOOP_UP
);
3868 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
3869 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
3870 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3872 rval
= qla2x00_loop_resync(ha
);
3874 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
3876 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
3883 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3886 struct scsi_qla_host
*vha
;
3887 struct qla_hw_data
*ha
= base_vha
->hw
;
3888 unsigned long flags
;
3890 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3891 /* Go with deferred removal of rport references. */
3892 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3893 atomic_inc(&vha
->vref_count
);
3894 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3895 if (fcport
->drport
&&
3896 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3897 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3899 qla2x00_rport_del(fcport
);
3901 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3904 atomic_dec(&vha
->vref_count
);
3906 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3910 * qla82xx_quiescent_state_cleanup
3911 * Description: This function will block the new I/Os
3912 * Its not aborting any I/Os as context
3913 * is not destroyed during quiescence
3914 * Arguments: scsi_qla_host_t
3918 qla82xx_quiescent_state_cleanup(scsi_qla_host_t
*vha
)
3920 struct qla_hw_data
*ha
= vha
->hw
;
3921 struct scsi_qla_host
*vp
;
3923 qla_printk(KERN_INFO
, ha
,
3924 "Performing ISP error recovery - ha= %p.\n", ha
);
3926 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3927 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3928 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3929 qla2x00_mark_all_devices_lost(vha
, 0);
3930 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3931 qla2x00_mark_all_devices_lost(vha
, 0);
3933 if (!atomic_read(&vha
->loop_down_timer
))
3934 atomic_set(&vha
->loop_down_timer
,
3937 /* Wait for pending cmds to complete */
3938 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
3942 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3944 struct qla_hw_data
*ha
= vha
->hw
;
3945 struct scsi_qla_host
*vp
;
3946 unsigned long flags
;
3949 /* For ISP82XX, driver waits for completion of the commands.
3950 * online flag should be set.
3952 if (!IS_QLA82XX(ha
))
3953 vha
->flags
.online
= 0;
3954 ha
->flags
.chip_reset_done
= 0;
3955 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3956 ha
->qla_stats
.total_isp_aborts
++;
3958 qla_printk(KERN_INFO
, ha
,
3959 "Performing ISP error recovery - ha= %p.\n", ha
);
3961 /* For ISP82XX, reset_chip is just disabling interrupts.
3962 * Driver waits for the completion of the commands.
3963 * the interrupts need to be enabled.
3965 if (!IS_QLA82XX(ha
))
3966 ha
->isp_ops
->reset_chip(vha
);
3968 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3969 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3970 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3971 qla2x00_mark_all_devices_lost(vha
, 0);
3973 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3974 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3975 atomic_inc(&vp
->vref_count
);
3976 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3978 qla2x00_mark_all_devices_lost(vp
, 0);
3980 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3981 atomic_dec(&vp
->vref_count
);
3983 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3985 if (!atomic_read(&vha
->loop_down_timer
))
3986 atomic_set(&vha
->loop_down_timer
,
3990 /* Clear all async request states across all VPs. */
3991 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3992 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3993 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3994 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3995 atomic_inc(&vp
->vref_count
);
3996 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3998 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
3999 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4001 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4002 atomic_dec(&vp
->vref_count
);
4004 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4006 if (!ha
->flags
.eeh_busy
) {
4007 /* Make sure for ISP 82XX IO DMA is complete */
4008 if (IS_QLA82XX(ha
)) {
4009 qla82xx_chip_reset_cleanup(vha
);
4011 /* Done waiting for pending commands.
4012 * Reset the online flag.
4014 vha
->flags
.online
= 0;
4017 /* Requeue all commands in outstanding command list. */
4018 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
4024 * Resets ISP and aborts all outstanding commands.
4027 * ha = adapter block pointer.
4033 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
4037 struct qla_hw_data
*ha
= vha
->hw
;
4038 struct scsi_qla_host
*vp
;
4039 struct req_que
*req
= ha
->req_q_map
[0];
4040 unsigned long flags
;
4042 if (vha
->flags
.online
) {
4043 qla2x00_abort_isp_cleanup(vha
);
4045 if (unlikely(pci_channel_offline(ha
->pdev
) &&
4046 ha
->flags
.pci_channel_io_perm_failure
)) {
4047 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4052 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
4054 ha
->isp_ops
->nvram_config(vha
);
4056 if (!qla2x00_restart_isp(vha
)) {
4057 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4059 if (!atomic_read(&vha
->loop_down_timer
)) {
4061 * Issue marker command only when we are going
4062 * to start the I/O .
4064 vha
->marker_needed
= 1;
4067 vha
->flags
.online
= 1;
4069 ha
->isp_ops
->enable_intrs(ha
);
4071 ha
->isp_abort_cnt
= 0;
4072 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4075 qla2x00_get_fw_version(vha
,
4076 &ha
->fw_major_version
,
4077 &ha
->fw_minor_version
,
4078 &ha
->fw_subminor_version
,
4079 &ha
->fw_attributes
, &ha
->fw_memory_size
,
4080 ha
->mpi_version
, &ha
->mpi_capabilities
,
4084 ha
->flags
.fce_enabled
= 1;
4086 fce_calc_size(ha
->fce_bufs
));
4087 rval
= qla2x00_enable_fce_trace(vha
,
4088 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
4091 qla_printk(KERN_WARNING
, ha
,
4092 "Unable to reinitialize FCE "
4094 ha
->flags
.fce_enabled
= 0;
4099 memset(ha
->eft
, 0, EFT_SIZE
);
4100 rval
= qla2x00_enable_eft_trace(vha
,
4101 ha
->eft_dma
, EFT_NUM_BUFFERS
);
4103 qla_printk(KERN_WARNING
, ha
,
4104 "Unable to reinitialize EFT "
4108 } else { /* failed the ISP abort */
4109 vha
->flags
.online
= 1;
4110 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
4111 if (ha
->isp_abort_cnt
== 0) {
4112 qla_printk(KERN_WARNING
, ha
,
4113 "ISP error recovery failed - "
4114 "board disabled\n");
4116 * The next call disables the board
4119 ha
->isp_ops
->reset_adapter(vha
);
4120 vha
->flags
.online
= 0;
4121 clear_bit(ISP_ABORT_RETRY
,
4124 } else { /* schedule another ISP abort */
4125 ha
->isp_abort_cnt
--;
4126 DEBUG(printk("qla%ld: ISP abort - "
4127 "retry remaining %d\n",
4128 vha
->host_no
, ha
->isp_abort_cnt
));
4132 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
4133 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4134 "- retrying (%d) more times\n",
4135 vha
->host_no
, ha
->isp_abort_cnt
));
4136 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4144 DEBUG(printk(KERN_INFO
4145 "qla2x00_abort_isp(%ld): succeeded.\n",
4148 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4149 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4151 atomic_inc(&vp
->vref_count
);
4152 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4154 qla2x00_vp_abort_isp(vp
);
4156 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4157 atomic_dec(&vp
->vref_count
);
4160 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4163 qla_printk(KERN_INFO
, ha
,
4164 "qla2x00_abort_isp: **** FAILED ****\n");
4171 * qla2x00_restart_isp
4172 * restarts the ISP after a reset
4175 * ha = adapter block pointer.
4181 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4185 struct qla_hw_data
*ha
= vha
->hw
;
4186 struct req_que
*req
= ha
->req_q_map
[0];
4187 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4189 /* If firmware needs to be loaded */
4190 if (qla2x00_isp_firmware(vha
)) {
4191 vha
->flags
.online
= 0;
4192 status
= ha
->isp_ops
->chip_diag(vha
);
4194 status
= qla2x00_setup_chip(vha
);
4197 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4198 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4199 ha
->flags
.chip_reset_done
= 1;
4200 /* Initialize the queues in use */
4201 qla25xx_init_queues(ha
);
4203 status
= qla2x00_fw_ready(vha
);
4205 DEBUG(printk("%s(): Start configure loop, "
4206 "status = %d\n", __func__
, status
));
4208 /* Issue a marker after FW becomes ready. */
4209 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4211 vha
->flags
.online
= 1;
4212 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4215 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4216 qla2x00_configure_loop(vha
);
4218 } while (!atomic_read(&vha
->loop_down_timer
) &&
4219 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4220 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4224 /* if no cable then assume it's good */
4225 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4228 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4236 qla25xx_init_queues(struct qla_hw_data
*ha
)
4238 struct rsp_que
*rsp
= NULL
;
4239 struct req_que
*req
= NULL
;
4240 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4244 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4245 rsp
= ha
->rsp_q_map
[i
];
4247 rsp
->options
&= ~BIT_0
;
4248 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4249 if (ret
!= QLA_SUCCESS
)
4250 DEBUG2_17(printk(KERN_WARNING
4251 "%s Rsp que:%d init failed\n", __func__
,
4254 DEBUG2_17(printk(KERN_INFO
4255 "%s Rsp que:%d inited\n", __func__
,
4259 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4260 req
= ha
->req_q_map
[i
];
4262 /* Clear outstanding commands array. */
4263 req
->options
&= ~BIT_0
;
4264 ret
= qla25xx_init_req_que(base_vha
, req
);
4265 if (ret
!= QLA_SUCCESS
)
4266 DEBUG2_17(printk(KERN_WARNING
4267 "%s Req que:%d init failed\n", __func__
,
4270 DEBUG2_17(printk(KERN_WARNING
4271 "%s Req que:%d inited\n", __func__
,
4279 * qla2x00_reset_adapter
4283 * ha = adapter block pointer.
4286 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4288 unsigned long flags
= 0;
4289 struct qla_hw_data
*ha
= vha
->hw
;
4290 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4292 vha
->flags
.online
= 0;
4293 ha
->isp_ops
->disable_intrs(ha
);
4295 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4296 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4297 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4298 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4299 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4300 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4304 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4306 unsigned long flags
= 0;
4307 struct qla_hw_data
*ha
= vha
->hw
;
4308 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4313 vha
->flags
.online
= 0;
4314 ha
->isp_ops
->disable_intrs(ha
);
4316 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4317 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4318 RD_REG_DWORD(®
->hccr
);
4319 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4320 RD_REG_DWORD(®
->hccr
);
4321 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4323 if (IS_NOPOLLING_TYPE(ha
))
4324 ha
->isp_ops
->enable_intrs(ha
);
4327 /* On sparc systems, obtain port and node WWN from firmware
4330 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4331 struct nvram_24xx
*nv
)
4334 struct qla_hw_data
*ha
= vha
->hw
;
4335 struct pci_dev
*pdev
= ha
->pdev
;
4336 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4340 val
= of_get_property(dp
, "port-wwn", &len
);
4341 if (val
&& len
>= WWN_SIZE
)
4342 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4344 val
= of_get_property(dp
, "node-wwn", &len
);
4345 if (val
&& len
>= WWN_SIZE
)
4346 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4351 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4354 struct init_cb_24xx
*icb
;
4355 struct nvram_24xx
*nv
;
4357 uint8_t *dptr1
, *dptr2
;
4360 struct qla_hw_data
*ha
= vha
->hw
;
4363 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4366 /* Determine NVRAM starting address. */
4367 if (ha
->flags
.port0
) {
4368 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4369 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4371 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4372 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4374 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4375 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4377 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4379 /* Get VPD data into cache */
4380 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4381 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4382 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4384 /* Get NVRAM data into cache and calculate checksum. */
4385 dptr
= (uint32_t *)nv
;
4386 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4388 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4389 chksum
+= le32_to_cpu(*dptr
++);
4391 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
4392 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
4394 /* Bad NVRAM data, set defaults parameters. */
4395 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4396 || nv
->id
[3] != ' ' ||
4397 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4398 /* Reset NVRAM data. */
4399 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4400 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4401 le16_to_cpu(nv
->nvram_version
));
4402 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4403 "invalid -- WWPN) defaults.\n");
4406 * Set default initialization control block.
4408 memset(nv
, 0, ha
->nvram_size
);
4409 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4410 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4411 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4412 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4413 nv
->exchange_count
= __constant_cpu_to_le16(0);
4414 nv
->hard_address
= __constant_cpu_to_le16(124);
4415 nv
->port_name
[0] = 0x21;
4416 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4417 nv
->port_name
[2] = 0x00;
4418 nv
->port_name
[3] = 0xe0;
4419 nv
->port_name
[4] = 0x8b;
4420 nv
->port_name
[5] = 0x1c;
4421 nv
->port_name
[6] = 0x55;
4422 nv
->port_name
[7] = 0x86;
4423 nv
->node_name
[0] = 0x20;
4424 nv
->node_name
[1] = 0x00;
4425 nv
->node_name
[2] = 0x00;
4426 nv
->node_name
[3] = 0xe0;
4427 nv
->node_name
[4] = 0x8b;
4428 nv
->node_name
[5] = 0x1c;
4429 nv
->node_name
[6] = 0x55;
4430 nv
->node_name
[7] = 0x86;
4431 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4432 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4433 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4434 nv
->login_timeout
= __constant_cpu_to_le16(0);
4435 nv
->firmware_options_1
=
4436 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4437 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4438 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4439 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4440 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4441 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4442 nv
->reset_delay
= 5;
4443 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4444 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4445 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4450 /* Reset Initialization control block */
4451 memset(icb
, 0, ha
->init_cb_size
);
4453 /* Copy 1st segment. */
4454 dptr1
= (uint8_t *)icb
;
4455 dptr2
= (uint8_t *)&nv
->version
;
4456 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4458 *dptr1
++ = *dptr2
++;
4460 icb
->login_retry_count
= nv
->login_retry_count
;
4461 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4463 /* Copy 2nd segment. */
4464 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4465 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4466 cnt
= (uint8_t *)&icb
->reserved_3
-
4467 (uint8_t *)&icb
->interrupt_delay_timer
;
4469 *dptr1
++ = *dptr2
++;
4472 * Setup driver NVRAM options.
4474 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4477 /* Use alternate WWN? */
4478 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4479 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4480 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4483 /* Prepare nodename */
4484 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4486 * Firmware will apply the following mask if the nodename was
4489 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4490 icb
->node_name
[0] &= 0xF0;
4493 /* Set host adapter parameters. */
4494 ha
->flags
.disable_risc_code_load
= 0;
4495 ha
->flags
.enable_lip_reset
= 0;
4496 ha
->flags
.enable_lip_full_login
=
4497 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4498 ha
->flags
.enable_target_reset
=
4499 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4500 ha
->flags
.enable_led_scheme
= 0;
4501 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4503 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4504 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4506 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4507 sizeof(ha
->fw_seriallink_options24
));
4509 /* save HBA serial number */
4510 ha
->serial0
= icb
->port_name
[5];
4511 ha
->serial1
= icb
->port_name
[6];
4512 ha
->serial2
= icb
->port_name
[7];
4513 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4514 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4516 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4518 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4520 /* Set minimum login_timeout to 4 seconds. */
4521 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4522 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4523 if (le16_to_cpu(nv
->login_timeout
) < 4)
4524 nv
->login_timeout
= __constant_cpu_to_le16(4);
4525 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4526 icb
->login_timeout
= nv
->login_timeout
;
4528 /* Set minimum RATOV to 100 tenths of a second. */
4531 ha
->loop_reset_delay
= nv
->reset_delay
;
4533 /* Link Down Timeout = 0:
4535 * When Port Down timer expires we will start returning
4536 * I/O's to OS with "DID_NO_CONNECT".
4538 * Link Down Timeout != 0:
4540 * The driver waits for the link to come up after link down
4541 * before returning I/Os to OS with "DID_NO_CONNECT".
4543 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4544 ha
->loop_down_abort_time
=
4545 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4547 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4548 ha
->loop_down_abort_time
=
4549 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4552 /* Need enough time to try and get the port back. */
4553 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4554 if (qlport_down_retry
)
4555 ha
->port_down_retry_count
= qlport_down_retry
;
4557 /* Set login_retry_count */
4558 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4559 if (ha
->port_down_retry_count
==
4560 le16_to_cpu(nv
->port_down_retry_count
) &&
4561 ha
->port_down_retry_count
> 3)
4562 ha
->login_retry_count
= ha
->port_down_retry_count
;
4563 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4564 ha
->login_retry_count
= ha
->port_down_retry_count
;
4565 if (ql2xloginretrycount
)
4566 ha
->login_retry_count
= ql2xloginretrycount
;
4569 if (!vha
->flags
.init_done
) {
4570 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4571 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4572 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4573 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4575 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4576 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4577 vha
->flags
.process_response_queue
= 0;
4578 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4579 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4581 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4582 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4583 ha
->zio_timer
* 100));
4584 qla_printk(KERN_INFO
, ha
,
4585 "ZIO mode %d enabled; timer delay (%d us).\n",
4586 ha
->zio_mode
, ha
->zio_timer
* 100);
4588 icb
->firmware_options_2
|= cpu_to_le32(
4589 (uint32_t)ha
->zio_mode
);
4590 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4591 vha
->flags
.process_response_queue
= 1;
4595 DEBUG2_3(printk(KERN_WARNING
4596 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4602 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4605 int rval
= QLA_SUCCESS
;
4606 int segments
, fragment
;
4607 uint32_t *dcode
, dlen
;
4611 struct qla_hw_data
*ha
= vha
->hw
;
4612 struct req_que
*req
= ha
->req_q_map
[0];
4614 qla_printk(KERN_INFO
, ha
,
4615 "FW: Loading from flash (%x)...\n", faddr
);
4619 segments
= FA_RISC_CODE_SEGMENTS
;
4620 dcode
= (uint32_t *)req
->ring
;
4623 /* Validate firmware image by checking version. */
4624 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4625 for (i
= 0; i
< 4; i
++)
4626 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4627 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4628 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4629 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4631 qla_printk(KERN_WARNING
, ha
,
4632 "Unable to verify integrity of flash firmware image!\n");
4633 qla_printk(KERN_WARNING
, ha
,
4634 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4635 dcode
[1], dcode
[2], dcode
[3]);
4637 return QLA_FUNCTION_FAILED
;
4640 while (segments
&& rval
== QLA_SUCCESS
) {
4641 /* Read segment's load information. */
4642 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4644 risc_addr
= be32_to_cpu(dcode
[2]);
4645 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4646 risc_size
= be32_to_cpu(dcode
[3]);
4649 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4650 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4651 if (dlen
> risc_size
)
4654 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4655 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4656 vha
->host_no
, risc_addr
, dlen
, faddr
));
4658 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4659 for (i
= 0; i
< dlen
; i
++)
4660 dcode
[i
] = swab32(dcode
[i
]);
4662 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4665 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4666 "segment %d of firmware\n", vha
->host_no
,
4668 qla_printk(KERN_WARNING
, ha
,
4669 "[ERROR] Failed to load segment %d of "
4670 "firmware\n", fragment
);
4687 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4690 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4694 uint16_t *wcode
, *fwcode
;
4695 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4696 struct fw_blob
*blob
;
4697 struct qla_hw_data
*ha
= vha
->hw
;
4698 struct req_que
*req
= ha
->req_q_map
[0];
4700 /* Load firmware blob. */
4701 blob
= qla2x00_request_firmware(vha
);
4703 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4704 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4705 "from: " QLA_FW_URL
".\n");
4706 return QLA_FUNCTION_FAILED
;
4711 wcode
= (uint16_t *)req
->ring
;
4713 fwcode
= (uint16_t *)blob
->fw
->data
;
4716 /* Validate firmware image by checking version. */
4717 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4718 qla_printk(KERN_WARNING
, ha
,
4719 "Unable to verify integrity of firmware image (%Zd)!\n",
4721 goto fail_fw_integrity
;
4723 for (i
= 0; i
< 4; i
++)
4724 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4725 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4726 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4727 wcode
[2] == 0 && wcode
[3] == 0)) {
4728 qla_printk(KERN_WARNING
, ha
,
4729 "Unable to verify integrity of firmware image!\n");
4730 qla_printk(KERN_WARNING
, ha
,
4731 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
4732 wcode
[1], wcode
[2], wcode
[3]);
4733 goto fail_fw_integrity
;
4737 while (*seg
&& rval
== QLA_SUCCESS
) {
4739 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4740 risc_size
= be16_to_cpu(fwcode
[3]);
4742 /* Validate firmware image size. */
4743 fwclen
+= risc_size
* sizeof(uint16_t);
4744 if (blob
->fw
->size
< fwclen
) {
4745 qla_printk(KERN_WARNING
, ha
,
4746 "Unable to verify integrity of firmware image "
4747 "(%Zd)!\n", blob
->fw
->size
);
4748 goto fail_fw_integrity
;
4752 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4753 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4754 if (wlen
> risc_size
)
4757 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4758 "addr %x, number of words 0x%x.\n", vha
->host_no
,
4761 for (i
= 0; i
< wlen
; i
++)
4762 wcode
[i
] = swab16(fwcode
[i
]);
4764 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4767 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4768 "segment %d of firmware\n", vha
->host_no
,
4770 qla_printk(KERN_WARNING
, ha
,
4771 "[ERROR] Failed to load segment %d of "
4772 "firmware\n", fragment
);
4788 return QLA_FUNCTION_FAILED
;
4792 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4795 int segments
, fragment
;
4796 uint32_t *dcode
, dlen
;
4800 struct fw_blob
*blob
;
4801 uint32_t *fwcode
, fwclen
;
4802 struct qla_hw_data
*ha
= vha
->hw
;
4803 struct req_que
*req
= ha
->req_q_map
[0];
4805 /* Load firmware blob. */
4806 blob
= qla2x00_request_firmware(vha
);
4808 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4809 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4810 "from: " QLA_FW_URL
".\n");
4812 return QLA_FUNCTION_FAILED
;
4815 qla_printk(KERN_INFO
, ha
,
4816 "FW: Loading via request-firmware...\n");
4820 segments
= FA_RISC_CODE_SEGMENTS
;
4821 dcode
= (uint32_t *)req
->ring
;
4823 fwcode
= (uint32_t *)blob
->fw
->data
;
4826 /* Validate firmware image by checking version. */
4827 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4828 qla_printk(KERN_WARNING
, ha
,
4829 "Unable to verify integrity of firmware image (%Zd)!\n",
4831 goto fail_fw_integrity
;
4833 for (i
= 0; i
< 4; i
++)
4834 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4835 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4836 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4837 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4839 qla_printk(KERN_WARNING
, ha
,
4840 "Unable to verify integrity of firmware image!\n");
4841 qla_printk(KERN_WARNING
, ha
,
4842 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4843 dcode
[1], dcode
[2], dcode
[3]);
4844 goto fail_fw_integrity
;
4847 while (segments
&& rval
== QLA_SUCCESS
) {
4848 risc_addr
= be32_to_cpu(fwcode
[2]);
4849 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4850 risc_size
= be32_to_cpu(fwcode
[3]);
4852 /* Validate firmware image size. */
4853 fwclen
+= risc_size
* sizeof(uint32_t);
4854 if (blob
->fw
->size
< fwclen
) {
4855 qla_printk(KERN_WARNING
, ha
,
4856 "Unable to verify integrity of firmware image "
4857 "(%Zd)!\n", blob
->fw
->size
);
4859 goto fail_fw_integrity
;
4863 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4864 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4865 if (dlen
> risc_size
)
4868 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4869 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4872 for (i
= 0; i
< dlen
; i
++)
4873 dcode
[i
] = swab32(fwcode
[i
]);
4875 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4878 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4879 "segment %d of firmware\n", vha
->host_no
,
4881 qla_printk(KERN_WARNING
, ha
,
4882 "[ERROR] Failed to load segment %d of "
4883 "firmware\n", fragment
);
4899 return QLA_FUNCTION_FAILED
;
4903 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4907 if (ql2xfwloadbin
== 1)
4908 return qla81xx_load_risc(vha
, srisc_addr
);
4912 * 1) Firmware via request-firmware interface (.bin file).
4913 * 2) Firmware residing in flash.
4915 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4916 if (rval
== QLA_SUCCESS
)
4919 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4920 vha
->hw
->flt_region_fw
);
4924 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4927 struct qla_hw_data
*ha
= vha
->hw
;
4929 if (ql2xfwloadbin
== 2)
4934 * 1) Firmware residing in flash.
4935 * 2) Firmware via request-firmware interface (.bin file).
4936 * 3) Golden-Firmware residing in flash -- limited operation.
4938 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4939 if (rval
== QLA_SUCCESS
)
4943 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4944 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4947 qla_printk(KERN_ERR
, ha
,
4948 "FW: Attempting to fallback to golden firmware...\n");
4949 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4950 if (rval
!= QLA_SUCCESS
)
4953 qla_printk(KERN_ERR
, ha
,
4954 "FW: Please update operational firmware...\n");
4955 ha
->flags
.running_gold_fw
= 1;
4961 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4964 struct qla_hw_data
*ha
= vha
->hw
;
4966 if (ha
->flags
.pci_channel_io_perm_failure
)
4968 if (!IS_FWI2_CAPABLE(ha
))
4970 if (!ha
->fw_major_version
)
4973 ret
= qla2x00_stop_firmware(vha
);
4974 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4975 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4976 ha
->isp_ops
->reset_chip(vha
);
4977 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4979 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4981 qla_printk(KERN_INFO
, ha
,
4982 "Attempting retry of stop-firmware command...\n");
4983 ret
= qla2x00_stop_firmware(vha
);
4988 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4990 int rval
= QLA_SUCCESS
;
4991 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4992 struct qla_hw_data
*ha
= vha
->hw
;
4993 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4994 struct req_que
*req
;
4995 struct rsp_que
*rsp
;
5000 rval
= qla2x00_fw_ready(base_vha
);
5001 if (ha
->flags
.cpu_affinity_enabled
)
5002 req
= ha
->req_q_map
[0];
5007 if (rval
== QLA_SUCCESS
) {
5008 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5009 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5012 vha
->flags
.management_server_logged_in
= 0;
5014 /* Login to SNS first */
5015 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
5016 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
5017 DEBUG15(qla_printk(KERN_INFO
, ha
,
5018 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5019 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
5020 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
5021 return (QLA_FUNCTION_FAILED
);
5024 atomic_set(&vha
->loop_down_timer
, 0);
5025 atomic_set(&vha
->loop_state
, LOOP_UP
);
5026 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5027 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5028 rval
= qla2x00_loop_resync(base_vha
);
5033 /* 84XX Support **************************************************************/
5035 static LIST_HEAD(qla_cs84xx_list
);
5036 static DEFINE_MUTEX(qla_cs84xx_mutex
);
5038 static struct qla_chip_state_84xx
*
5039 qla84xx_get_chip(struct scsi_qla_host
*vha
)
5041 struct qla_chip_state_84xx
*cs84xx
;
5042 struct qla_hw_data
*ha
= vha
->hw
;
5044 mutex_lock(&qla_cs84xx_mutex
);
5046 /* Find any shared 84xx chip. */
5047 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
5048 if (cs84xx
->bus
== ha
->pdev
->bus
) {
5049 kref_get(&cs84xx
->kref
);
5054 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
5058 kref_init(&cs84xx
->kref
);
5059 spin_lock_init(&cs84xx
->access_lock
);
5060 mutex_init(&cs84xx
->fw_update_mutex
);
5061 cs84xx
->bus
= ha
->pdev
->bus
;
5063 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
5065 mutex_unlock(&qla_cs84xx_mutex
);
5070 __qla84xx_chip_release(struct kref
*kref
)
5072 struct qla_chip_state_84xx
*cs84xx
=
5073 container_of(kref
, struct qla_chip_state_84xx
, kref
);
5075 mutex_lock(&qla_cs84xx_mutex
);
5076 list_del(&cs84xx
->list
);
5077 mutex_unlock(&qla_cs84xx_mutex
);
5082 qla84xx_put_chip(struct scsi_qla_host
*vha
)
5084 struct qla_hw_data
*ha
= vha
->hw
;
5086 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
5090 qla84xx_init_chip(scsi_qla_host_t
*vha
)
5094 struct qla_hw_data
*ha
= vha
->hw
;
5096 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
5098 rval
= qla84xx_verify_chip(vha
, status
);
5100 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
5102 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
5106 /* 81XX Support **************************************************************/
5109 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
5112 struct init_cb_81xx
*icb
;
5113 struct nvram_81xx
*nv
;
5115 uint8_t *dptr1
, *dptr2
;
5118 struct qla_hw_data
*ha
= vha
->hw
;
5121 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
5124 /* Determine NVRAM starting address. */
5125 ha
->nvram_size
= sizeof(struct nvram_81xx
);
5126 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
5128 /* Get VPD data into cache */
5129 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
5130 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
5133 /* Get NVRAM data into cache and calculate checksum. */
5134 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
5136 dptr
= (uint32_t *)nv
;
5137 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
5138 chksum
+= le32_to_cpu(*dptr
++);
5140 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
5141 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
5143 /* Bad NVRAM data, set defaults parameters. */
5144 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
5145 || nv
->id
[3] != ' ' ||
5146 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
5147 /* Reset NVRAM data. */
5148 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
5149 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
5150 le16_to_cpu(nv
->nvram_version
));
5151 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
5152 "invalid -- WWPN) defaults.\n");
5155 * Set default initialization control block.
5157 memset(nv
, 0, ha
->nvram_size
);
5158 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5159 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5160 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5161 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5162 nv
->exchange_count
= __constant_cpu_to_le16(0);
5163 nv
->port_name
[0] = 0x21;
5164 nv
->port_name
[1] = 0x00 + ha
->port_no
;
5165 nv
->port_name
[2] = 0x00;
5166 nv
->port_name
[3] = 0xe0;
5167 nv
->port_name
[4] = 0x8b;
5168 nv
->port_name
[5] = 0x1c;
5169 nv
->port_name
[6] = 0x55;
5170 nv
->port_name
[7] = 0x86;
5171 nv
->node_name
[0] = 0x20;
5172 nv
->node_name
[1] = 0x00;
5173 nv
->node_name
[2] = 0x00;
5174 nv
->node_name
[3] = 0xe0;
5175 nv
->node_name
[4] = 0x8b;
5176 nv
->node_name
[5] = 0x1c;
5177 nv
->node_name
[6] = 0x55;
5178 nv
->node_name
[7] = 0x86;
5179 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5180 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5181 nv
->login_timeout
= __constant_cpu_to_le16(0);
5182 nv
->firmware_options_1
=
5183 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5184 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5185 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5186 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5187 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5188 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5189 nv
->reset_delay
= 5;
5190 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5191 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5192 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
5193 nv
->enode_mac
[0] = 0x00;
5194 nv
->enode_mac
[1] = 0x02;
5195 nv
->enode_mac
[2] = 0x03;
5196 nv
->enode_mac
[3] = 0x04;
5197 nv
->enode_mac
[4] = 0x05;
5198 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5203 /* Reset Initialization control block */
5204 memset(icb
, 0, sizeof(struct init_cb_81xx
));
5206 /* Copy 1st segment. */
5207 dptr1
= (uint8_t *)icb
;
5208 dptr2
= (uint8_t *)&nv
->version
;
5209 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5211 *dptr1
++ = *dptr2
++;
5213 icb
->login_retry_count
= nv
->login_retry_count
;
5215 /* Copy 2nd segment. */
5216 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5217 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5218 cnt
= (uint8_t *)&icb
->reserved_5
-
5219 (uint8_t *)&icb
->interrupt_delay_timer
;
5221 *dptr1
++ = *dptr2
++;
5223 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5224 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5225 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5226 icb
->enode_mac
[0] = 0x01;
5227 icb
->enode_mac
[1] = 0x02;
5228 icb
->enode_mac
[2] = 0x03;
5229 icb
->enode_mac
[3] = 0x04;
5230 icb
->enode_mac
[4] = 0x05;
5231 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5234 /* Use extended-initialization control block. */
5235 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5238 * Setup driver NVRAM options.
5240 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5243 /* Use alternate WWN? */
5244 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5245 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5246 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5249 /* Prepare nodename */
5250 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5252 * Firmware will apply the following mask if the nodename was
5255 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5256 icb
->node_name
[0] &= 0xF0;
5259 /* Set host adapter parameters. */
5260 ha
->flags
.disable_risc_code_load
= 0;
5261 ha
->flags
.enable_lip_reset
= 0;
5262 ha
->flags
.enable_lip_full_login
=
5263 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5264 ha
->flags
.enable_target_reset
=
5265 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5266 ha
->flags
.enable_led_scheme
= 0;
5267 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5269 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5270 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5272 /* save HBA serial number */
5273 ha
->serial0
= icb
->port_name
[5];
5274 ha
->serial1
= icb
->port_name
[6];
5275 ha
->serial2
= icb
->port_name
[7];
5276 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5277 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5279 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5281 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5283 /* Set minimum login_timeout to 4 seconds. */
5284 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5285 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5286 if (le16_to_cpu(nv
->login_timeout
) < 4)
5287 nv
->login_timeout
= __constant_cpu_to_le16(4);
5288 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5289 icb
->login_timeout
= nv
->login_timeout
;
5291 /* Set minimum RATOV to 100 tenths of a second. */
5294 ha
->loop_reset_delay
= nv
->reset_delay
;
5296 /* Link Down Timeout = 0:
5298 * When Port Down timer expires we will start returning
5299 * I/O's to OS with "DID_NO_CONNECT".
5301 * Link Down Timeout != 0:
5303 * The driver waits for the link to come up after link down
5304 * before returning I/Os to OS with "DID_NO_CONNECT".
5306 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5307 ha
->loop_down_abort_time
=
5308 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5310 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5311 ha
->loop_down_abort_time
=
5312 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5315 /* Need enough time to try and get the port back. */
5316 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5317 if (qlport_down_retry
)
5318 ha
->port_down_retry_count
= qlport_down_retry
;
5320 /* Set login_retry_count */
5321 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5322 if (ha
->port_down_retry_count
==
5323 le16_to_cpu(nv
->port_down_retry_count
) &&
5324 ha
->port_down_retry_count
> 3)
5325 ha
->login_retry_count
= ha
->port_down_retry_count
;
5326 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5327 ha
->login_retry_count
= ha
->port_down_retry_count
;
5328 if (ql2xloginretrycount
)
5329 ha
->login_retry_count
= ql2xloginretrycount
;
5332 if (!vha
->flags
.init_done
) {
5333 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5334 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5335 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5336 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5338 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5339 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5340 vha
->flags
.process_response_queue
= 0;
5341 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5342 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5344 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5345 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
5346 ha
->zio_timer
* 100));
5347 qla_printk(KERN_INFO
, ha
,
5348 "ZIO mode %d enabled; timer delay (%d us).\n",
5349 ha
->zio_mode
, ha
->zio_timer
* 100);
5351 icb
->firmware_options_2
|= cpu_to_le32(
5352 (uint32_t)ha
->zio_mode
);
5353 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5354 vha
->flags
.process_response_queue
= 1;
5358 DEBUG2_3(printk(KERN_WARNING
5359 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
5365 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5369 struct qla_hw_data
*ha
= vha
->hw
;
5370 struct req_que
*req
= ha
->req_q_map
[0];
5371 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5372 struct scsi_qla_host
*vp
;
5373 unsigned long flags
;
5375 status
= qla2x00_init_rings(vha
);
5377 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5378 ha
->flags
.chip_reset_done
= 1;
5380 status
= qla2x00_fw_ready(vha
);
5382 qla_printk(KERN_INFO
, ha
,
5383 "%s(): Start configure loop, "
5384 "status = %d\n", __func__
, status
);
5386 /* Issue a marker after FW becomes ready. */
5387 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5389 vha
->flags
.online
= 1;
5390 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5393 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5394 qla2x00_configure_loop(vha
);
5396 } while (!atomic_read(&vha
->loop_down_timer
) &&
5397 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5399 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5402 /* if no cable then assume it's good */
5403 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5406 qla_printk(KERN_INFO
, ha
,
5407 "%s(): Configure loop done, status = 0x%x\n",
5412 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5414 if (!atomic_read(&vha
->loop_down_timer
)) {
5416 * Issue marker command only when we are going
5417 * to start the I/O .
5419 vha
->marker_needed
= 1;
5422 vha
->flags
.online
= 1;
5424 ha
->isp_ops
->enable_intrs(ha
);
5426 ha
->isp_abort_cnt
= 0;
5427 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5430 ha
->flags
.fce_enabled
= 1;
5432 fce_calc_size(ha
->fce_bufs
));
5433 rval
= qla2x00_enable_fce_trace(vha
,
5434 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5437 qla_printk(KERN_WARNING
, ha
,
5438 "Unable to reinitialize FCE "
5440 ha
->flags
.fce_enabled
= 0;
5445 memset(ha
->eft
, 0, EFT_SIZE
);
5446 rval
= qla2x00_enable_eft_trace(vha
,
5447 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5449 qla_printk(KERN_WARNING
, ha
,
5450 "Unable to reinitialize EFT "
5457 DEBUG(printk(KERN_INFO
5458 "qla82xx_restart_isp(%ld): succeeded.\n",
5461 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5462 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5464 atomic_inc(&vp
->vref_count
);
5465 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5467 qla2x00_vp_abort_isp(vp
);
5469 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5470 atomic_dec(&vp
->vref_count
);
5473 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5476 qla_printk(KERN_INFO
, ha
,
5477 "qla82xx_restart_isp: **** FAILED ****\n");
5484 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5486 struct qla_hw_data
*ha
= vha
->hw
;
5491 /* Enable ETS Burst. */
5492 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5493 ha
->fw_options
[2] |= BIT_9
;
5494 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5498 * qla24xx_get_fcp_prio
5499 * Gets the fcp cmd priority value for the logged in port.
5500 * Looks for a match of the port descriptors within
5501 * each of the fcp prio config entries. If a match is found,
5502 * the tag (priority) value is returned.
5505 * vha = scsi host structure pointer.
5506 * fcport = port structure pointer.
5509 * non-zero (if found)
5516 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5519 uint8_t pid_match
, wwn_match
;
5521 uint32_t pid1
, pid2
;
5522 uint64_t wwn1
, wwn2
;
5523 struct qla_fcp_prio_entry
*pri_entry
;
5524 struct qla_hw_data
*ha
= vha
->hw
;
5526 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5530 entries
= ha
->fcp_prio_cfg
->num_entries
;
5531 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5533 for (i
= 0; i
< entries
; i
++) {
5534 pid_match
= wwn_match
= 0;
5536 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5541 /* check source pid for a match */
5542 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5543 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5544 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5545 if (pid1
== INVALID_PORT_ID
)
5547 else if (pid1
== pid2
)
5551 /* check destination pid for a match */
5552 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5553 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5554 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5555 if (pid1
== INVALID_PORT_ID
)
5557 else if (pid1
== pid2
)
5561 /* check source WWN for a match */
5562 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5563 wwn1
= wwn_to_u64(vha
->port_name
);
5564 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5565 if (wwn2
== (uint64_t)-1)
5567 else if (wwn1
== wwn2
)
5571 /* check destination WWN for a match */
5572 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5573 wwn1
= wwn_to_u64(fcport
->port_name
);
5574 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5575 if (wwn2
== (uint64_t)-1)
5577 else if (wwn1
== wwn2
)
5581 if (pid_match
== 2 || wwn_match
== 2) {
5582 /* Found a matching entry */
5583 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5584 priority
= pri_entry
->tag
;
5595 * qla24xx_update_fcport_fcp_prio
5596 * Activates fcp priority for the logged in fc port
5599 * vha = scsi host structure pointer.
5600 * fcp = port structure pointer.
5603 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5609 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5615 if (fcport
->port_type
!= FCT_TARGET
||
5616 fcport
->loop_id
== FC_NO_LOOP_ID
)
5617 return QLA_FUNCTION_FAILED
;
5619 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
5621 return QLA_FUNCTION_FAILED
;
5623 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
5624 if (ret
== QLA_SUCCESS
)
5625 fcport
->fcp_prio
= priority
;
5627 DEBUG2(printk(KERN_WARNING
5628 "scsi(%ld): Unable to activate fcp priority, "
5629 " ret=0x%x\n", vha
->host_no
, ret
));
5635 * qla24xx_update_all_fcp_prio
5636 * Activates fcp priority for all the logged in ports
5639 * ha = adapter block pointer.
5642 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5648 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5653 ret
= QLA_FUNCTION_FAILED
;
5654 /* We need to set priority for all logged in ports */
5655 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5656 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);