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_sync(&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 fcport
->flags
|= FCF_ASYNC_SENT
;
390 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
393 qla2x00_update_fcport(vha
, fcport
);
395 case MBS_COMMAND_ERROR
:
396 fcport
->flags
&= ~FCF_ASYNC_SENT
;
397 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
398 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
400 qla2x00_mark_device_lost(vha
, fcport
, 1, 1);
402 case MBS_PORT_ID_USED
:
403 fcport
->loop_id
= data
[1];
404 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
405 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
407 case MBS_LOOP_ID_USED
:
409 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
410 if (rval
!= QLA_SUCCESS
) {
411 fcport
->flags
&= ~FCF_ASYNC_SENT
;
412 qla2x00_mark_device_lost(vha
, fcport
, 1, 1);
415 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
422 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
425 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
430 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
433 if (data
[0] == MBS_COMMAND_COMPLETE
) {
434 qla2x00_update_fcport(vha
, fcport
);
440 fcport
->flags
&= ~FCF_ASYNC_SENT
;
441 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
442 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
444 qla2x00_mark_device_lost(vha
, fcport
, 1, 1);
450 qla2x00_async_tm_cmd_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
451 struct srb_iocb
*iocb
)
457 flags
= iocb
->u
.tmf
.flags
;
458 lun
= (uint16_t)iocb
->u
.tmf
.lun
;
460 /* Issue Marker IOCB */
461 rval
= qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
462 vha
->hw
->rsp_q_map
[0], fcport
->loop_id
, lun
,
463 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
465 if ((rval
!= QLA_SUCCESS
) || iocb
->u
.tmf
.data
) {
466 DEBUG2_3_11(printk(KERN_WARNING
467 "%s(%ld): TM IOCB failed (%x).\n",
468 __func__
, vha
->host_no
, rval
));
474 /****************************************************************************/
475 /* QLogic ISP2x00 Hardware Support Functions. */
476 /****************************************************************************/
479 * qla2x00_initialize_adapter
483 * ha = adapter block pointer.
489 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
492 struct qla_hw_data
*ha
= vha
->hw
;
493 struct req_que
*req
= ha
->req_q_map
[0];
495 /* Clear adapter flags. */
496 vha
->flags
.online
= 0;
497 ha
->flags
.chip_reset_done
= 0;
498 vha
->flags
.reset_active
= 0;
499 ha
->flags
.pci_channel_io_perm_failure
= 0;
500 ha
->flags
.eeh_busy
= 0;
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 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
960 * Returns 0 on success.
963 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
965 unsigned long flags
= 0;
966 struct qla_hw_data
*ha
= vha
->hw
;
967 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
971 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
974 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
975 for (cnt
= 0; cnt
< 30000; cnt
++) {
976 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
982 WRT_REG_DWORD(®
->ctrl_status
,
983 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
984 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
987 /* Wait for firmware to complete NVRAM accesses. */
988 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
989 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
991 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
995 /* Wait for soft-reset to complete. */
996 d2
= RD_REG_DWORD(®
->ctrl_status
);
997 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
999 d2
= RD_REG_DWORD(®
->ctrl_status
);
1003 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
1004 RD_REG_DWORD(®
->hccr
);
1006 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
1007 RD_REG_DWORD(®
->hccr
);
1009 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1010 RD_REG_DWORD(®
->hccr
);
1012 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1013 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1015 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1019 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1021 if (IS_NOPOLLING_TYPE(ha
))
1022 ha
->isp_ops
->enable_intrs(ha
);
1026 * qla24xx_reset_chip() - Reset ISP24xx chip.
1029 * Returns 0 on success.
1032 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1034 struct qla_hw_data
*ha
= vha
->hw
;
1036 if (pci_channel_offline(ha
->pdev
) &&
1037 ha
->flags
.pci_channel_io_perm_failure
) {
1041 ha
->isp_ops
->disable_intrs(ha
);
1043 /* Perform RISC reset. */
1044 qla24xx_reset_risc(vha
);
1048 * qla2x00_chip_diag() - Test chip for proper operation.
1051 * Returns 0 on success.
1054 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1057 struct qla_hw_data
*ha
= vha
->hw
;
1058 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1059 unsigned long flags
= 0;
1063 struct req_que
*req
= ha
->req_q_map
[0];
1065 /* Assume a failed state */
1066 rval
= QLA_FUNCTION_FAILED
;
1068 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
1069 vha
->host_no
, (u_long
)®
->flash_address
));
1071 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1073 /* Reset ISP chip. */
1074 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1077 * We need to have a delay here since the card will not respond while
1078 * in reset causing an MCA on some architectures.
1081 data
= qla2x00_debounce_register(®
->ctrl_status
);
1082 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1084 data
= RD_REG_WORD(®
->ctrl_status
);
1089 goto chip_diag_failed
;
1091 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
1094 /* Reset RISC processor. */
1095 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1096 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1098 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1099 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1100 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1102 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1109 goto chip_diag_failed
;
1111 /* Check product ID of chip */
1112 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha
->host_no
));
1114 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1115 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1116 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1117 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1118 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1119 mb
[3] != PROD_ID_3
) {
1120 qla_printk(KERN_WARNING
, ha
,
1121 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
1123 goto chip_diag_failed
;
1125 ha
->product_id
[0] = mb
[1];
1126 ha
->product_id
[1] = mb
[2];
1127 ha
->product_id
[2] = mb
[3];
1128 ha
->product_id
[3] = mb
[4];
1130 /* Adjust fw RISC transfer size */
1131 if (req
->length
> 1024)
1132 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1134 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1137 if (IS_QLA2200(ha
) &&
1138 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1139 /* Limit firmware transfer size with a 2200A */
1140 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
1143 ha
->device_type
|= DT_ISP2200A
;
1144 ha
->fw_transfer_size
= 128;
1147 /* Wrap Incoming Mailboxes Test. */
1148 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1150 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
1151 rval
= qla2x00_mbx_reg_test(vha
);
1153 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1155 qla_printk(KERN_WARNING
, ha
,
1156 "Failed mailbox send register test\n");
1159 /* Flag a successful rval */
1162 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1166 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
1167 "****\n", vha
->host_no
));
1169 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1175 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1178 * Returns 0 on success.
1181 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1184 struct qla_hw_data
*ha
= vha
->hw
;
1185 struct req_que
*req
= ha
->req_q_map
[0];
1190 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1192 rval
= qla2x00_mbx_reg_test(vha
);
1194 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1196 qla_printk(KERN_WARNING
, ha
,
1197 "Failed mailbox send register test\n");
1199 /* Flag a successful rval */
1207 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1210 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1211 eft_size
, fce_size
, mq_size
;
1214 struct qla_hw_data
*ha
= vha
->hw
;
1215 struct req_que
*req
= ha
->req_q_map
[0];
1216 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1219 qla_printk(KERN_WARNING
, ha
,
1220 "Firmware dump previously allocated.\n");
1225 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1226 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1227 fixed_size
= sizeof(struct qla2100_fw_dump
);
1228 } else if (IS_QLA23XX(ha
)) {
1229 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1230 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1232 } else if (IS_FWI2_CAPABLE(ha
)) {
1234 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1235 else if (IS_QLA25XX(ha
))
1236 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1238 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1239 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1242 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1243 /* Allocate memory for Fibre Channel Event Buffer. */
1244 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1247 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1250 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1251 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
1255 memset(tc
, 0, FCE_SIZE
);
1256 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1257 ha
->fce_mb
, &ha
->fce_bufs
);
1259 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1260 "FCE (%d).\n", rval
);
1261 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1263 ha
->flags
.fce_enabled
= 0;
1267 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
1270 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1271 ha
->flags
.fce_enabled
= 1;
1272 ha
->fce_dma
= tc_dma
;
1275 /* Allocate memory for Extended Trace Buffer. */
1276 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1279 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1280 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
1284 memset(tc
, 0, EFT_SIZE
);
1285 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1287 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1288 "EFT (%d).\n", rval
);
1289 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1294 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
1297 eft_size
= EFT_SIZE
;
1298 ha
->eft_dma
= tc_dma
;
1302 req_q_size
= req
->length
* sizeof(request_t
);
1303 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1305 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1306 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1307 ha
->chain_offset
= dump_size
;
1308 dump_size
+= mq_size
+ fce_size
;
1310 ha
->fw_dump
= vmalloc(dump_size
);
1312 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
1313 "firmware dump!!!\n", dump_size
/ 1024);
1316 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1323 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
1326 ha
->fw_dump_len
= dump_size
;
1327 ha
->fw_dump
->signature
[0] = 'Q';
1328 ha
->fw_dump
->signature
[1] = 'L';
1329 ha
->fw_dump
->signature
[2] = 'G';
1330 ha
->fw_dump
->signature
[3] = 'C';
1331 ha
->fw_dump
->version
= __constant_htonl(1);
1333 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1334 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1335 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1336 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1338 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1339 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1340 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1342 ha
->fw_dump
->header_size
=
1343 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1347 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1349 #define MPS_MASK 0xe0
1353 struct qla_hw_data
*ha
= vha
->hw
;
1355 if (!IS_QLA81XX(vha
->hw
))
1358 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1359 if (rval
!= QLA_SUCCESS
) {
1360 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1361 "Sync-MPI: Unable to acquire semaphore.\n"));
1365 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1366 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1367 if (rval
!= QLA_SUCCESS
) {
1368 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1369 "Sync-MPI: Unable to read sync.\n"));
1374 if (dc
== (dw
& MPS_MASK
))
1379 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1380 if (rval
!= QLA_SUCCESS
) {
1381 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1382 "Sync-MPI: Unable to gain sync.\n"));
1386 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1387 if (rval
!= QLA_SUCCESS
) {
1388 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1389 "Sync-MPI: Unable to release semaphore.\n"));
1397 * qla2x00_setup_chip() - Load and start RISC firmware.
1400 * Returns 0 on success.
1403 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1406 uint32_t srisc_address
= 0;
1407 struct qla_hw_data
*ha
= vha
->hw
;
1408 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1409 unsigned long flags
;
1410 uint16_t fw_major_version
;
1412 if (IS_QLA82XX(ha
)) {
1413 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1414 if (rval
== QLA_SUCCESS
) {
1415 qla2x00_stop_firmware(vha
);
1416 goto enable_82xx_npiv
;
1421 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1422 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1423 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1424 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1425 RD_REG_WORD(®
->hccr
);
1426 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1429 qla81xx_mpi_sync(vha
);
1431 /* Load firmware sequences */
1432 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1433 if (rval
== QLA_SUCCESS
) {
1434 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1435 "code.\n", vha
->host_no
));
1437 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1438 if (rval
== QLA_SUCCESS
) {
1439 /* Start firmware execution. */
1440 DEBUG(printk("scsi(%ld): Checksum OK, start "
1441 "firmware.\n", vha
->host_no
));
1443 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1444 /* Retrieve firmware information. */
1445 if (rval
== QLA_SUCCESS
) {
1447 fw_major_version
= ha
->fw_major_version
;
1448 rval
= qla2x00_get_fw_version(vha
,
1449 &ha
->fw_major_version
,
1450 &ha
->fw_minor_version
,
1451 &ha
->fw_subminor_version
,
1452 &ha
->fw_attributes
, &ha
->fw_memory_size
,
1453 ha
->mpi_version
, &ha
->mpi_capabilities
,
1455 if (rval
!= QLA_SUCCESS
)
1457 ha
->flags
.npiv_supported
= 0;
1458 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1459 (ha
->fw_attributes
& BIT_2
)) {
1460 ha
->flags
.npiv_supported
= 1;
1461 if ((!ha
->max_npiv_vports
) ||
1462 ((ha
->max_npiv_vports
+ 1) %
1463 MIN_MULTI_ID_FABRIC
))
1464 ha
->max_npiv_vports
=
1465 MIN_MULTI_ID_FABRIC
- 1;
1467 qla2x00_get_resource_cnts(vha
, NULL
,
1468 &ha
->fw_xcb_count
, NULL
, NULL
,
1469 &ha
->max_npiv_vports
, NULL
);
1471 if (!fw_major_version
&& ql2xallocfwdump
) {
1472 if (!IS_QLA82XX(ha
))
1473 qla2x00_alloc_fw_dump(vha
);
1477 DEBUG2(printk(KERN_INFO
1478 "scsi(%ld): ISP Firmware failed checksum.\n",
1483 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1484 /* Enable proper parity. */
1485 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1488 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1490 /* SRAM, Instruction RAM and GP RAM parity */
1491 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1492 RD_REG_WORD(®
->hccr
);
1493 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1496 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1499 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1500 if (rval
== QLA_SUCCESS
) {
1501 ha
->flags
.fac_supported
= 1;
1502 ha
->fdt_block_size
= size
<< 2;
1504 qla_printk(KERN_ERR
, ha
,
1505 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1506 ha
->fw_major_version
, ha
->fw_minor_version
,
1507 ha
->fw_subminor_version
);
1512 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1520 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1523 * Beginning of request ring has initialization control block already built
1524 * by nvram config routine.
1526 * Returns 0 on success.
1529 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1534 rsp
->ring_ptr
= rsp
->ring
;
1535 rsp
->ring_index
= 0;
1536 rsp
->status_srb
= NULL
;
1537 pkt
= rsp
->ring_ptr
;
1538 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1539 pkt
->signature
= RESPONSE_PROCESSED
;
1545 * qla2x00_update_fw_options() - Read and process firmware options.
1548 * Returns 0 on success.
1551 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1553 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1554 struct qla_hw_data
*ha
= vha
->hw
;
1556 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1557 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1559 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1562 /* Serial Link options. */
1563 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1565 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1566 sizeof(ha
->fw_seriallink_options
)));
1568 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1569 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1570 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1573 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1574 emphasis
= (ha
->fw_seriallink_options
[2] &
1575 (BIT_4
| BIT_3
)) >> 3;
1576 tx_sens
= ha
->fw_seriallink_options
[0] &
1577 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1578 rx_sens
= (ha
->fw_seriallink_options
[0] &
1579 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1580 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1581 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1584 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1585 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1586 ha
->fw_options
[10] |= BIT_5
|
1587 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1588 (tx_sens
& (BIT_1
| BIT_0
));
1591 swing
= (ha
->fw_seriallink_options
[2] &
1592 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1593 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1594 tx_sens
= ha
->fw_seriallink_options
[1] &
1595 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1596 rx_sens
= (ha
->fw_seriallink_options
[1] &
1597 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1598 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1599 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1602 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1603 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1604 ha
->fw_options
[11] |= BIT_5
|
1605 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1606 (tx_sens
& (BIT_1
| BIT_0
));
1610 /* Return command IOCBs without waiting for an ABTS to complete. */
1611 ha
->fw_options
[3] |= BIT_13
;
1614 if (ha
->flags
.enable_led_scheme
)
1615 ha
->fw_options
[2] |= BIT_12
;
1617 /* Detect ISP6312. */
1619 ha
->fw_options
[2] |= BIT_13
;
1621 /* Update firmware options. */
1622 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1626 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1629 struct qla_hw_data
*ha
= vha
->hw
;
1634 /* Update Serial Link options. */
1635 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1638 rval
= qla2x00_set_serdes_params(vha
,
1639 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1640 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1641 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1642 if (rval
!= QLA_SUCCESS
) {
1643 qla_printk(KERN_WARNING
, ha
,
1644 "Unable to update Serial Link options (%x).\n", rval
);
1649 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1651 struct qla_hw_data
*ha
= vha
->hw
;
1652 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1653 struct req_que
*req
= ha
->req_q_map
[0];
1654 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1656 /* Setup ring parameters in initialization control block. */
1657 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1658 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1659 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1660 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1661 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1662 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1663 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1664 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1666 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1667 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1668 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1669 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1670 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1674 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1676 struct qla_hw_data
*ha
= vha
->hw
;
1677 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1678 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1679 struct qla_msix_entry
*msix
;
1680 struct init_cb_24xx
*icb
;
1682 struct req_que
*req
= ha
->req_q_map
[0];
1683 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1685 /* Setup ring parameters in initialization control block. */
1686 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1687 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1688 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1689 icb
->request_q_length
= cpu_to_le16(req
->length
);
1690 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1691 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1692 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1693 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1694 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1697 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1698 icb
->rid
= __constant_cpu_to_le16(rid
);
1699 if (ha
->flags
.msix_enabled
) {
1700 msix
= &ha
->msix_entries
[1];
1701 DEBUG2_17(printk(KERN_INFO
1702 "Registering vector 0x%x for base que\n", msix
->entry
));
1703 icb
->msix
= cpu_to_le16(msix
->entry
);
1705 /* Use alternate PCI bus number */
1707 icb
->firmware_options_2
|=
1708 __constant_cpu_to_le32(BIT_19
);
1709 /* Use alternate PCI devfn */
1711 icb
->firmware_options_2
|=
1712 __constant_cpu_to_le32(BIT_18
);
1714 /* Use Disable MSIX Handshake mode for capable adapters */
1715 if (IS_MSIX_NACK_CAPABLE(ha
)) {
1716 icb
->firmware_options_2
&=
1717 __constant_cpu_to_le32(~BIT_22
);
1718 ha
->flags
.disable_msix_handshake
= 1;
1719 qla_printk(KERN_INFO
, ha
,
1720 "MSIX Handshake Disable Mode turned on\n");
1722 icb
->firmware_options_2
|=
1723 __constant_cpu_to_le32(BIT_22
);
1725 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1727 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1728 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1729 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1730 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1732 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1733 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1734 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1735 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1738 RD_REG_DWORD(&ioreg
->hccr
);
1742 * qla2x00_init_rings() - Initializes firmware.
1745 * Beginning of request ring has initialization control block already built
1746 * by nvram config routine.
1748 * Returns 0 on success.
1751 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1754 unsigned long flags
= 0;
1756 struct qla_hw_data
*ha
= vha
->hw
;
1757 struct req_que
*req
;
1758 struct rsp_que
*rsp
;
1759 struct scsi_qla_host
*vp
;
1760 struct mid_init_cb_24xx
*mid_init_cb
=
1761 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1763 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1765 /* Clear outstanding commands array. */
1766 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1767 req
= ha
->req_q_map
[que
];
1770 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1771 req
->outstanding_cmds
[cnt
] = NULL
;
1773 req
->current_outstanding_cmd
= 1;
1775 /* Initialize firmware. */
1776 req
->ring_ptr
= req
->ring
;
1777 req
->ring_index
= 0;
1778 req
->cnt
= req
->length
;
1781 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1782 rsp
= ha
->rsp_q_map
[que
];
1785 /* Initialize response queue entries */
1786 qla2x00_init_response_q_entries(rsp
);
1789 spin_lock_irqsave(&ha
->vport_slock
, flags
);
1790 /* Clear RSCN queue. */
1791 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
1792 vp
->rscn_in_ptr
= 0;
1793 vp
->rscn_out_ptr
= 0;
1796 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
1798 ha
->isp_ops
->config_rings(vha
);
1800 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1802 /* Update any ISP specific firmware options before initialization. */
1803 ha
->isp_ops
->update_fw_options(vha
);
1805 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1807 if (ha
->flags
.npiv_supported
) {
1808 if (ha
->operating_mode
== LOOP
)
1809 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1810 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1813 if (IS_FWI2_CAPABLE(ha
)) {
1814 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1815 mid_init_cb
->init_cb
.execution_throttle
=
1816 cpu_to_le16(ha
->fw_xcb_count
);
1819 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1821 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1824 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1832 * qla2x00_fw_ready() - Waits for firmware ready.
1835 * Returns 0 on success.
1838 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1841 unsigned long wtime
, mtime
, cs84xx_time
;
1842 uint16_t min_wait
; /* Minimum wait time if loop is down */
1843 uint16_t wait_time
; /* Wait time if loop is coming ready */
1845 struct qla_hw_data
*ha
= vha
->hw
;
1849 /* 20 seconds for loop down. */
1853 * Firmware should take at most one RATOV to login, plus 5 seconds for
1854 * our own processing.
1856 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1857 wait_time
= min_wait
;
1860 /* Min wait time if loop down */
1861 mtime
= jiffies
+ (min_wait
* HZ
);
1863 /* wait time before firmware ready */
1864 wtime
= jiffies
+ (wait_time
* HZ
);
1866 /* Wait for ISP to finish LIP */
1867 if (!vha
->flags
.init_done
)
1868 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1870 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1874 rval
= qla2x00_get_firmware_state(vha
, state
);
1875 if (rval
== QLA_SUCCESS
) {
1876 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1877 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1879 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1880 DEBUG16(printk("scsi(%ld): fw_state=%x "
1881 "84xx=%x.\n", vha
->host_no
, state
[0],
1883 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1884 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1885 DEBUG16(printk("scsi(%ld): Sending "
1886 "verify iocb.\n", vha
->host_no
));
1888 cs84xx_time
= jiffies
;
1889 rval
= qla84xx_init_chip(vha
);
1890 if (rval
!= QLA_SUCCESS
)
1893 /* Add time taken to initialize. */
1894 cs84xx_time
= jiffies
- cs84xx_time
;
1895 wtime
+= cs84xx_time
;
1896 mtime
+= cs84xx_time
;
1897 DEBUG16(printk("scsi(%ld): Increasing "
1898 "wait time by %ld. New time %ld\n",
1899 vha
->host_no
, cs84xx_time
, wtime
));
1901 } else if (state
[0] == FSTATE_READY
) {
1902 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1905 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1906 &ha
->login_timeout
, &ha
->r_a_tov
);
1912 rval
= QLA_FUNCTION_FAILED
;
1914 if (atomic_read(&vha
->loop_down_timer
) &&
1915 state
[0] != FSTATE_READY
) {
1916 /* Loop down. Timeout on min_wait for states
1917 * other than Wait for Login.
1919 if (time_after_eq(jiffies
, mtime
)) {
1920 qla_printk(KERN_INFO
, ha
,
1921 "Cable is unplugged...\n");
1923 vha
->device_flags
|= DFLG_NO_CABLE
;
1928 /* Mailbox cmd failed. Timeout on min_wait. */
1929 if (time_after_eq(jiffies
, mtime
) ||
1930 (IS_QLA82XX(ha
) && ha
->flags
.fw_hung
))
1934 if (time_after_eq(jiffies
, wtime
))
1937 /* Delay for a while */
1940 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1941 vha
->host_no
, state
[0], jiffies
));
1944 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1945 vha
->host_no
, state
[0], state
[1], state
[2], state
[3], state
[4],
1949 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1957 * qla2x00_configure_hba
1958 * Setup adapter context.
1961 * ha = adapter state pointer.
1970 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1979 char connect_type
[22];
1980 struct qla_hw_data
*ha
= vha
->hw
;
1982 /* Get host addresses. */
1983 rval
= qla2x00_get_adapter_id(vha
,
1984 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1985 if (rval
!= QLA_SUCCESS
) {
1986 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
1987 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1988 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1989 __func__
, vha
->host_no
));
1991 qla_printk(KERN_WARNING
, ha
,
1992 "ERROR -- Unable to get host loop ID.\n");
1993 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1999 qla_printk(KERN_INFO
, ha
,
2000 "Cannot get topology - retrying.\n");
2001 return (QLA_FUNCTION_FAILED
);
2004 vha
->loop_id
= loop_id
;
2007 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2008 ha
->operating_mode
= LOOP
;
2013 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
2015 ha
->current_topology
= ISP_CFG_NL
;
2016 strcpy(connect_type
, "(Loop)");
2020 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
2022 ha
->switch_cap
= sw_cap
;
2023 ha
->current_topology
= ISP_CFG_FL
;
2024 strcpy(connect_type
, "(FL_Port)");
2028 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
2030 ha
->operating_mode
= P2P
;
2031 ha
->current_topology
= ISP_CFG_N
;
2032 strcpy(connect_type
, "(N_Port-to-N_Port)");
2036 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
2038 ha
->switch_cap
= sw_cap
;
2039 ha
->operating_mode
= P2P
;
2040 ha
->current_topology
= ISP_CFG_F
;
2041 strcpy(connect_type
, "(F_Port)");
2045 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2047 vha
->host_no
, topo
));
2048 ha
->current_topology
= ISP_CFG_NL
;
2049 strcpy(connect_type
, "(Loop)");
2053 /* Save Host port and loop ID. */
2054 /* byte order - Big Endian */
2055 vha
->d_id
.b
.domain
= domain
;
2056 vha
->d_id
.b
.area
= area
;
2057 vha
->d_id
.b
.al_pa
= al_pa
;
2059 if (!vha
->flags
.init_done
)
2060 qla_printk(KERN_INFO
, ha
,
2061 "Topology - %s, Host Loop address 0x%x\n",
2062 connect_type
, vha
->loop_id
);
2065 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
2067 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
2074 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2079 struct qla_hw_data
*ha
= vha
->hw
;
2080 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2081 !IS_QLA8XXX_TYPE(ha
);
2083 if (memcmp(model
, BINZERO
, len
) != 0) {
2084 strncpy(ha
->model_number
, model
, len
);
2085 st
= en
= ha
->model_number
;
2088 if (*en
!= 0x20 && *en
!= 0x00)
2093 index
= (ha
->pdev
->subsystem_device
& 0xff);
2095 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2096 index
< QLA_MODEL_NAMES
)
2097 strncpy(ha
->model_desc
,
2098 qla2x00_model_name
[index
* 2 + 1],
2099 sizeof(ha
->model_desc
) - 1);
2101 index
= (ha
->pdev
->subsystem_device
& 0xff);
2103 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2104 index
< QLA_MODEL_NAMES
) {
2105 strcpy(ha
->model_number
,
2106 qla2x00_model_name
[index
* 2]);
2107 strncpy(ha
->model_desc
,
2108 qla2x00_model_name
[index
* 2 + 1],
2109 sizeof(ha
->model_desc
) - 1);
2111 strcpy(ha
->model_number
, def
);
2114 if (IS_FWI2_CAPABLE(ha
))
2115 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2116 sizeof(ha
->model_desc
));
2119 /* On sparc systems, obtain port and node WWN from firmware
2122 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2125 struct qla_hw_data
*ha
= vha
->hw
;
2126 struct pci_dev
*pdev
= ha
->pdev
;
2127 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2131 val
= of_get_property(dp
, "port-wwn", &len
);
2132 if (val
&& len
>= WWN_SIZE
)
2133 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2135 val
= of_get_property(dp
, "node-wwn", &len
);
2136 if (val
&& len
>= WWN_SIZE
)
2137 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2142 * NVRAM configuration for ISP 2xxx
2145 * ha = adapter block pointer.
2148 * initialization control block in response_ring
2149 * host adapters parameters in host adapter block
2155 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2160 uint8_t *dptr1
, *dptr2
;
2161 struct qla_hw_data
*ha
= vha
->hw
;
2162 init_cb_t
*icb
= ha
->init_cb
;
2163 nvram_t
*nv
= ha
->nvram
;
2164 uint8_t *ptr
= ha
->nvram
;
2165 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2169 /* Determine NVRAM starting address. */
2170 ha
->nvram_size
= sizeof(nvram_t
);
2172 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2173 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2174 ha
->nvram_base
= 0x80;
2176 /* Get NVRAM data and calculate checksum. */
2177 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2178 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2181 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
2182 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
2184 /* Bad NVRAM data, set defaults parameters. */
2185 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2186 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2187 /* Reset NVRAM data. */
2188 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
2189 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
2191 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
2192 "invalid -- WWPN) defaults.\n");
2195 * Set default initialization control block.
2197 memset(nv
, 0, ha
->nvram_size
);
2198 nv
->parameter_block_version
= ICB_VERSION
;
2200 if (IS_QLA23XX(ha
)) {
2201 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2202 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2203 nv
->add_firmware_options
[0] = BIT_5
;
2204 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2205 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2206 nv
->special_options
[1] = BIT_7
;
2207 } else if (IS_QLA2200(ha
)) {
2208 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2209 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2210 nv
->add_firmware_options
[0] = BIT_5
;
2211 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2212 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2213 } else if (IS_QLA2100(ha
)) {
2214 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2215 nv
->firmware_options
[1] = BIT_5
;
2216 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2219 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2220 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2221 nv
->retry_count
= 8;
2222 nv
->retry_delay
= 1;
2224 nv
->port_name
[0] = 33;
2225 nv
->port_name
[3] = 224;
2226 nv
->port_name
[4] = 139;
2228 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2230 nv
->login_timeout
= 4;
2233 * Set default host adapter parameters
2235 nv
->host_p
[1] = BIT_2
;
2236 nv
->reset_delay
= 5;
2237 nv
->port_down_retry_count
= 8;
2238 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2239 nv
->link_down_timeout
= 60;
2244 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2246 * The SN2 does not provide BIOS emulation which means you can't change
2247 * potentially bogus BIOS settings. Force the use of default settings
2248 * for link rate and frame size. Hope that the rest of the settings
2251 if (ia64_platform_is("sn2")) {
2252 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2254 nv
->special_options
[1] = BIT_7
;
2258 /* Reset Initialization control block */
2259 memset(icb
, 0, ha
->init_cb_size
);
2262 * Setup driver NVRAM options.
2264 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2265 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2266 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2267 nv
->firmware_options
[1] &= ~BIT_4
;
2269 if (IS_QLA23XX(ha
)) {
2270 nv
->firmware_options
[0] |= BIT_2
;
2271 nv
->firmware_options
[0] &= ~BIT_3
;
2272 nv
->firmware_options
[0] &= ~BIT_6
;
2273 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2275 if (IS_QLA2300(ha
)) {
2276 if (ha
->fb_rev
== FPM_2310
) {
2277 strcpy(ha
->model_number
, "QLA2310");
2279 strcpy(ha
->model_number
, "QLA2300");
2282 qla2x00_set_model_info(vha
, nv
->model_number
,
2283 sizeof(nv
->model_number
), "QLA23xx");
2285 } else if (IS_QLA2200(ha
)) {
2286 nv
->firmware_options
[0] |= BIT_2
;
2288 * 'Point-to-point preferred, else loop' is not a safe
2289 * connection mode setting.
2291 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2293 /* Force 'loop preferred, else point-to-point'. */
2294 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2295 nv
->add_firmware_options
[0] |= BIT_5
;
2297 strcpy(ha
->model_number
, "QLA22xx");
2298 } else /*if (IS_QLA2100(ha))*/ {
2299 strcpy(ha
->model_number
, "QLA2100");
2303 * Copy over NVRAM RISC parameter block to initialization control block.
2305 dptr1
= (uint8_t *)icb
;
2306 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2307 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2309 *dptr1
++ = *dptr2
++;
2311 /* Copy 2nd half. */
2312 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2313 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2315 *dptr1
++ = *dptr2
++;
2317 /* Use alternate WWN? */
2318 if (nv
->host_p
[1] & BIT_7
) {
2319 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2320 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2323 /* Prepare nodename */
2324 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2326 * Firmware will apply the following mask if the nodename was
2329 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2330 icb
->node_name
[0] &= 0xF0;
2334 * Set host adapter parameters.
2336 if (nv
->host_p
[0] & BIT_7
)
2337 ql2xextended_error_logging
= 1;
2338 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2339 /* Always load RISC code on non ISP2[12]00 chips. */
2340 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2341 ha
->flags
.disable_risc_code_load
= 0;
2342 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2343 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2344 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2345 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2346 ha
->flags
.disable_serdes
= 0;
2348 ha
->operating_mode
=
2349 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2351 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2352 sizeof(ha
->fw_seriallink_options
));
2354 /* save HBA serial number */
2355 ha
->serial0
= icb
->port_name
[5];
2356 ha
->serial1
= icb
->port_name
[6];
2357 ha
->serial2
= icb
->port_name
[7];
2358 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2359 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2361 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2363 ha
->retry_count
= nv
->retry_count
;
2365 /* Set minimum login_timeout to 4 seconds. */
2366 if (nv
->login_timeout
!= ql2xlogintimeout
)
2367 nv
->login_timeout
= ql2xlogintimeout
;
2368 if (nv
->login_timeout
< 4)
2369 nv
->login_timeout
= 4;
2370 ha
->login_timeout
= nv
->login_timeout
;
2371 icb
->login_timeout
= nv
->login_timeout
;
2373 /* Set minimum RATOV to 100 tenths of a second. */
2376 ha
->loop_reset_delay
= nv
->reset_delay
;
2378 /* Link Down Timeout = 0:
2380 * When Port Down timer expires we will start returning
2381 * I/O's to OS with "DID_NO_CONNECT".
2383 * Link Down Timeout != 0:
2385 * The driver waits for the link to come up after link down
2386 * before returning I/Os to OS with "DID_NO_CONNECT".
2388 if (nv
->link_down_timeout
== 0) {
2389 ha
->loop_down_abort_time
=
2390 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2392 ha
->link_down_timeout
= nv
->link_down_timeout
;
2393 ha
->loop_down_abort_time
=
2394 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2398 * Need enough time to try and get the port back.
2400 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2401 if (qlport_down_retry
)
2402 ha
->port_down_retry_count
= qlport_down_retry
;
2403 /* Set login_retry_count */
2404 ha
->login_retry_count
= nv
->retry_count
;
2405 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2406 ha
->port_down_retry_count
> 3)
2407 ha
->login_retry_count
= ha
->port_down_retry_count
;
2408 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2409 ha
->login_retry_count
= ha
->port_down_retry_count
;
2410 if (ql2xloginretrycount
)
2411 ha
->login_retry_count
= ql2xloginretrycount
;
2413 icb
->lun_enables
= __constant_cpu_to_le16(0);
2414 icb
->command_resource_count
= 0;
2415 icb
->immediate_notify_resource_count
= 0;
2416 icb
->timeout
= __constant_cpu_to_le16(0);
2418 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2420 icb
->firmware_options
[0] &= ~BIT_3
;
2421 icb
->add_firmware_options
[0] &=
2422 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2423 icb
->add_firmware_options
[0] |= BIT_2
;
2424 icb
->response_accumulation_timer
= 3;
2425 icb
->interrupt_delay_timer
= 5;
2427 vha
->flags
.process_response_queue
= 1;
2430 if (!vha
->flags
.init_done
) {
2431 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2432 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2433 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2434 icb
->interrupt_delay_timer
: 2;
2436 icb
->add_firmware_options
[0] &=
2437 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2438 vha
->flags
.process_response_queue
= 0;
2439 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2440 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2442 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2443 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
2444 ha
->zio_timer
* 100));
2445 qla_printk(KERN_INFO
, ha
,
2446 "ZIO mode %d enabled; timer delay (%d us).\n",
2447 ha
->zio_mode
, ha
->zio_timer
* 100);
2449 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2450 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2451 vha
->flags
.process_response_queue
= 1;
2456 DEBUG2_3(printk(KERN_WARNING
2457 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
2463 qla2x00_rport_del(void *data
)
2465 fc_port_t
*fcport
= data
;
2466 struct fc_rport
*rport
;
2468 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2469 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2470 fcport
->drport
= NULL
;
2471 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2473 fc_remote_port_delete(rport
);
2477 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2479 * @flags: allocation flags
2481 * Returns a pointer to the allocated fcport, or NULL, if none available.
2484 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2488 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2492 /* Setup fcport template structure. */
2494 fcport
->vp_idx
= vha
->vp_idx
;
2495 fcport
->port_type
= FCT_UNKNOWN
;
2496 fcport
->loop_id
= FC_NO_LOOP_ID
;
2497 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
2498 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2504 * qla2x00_configure_loop
2505 * Updates Fibre Channel Device Database with what is actually on loop.
2508 * ha = adapter block pointer.
2513 * 2 = database was full and device was not configured.
2516 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2519 unsigned long flags
, save_flags
;
2520 struct qla_hw_data
*ha
= vha
->hw
;
2523 /* Get Initiator ID */
2524 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2525 rval
= qla2x00_configure_hba(vha
);
2526 if (rval
!= QLA_SUCCESS
) {
2527 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2533 save_flags
= flags
= vha
->dpc_flags
;
2534 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2535 vha
->host_no
, flags
));
2538 * If we have both an RSCN and PORT UPDATE pending then handle them
2539 * both at the same time.
2541 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2542 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2544 qla2x00_get_data_rate(vha
);
2546 /* Determine what we need to do */
2547 if (ha
->current_topology
== ISP_CFG_FL
&&
2548 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2550 vha
->flags
.rscn_queue_overflow
= 1;
2551 set_bit(RSCN_UPDATE
, &flags
);
2553 } else if (ha
->current_topology
== ISP_CFG_F
&&
2554 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2556 vha
->flags
.rscn_queue_overflow
= 1;
2557 set_bit(RSCN_UPDATE
, &flags
);
2558 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2560 } else if (ha
->current_topology
== ISP_CFG_N
) {
2561 clear_bit(RSCN_UPDATE
, &flags
);
2563 } else if (!vha
->flags
.online
||
2564 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2566 vha
->flags
.rscn_queue_overflow
= 1;
2567 set_bit(RSCN_UPDATE
, &flags
);
2568 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2571 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2572 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2573 rval
= QLA_FUNCTION_FAILED
;
2575 rval
= qla2x00_configure_local_loop(vha
);
2578 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2579 if (LOOP_TRANSITION(vha
))
2580 rval
= QLA_FUNCTION_FAILED
;
2582 rval
= qla2x00_configure_fabric(vha
);
2585 if (rval
== QLA_SUCCESS
) {
2586 if (atomic_read(&vha
->loop_down_timer
) ||
2587 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2588 rval
= QLA_FUNCTION_FAILED
;
2590 atomic_set(&vha
->loop_state
, LOOP_READY
);
2592 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2597 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2598 __func__
, vha
->host_no
));
2600 DEBUG3(printk("%s: exiting normally\n", __func__
));
2603 /* Restore state if a resync event occurred during processing */
2604 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2605 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2606 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2607 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2608 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2609 if (!IS_ALOGIO_CAPABLE(ha
))
2610 vha
->flags
.rscn_queue_overflow
= 1;
2620 * qla2x00_configure_local_loop
2621 * Updates Fibre Channel Device Database with local loop devices.
2624 * ha = adapter block pointer.
2630 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2635 fc_port_t
*fcport
, *new_fcport
;
2641 uint8_t domain
, area
, al_pa
;
2642 struct qla_hw_data
*ha
= vha
->hw
;
2646 entries
= MAX_FIBRE_DEVICES
;
2648 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2649 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2651 /* Get list of logged in devices. */
2652 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2653 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2655 if (rval
!= QLA_SUCCESS
)
2656 goto cleanup_allocation
;
2658 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2659 vha
->host_no
, entries
));
2660 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2661 entries
* sizeof(struct gid_list_info
)));
2663 /* Allocate temporary fcport for any new fcports discovered. */
2664 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2665 if (new_fcport
== NULL
) {
2666 rval
= QLA_MEMORY_ALLOC_FAILED
;
2667 goto cleanup_allocation
;
2669 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2672 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2674 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2675 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2676 fcport
->port_type
!= FCT_BROADCAST
&&
2677 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2679 DEBUG(printk("scsi(%ld): Marking port lost, "
2681 vha
->host_no
, fcport
->loop_id
));
2683 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2687 /* Add devices to port list. */
2688 id_iter
= (char *)ha
->gid_list
;
2689 for (index
= 0; index
< entries
; index
++) {
2690 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2691 area
= ((struct gid_list_info
*)id_iter
)->area
;
2692 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2693 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2694 loop_id
= (uint16_t)
2695 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2697 loop_id
= le16_to_cpu(
2698 ((struct gid_list_info
*)id_iter
)->loop_id
);
2699 id_iter
+= ha
->gid_list_info_size
;
2701 /* Bypass reserved domain fields. */
2702 if ((domain
& 0xf0) == 0xf0)
2705 /* Bypass if not same domain and area of adapter. */
2706 if (area
&& domain
&&
2707 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2710 /* Bypass invalid local loop ID. */
2711 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2714 /* Fill in member data. */
2715 new_fcport
->d_id
.b
.domain
= domain
;
2716 new_fcport
->d_id
.b
.area
= area
;
2717 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2718 new_fcport
->loop_id
= loop_id
;
2719 new_fcport
->vp_idx
= vha
->vp_idx
;
2720 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2721 if (rval2
!= QLA_SUCCESS
) {
2722 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2723 "information -- get_port_database=%x, "
2725 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2726 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2728 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2732 /* Check for matching device in port list. */
2735 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2736 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2740 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2741 fcport
->loop_id
= new_fcport
->loop_id
;
2742 fcport
->port_type
= new_fcport
->port_type
;
2743 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2744 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2752 /* New device, add to fcports list. */
2754 new_fcport
->vha
= vha
;
2755 new_fcport
->vp_idx
= vha
->vp_idx
;
2757 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2759 /* Allocate a new replacement fcport. */
2760 fcport
= new_fcport
;
2761 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2762 if (new_fcport
== NULL
) {
2763 rval
= QLA_MEMORY_ALLOC_FAILED
;
2764 goto cleanup_allocation
;
2766 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2769 /* Base iIDMA settings on HBA port speed. */
2770 fcport
->fp_speed
= ha
->link_data_rate
;
2772 qla2x00_update_fcport(vha
, fcport
);
2780 if (rval
!= QLA_SUCCESS
) {
2781 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2782 "rval=%x\n", vha
->host_no
, rval
));
2789 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2791 #define LS_UNKNOWN 2
2792 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
2796 struct qla_hw_data
*ha
= vha
->hw
;
2798 if (!IS_IIDMA_CAPABLE(ha
))
2801 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2802 fcport
->fp_speed
> ha
->link_data_rate
)
2805 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2807 if (rval
!= QLA_SUCCESS
) {
2808 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2809 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2810 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2811 fcport
->port_name
[2], fcport
->port_name
[3],
2812 fcport
->port_name
[4], fcport
->port_name
[5],
2813 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2814 fcport
->fp_speed
, mb
[0], mb
[1]));
2816 link_speed
= link_speeds
[LS_UNKNOWN
];
2817 if (fcport
->fp_speed
< 5)
2818 link_speed
= link_speeds
[fcport
->fp_speed
];
2819 else if (fcport
->fp_speed
== 0x13)
2820 link_speed
= link_speeds
[5];
2821 DEBUG2(qla_printk(KERN_INFO
, ha
,
2822 "iIDMA adjusted to %s GB/s on "
2823 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2824 link_speed
, fcport
->port_name
[0],
2825 fcport
->port_name
[1], fcport
->port_name
[2],
2826 fcport
->port_name
[3], fcport
->port_name
[4],
2827 fcport
->port_name
[5], fcport
->port_name
[6],
2828 fcport
->port_name
[7]));
2833 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2835 struct fc_rport_identifiers rport_ids
;
2836 struct fc_rport
*rport
;
2837 struct qla_hw_data
*ha
= vha
->hw
;
2839 qla2x00_rport_del(fcport
);
2841 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2842 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2843 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2844 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2845 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2846 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2848 qla_printk(KERN_WARNING
, ha
,
2849 "Unable to allocate fc remote port!\n");
2852 spin_lock_irq(fcport
->vha
->host
->host_lock
);
2853 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2854 spin_unlock_irq(fcport
->vha
->host
->host_lock
);
2856 rport
->supported_classes
= fcport
->supported_classes
;
2858 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2859 if (fcport
->port_type
== FCT_INITIATOR
)
2860 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2861 if (fcport
->port_type
== FCT_TARGET
)
2862 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2863 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2867 * qla2x00_update_fcport
2868 * Updates device on list.
2871 * ha = adapter block pointer.
2872 * fcport = port structure pointer.
2882 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2884 struct qla_hw_data
*ha
= vha
->hw
;
2887 fcport
->login_retry
= 0;
2888 fcport
->port_login_retry_count
= ha
->port_down_retry_count
*
2890 atomic_set(&fcport
->port_down_timer
, ha
->port_down_retry_count
*
2892 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
2894 qla2x00_iidma_fcport(vha
, fcport
);
2896 atomic_set(&fcport
->state
, FCS_ONLINE
);
2898 qla2x00_reg_remote_port(vha
, fcport
);
2902 * qla2x00_configure_fabric
2903 * Setup SNS devices with loop ID's.
2906 * ha = adapter block pointer.
2913 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2916 fc_port_t
*fcport
, *fcptemp
;
2917 uint16_t next_loopid
;
2918 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2920 LIST_HEAD(new_fcports
);
2921 struct qla_hw_data
*ha
= vha
->hw
;
2922 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2924 /* If FL port exists, then SNS is present */
2925 if (IS_FWI2_CAPABLE(ha
))
2926 loop_id
= NPH_F_PORT
;
2928 loop_id
= SNS_FL_PORT
;
2929 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2930 if (rval
!= QLA_SUCCESS
) {
2931 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2932 "Port\n", vha
->host_no
));
2934 vha
->device_flags
&= ~SWITCH_FOUND
;
2935 return (QLA_SUCCESS
);
2937 vha
->device_flags
|= SWITCH_FOUND
;
2939 /* Mark devices that need re-synchronization. */
2940 rval2
= qla2x00_device_resync(vha
);
2941 if (rval2
== QLA_RSCNS_HANDLED
) {
2942 /* No point doing the scan, just continue. */
2943 return (QLA_SUCCESS
);
2947 if (ql2xfdmienable
&&
2948 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2949 qla2x00_fdmi_register(vha
);
2951 /* Ensure we are logged into the SNS. */
2952 if (IS_FWI2_CAPABLE(ha
))
2955 loop_id
= SIMPLE_NAME_SERVER
;
2956 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2957 0xfc, mb
, BIT_1
| BIT_0
);
2958 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2959 DEBUG2(qla_printk(KERN_INFO
, ha
,
2960 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2961 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2962 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2963 return (QLA_SUCCESS
);
2966 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
2967 if (qla2x00_rft_id(vha
)) {
2969 DEBUG2(printk("scsi(%ld): Register FC-4 "
2970 "TYPE failed.\n", vha
->host_no
));
2972 if (qla2x00_rff_id(vha
)) {
2974 DEBUG2(printk("scsi(%ld): Register FC-4 "
2975 "Features failed.\n", vha
->host_no
));
2977 if (qla2x00_rnn_id(vha
)) {
2979 DEBUG2(printk("scsi(%ld): Register Node Name "
2980 "failed.\n", vha
->host_no
));
2981 } else if (qla2x00_rsnn_nn(vha
)) {
2983 DEBUG2(printk("scsi(%ld): Register Symbolic "
2984 "Node Name failed.\n", vha
->host_no
));
2988 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
2989 if (rval
!= QLA_SUCCESS
)
2993 * Logout all previous fabric devices marked lost, except
2996 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2997 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3000 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3003 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
3004 qla2x00_mark_device_lost(vha
, fcport
,
3005 ql2xplogiabsentdevice
, 0);
3006 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3007 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3008 fcport
->port_type
!= FCT_INITIATOR
&&
3009 fcport
->port_type
!= FCT_BROADCAST
) {
3010 ha
->isp_ops
->fabric_logout(vha
,
3012 fcport
->d_id
.b
.domain
,
3013 fcport
->d_id
.b
.area
,
3014 fcport
->d_id
.b
.al_pa
);
3015 fcport
->loop_id
= FC_NO_LOOP_ID
;
3020 /* Starting free loop ID. */
3021 next_loopid
= ha
->min_external_loopid
;
3024 * Scan through our port list and login entries that need to be
3027 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3028 if (atomic_read(&vha
->loop_down_timer
) ||
3029 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3032 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3033 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
3036 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3037 fcport
->loop_id
= next_loopid
;
3038 rval
= qla2x00_find_new_loop_id(
3040 if (rval
!= QLA_SUCCESS
) {
3041 /* Ran out of IDs to use */
3045 /* Login and update database */
3046 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3049 /* Exit if out of loop IDs. */
3050 if (rval
!= QLA_SUCCESS
) {
3055 * Login and add the new devices to our port list.
3057 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3058 if (atomic_read(&vha
->loop_down_timer
) ||
3059 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3062 /* Find a new loop ID to use. */
3063 fcport
->loop_id
= next_loopid
;
3064 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
3065 if (rval
!= QLA_SUCCESS
) {
3066 /* Ran out of IDs to use */
3070 /* Login and update database */
3071 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3075 fcport
->vp_idx
= vha
->vp_idx
;
3077 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
3081 /* Free all new device structures not processed. */
3082 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3083 list_del(&fcport
->list
);
3088 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
3089 "rval=%d\n", vha
->host_no
, rval
));
3096 * qla2x00_find_all_fabric_devs
3099 * ha = adapter block pointer.
3100 * dev = database device entry pointer.
3109 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3110 struct list_head
*new_fcports
)
3114 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3119 int first_dev
, last_dev
;
3120 port_id_t wrap
= {}, nxt_d_id
;
3121 struct qla_hw_data
*ha
= vha
->hw
;
3122 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3123 struct scsi_qla_host
*tvp
;
3127 /* Try GID_PT to get device list, else GAN. */
3128 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
3131 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
3132 "on GA_NXT\n", vha
->host_no
));
3134 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3137 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3140 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3143 } else if (ql2xiidmaenable
&&
3144 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3145 qla2x00_gpsc(vha
, swl
);
3148 /* If other queries succeeded probe for FC-4 type */
3150 qla2x00_gff_id(vha
, swl
);
3154 /* Allocate temporary fcport for any new fcports discovered. */
3155 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3156 if (new_fcport
== NULL
) {
3158 return (QLA_MEMORY_ALLOC_FAILED
);
3160 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3161 /* Set start port ID scan at adapter ID. */
3165 /* Starting free loop ID. */
3166 loop_id
= ha
->min_external_loopid
;
3167 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3168 if (qla2x00_is_reserved_id(vha
, loop_id
))
3171 if (ha
->current_topology
== ISP_CFG_FL
&&
3172 (atomic_read(&vha
->loop_down_timer
) ||
3173 LOOP_TRANSITION(vha
))) {
3174 atomic_set(&vha
->loop_down_timer
, 0);
3175 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3176 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3182 wrap
.b24
= new_fcport
->d_id
.b24
;
3184 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3185 memcpy(new_fcport
->node_name
,
3186 swl
[swl_idx
].node_name
, WWN_SIZE
);
3187 memcpy(new_fcport
->port_name
,
3188 swl
[swl_idx
].port_name
, WWN_SIZE
);
3189 memcpy(new_fcport
->fabric_port_name
,
3190 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3191 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3192 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3194 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3200 /* Send GA_NXT to the switch */
3201 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3202 if (rval
!= QLA_SUCCESS
) {
3203 qla_printk(KERN_WARNING
, ha
,
3204 "SNS scan failed -- assuming zero-entry "
3206 list_for_each_entry_safe(fcport
, fcptemp
,
3207 new_fcports
, list
) {
3208 list_del(&fcport
->list
);
3216 /* If wrap on switch device list, exit. */
3218 wrap
.b24
= new_fcport
->d_id
.b24
;
3220 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3221 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
3222 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
3223 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
3227 /* Bypass if same physical adapter. */
3228 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3231 /* Bypass virtual ports of the same host. */
3233 if (ha
->num_vhosts
) {
3234 unsigned long flags
;
3236 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3237 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3238 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3243 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3249 /* Bypass if same domain and area of adapter. */
3250 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3251 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3255 /* Bypass reserved domain fields. */
3256 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3259 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3260 if (ql2xgffidenable
&&
3261 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3262 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3265 /* Locate matching device in database. */
3267 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3268 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3274 /* Update port state. */
3275 memcpy(fcport
->fabric_port_name
,
3276 new_fcport
->fabric_port_name
, WWN_SIZE
);
3277 fcport
->fp_speed
= new_fcport
->fp_speed
;
3280 * If address the same and state FCS_ONLINE, nothing
3283 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3284 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3289 * If device was not a fabric device before.
3291 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3292 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3293 fcport
->loop_id
= FC_NO_LOOP_ID
;
3294 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3300 * Port ID changed or device was marked to be updated;
3301 * Log it out if still logged in and mark it for
3304 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3305 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3306 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3307 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3308 fcport
->port_type
!= FCT_INITIATOR
&&
3309 fcport
->port_type
!= FCT_BROADCAST
) {
3310 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3311 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3312 fcport
->d_id
.b
.al_pa
);
3313 fcport
->loop_id
= FC_NO_LOOP_ID
;
3321 /* If device was not in our fcports list, then add it. */
3322 list_add_tail(&new_fcport
->list
, new_fcports
);
3324 /* Allocate a new replacement fcport. */
3325 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3326 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3327 if (new_fcport
== NULL
) {
3329 return (QLA_MEMORY_ALLOC_FAILED
);
3331 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3332 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3342 * qla2x00_find_new_loop_id
3343 * Scan through our port list and find a new usable loop ID.
3346 * ha: adapter state pointer.
3347 * dev: port structure pointer.
3350 * qla2x00 local function return status code.
3356 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3361 uint16_t first_loop_id
;
3362 struct qla_hw_data
*ha
= vha
->hw
;
3363 struct scsi_qla_host
*vp
;
3364 struct scsi_qla_host
*tvp
;
3365 unsigned long flags
= 0;
3369 /* Save starting loop ID. */
3370 first_loop_id
= dev
->loop_id
;
3373 /* Skip loop ID if already used by adapter. */
3374 if (dev
->loop_id
== vha
->loop_id
)
3377 /* Skip reserved loop IDs. */
3378 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3381 /* Reset loop ID if passed the end. */
3382 if (dev
->loop_id
> ha
->max_loop_id
) {
3383 /* first loop ID. */
3384 dev
->loop_id
= ha
->min_external_loopid
;
3387 /* Check for loop ID being already in use. */
3391 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3392 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3393 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3394 if (fcport
->loop_id
== dev
->loop_id
&&
3396 /* ID possibly in use */
3404 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3406 /* If not in use then it is free to use. */
3411 /* ID in use. Try next value. */
3414 /* If wrap around. No free ID to use. */
3415 if (dev
->loop_id
== first_loop_id
) {
3416 dev
->loop_id
= FC_NO_LOOP_ID
;
3417 rval
= QLA_FUNCTION_FAILED
;
3426 * qla2x00_device_resync
3427 * Marks devices in the database that needs resynchronization.
3430 * ha = adapter block pointer.
3436 qla2x00_device_resync(scsi_qla_host_t
*vha
)
3441 uint32_t rscn_entry
;
3442 uint8_t rscn_out_iter
;
3444 port_id_t d_id
= {};
3446 rval
= QLA_RSCNS_HANDLED
;
3448 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
3449 vha
->flags
.rscn_queue_overflow
) {
3451 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
3452 format
= MSB(MSW(rscn_entry
));
3453 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
3454 d_id
.b
.area
= MSB(LSW(rscn_entry
));
3455 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
3457 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3458 "[%02x/%02x%02x%02x].\n",
3459 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
3460 d_id
.b
.area
, d_id
.b
.al_pa
));
3462 vha
->rscn_out_ptr
++;
3463 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
3464 vha
->rscn_out_ptr
= 0;
3466 /* Skip duplicate entries. */
3467 for (rscn_out_iter
= vha
->rscn_out_ptr
;
3468 !vha
->flags
.rscn_queue_overflow
&&
3469 rscn_out_iter
!= vha
->rscn_in_ptr
;
3470 rscn_out_iter
= (rscn_out_iter
==
3471 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
3473 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
3476 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3477 "entry found at [%d].\n", vha
->host_no
,
3480 vha
->rscn_out_ptr
= rscn_out_iter
;
3483 /* Queue overflow, set switch default case. */
3484 if (vha
->flags
.rscn_queue_overflow
) {
3485 DEBUG(printk("scsi(%ld): device_resync: rscn "
3486 "overflow.\n", vha
->host_no
));
3489 vha
->flags
.rscn_queue_overflow
= 0;
3505 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
3511 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3512 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3513 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
3514 fcport
->port_type
== FCT_BROADCAST
)
3517 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3519 fcport
->port_type
!= FCT_INITIATOR
) {
3520 qla2x00_mark_device_lost(vha
, fcport
,
3530 * qla2x00_fabric_dev_login
3531 * Login fabric target device and update FC port database.
3534 * ha: adapter state pointer.
3535 * fcport: port structure list pointer.
3536 * next_loopid: contains value of a new loop ID that can be used
3537 * by the next login attempt.
3540 * qla2x00 local function return status code.
3546 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3547 uint16_t *next_loopid
)
3552 struct qla_hw_data
*ha
= vha
->hw
;
3557 if (IS_ALOGIO_CAPABLE(ha
)) {
3558 if (fcport
->flags
& FCF_ASYNC_SENT
)
3560 fcport
->flags
|= FCF_ASYNC_SENT
;
3561 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3566 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3567 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3568 if (rval
== QLA_SUCCESS
) {
3569 /* Send an ADISC to FCP2 devices.*/
3571 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3573 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3574 if (rval
!= QLA_SUCCESS
) {
3575 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3576 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3577 fcport
->d_id
.b
.al_pa
);
3578 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3580 qla2x00_update_fcport(vha
, fcport
);
3588 * qla2x00_fabric_login
3589 * Issue fabric login command.
3592 * ha = adapter block pointer.
3593 * device = pointer to FC device type structure.
3596 * 0 - Login successfully
3598 * 2 - Initiator device
3602 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3603 uint16_t *next_loopid
)
3607 uint16_t tmp_loopid
;
3608 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3609 struct qla_hw_data
*ha
= vha
->hw
;
3615 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3616 "for port %02x%02x%02x.\n",
3617 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3618 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3620 /* Login fcport on switch. */
3621 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3622 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3623 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3624 if (mb
[0] == MBS_PORT_ID_USED
) {
3626 * Device has another loop ID. The firmware team
3627 * recommends the driver perform an implicit login with
3628 * the specified ID again. The ID we just used is save
3629 * here so we return with an ID that can be tried by
3633 tmp_loopid
= fcport
->loop_id
;
3634 fcport
->loop_id
= mb
[1];
3636 DEBUG(printk("Fabric Login: port in use - next "
3637 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3638 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3639 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3641 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3646 /* A retry occurred before. */
3647 *next_loopid
= tmp_loopid
;
3650 * No retry occurred before. Just increment the
3651 * ID value for next login.
3653 *next_loopid
= (fcport
->loop_id
+ 1);
3656 if (mb
[1] & BIT_0
) {
3657 fcport
->port_type
= FCT_INITIATOR
;
3659 fcport
->port_type
= FCT_TARGET
;
3660 if (mb
[1] & BIT_1
) {
3661 fcport
->flags
|= FCF_FCP2_DEVICE
;
3666 fcport
->supported_classes
|= FC_COS_CLASS2
;
3668 fcport
->supported_classes
|= FC_COS_CLASS3
;
3672 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3674 * Loop ID already used, try next loop ID.
3677 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3678 if (rval
!= QLA_SUCCESS
) {
3679 /* Ran out of loop IDs to use */
3682 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3684 * Firmware possibly timed out during login. If NO
3685 * retries are left to do then the device is declared
3688 *next_loopid
= fcport
->loop_id
;
3689 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3690 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3691 fcport
->d_id
.b
.al_pa
);
3692 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3698 * unrecoverable / not handled error
3700 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3701 "loop_id=%x jiffies=%lx.\n",
3702 __func__
, vha
->host_no
, mb
[0],
3703 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3704 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3706 *next_loopid
= fcport
->loop_id
;
3707 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3708 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3709 fcport
->d_id
.b
.al_pa
);
3710 fcport
->loop_id
= FC_NO_LOOP_ID
;
3711 fcport
->login_retry
= 0;
3722 * qla2x00_local_device_login
3723 * Issue local device login command.
3726 * ha = adapter block pointer.
3727 * loop_id = loop id of device to login to.
3729 * Returns (Where's the #define!!!!):
3730 * 0 - Login successfully
3735 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3738 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3740 memset(mb
, 0, sizeof(mb
));
3741 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3742 if (rval
== QLA_SUCCESS
) {
3743 /* Interrogate mailbox registers for any errors */
3744 if (mb
[0] == MBS_COMMAND_ERROR
)
3746 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3747 /* device not in PCB table */
3755 * qla2x00_loop_resync
3756 * Resync with fibre channel devices.
3759 * ha = adapter block pointer.
3765 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3767 int rval
= QLA_SUCCESS
;
3769 struct req_que
*req
;
3770 struct rsp_que
*rsp
;
3772 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3773 req
= vha
->hw
->req_q_map
[0];
3778 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3779 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3780 if (vha
->flags
.online
) {
3781 if (!(rval
= qla2x00_fw_ready(vha
))) {
3782 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3785 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3787 /* Issue a marker after FW becomes ready. */
3788 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3790 vha
->marker_needed
= 0;
3792 /* Remap devices on Loop. */
3793 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3795 qla2x00_configure_loop(vha
);
3797 } while (!atomic_read(&vha
->loop_down_timer
) &&
3798 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3799 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3804 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3805 return (QLA_FUNCTION_FAILED
);
3808 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3814 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3817 struct scsi_qla_host
*vha
;
3818 struct qla_hw_data
*ha
= base_vha
->hw
;
3819 unsigned long flags
;
3821 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3822 /* Go with deferred removal of rport references. */
3823 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3824 atomic_inc(&vha
->vref_count
);
3825 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3826 if (fcport
&& fcport
->drport
&&
3827 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3828 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3830 qla2x00_rport_del(fcport
);
3832 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3835 atomic_dec(&vha
->vref_count
);
3837 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3841 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3843 struct qla_hw_data
*ha
= vha
->hw
;
3844 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3845 unsigned long flags
;
3847 vha
->flags
.online
= 0;
3848 ha
->flags
.chip_reset_done
= 0;
3849 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3850 ha
->qla_stats
.total_isp_aborts
++;
3852 qla_printk(KERN_INFO
, ha
,
3853 "Performing ISP error recovery - ha= %p.\n", ha
);
3855 /* Chip reset does not apply to 82XX */
3856 if (!IS_QLA82XX(ha
))
3857 ha
->isp_ops
->reset_chip(vha
);
3859 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3860 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3861 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3862 qla2x00_mark_all_devices_lost(vha
, 0);
3864 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3865 list_for_each_entry(vp
, &base_vha
->hw
->vp_list
, list
) {
3866 atomic_inc(&vp
->vref_count
);
3867 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3869 qla2x00_mark_all_devices_lost(vp
, 0);
3871 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3872 atomic_dec(&vp
->vref_count
);
3874 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3876 if (!atomic_read(&vha
->loop_down_timer
))
3877 atomic_set(&vha
->loop_down_timer
,
3881 /* Make sure for ISP 82XX IO DMA is complete */
3882 if (IS_QLA82XX(ha
)) {
3883 if (qla2x00_eh_wait_for_pending_commands(vha
, 0, 0,
3884 WAIT_HOST
) == QLA_SUCCESS
) {
3885 DEBUG2(qla_printk(KERN_INFO
, ha
,
3886 "Done wait for pending commands\n"));
3890 /* Requeue all commands in outstanding command list. */
3891 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3896 * Resets ISP and aborts all outstanding commands.
3899 * ha = adapter block pointer.
3905 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3909 struct qla_hw_data
*ha
= vha
->hw
;
3910 struct scsi_qla_host
*vp
;
3911 struct req_que
*req
= ha
->req_q_map
[0];
3912 unsigned long flags
;
3914 if (vha
->flags
.online
) {
3915 qla2x00_abort_isp_cleanup(vha
);
3917 if (unlikely(pci_channel_offline(ha
->pdev
) &&
3918 ha
->flags
.pci_channel_io_perm_failure
)) {
3919 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3924 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3926 ha
->isp_ops
->nvram_config(vha
);
3928 if (!qla2x00_restart_isp(vha
)) {
3929 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3931 if (!atomic_read(&vha
->loop_down_timer
)) {
3933 * Issue marker command only when we are going
3934 * to start the I/O .
3936 vha
->marker_needed
= 1;
3939 vha
->flags
.online
= 1;
3941 ha
->isp_ops
->enable_intrs(ha
);
3943 ha
->isp_abort_cnt
= 0;
3944 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3947 qla2x00_get_fw_version(vha
,
3948 &ha
->fw_major_version
,
3949 &ha
->fw_minor_version
,
3950 &ha
->fw_subminor_version
,
3951 &ha
->fw_attributes
, &ha
->fw_memory_size
,
3952 ha
->mpi_version
, &ha
->mpi_capabilities
,
3956 ha
->flags
.fce_enabled
= 1;
3958 fce_calc_size(ha
->fce_bufs
));
3959 rval
= qla2x00_enable_fce_trace(vha
,
3960 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3963 qla_printk(KERN_WARNING
, ha
,
3964 "Unable to reinitialize FCE "
3966 ha
->flags
.fce_enabled
= 0;
3971 memset(ha
->eft
, 0, EFT_SIZE
);
3972 rval
= qla2x00_enable_eft_trace(vha
,
3973 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3975 qla_printk(KERN_WARNING
, ha
,
3976 "Unable to reinitialize EFT "
3980 } else { /* failed the ISP abort */
3981 vha
->flags
.online
= 1;
3982 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3983 if (ha
->isp_abort_cnt
== 0) {
3984 qla_printk(KERN_WARNING
, ha
,
3985 "ISP error recovery failed - "
3986 "board disabled\n");
3988 * The next call disables the board
3991 ha
->isp_ops
->reset_adapter(vha
);
3992 vha
->flags
.online
= 0;
3993 clear_bit(ISP_ABORT_RETRY
,
3996 } else { /* schedule another ISP abort */
3997 ha
->isp_abort_cnt
--;
3998 DEBUG(printk("qla%ld: ISP abort - "
3999 "retry remaining %d\n",
4000 vha
->host_no
, ha
->isp_abort_cnt
));
4004 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
4005 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4006 "- retrying (%d) more times\n",
4007 vha
->host_no
, ha
->isp_abort_cnt
));
4008 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4016 DEBUG(printk(KERN_INFO
4017 "qla2x00_abort_isp(%ld): succeeded.\n",
4020 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4021 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4023 atomic_inc(&vp
->vref_count
);
4024 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4026 qla2x00_vp_abort_isp(vp
);
4028 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4029 atomic_dec(&vp
->vref_count
);
4032 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4035 qla_printk(KERN_INFO
, ha
,
4036 "qla2x00_abort_isp: **** FAILED ****\n");
4043 * qla2x00_restart_isp
4044 * restarts the ISP after a reset
4047 * ha = adapter block pointer.
4053 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4057 struct qla_hw_data
*ha
= vha
->hw
;
4058 struct req_que
*req
= ha
->req_q_map
[0];
4059 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4061 /* If firmware needs to be loaded */
4062 if (qla2x00_isp_firmware(vha
)) {
4063 vha
->flags
.online
= 0;
4064 status
= ha
->isp_ops
->chip_diag(vha
);
4066 status
= qla2x00_setup_chip(vha
);
4069 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4070 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4071 ha
->flags
.chip_reset_done
= 1;
4072 /* Initialize the queues in use */
4073 qla25xx_init_queues(ha
);
4075 status
= qla2x00_fw_ready(vha
);
4077 DEBUG(printk("%s(): Start configure loop, "
4078 "status = %d\n", __func__
, status
));
4080 /* Issue a marker after FW becomes ready. */
4081 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4083 vha
->flags
.online
= 1;
4084 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4087 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4088 qla2x00_configure_loop(vha
);
4090 } while (!atomic_read(&vha
->loop_down_timer
) &&
4091 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4092 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4096 /* if no cable then assume it's good */
4097 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4100 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4108 qla25xx_init_queues(struct qla_hw_data
*ha
)
4110 struct rsp_que
*rsp
= NULL
;
4111 struct req_que
*req
= NULL
;
4112 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4116 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4117 rsp
= ha
->rsp_q_map
[i
];
4119 rsp
->options
&= ~BIT_0
;
4120 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4121 if (ret
!= QLA_SUCCESS
)
4122 DEBUG2_17(printk(KERN_WARNING
4123 "%s Rsp que:%d init failed\n", __func__
,
4126 DEBUG2_17(printk(KERN_INFO
4127 "%s Rsp que:%d inited\n", __func__
,
4131 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4132 req
= ha
->req_q_map
[i
];
4134 /* Clear outstanding commands array. */
4135 req
->options
&= ~BIT_0
;
4136 ret
= qla25xx_init_req_que(base_vha
, req
);
4137 if (ret
!= QLA_SUCCESS
)
4138 DEBUG2_17(printk(KERN_WARNING
4139 "%s Req que:%d init failed\n", __func__
,
4142 DEBUG2_17(printk(KERN_WARNING
4143 "%s Req que:%d inited\n", __func__
,
4151 * qla2x00_reset_adapter
4155 * ha = adapter block pointer.
4158 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4160 unsigned long flags
= 0;
4161 struct qla_hw_data
*ha
= vha
->hw
;
4162 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4164 vha
->flags
.online
= 0;
4165 ha
->isp_ops
->disable_intrs(ha
);
4167 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4168 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4169 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4170 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4171 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4172 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4176 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4178 unsigned long flags
= 0;
4179 struct qla_hw_data
*ha
= vha
->hw
;
4180 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4185 vha
->flags
.online
= 0;
4186 ha
->isp_ops
->disable_intrs(ha
);
4188 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4189 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4190 RD_REG_DWORD(®
->hccr
);
4191 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4192 RD_REG_DWORD(®
->hccr
);
4193 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4195 if (IS_NOPOLLING_TYPE(ha
))
4196 ha
->isp_ops
->enable_intrs(ha
);
4199 /* On sparc systems, obtain port and node WWN from firmware
4202 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4203 struct nvram_24xx
*nv
)
4206 struct qla_hw_data
*ha
= vha
->hw
;
4207 struct pci_dev
*pdev
= ha
->pdev
;
4208 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4212 val
= of_get_property(dp
, "port-wwn", &len
);
4213 if (val
&& len
>= WWN_SIZE
)
4214 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4216 val
= of_get_property(dp
, "node-wwn", &len
);
4217 if (val
&& len
>= WWN_SIZE
)
4218 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4223 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4226 struct init_cb_24xx
*icb
;
4227 struct nvram_24xx
*nv
;
4229 uint8_t *dptr1
, *dptr2
;
4232 struct qla_hw_data
*ha
= vha
->hw
;
4235 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4238 /* Determine NVRAM starting address. */
4239 if (ha
->flags
.port0
) {
4240 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4241 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4243 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4244 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4246 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4247 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4249 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4251 /* Get VPD data into cache */
4252 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4253 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4254 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4256 /* Get NVRAM data into cache and calculate checksum. */
4257 dptr
= (uint32_t *)nv
;
4258 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4260 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4261 chksum
+= le32_to_cpu(*dptr
++);
4263 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
4264 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
4266 /* Bad NVRAM data, set defaults parameters. */
4267 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4268 || nv
->id
[3] != ' ' ||
4269 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4270 /* Reset NVRAM data. */
4271 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4272 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4273 le16_to_cpu(nv
->nvram_version
));
4274 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4275 "invalid -- WWPN) defaults.\n");
4278 * Set default initialization control block.
4280 memset(nv
, 0, ha
->nvram_size
);
4281 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4282 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4283 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4284 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4285 nv
->exchange_count
= __constant_cpu_to_le16(0);
4286 nv
->hard_address
= __constant_cpu_to_le16(124);
4287 nv
->port_name
[0] = 0x21;
4288 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4289 nv
->port_name
[2] = 0x00;
4290 nv
->port_name
[3] = 0xe0;
4291 nv
->port_name
[4] = 0x8b;
4292 nv
->port_name
[5] = 0x1c;
4293 nv
->port_name
[6] = 0x55;
4294 nv
->port_name
[7] = 0x86;
4295 nv
->node_name
[0] = 0x20;
4296 nv
->node_name
[1] = 0x00;
4297 nv
->node_name
[2] = 0x00;
4298 nv
->node_name
[3] = 0xe0;
4299 nv
->node_name
[4] = 0x8b;
4300 nv
->node_name
[5] = 0x1c;
4301 nv
->node_name
[6] = 0x55;
4302 nv
->node_name
[7] = 0x86;
4303 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4304 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4305 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4306 nv
->login_timeout
= __constant_cpu_to_le16(0);
4307 nv
->firmware_options_1
=
4308 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4309 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4310 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4311 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4312 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4313 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4314 nv
->reset_delay
= 5;
4315 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4316 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4317 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4322 /* Reset Initialization control block */
4323 memset(icb
, 0, ha
->init_cb_size
);
4325 /* Copy 1st segment. */
4326 dptr1
= (uint8_t *)icb
;
4327 dptr2
= (uint8_t *)&nv
->version
;
4328 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4330 *dptr1
++ = *dptr2
++;
4332 icb
->login_retry_count
= nv
->login_retry_count
;
4333 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4335 /* Copy 2nd segment. */
4336 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4337 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4338 cnt
= (uint8_t *)&icb
->reserved_3
-
4339 (uint8_t *)&icb
->interrupt_delay_timer
;
4341 *dptr1
++ = *dptr2
++;
4344 * Setup driver NVRAM options.
4346 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4349 /* Use alternate WWN? */
4350 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4351 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4352 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4355 /* Prepare nodename */
4356 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4358 * Firmware will apply the following mask if the nodename was
4361 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4362 icb
->node_name
[0] &= 0xF0;
4365 /* Set host adapter parameters. */
4366 ha
->flags
.disable_risc_code_load
= 0;
4367 ha
->flags
.enable_lip_reset
= 0;
4368 ha
->flags
.enable_lip_full_login
=
4369 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4370 ha
->flags
.enable_target_reset
=
4371 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4372 ha
->flags
.enable_led_scheme
= 0;
4373 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4375 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4376 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4378 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4379 sizeof(ha
->fw_seriallink_options24
));
4381 /* save HBA serial number */
4382 ha
->serial0
= icb
->port_name
[5];
4383 ha
->serial1
= icb
->port_name
[6];
4384 ha
->serial2
= icb
->port_name
[7];
4385 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4386 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4388 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4390 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4392 /* Set minimum login_timeout to 4 seconds. */
4393 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4394 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4395 if (le16_to_cpu(nv
->login_timeout
) < 4)
4396 nv
->login_timeout
= __constant_cpu_to_le16(4);
4397 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4398 icb
->login_timeout
= nv
->login_timeout
;
4400 /* Set minimum RATOV to 100 tenths of a second. */
4403 ha
->loop_reset_delay
= nv
->reset_delay
;
4405 /* Link Down Timeout = 0:
4407 * When Port Down timer expires we will start returning
4408 * I/O's to OS with "DID_NO_CONNECT".
4410 * Link Down Timeout != 0:
4412 * The driver waits for the link to come up after link down
4413 * before returning I/Os to OS with "DID_NO_CONNECT".
4415 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4416 ha
->loop_down_abort_time
=
4417 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4419 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4420 ha
->loop_down_abort_time
=
4421 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4424 /* Need enough time to try and get the port back. */
4425 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4426 if (qlport_down_retry
)
4427 ha
->port_down_retry_count
= qlport_down_retry
;
4429 /* Set login_retry_count */
4430 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4431 if (ha
->port_down_retry_count
==
4432 le16_to_cpu(nv
->port_down_retry_count
) &&
4433 ha
->port_down_retry_count
> 3)
4434 ha
->login_retry_count
= ha
->port_down_retry_count
;
4435 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4436 ha
->login_retry_count
= ha
->port_down_retry_count
;
4437 if (ql2xloginretrycount
)
4438 ha
->login_retry_count
= ql2xloginretrycount
;
4441 if (!vha
->flags
.init_done
) {
4442 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4443 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4444 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4445 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4447 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4448 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4449 vha
->flags
.process_response_queue
= 0;
4450 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4451 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4453 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4454 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4455 ha
->zio_timer
* 100));
4456 qla_printk(KERN_INFO
, ha
,
4457 "ZIO mode %d enabled; timer delay (%d us).\n",
4458 ha
->zio_mode
, ha
->zio_timer
* 100);
4460 icb
->firmware_options_2
|= cpu_to_le32(
4461 (uint32_t)ha
->zio_mode
);
4462 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4463 vha
->flags
.process_response_queue
= 1;
4467 DEBUG2_3(printk(KERN_WARNING
4468 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4474 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4477 int rval
= QLA_SUCCESS
;
4478 int segments
, fragment
;
4479 uint32_t *dcode
, dlen
;
4483 struct qla_hw_data
*ha
= vha
->hw
;
4484 struct req_que
*req
= ha
->req_q_map
[0];
4486 qla_printk(KERN_INFO
, ha
,
4487 "FW: Loading from flash (%x)...\n", faddr
);
4491 segments
= FA_RISC_CODE_SEGMENTS
;
4492 dcode
= (uint32_t *)req
->ring
;
4495 /* Validate firmware image by checking version. */
4496 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4497 for (i
= 0; i
< 4; i
++)
4498 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4499 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4500 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4501 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4503 qla_printk(KERN_WARNING
, ha
,
4504 "Unable to verify integrity of flash firmware image!\n");
4505 qla_printk(KERN_WARNING
, ha
,
4506 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4507 dcode
[1], dcode
[2], dcode
[3]);
4509 return QLA_FUNCTION_FAILED
;
4512 while (segments
&& rval
== QLA_SUCCESS
) {
4513 /* Read segment's load information. */
4514 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4516 risc_addr
= be32_to_cpu(dcode
[2]);
4517 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4518 risc_size
= be32_to_cpu(dcode
[3]);
4521 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4522 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4523 if (dlen
> risc_size
)
4526 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4527 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4528 vha
->host_no
, risc_addr
, dlen
, faddr
));
4530 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4531 for (i
= 0; i
< dlen
; i
++)
4532 dcode
[i
] = swab32(dcode
[i
]);
4534 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4537 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4538 "segment %d of firmware\n", vha
->host_no
,
4540 qla_printk(KERN_WARNING
, ha
,
4541 "[ERROR] Failed to load segment %d of "
4542 "firmware\n", fragment
);
4559 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4562 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4566 uint16_t *wcode
, *fwcode
;
4567 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4568 struct fw_blob
*blob
;
4569 struct qla_hw_data
*ha
= vha
->hw
;
4570 struct req_que
*req
= ha
->req_q_map
[0];
4572 /* Load firmware blob. */
4573 blob
= qla2x00_request_firmware(vha
);
4575 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4576 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4577 "from: " QLA_FW_URL
".\n");
4578 return QLA_FUNCTION_FAILED
;
4583 wcode
= (uint16_t *)req
->ring
;
4585 fwcode
= (uint16_t *)blob
->fw
->data
;
4588 /* Validate firmware image by checking version. */
4589 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4590 qla_printk(KERN_WARNING
, ha
,
4591 "Unable to verify integrity of firmware image (%Zd)!\n",
4593 goto fail_fw_integrity
;
4595 for (i
= 0; i
< 4; i
++)
4596 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4597 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4598 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4599 wcode
[2] == 0 && wcode
[3] == 0)) {
4600 qla_printk(KERN_WARNING
, ha
,
4601 "Unable to verify integrity of firmware image!\n");
4602 qla_printk(KERN_WARNING
, ha
,
4603 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
4604 wcode
[1], wcode
[2], wcode
[3]);
4605 goto fail_fw_integrity
;
4609 while (*seg
&& rval
== QLA_SUCCESS
) {
4611 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4612 risc_size
= be16_to_cpu(fwcode
[3]);
4614 /* Validate firmware image size. */
4615 fwclen
+= risc_size
* sizeof(uint16_t);
4616 if (blob
->fw
->size
< fwclen
) {
4617 qla_printk(KERN_WARNING
, ha
,
4618 "Unable to verify integrity of firmware image "
4619 "(%Zd)!\n", blob
->fw
->size
);
4620 goto fail_fw_integrity
;
4624 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4625 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4626 if (wlen
> risc_size
)
4629 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4630 "addr %x, number of words 0x%x.\n", vha
->host_no
,
4633 for (i
= 0; i
< wlen
; i
++)
4634 wcode
[i
] = swab16(fwcode
[i
]);
4636 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4639 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4640 "segment %d of firmware\n", vha
->host_no
,
4642 qla_printk(KERN_WARNING
, ha
,
4643 "[ERROR] Failed to load segment %d of "
4644 "firmware\n", fragment
);
4660 return QLA_FUNCTION_FAILED
;
4664 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4667 int segments
, fragment
;
4668 uint32_t *dcode
, dlen
;
4672 struct fw_blob
*blob
;
4673 uint32_t *fwcode
, fwclen
;
4674 struct qla_hw_data
*ha
= vha
->hw
;
4675 struct req_que
*req
= ha
->req_q_map
[0];
4677 /* Load firmware blob. */
4678 blob
= qla2x00_request_firmware(vha
);
4680 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4681 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4682 "from: " QLA_FW_URL
".\n");
4684 return QLA_FUNCTION_FAILED
;
4687 qla_printk(KERN_INFO
, ha
,
4688 "FW: Loading via request-firmware...\n");
4692 segments
= FA_RISC_CODE_SEGMENTS
;
4693 dcode
= (uint32_t *)req
->ring
;
4695 fwcode
= (uint32_t *)blob
->fw
->data
;
4698 /* Validate firmware image by checking version. */
4699 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4700 qla_printk(KERN_WARNING
, ha
,
4701 "Unable to verify integrity of firmware image (%Zd)!\n",
4703 goto fail_fw_integrity
;
4705 for (i
= 0; i
< 4; i
++)
4706 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4707 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4708 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4709 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4711 qla_printk(KERN_WARNING
, ha
,
4712 "Unable to verify integrity of firmware image!\n");
4713 qla_printk(KERN_WARNING
, ha
,
4714 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4715 dcode
[1], dcode
[2], dcode
[3]);
4716 goto fail_fw_integrity
;
4719 while (segments
&& rval
== QLA_SUCCESS
) {
4720 risc_addr
= be32_to_cpu(fwcode
[2]);
4721 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4722 risc_size
= be32_to_cpu(fwcode
[3]);
4724 /* Validate firmware image size. */
4725 fwclen
+= risc_size
* sizeof(uint32_t);
4726 if (blob
->fw
->size
< fwclen
) {
4727 qla_printk(KERN_WARNING
, ha
,
4728 "Unable to verify integrity of firmware image "
4729 "(%Zd)!\n", blob
->fw
->size
);
4731 goto fail_fw_integrity
;
4735 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4736 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4737 if (dlen
> risc_size
)
4740 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4741 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4744 for (i
= 0; i
< dlen
; i
++)
4745 dcode
[i
] = swab32(fwcode
[i
]);
4747 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4750 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4751 "segment %d of firmware\n", vha
->host_no
,
4753 qla_printk(KERN_WARNING
, ha
,
4754 "[ERROR] Failed to load segment %d of "
4755 "firmware\n", fragment
);
4771 return QLA_FUNCTION_FAILED
;
4775 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4779 if (ql2xfwloadbin
== 1)
4780 return qla81xx_load_risc(vha
, srisc_addr
);
4784 * 1) Firmware via request-firmware interface (.bin file).
4785 * 2) Firmware residing in flash.
4787 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4788 if (rval
== QLA_SUCCESS
)
4791 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4792 vha
->hw
->flt_region_fw
);
4796 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4799 struct qla_hw_data
*ha
= vha
->hw
;
4801 if (ql2xfwloadbin
== 2)
4806 * 1) Firmware residing in flash.
4807 * 2) Firmware via request-firmware interface (.bin file).
4808 * 3) Golden-Firmware residing in flash -- limited operation.
4810 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4811 if (rval
== QLA_SUCCESS
)
4815 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4816 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4819 qla_printk(KERN_ERR
, ha
,
4820 "FW: Attempting to fallback to golden firmware...\n");
4821 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4822 if (rval
!= QLA_SUCCESS
)
4825 qla_printk(KERN_ERR
, ha
,
4826 "FW: Please update operational firmware...\n");
4827 ha
->flags
.running_gold_fw
= 1;
4833 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4836 struct qla_hw_data
*ha
= vha
->hw
;
4838 if (ha
->flags
.pci_channel_io_perm_failure
)
4840 if (!IS_FWI2_CAPABLE(ha
))
4842 if (!ha
->fw_major_version
)
4845 ret
= qla2x00_stop_firmware(vha
);
4846 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4847 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4848 ha
->isp_ops
->reset_chip(vha
);
4849 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4851 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4853 qla_printk(KERN_INFO
, ha
,
4854 "Attempting retry of stop-firmware command...\n");
4855 ret
= qla2x00_stop_firmware(vha
);
4860 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4862 int rval
= QLA_SUCCESS
;
4863 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4864 struct qla_hw_data
*ha
= vha
->hw
;
4865 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4866 struct req_que
*req
;
4867 struct rsp_que
*rsp
;
4872 rval
= qla2x00_fw_ready(base_vha
);
4873 if (ha
->flags
.cpu_affinity_enabled
)
4874 req
= ha
->req_q_map
[0];
4879 if (rval
== QLA_SUCCESS
) {
4880 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4881 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4884 vha
->flags
.management_server_logged_in
= 0;
4886 /* Login to SNS first */
4887 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
4888 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
4889 DEBUG15(qla_printk(KERN_INFO
, ha
,
4890 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4891 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
4892 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
4893 return (QLA_FUNCTION_FAILED
);
4896 atomic_set(&vha
->loop_down_timer
, 0);
4897 atomic_set(&vha
->loop_state
, LOOP_UP
);
4898 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4899 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4900 rval
= qla2x00_loop_resync(base_vha
);
4905 /* 84XX Support **************************************************************/
4907 static LIST_HEAD(qla_cs84xx_list
);
4908 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4910 static struct qla_chip_state_84xx
*
4911 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4913 struct qla_chip_state_84xx
*cs84xx
;
4914 struct qla_hw_data
*ha
= vha
->hw
;
4916 mutex_lock(&qla_cs84xx_mutex
);
4918 /* Find any shared 84xx chip. */
4919 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4920 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4921 kref_get(&cs84xx
->kref
);
4926 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4930 kref_init(&cs84xx
->kref
);
4931 spin_lock_init(&cs84xx
->access_lock
);
4932 mutex_init(&cs84xx
->fw_update_mutex
);
4933 cs84xx
->bus
= ha
->pdev
->bus
;
4935 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4937 mutex_unlock(&qla_cs84xx_mutex
);
4942 __qla84xx_chip_release(struct kref
*kref
)
4944 struct qla_chip_state_84xx
*cs84xx
=
4945 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4947 mutex_lock(&qla_cs84xx_mutex
);
4948 list_del(&cs84xx
->list
);
4949 mutex_unlock(&qla_cs84xx_mutex
);
4954 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4956 struct qla_hw_data
*ha
= vha
->hw
;
4958 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4962 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4966 struct qla_hw_data
*ha
= vha
->hw
;
4968 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4970 rval
= qla84xx_verify_chip(vha
, status
);
4972 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4974 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
4978 /* 81XX Support **************************************************************/
4981 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
4984 struct init_cb_81xx
*icb
;
4985 struct nvram_81xx
*nv
;
4987 uint8_t *dptr1
, *dptr2
;
4990 struct qla_hw_data
*ha
= vha
->hw
;
4993 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
4996 /* Determine NVRAM starting address. */
4997 ha
->nvram_size
= sizeof(struct nvram_81xx
);
4998 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
5000 /* Get VPD data into cache */
5001 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
5002 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
5005 /* Get NVRAM data into cache and calculate checksum. */
5006 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
5008 dptr
= (uint32_t *)nv
;
5009 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
5010 chksum
+= le32_to_cpu(*dptr
++);
5012 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
5013 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
5015 /* Bad NVRAM data, set defaults parameters. */
5016 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
5017 || nv
->id
[3] != ' ' ||
5018 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
5019 /* Reset NVRAM data. */
5020 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
5021 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
5022 le16_to_cpu(nv
->nvram_version
));
5023 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
5024 "invalid -- WWPN) defaults.\n");
5027 * Set default initialization control block.
5029 memset(nv
, 0, ha
->nvram_size
);
5030 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5031 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5032 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5033 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5034 nv
->exchange_count
= __constant_cpu_to_le16(0);
5035 nv
->port_name
[0] = 0x21;
5036 nv
->port_name
[1] = 0x00 + ha
->port_no
;
5037 nv
->port_name
[2] = 0x00;
5038 nv
->port_name
[3] = 0xe0;
5039 nv
->port_name
[4] = 0x8b;
5040 nv
->port_name
[5] = 0x1c;
5041 nv
->port_name
[6] = 0x55;
5042 nv
->port_name
[7] = 0x86;
5043 nv
->node_name
[0] = 0x20;
5044 nv
->node_name
[1] = 0x00;
5045 nv
->node_name
[2] = 0x00;
5046 nv
->node_name
[3] = 0xe0;
5047 nv
->node_name
[4] = 0x8b;
5048 nv
->node_name
[5] = 0x1c;
5049 nv
->node_name
[6] = 0x55;
5050 nv
->node_name
[7] = 0x86;
5051 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5052 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5053 nv
->login_timeout
= __constant_cpu_to_le16(0);
5054 nv
->firmware_options_1
=
5055 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5056 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5057 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5058 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5059 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5060 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5061 nv
->reset_delay
= 5;
5062 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5063 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5064 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
5065 nv
->enode_mac
[0] = 0x00;
5066 nv
->enode_mac
[1] = 0x02;
5067 nv
->enode_mac
[2] = 0x03;
5068 nv
->enode_mac
[3] = 0x04;
5069 nv
->enode_mac
[4] = 0x05;
5070 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5075 /* Reset Initialization control block */
5076 memset(icb
, 0, sizeof(struct init_cb_81xx
));
5078 /* Copy 1st segment. */
5079 dptr1
= (uint8_t *)icb
;
5080 dptr2
= (uint8_t *)&nv
->version
;
5081 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5083 *dptr1
++ = *dptr2
++;
5085 icb
->login_retry_count
= nv
->login_retry_count
;
5087 /* Copy 2nd segment. */
5088 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5089 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5090 cnt
= (uint8_t *)&icb
->reserved_5
-
5091 (uint8_t *)&icb
->interrupt_delay_timer
;
5093 *dptr1
++ = *dptr2
++;
5095 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5096 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5097 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5098 icb
->enode_mac
[0] = 0x01;
5099 icb
->enode_mac
[1] = 0x02;
5100 icb
->enode_mac
[2] = 0x03;
5101 icb
->enode_mac
[3] = 0x04;
5102 icb
->enode_mac
[4] = 0x05;
5103 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5106 /* Use extended-initialization control block. */
5107 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5110 * Setup driver NVRAM options.
5112 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5115 /* Use alternate WWN? */
5116 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5117 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5118 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5121 /* Prepare nodename */
5122 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5124 * Firmware will apply the following mask if the nodename was
5127 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5128 icb
->node_name
[0] &= 0xF0;
5131 /* Set host adapter parameters. */
5132 ha
->flags
.disable_risc_code_load
= 0;
5133 ha
->flags
.enable_lip_reset
= 0;
5134 ha
->flags
.enable_lip_full_login
=
5135 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5136 ha
->flags
.enable_target_reset
=
5137 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5138 ha
->flags
.enable_led_scheme
= 0;
5139 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5141 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5142 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5144 /* save HBA serial number */
5145 ha
->serial0
= icb
->port_name
[5];
5146 ha
->serial1
= icb
->port_name
[6];
5147 ha
->serial2
= icb
->port_name
[7];
5148 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5149 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5151 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5153 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5155 /* Set minimum login_timeout to 4 seconds. */
5156 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5157 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5158 if (le16_to_cpu(nv
->login_timeout
) < 4)
5159 nv
->login_timeout
= __constant_cpu_to_le16(4);
5160 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5161 icb
->login_timeout
= nv
->login_timeout
;
5163 /* Set minimum RATOV to 100 tenths of a second. */
5166 ha
->loop_reset_delay
= nv
->reset_delay
;
5168 /* Link Down Timeout = 0:
5170 * When Port Down timer expires we will start returning
5171 * I/O's to OS with "DID_NO_CONNECT".
5173 * Link Down Timeout != 0:
5175 * The driver waits for the link to come up after link down
5176 * before returning I/Os to OS with "DID_NO_CONNECT".
5178 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5179 ha
->loop_down_abort_time
=
5180 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5182 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5183 ha
->loop_down_abort_time
=
5184 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5187 /* Need enough time to try and get the port back. */
5188 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5189 if (qlport_down_retry
)
5190 ha
->port_down_retry_count
= qlport_down_retry
;
5192 /* Set login_retry_count */
5193 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5194 if (ha
->port_down_retry_count
==
5195 le16_to_cpu(nv
->port_down_retry_count
) &&
5196 ha
->port_down_retry_count
> 3)
5197 ha
->login_retry_count
= ha
->port_down_retry_count
;
5198 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5199 ha
->login_retry_count
= ha
->port_down_retry_count
;
5200 if (ql2xloginretrycount
)
5201 ha
->login_retry_count
= ql2xloginretrycount
;
5204 if (!vha
->flags
.init_done
) {
5205 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5206 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5207 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5208 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5210 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5211 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5212 vha
->flags
.process_response_queue
= 0;
5213 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5214 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5216 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5217 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
5218 ha
->zio_timer
* 100));
5219 qla_printk(KERN_INFO
, ha
,
5220 "ZIO mode %d enabled; timer delay (%d us).\n",
5221 ha
->zio_mode
, ha
->zio_timer
* 100);
5223 icb
->firmware_options_2
|= cpu_to_le32(
5224 (uint32_t)ha
->zio_mode
);
5225 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5226 vha
->flags
.process_response_queue
= 1;
5230 DEBUG2_3(printk(KERN_WARNING
5231 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
5237 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5241 struct qla_hw_data
*ha
= vha
->hw
;
5242 struct req_que
*req
= ha
->req_q_map
[0];
5243 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5244 struct scsi_qla_host
*vp
;
5245 unsigned long flags
;
5247 status
= qla2x00_init_rings(vha
);
5249 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5250 ha
->flags
.chip_reset_done
= 1;
5252 status
= qla2x00_fw_ready(vha
);
5254 qla_printk(KERN_INFO
, ha
,
5255 "%s(): Start configure loop, "
5256 "status = %d\n", __func__
, status
);
5258 /* Issue a marker after FW becomes ready. */
5259 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5261 vha
->flags
.online
= 1;
5262 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5265 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5266 qla2x00_configure_loop(vha
);
5268 } while (!atomic_read(&vha
->loop_down_timer
) &&
5269 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5271 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5274 /* if no cable then assume it's good */
5275 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5278 qla_printk(KERN_INFO
, ha
,
5279 "%s(): Configure loop done, status = 0x%x\n",
5284 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5286 if (!atomic_read(&vha
->loop_down_timer
)) {
5288 * Issue marker command only when we are going
5289 * to start the I/O .
5291 vha
->marker_needed
= 1;
5294 vha
->flags
.online
= 1;
5296 ha
->isp_ops
->enable_intrs(ha
);
5298 ha
->isp_abort_cnt
= 0;
5299 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5302 ha
->flags
.fce_enabled
= 1;
5304 fce_calc_size(ha
->fce_bufs
));
5305 rval
= qla2x00_enable_fce_trace(vha
,
5306 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5309 qla_printk(KERN_WARNING
, ha
,
5310 "Unable to reinitialize FCE "
5312 ha
->flags
.fce_enabled
= 0;
5317 memset(ha
->eft
, 0, EFT_SIZE
);
5318 rval
= qla2x00_enable_eft_trace(vha
,
5319 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5321 qla_printk(KERN_WARNING
, ha
,
5322 "Unable to reinitialize EFT "
5329 DEBUG(printk(KERN_INFO
5330 "qla82xx_restart_isp(%ld): succeeded.\n",
5333 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5334 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5336 atomic_inc(&vp
->vref_count
);
5337 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5339 qla2x00_vp_abort_isp(vp
);
5341 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5342 atomic_dec(&vp
->vref_count
);
5345 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5348 qla_printk(KERN_INFO
, ha
,
5349 "qla82xx_restart_isp: **** FAILED ****\n");
5356 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5358 struct qla_hw_data
*ha
= vha
->hw
;
5363 /* Enable ETS Burst. */
5364 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5365 ha
->fw_options
[2] |= BIT_9
;
5366 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5370 * qla24xx_get_fcp_prio
5371 * Gets the fcp cmd priority value for the logged in port.
5372 * Looks for a match of the port descriptors within
5373 * each of the fcp prio config entries. If a match is found,
5374 * the tag (priority) value is returned.
5377 * ha = adapter block po
5378 * fcport = port structure pointer.
5381 * non-zero (if found)
5388 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5391 uint8_t pid_match
, wwn_match
;
5393 uint32_t pid1
, pid2
;
5394 uint64_t wwn1
, wwn2
;
5395 struct qla_fcp_prio_entry
*pri_entry
;
5396 struct qla_hw_data
*ha
= vha
->hw
;
5398 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5402 entries
= ha
->fcp_prio_cfg
->num_entries
;
5403 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5405 for (i
= 0; i
< entries
; i
++) {
5406 pid_match
= wwn_match
= 0;
5408 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5413 /* check source pid for a match */
5414 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5415 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5416 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5417 if (pid1
== INVALID_PORT_ID
)
5419 else if (pid1
== pid2
)
5423 /* check destination pid for a match */
5424 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5425 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5426 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5427 if (pid1
== INVALID_PORT_ID
)
5429 else if (pid1
== pid2
)
5433 /* check source WWN for a match */
5434 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5435 wwn1
= wwn_to_u64(vha
->port_name
);
5436 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5437 if (wwn2
== (uint64_t)-1)
5439 else if (wwn1
== wwn2
)
5443 /* check destination WWN for a match */
5444 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5445 wwn1
= wwn_to_u64(fcport
->port_name
);
5446 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5447 if (wwn2
== (uint64_t)-1)
5449 else if (wwn1
== wwn2
)
5453 if (pid_match
== 2 || wwn_match
== 2) {
5454 /* Found a matching entry */
5455 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5456 priority
= pri_entry
->tag
;
5467 * qla24xx_update_fcport_fcp_prio
5468 * Activates fcp priority for the logged in fc port
5471 * ha = adapter block pointer.
5472 * fcp = port structure pointer.
5475 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5481 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*ha
, fc_port_t
*fcport
)
5487 if (atomic_read(&fcport
->state
) == FCS_UNCONFIGURED
||
5488 fcport
->port_type
!= FCT_TARGET
||
5489 fcport
->loop_id
== FC_NO_LOOP_ID
)
5490 return QLA_FUNCTION_FAILED
;
5492 priority
= qla24xx_get_fcp_prio(ha
, fcport
);
5493 ret
= qla24xx_set_fcp_prio(ha
, fcport
->loop_id
, priority
, mb
);
5494 if (ret
== QLA_SUCCESS
)
5495 fcport
->fcp_prio
= priority
;
5497 DEBUG2(printk(KERN_WARNING
5498 "scsi(%ld): Unable to activate fcp priority, "
5499 " ret=0x%x\n", ha
->host_no
, ret
));
5505 * qla24xx_update_all_fcp_prio
5506 * Activates fcp priority for all the logged in ports
5509 * ha = adapter block pointer.
5512 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5518 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5523 ret
= QLA_FUNCTION_FAILED
;
5524 /* We need to set priority for all logged in ports */
5525 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5526 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);