2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
21 * QLogic ISP2x00 Hardware Support Function Prototypes.
23 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
24 static int qla2x00_setup_chip(scsi_qla_host_t
*);
25 static int qla2x00_init_rings(scsi_qla_host_t
*);
26 static int qla2x00_fw_ready(scsi_qla_host_t
*);
27 static int qla2x00_configure_hba(scsi_qla_host_t
*);
28 static int qla2x00_configure_loop(scsi_qla_host_t
*);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
30 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
32 static int qla2x00_device_resync(scsi_qla_host_t
*);
33 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
36 static int qla2x00_restart_isp(scsi_qla_host_t
*);
38 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
39 static int qla84xx_init_chip(scsi_qla_host_t
*);
40 static int qla25xx_init_queues(struct qla_hw_data
*);
42 /* SRB Extensions ---------------------------------------------------------- */
45 qla2x00_ctx_sp_timeout(unsigned long __data
)
47 srb_t
*sp
= (srb_t
*)__data
;
49 struct srb_iocb
*iocb
;
50 fc_port_t
*fcport
= sp
->fcport
;
51 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
55 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
56 req
= ha
->req_q_map
[0];
57 req
->outstanding_cmds
[sp
->handle
] = NULL
;
59 iocb
= ctx
->u
.iocb_cmd
;
62 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
66 qla2x00_ctx_sp_free(srb_t
*sp
)
68 struct srb_ctx
*ctx
= sp
->ctx
;
69 struct srb_iocb
*iocb
= ctx
->u
.iocb_cmd
;
70 struct scsi_qla_host
*vha
= sp
->fcport
->vha
;
72 del_timer(&iocb
->timer
);
75 mempool_free(sp
, sp
->fcport
->vha
->hw
->srb_mempool
);
77 QLA_VHA_MARK_NOT_BUSY(vha
);
81 qla2x00_get_ctx_sp(scsi_qla_host_t
*vha
, fc_port_t
*fcport
, size_t size
,
85 struct qla_hw_data
*ha
= vha
->hw
;
87 struct srb_iocb
*iocb
;
90 QLA_VHA_MARK_BUSY(vha
, bail
);
94 sp
= mempool_alloc(ha
->srb_mempool
, GFP_KERNEL
);
97 ctx
= kzalloc(size
, GFP_KERNEL
);
99 mempool_free(sp
, ha
->srb_mempool
);
103 iocb
= kzalloc(sizeof(struct srb_iocb
), GFP_KERNEL
);
105 mempool_free(sp
, ha
->srb_mempool
);
111 memset(sp
, 0, sizeof(*sp
));
114 ctx
->u
.iocb_cmd
= iocb
;
115 iocb
->free
= qla2x00_ctx_sp_free
;
117 init_timer(&iocb
->timer
);
120 iocb
->timer
.expires
= jiffies
+ tmo
* HZ
;
121 iocb
->timer
.data
= (unsigned long)sp
;
122 iocb
->timer
.function
= qla2x00_ctx_sp_timeout
;
123 add_timer(&iocb
->timer
);
126 QLA_VHA_MARK_NOT_BUSY(vha
);
130 /* Asynchronous Login/Logout Routines -------------------------------------- */
132 static inline unsigned long
133 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
136 struct qla_hw_data
*ha
= vha
->hw
;
138 /* Firmware should use switch negotiated r_a_tov for timeout. */
139 tmo
= ha
->r_a_tov
/ 10 * 2;
140 if (!IS_FWI2_CAPABLE(ha
)) {
142 * Except for earlier ISPs where the timeout is seeded from the
143 * initialization control block.
145 tmo
= ha
->login_timeout
;
151 qla2x00_async_iocb_timeout(srb_t
*sp
)
153 fc_port_t
*fcport
= sp
->fcport
;
154 struct srb_ctx
*ctx
= sp
->ctx
;
156 DEBUG2(printk(KERN_WARNING
157 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
158 fcport
->vha
->host_no
, sp
->handle
,
159 ctx
->name
, fcport
->d_id
.b
.domain
,
160 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
162 fcport
->flags
&= ~FCF_ASYNC_SENT
;
163 if (ctx
->type
== SRB_LOGIN_CMD
) {
164 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
165 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
166 /* Retry as needed. */
167 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
168 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
169 QLA_LOGIO_LOGIN_RETRIED
: 0;
170 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
,
176 qla2x00_async_login_ctx_done(srb_t
*sp
)
178 struct srb_ctx
*ctx
= sp
->ctx
;
179 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
181 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
187 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
192 struct srb_iocb
*lio
;
195 rval
= QLA_FUNCTION_FAILED
;
196 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
197 qla2x00_get_async_timeout(vha
) + 2);
202 ctx
->type
= SRB_LOGIN_CMD
;
204 lio
= ctx
->u
.iocb_cmd
;
205 lio
->timeout
= qla2x00_async_iocb_timeout
;
206 lio
->done
= qla2x00_async_login_ctx_done
;
207 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
208 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
209 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
210 rval
= qla2x00_start_sp(sp
);
211 if (rval
!= QLA_SUCCESS
)
214 DEBUG2(printk(KERN_DEBUG
215 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
216 "retries=%d.\n", fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
217 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
218 fcport
->login_retry
));
228 qla2x00_async_logout_ctx_done(srb_t
*sp
)
230 struct srb_ctx
*ctx
= sp
->ctx
;
231 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
233 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
239 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
243 struct srb_iocb
*lio
;
246 rval
= QLA_FUNCTION_FAILED
;
247 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
248 qla2x00_get_async_timeout(vha
) + 2);
253 ctx
->type
= SRB_LOGOUT_CMD
;
254 ctx
->name
= "logout";
255 lio
= ctx
->u
.iocb_cmd
;
256 lio
->timeout
= qla2x00_async_iocb_timeout
;
257 lio
->done
= qla2x00_async_logout_ctx_done
;
258 rval
= qla2x00_start_sp(sp
);
259 if (rval
!= QLA_SUCCESS
)
262 DEBUG2(printk(KERN_DEBUG
263 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
264 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
265 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
275 qla2x00_async_adisc_ctx_done(srb_t
*sp
)
277 struct srb_ctx
*ctx
= sp
->ctx
;
278 struct srb_iocb
*lio
= ctx
->u
.iocb_cmd
;
280 qla2x00_post_async_adisc_done_work(sp
->fcport
->vha
, sp
->fcport
,
286 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
291 struct srb_iocb
*lio
;
294 rval
= QLA_FUNCTION_FAILED
;
295 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
296 qla2x00_get_async_timeout(vha
) + 2);
301 ctx
->type
= SRB_ADISC_CMD
;
303 lio
= ctx
->u
.iocb_cmd
;
304 lio
->timeout
= qla2x00_async_iocb_timeout
;
305 lio
->done
= qla2x00_async_adisc_ctx_done
;
306 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
307 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
308 rval
= qla2x00_start_sp(sp
);
309 if (rval
!= QLA_SUCCESS
)
312 DEBUG2(printk(KERN_DEBUG
313 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
314 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
315 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
326 qla2x00_async_tm_cmd_ctx_done(srb_t
*sp
)
328 struct srb_ctx
*ctx
= sp
->ctx
;
329 struct srb_iocb
*iocb
= (struct srb_iocb
*)ctx
->u
.iocb_cmd
;
331 qla2x00_async_tm_cmd_done(sp
->fcport
->vha
, sp
->fcport
, iocb
);
336 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
339 struct scsi_qla_host
*vha
= fcport
->vha
;
342 struct srb_iocb
*tcf
;
345 rval
= QLA_FUNCTION_FAILED
;
346 sp
= qla2x00_get_ctx_sp(vha
, fcport
, sizeof(struct srb_ctx
),
347 qla2x00_get_async_timeout(vha
) + 2);
352 ctx
->type
= SRB_TM_CMD
;
354 tcf
= ctx
->u
.iocb_cmd
;
355 tcf
->u
.tmf
.flags
= flags
;
356 tcf
->u
.tmf
.lun
= lun
;
357 tcf
->u
.tmf
.data
= tag
;
358 tcf
->timeout
= qla2x00_async_iocb_timeout
;
359 tcf
->done
= qla2x00_async_tm_cmd_ctx_done
;
361 rval
= qla2x00_start_sp(sp
);
362 if (rval
!= QLA_SUCCESS
)
365 DEBUG2(printk(KERN_DEBUG
366 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
367 fcport
->vha
->host_no
, sp
->handle
, fcport
->loop_id
,
368 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
379 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
385 case MBS_COMMAND_COMPLETE
:
386 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
387 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
390 qla2x00_update_fcport(vha
, fcport
);
392 case MBS_COMMAND_ERROR
:
393 fcport
->flags
&= ~FCF_ASYNC_SENT
;
394 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
395 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
397 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
399 case MBS_PORT_ID_USED
:
400 fcport
->loop_id
= data
[1];
401 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
402 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
404 case MBS_LOOP_ID_USED
:
406 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
407 if (rval
!= QLA_SUCCESS
) {
408 fcport
->flags
&= ~FCF_ASYNC_SENT
;
409 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
412 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
419 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
422 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
427 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
430 if (data
[0] == MBS_COMMAND_COMPLETE
) {
431 qla2x00_update_fcport(vha
, fcport
);
437 fcport
->flags
&= ~FCF_ASYNC_SENT
;
438 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
439 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
441 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
447 qla2x00_async_tm_cmd_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
448 struct srb_iocb
*iocb
)
454 flags
= iocb
->u
.tmf
.flags
;
455 lun
= (uint16_t)iocb
->u
.tmf
.lun
;
457 /* Issue Marker IOCB */
458 rval
= qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
459 vha
->hw
->rsp_q_map
[0], fcport
->loop_id
, lun
,
460 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
462 if ((rval
!= QLA_SUCCESS
) || iocb
->u
.tmf
.data
) {
463 DEBUG2_3_11(printk(KERN_WARNING
464 "%s(%ld): TM IOCB failed (%x).\n",
465 __func__
, vha
->host_no
, rval
));
471 /****************************************************************************/
472 /* QLogic ISP2x00 Hardware Support Functions. */
473 /****************************************************************************/
476 * qla2x00_initialize_adapter
480 * ha = adapter block pointer.
486 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
489 struct qla_hw_data
*ha
= vha
->hw
;
490 struct req_que
*req
= ha
->req_q_map
[0];
492 /* Clear adapter flags. */
493 vha
->flags
.online
= 0;
494 ha
->flags
.chip_reset_done
= 0;
495 vha
->flags
.reset_active
= 0;
496 ha
->flags
.pci_channel_io_perm_failure
= 0;
497 ha
->flags
.eeh_busy
= 0;
498 ha
->flags
.thermal_supported
= 1;
499 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
500 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
501 vha
->device_flags
= DFLG_NO_CABLE
;
503 vha
->flags
.management_server_logged_in
= 0;
504 vha
->marker_needed
= 0;
505 ha
->isp_abort_cnt
= 0;
506 ha
->beacon_blink_led
= 0;
508 set_bit(0, ha
->req_qid_map
);
509 set_bit(0, ha
->rsp_qid_map
);
511 qla_printk(KERN_INFO
, ha
, "Configuring PCI space...\n");
512 rval
= ha
->isp_ops
->pci_config(vha
);
514 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
519 ha
->isp_ops
->reset_chip(vha
);
521 rval
= qla2xxx_get_flash_info(vha
);
523 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
528 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
530 qla_printk(KERN_INFO
, ha
, "Configure NVRAM parameters...\n");
532 ha
->isp_ops
->nvram_config(vha
);
534 if (ha
->flags
.disable_serdes
) {
535 /* Mask HBA via NVRAM settings? */
536 qla_printk(KERN_INFO
, ha
, "Masking HBA WWPN "
537 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
538 vha
->port_name
[0], vha
->port_name
[1],
539 vha
->port_name
[2], vha
->port_name
[3],
540 vha
->port_name
[4], vha
->port_name
[5],
541 vha
->port_name
[6], vha
->port_name
[7]);
542 return QLA_FUNCTION_FAILED
;
545 qla_printk(KERN_INFO
, ha
, "Verifying loaded RISC code...\n");
547 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
548 rval
= ha
->isp_ops
->chip_diag(vha
);
551 rval
= qla2x00_setup_chip(vha
);
556 if (IS_QLA84XX(ha
)) {
557 ha
->cs84xx
= qla84xx_get_chip(vha
);
559 qla_printk(KERN_ERR
, ha
,
560 "Unable to configure ISP84XX.\n");
561 return QLA_FUNCTION_FAILED
;
564 rval
= qla2x00_init_rings(vha
);
565 ha
->flags
.chip_reset_done
= 1;
567 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
568 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
569 rval
= qla84xx_init_chip(vha
);
570 if (rval
!= QLA_SUCCESS
) {
571 qla_printk(KERN_ERR
, ha
,
572 "Unable to initialize ISP84XX.\n");
573 qla84xx_put_chip(vha
);
577 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
578 qla24xx_read_fcp_prio_cfg(vha
);
584 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
587 * Returns 0 on success.
590 qla2100_pci_config(scsi_qla_host_t
*vha
)
594 struct qla_hw_data
*ha
= vha
->hw
;
595 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
597 pci_set_master(ha
->pdev
);
598 pci_try_set_mwi(ha
->pdev
);
600 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
601 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
602 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
604 pci_disable_rom(ha
->pdev
);
606 /* Get PCI bus information. */
607 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
608 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
609 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
615 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
618 * Returns 0 on success.
621 qla2300_pci_config(scsi_qla_host_t
*vha
)
624 unsigned long flags
= 0;
626 struct qla_hw_data
*ha
= vha
->hw
;
627 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
629 pci_set_master(ha
->pdev
);
630 pci_try_set_mwi(ha
->pdev
);
632 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
633 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
635 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
636 w
&= ~PCI_COMMAND_INTX_DISABLE
;
637 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
640 * If this is a 2300 card and not 2312, reset the
641 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
642 * the 2310 also reports itself as a 2300 so we need to get the
643 * fb revision level -- a 6 indicates it really is a 2300 and
646 if (IS_QLA2300(ha
)) {
647 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
650 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
651 for (cnt
= 0; cnt
< 30000; cnt
++) {
652 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
658 /* Select FPM registers. */
659 WRT_REG_WORD(®
->ctrl_status
, 0x20);
660 RD_REG_WORD(®
->ctrl_status
);
662 /* Get the fb rev level */
663 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
665 if (ha
->fb_rev
== FPM_2300
)
666 pci_clear_mwi(ha
->pdev
);
668 /* Deselect FPM registers. */
669 WRT_REG_WORD(®
->ctrl_status
, 0x0);
670 RD_REG_WORD(®
->ctrl_status
);
672 /* Release RISC module. */
673 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
674 for (cnt
= 0; cnt
< 30000; cnt
++) {
675 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
681 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
684 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
686 pci_disable_rom(ha
->pdev
);
688 /* Get PCI bus information. */
689 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
690 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
691 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
697 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
700 * Returns 0 on success.
703 qla24xx_pci_config(scsi_qla_host_t
*vha
)
706 unsigned long flags
= 0;
707 struct qla_hw_data
*ha
= vha
->hw
;
708 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
710 pci_set_master(ha
->pdev
);
711 pci_try_set_mwi(ha
->pdev
);
713 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
714 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
715 w
&= ~PCI_COMMAND_INTX_DISABLE
;
716 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
718 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
720 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
721 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
722 pcix_set_mmrbc(ha
->pdev
, 2048);
724 /* PCIe -- adjust Maximum Read Request Size (2048). */
725 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
726 pcie_set_readrq(ha
->pdev
, 2048);
728 pci_disable_rom(ha
->pdev
);
730 ha
->chip_revision
= ha
->pdev
->revision
;
732 /* Get PCI bus information. */
733 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
734 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
735 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
741 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
744 * Returns 0 on success.
747 qla25xx_pci_config(scsi_qla_host_t
*vha
)
750 struct qla_hw_data
*ha
= vha
->hw
;
752 pci_set_master(ha
->pdev
);
753 pci_try_set_mwi(ha
->pdev
);
755 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
756 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
757 w
&= ~PCI_COMMAND_INTX_DISABLE
;
758 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
760 /* PCIe -- adjust Maximum Read Request Size (2048). */
761 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
762 pcie_set_readrq(ha
->pdev
, 2048);
764 pci_disable_rom(ha
->pdev
);
766 ha
->chip_revision
= ha
->pdev
->revision
;
772 * qla2x00_isp_firmware() - Choose firmware image.
775 * Returns 0 on success.
778 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
781 uint16_t loop_id
, topo
, sw_cap
;
782 uint8_t domain
, area
, al_pa
;
783 struct qla_hw_data
*ha
= vha
->hw
;
785 /* Assume loading risc code */
786 rval
= QLA_FUNCTION_FAILED
;
788 if (ha
->flags
.disable_risc_code_load
) {
789 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
791 qla_printk(KERN_INFO
, ha
, "RISC CODE NOT loaded\n");
793 /* Verify checksum of loaded RISC code. */
794 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
795 if (rval
== QLA_SUCCESS
) {
796 /* And, verify we are not in ROM code. */
797 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
798 &area
, &domain
, &topo
, &sw_cap
);
803 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
811 * qla2x00_reset_chip() - Reset ISP chip.
814 * Returns 0 on success.
817 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
819 unsigned long flags
= 0;
820 struct qla_hw_data
*ha
= vha
->hw
;
821 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
825 if (unlikely(pci_channel_offline(ha
->pdev
)))
828 ha
->isp_ops
->disable_intrs(ha
);
830 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
832 /* Turn off master enable */
834 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
835 cmd
&= ~PCI_COMMAND_MASTER
;
836 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
838 if (!IS_QLA2100(ha
)) {
840 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
841 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
842 for (cnt
= 0; cnt
< 30000; cnt
++) {
843 if ((RD_REG_WORD(®
->hccr
) &
844 HCCR_RISC_PAUSE
) != 0)
849 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
853 /* Select FPM registers. */
854 WRT_REG_WORD(®
->ctrl_status
, 0x20);
855 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
857 /* FPM Soft Reset. */
858 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
859 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
861 /* Toggle Fpm Reset. */
862 if (!IS_QLA2200(ha
)) {
863 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
864 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
867 /* Select frame buffer registers. */
868 WRT_REG_WORD(®
->ctrl_status
, 0x10);
869 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
871 /* Reset frame buffer FIFOs. */
872 if (IS_QLA2200(ha
)) {
873 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
874 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
876 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
878 /* Read back fb_cmd until zero or 3 seconds max */
879 for (cnt
= 0; cnt
< 3000; cnt
++) {
880 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
886 /* Select RISC module registers. */
887 WRT_REG_WORD(®
->ctrl_status
, 0);
888 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
890 /* Reset RISC processor. */
891 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
892 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
894 /* Release RISC processor. */
895 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
896 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
899 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
900 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
902 /* Reset ISP chip. */
903 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
905 /* Wait for RISC to recover from reset. */
906 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
908 * It is necessary to for a delay here since the card doesn't
909 * respond to PCI reads during a reset. On some architectures
910 * this will result in an MCA.
913 for (cnt
= 30000; cnt
; cnt
--) {
914 if ((RD_REG_WORD(®
->ctrl_status
) &
915 CSR_ISP_SOFT_RESET
) == 0)
922 /* Reset RISC processor. */
923 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
925 WRT_REG_WORD(®
->semaphore
, 0);
927 /* Release RISC processor. */
928 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
929 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
931 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
932 for (cnt
= 0; cnt
< 30000; cnt
++) {
933 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
941 /* Turn on master enable */
942 cmd
|= PCI_COMMAND_MASTER
;
943 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
945 /* Disable RISC pause on FPM parity error. */
946 if (!IS_QLA2100(ha
)) {
947 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
948 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
951 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
955 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
957 * Returns 0 on success.
960 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
962 uint16_t mb
[4] = {0x1010, 0, 1, 0};
964 return qla81xx_write_mpi_register(vha
, mb
);
968 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
971 * Returns 0 on success.
974 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
976 unsigned long flags
= 0;
977 struct qla_hw_data
*ha
= vha
->hw
;
978 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
981 static int abts_cnt
; /* ISP abort retry counts */
983 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
986 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
987 for (cnt
= 0; cnt
< 30000; cnt
++) {
988 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
994 WRT_REG_DWORD(®
->ctrl_status
,
995 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
996 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
999 /* Wait for firmware to complete NVRAM accesses. */
1000 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1001 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
1003 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1007 /* Wait for soft-reset to complete. */
1008 d2
= RD_REG_DWORD(®
->ctrl_status
);
1009 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
1011 d2
= RD_REG_DWORD(®
->ctrl_status
);
1015 /* If required, do an MPI FW reset now */
1016 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
1017 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
1018 if (++abts_cnt
< 5) {
1019 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1020 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
1023 * We exhausted the ISP abort retries. We have to
1024 * set the board offline.
1027 vha
->flags
.online
= 0;
1032 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
1033 RD_REG_DWORD(®
->hccr
);
1035 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
1036 RD_REG_DWORD(®
->hccr
);
1038 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1039 RD_REG_DWORD(®
->hccr
);
1041 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1042 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1044 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1048 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1050 if (IS_NOPOLLING_TYPE(ha
))
1051 ha
->isp_ops
->enable_intrs(ha
);
1055 * qla24xx_reset_chip() - Reset ISP24xx chip.
1058 * Returns 0 on success.
1061 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1063 struct qla_hw_data
*ha
= vha
->hw
;
1065 if (pci_channel_offline(ha
->pdev
) &&
1066 ha
->flags
.pci_channel_io_perm_failure
) {
1070 ha
->isp_ops
->disable_intrs(ha
);
1072 /* Perform RISC reset. */
1073 qla24xx_reset_risc(vha
);
1077 * qla2x00_chip_diag() - Test chip for proper operation.
1080 * Returns 0 on success.
1083 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1086 struct qla_hw_data
*ha
= vha
->hw
;
1087 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1088 unsigned long flags
= 0;
1092 struct req_que
*req
= ha
->req_q_map
[0];
1094 /* Assume a failed state */
1095 rval
= QLA_FUNCTION_FAILED
;
1097 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
1098 vha
->host_no
, (u_long
)®
->flash_address
));
1100 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1102 /* Reset ISP chip. */
1103 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1106 * We need to have a delay here since the card will not respond while
1107 * in reset causing an MCA on some architectures.
1110 data
= qla2x00_debounce_register(®
->ctrl_status
);
1111 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1113 data
= RD_REG_WORD(®
->ctrl_status
);
1118 goto chip_diag_failed
;
1120 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
1123 /* Reset RISC processor. */
1124 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1125 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1127 /* Workaround for QLA2312 PCI parity error */
1128 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1129 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1130 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1132 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1139 goto chip_diag_failed
;
1141 /* Check product ID of chip */
1142 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha
->host_no
));
1144 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1145 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1146 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1147 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1148 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1149 mb
[3] != PROD_ID_3
) {
1150 qla_printk(KERN_WARNING
, ha
,
1151 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb
[1], mb
[2], mb
[3]);
1153 goto chip_diag_failed
;
1155 ha
->product_id
[0] = mb
[1];
1156 ha
->product_id
[1] = mb
[2];
1157 ha
->product_id
[2] = mb
[3];
1158 ha
->product_id
[3] = mb
[4];
1160 /* Adjust fw RISC transfer size */
1161 if (req
->length
> 1024)
1162 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1164 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1167 if (IS_QLA2200(ha
) &&
1168 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1169 /* Limit firmware transfer size with a 2200A */
1170 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
1173 ha
->device_type
|= DT_ISP2200A
;
1174 ha
->fw_transfer_size
= 128;
1177 /* Wrap Incoming Mailboxes Test. */
1178 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1180 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha
->host_no
));
1181 rval
= qla2x00_mbx_reg_test(vha
);
1183 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1185 qla_printk(KERN_WARNING
, ha
,
1186 "Failed mailbox send register test\n");
1189 /* Flag a successful rval */
1192 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1196 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
1197 "****\n", vha
->host_no
));
1199 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1205 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1208 * Returns 0 on success.
1211 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1214 struct qla_hw_data
*ha
= vha
->hw
;
1215 struct req_que
*req
= ha
->req_q_map
[0];
1220 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1222 rval
= qla2x00_mbx_reg_test(vha
);
1224 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1226 qla_printk(KERN_WARNING
, ha
,
1227 "Failed mailbox send register test\n");
1229 /* Flag a successful rval */
1237 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1240 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1241 eft_size
, fce_size
, mq_size
;
1244 struct qla_hw_data
*ha
= vha
->hw
;
1245 struct req_que
*req
= ha
->req_q_map
[0];
1246 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1249 qla_printk(KERN_WARNING
, ha
,
1250 "Firmware dump previously allocated.\n");
1255 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1256 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1257 fixed_size
= sizeof(struct qla2100_fw_dump
);
1258 } else if (IS_QLA23XX(ha
)) {
1259 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1260 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1262 } else if (IS_FWI2_CAPABLE(ha
)) {
1264 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1265 else if (IS_QLA25XX(ha
))
1266 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1268 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1269 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1272 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1273 /* Allocate memory for Fibre Channel Event Buffer. */
1274 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
))
1277 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1280 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1281 "(%d KB) for FCE.\n", FCE_SIZE
/ 1024);
1285 memset(tc
, 0, FCE_SIZE
);
1286 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1287 ha
->fce_mb
, &ha
->fce_bufs
);
1289 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1290 "FCE (%d).\n", rval
);
1291 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1293 ha
->flags
.fce_enabled
= 0;
1297 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for FCE...\n",
1300 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1301 ha
->flags
.fce_enabled
= 1;
1302 ha
->fce_dma
= tc_dma
;
1305 /* Allocate memory for Extended Trace Buffer. */
1306 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1309 qla_printk(KERN_WARNING
, ha
, "Unable to allocate "
1310 "(%d KB) for EFT.\n", EFT_SIZE
/ 1024);
1314 memset(tc
, 0, EFT_SIZE
);
1315 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1317 qla_printk(KERN_WARNING
, ha
, "Unable to initialize "
1318 "EFT (%d).\n", rval
);
1319 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1324 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for EFT...\n",
1327 eft_size
= EFT_SIZE
;
1328 ha
->eft_dma
= tc_dma
;
1332 req_q_size
= req
->length
* sizeof(request_t
);
1333 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1335 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1336 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1337 ha
->chain_offset
= dump_size
;
1338 dump_size
+= mq_size
+ fce_size
;
1340 ha
->fw_dump
= vmalloc(dump_size
);
1342 qla_printk(KERN_WARNING
, ha
, "Unable to allocate (%d KB) for "
1343 "firmware dump!!!\n", dump_size
/ 1024);
1346 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1353 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1360 qla_printk(KERN_INFO
, ha
, "Allocated (%d KB) for firmware dump...\n",
1363 ha
->fw_dump_len
= dump_size
;
1364 ha
->fw_dump
->signature
[0] = 'Q';
1365 ha
->fw_dump
->signature
[1] = 'L';
1366 ha
->fw_dump
->signature
[2] = 'G';
1367 ha
->fw_dump
->signature
[3] = 'C';
1368 ha
->fw_dump
->version
= __constant_htonl(1);
1370 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1371 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1372 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1373 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1375 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1376 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1377 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1379 ha
->fw_dump
->header_size
=
1380 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1384 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1386 #define MPS_MASK 0xe0
1390 struct qla_hw_data
*ha
= vha
->hw
;
1392 if (!IS_QLA81XX(vha
->hw
))
1395 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1396 if (rval
!= QLA_SUCCESS
) {
1397 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1398 "Sync-MPI: Unable to acquire semaphore.\n"));
1402 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1403 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1404 if (rval
!= QLA_SUCCESS
) {
1405 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1406 "Sync-MPI: Unable to read sync.\n"));
1411 if (dc
== (dw
& MPS_MASK
))
1416 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1417 if (rval
!= QLA_SUCCESS
) {
1418 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1419 "Sync-MPI: Unable to gain sync.\n"));
1423 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1424 if (rval
!= QLA_SUCCESS
) {
1425 DEBUG2(qla_printk(KERN_WARNING
, ha
,
1426 "Sync-MPI: Unable to release semaphore.\n"));
1434 * qla2x00_setup_chip() - Load and start RISC firmware.
1437 * Returns 0 on success.
1440 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1443 uint32_t srisc_address
= 0;
1444 struct qla_hw_data
*ha
= vha
->hw
;
1445 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1446 unsigned long flags
;
1447 uint16_t fw_major_version
;
1449 if (IS_QLA82XX(ha
)) {
1450 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1451 if (rval
== QLA_SUCCESS
) {
1452 qla2x00_stop_firmware(vha
);
1453 goto enable_82xx_npiv
;
1458 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1459 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1460 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1461 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1462 RD_REG_WORD(®
->hccr
);
1463 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1466 qla81xx_mpi_sync(vha
);
1468 /* Load firmware sequences */
1469 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1470 if (rval
== QLA_SUCCESS
) {
1471 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
1472 "code.\n", vha
->host_no
));
1474 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1475 if (rval
== QLA_SUCCESS
) {
1476 /* Start firmware execution. */
1477 DEBUG(printk("scsi(%ld): Checksum OK, start "
1478 "firmware.\n", vha
->host_no
));
1480 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1481 /* Retrieve firmware information. */
1482 if (rval
== QLA_SUCCESS
) {
1484 fw_major_version
= ha
->fw_major_version
;
1485 rval
= qla2x00_get_fw_version(vha
,
1486 &ha
->fw_major_version
,
1487 &ha
->fw_minor_version
,
1488 &ha
->fw_subminor_version
,
1489 &ha
->fw_attributes
, &ha
->fw_memory_size
,
1490 ha
->mpi_version
, &ha
->mpi_capabilities
,
1492 if (rval
!= QLA_SUCCESS
)
1494 ha
->flags
.npiv_supported
= 0;
1495 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1496 (ha
->fw_attributes
& BIT_2
)) {
1497 ha
->flags
.npiv_supported
= 1;
1498 if ((!ha
->max_npiv_vports
) ||
1499 ((ha
->max_npiv_vports
+ 1) %
1500 MIN_MULTI_ID_FABRIC
))
1501 ha
->max_npiv_vports
=
1502 MIN_MULTI_ID_FABRIC
- 1;
1504 qla2x00_get_resource_cnts(vha
, NULL
,
1505 &ha
->fw_xcb_count
, NULL
, NULL
,
1506 &ha
->max_npiv_vports
, NULL
);
1508 if (!fw_major_version
&& ql2xallocfwdump
) {
1509 if (!IS_QLA82XX(ha
))
1510 qla2x00_alloc_fw_dump(vha
);
1514 DEBUG2(printk(KERN_INFO
1515 "scsi(%ld): ISP Firmware failed checksum.\n",
1520 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1521 /* Enable proper parity. */
1522 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1525 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1527 /* SRAM, Instruction RAM and GP RAM parity */
1528 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1529 RD_REG_WORD(®
->hccr
);
1530 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1533 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1536 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1537 if (rval
== QLA_SUCCESS
) {
1538 ha
->flags
.fac_supported
= 1;
1539 ha
->fdt_block_size
= size
<< 2;
1541 qla_printk(KERN_ERR
, ha
,
1542 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1543 ha
->fw_major_version
, ha
->fw_minor_version
,
1544 ha
->fw_subminor_version
);
1549 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
1557 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1560 * Beginning of request ring has initialization control block already built
1561 * by nvram config routine.
1563 * Returns 0 on success.
1566 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1571 rsp
->ring_ptr
= rsp
->ring
;
1572 rsp
->ring_index
= 0;
1573 rsp
->status_srb
= NULL
;
1574 pkt
= rsp
->ring_ptr
;
1575 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1576 pkt
->signature
= RESPONSE_PROCESSED
;
1582 * qla2x00_update_fw_options() - Read and process firmware options.
1585 * Returns 0 on success.
1588 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1590 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1591 struct qla_hw_data
*ha
= vha
->hw
;
1593 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1594 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1596 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1599 /* Serial Link options. */
1600 DEBUG3(printk("scsi(%ld): Serial link options:\n",
1602 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha
->fw_seriallink_options
,
1603 sizeof(ha
->fw_seriallink_options
)));
1605 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1606 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1607 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1610 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1611 emphasis
= (ha
->fw_seriallink_options
[2] &
1612 (BIT_4
| BIT_3
)) >> 3;
1613 tx_sens
= ha
->fw_seriallink_options
[0] &
1614 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1615 rx_sens
= (ha
->fw_seriallink_options
[0] &
1616 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1617 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1618 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1621 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1622 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1623 ha
->fw_options
[10] |= BIT_5
|
1624 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1625 (tx_sens
& (BIT_1
| BIT_0
));
1628 swing
= (ha
->fw_seriallink_options
[2] &
1629 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1630 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1631 tx_sens
= ha
->fw_seriallink_options
[1] &
1632 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1633 rx_sens
= (ha
->fw_seriallink_options
[1] &
1634 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1635 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1636 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1639 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1640 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1641 ha
->fw_options
[11] |= BIT_5
|
1642 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1643 (tx_sens
& (BIT_1
| BIT_0
));
1647 /* Return command IOCBs without waiting for an ABTS to complete. */
1648 ha
->fw_options
[3] |= BIT_13
;
1651 if (ha
->flags
.enable_led_scheme
)
1652 ha
->fw_options
[2] |= BIT_12
;
1654 /* Detect ISP6312. */
1656 ha
->fw_options
[2] |= BIT_13
;
1658 /* Update firmware options. */
1659 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1663 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1666 struct qla_hw_data
*ha
= vha
->hw
;
1671 /* Update Serial Link options. */
1672 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1675 rval
= qla2x00_set_serdes_params(vha
,
1676 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1677 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1678 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1679 if (rval
!= QLA_SUCCESS
) {
1680 qla_printk(KERN_WARNING
, ha
,
1681 "Unable to update Serial Link options (%x).\n", rval
);
1686 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1688 struct qla_hw_data
*ha
= vha
->hw
;
1689 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1690 struct req_que
*req
= ha
->req_q_map
[0];
1691 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1693 /* Setup ring parameters in initialization control block. */
1694 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1695 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1696 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1697 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1698 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1699 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1700 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1701 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1703 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1704 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1705 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1706 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1707 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1711 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1713 struct qla_hw_data
*ha
= vha
->hw
;
1714 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1715 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1716 struct qla_msix_entry
*msix
;
1717 struct init_cb_24xx
*icb
;
1719 struct req_que
*req
= ha
->req_q_map
[0];
1720 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1722 /* Setup ring parameters in initialization control block. */
1723 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1724 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1725 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1726 icb
->request_q_length
= cpu_to_le16(req
->length
);
1727 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1728 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1729 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1730 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1731 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1734 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1735 icb
->rid
= __constant_cpu_to_le16(rid
);
1736 if (ha
->flags
.msix_enabled
) {
1737 msix
= &ha
->msix_entries
[1];
1738 DEBUG2_17(printk(KERN_INFO
1739 "Registering vector 0x%x for base que\n", msix
->entry
));
1740 icb
->msix
= cpu_to_le16(msix
->entry
);
1742 /* Use alternate PCI bus number */
1744 icb
->firmware_options_2
|=
1745 __constant_cpu_to_le32(BIT_19
);
1746 /* Use alternate PCI devfn */
1748 icb
->firmware_options_2
|=
1749 __constant_cpu_to_le32(BIT_18
);
1751 /* Use Disable MSIX Handshake mode for capable adapters */
1752 if (IS_MSIX_NACK_CAPABLE(ha
)) {
1753 icb
->firmware_options_2
&=
1754 __constant_cpu_to_le32(~BIT_22
);
1755 ha
->flags
.disable_msix_handshake
= 1;
1756 qla_printk(KERN_INFO
, ha
,
1757 "MSIX Handshake Disable Mode turned on\n");
1759 icb
->firmware_options_2
|=
1760 __constant_cpu_to_le32(BIT_22
);
1762 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1764 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1765 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1766 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1767 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1769 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1770 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1771 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1772 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1775 RD_REG_DWORD(&ioreg
->hccr
);
1779 * qla2x00_init_rings() - Initializes firmware.
1782 * Beginning of request ring has initialization control block already built
1783 * by nvram config routine.
1785 * Returns 0 on success.
1788 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1791 unsigned long flags
= 0;
1793 struct qla_hw_data
*ha
= vha
->hw
;
1794 struct req_que
*req
;
1795 struct rsp_que
*rsp
;
1796 struct scsi_qla_host
*vp
;
1797 struct mid_init_cb_24xx
*mid_init_cb
=
1798 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1800 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1802 /* Clear outstanding commands array. */
1803 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1804 req
= ha
->req_q_map
[que
];
1807 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1808 req
->outstanding_cmds
[cnt
] = NULL
;
1810 req
->current_outstanding_cmd
= 1;
1812 /* Initialize firmware. */
1813 req
->ring_ptr
= req
->ring
;
1814 req
->ring_index
= 0;
1815 req
->cnt
= req
->length
;
1818 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1819 rsp
= ha
->rsp_q_map
[que
];
1822 /* Initialize response queue entries */
1823 qla2x00_init_response_q_entries(rsp
);
1826 spin_lock(&ha
->vport_slock
);
1827 /* Clear RSCN queue. */
1828 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
1829 vp
->rscn_in_ptr
= 0;
1830 vp
->rscn_out_ptr
= 0;
1833 spin_unlock(&ha
->vport_slock
);
1835 ha
->isp_ops
->config_rings(vha
);
1837 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1839 /* Update any ISP specific firmware options before initialization. */
1840 ha
->isp_ops
->update_fw_options(vha
);
1842 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha
->host_no
));
1844 if (ha
->flags
.npiv_supported
) {
1845 if (ha
->operating_mode
== LOOP
)
1846 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1847 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1850 if (IS_FWI2_CAPABLE(ha
)) {
1851 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1852 mid_init_cb
->init_cb
.execution_throttle
=
1853 cpu_to_le16(ha
->fw_xcb_count
);
1856 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1858 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1861 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1869 * qla2x00_fw_ready() - Waits for firmware ready.
1872 * Returns 0 on success.
1875 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1878 unsigned long wtime
, mtime
, cs84xx_time
;
1879 uint16_t min_wait
; /* Minimum wait time if loop is down */
1880 uint16_t wait_time
; /* Wait time if loop is coming ready */
1882 struct qla_hw_data
*ha
= vha
->hw
;
1886 /* 20 seconds for loop down. */
1890 * Firmware should take at most one RATOV to login, plus 5 seconds for
1891 * our own processing.
1893 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1894 wait_time
= min_wait
;
1897 /* Min wait time if loop down */
1898 mtime
= jiffies
+ (min_wait
* HZ
);
1900 /* wait time before firmware ready */
1901 wtime
= jiffies
+ (wait_time
* HZ
);
1903 /* Wait for ISP to finish LIP */
1904 if (!vha
->flags
.init_done
)
1905 qla_printk(KERN_INFO
, ha
, "Waiting for LIP to complete...\n");
1907 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1911 rval
= qla2x00_get_firmware_state(vha
, state
);
1912 if (rval
== QLA_SUCCESS
) {
1913 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1914 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1916 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1917 DEBUG16(printk("scsi(%ld): fw_state=%x "
1918 "84xx=%x.\n", vha
->host_no
, state
[0],
1920 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1921 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1922 DEBUG16(printk("scsi(%ld): Sending "
1923 "verify iocb.\n", vha
->host_no
));
1925 cs84xx_time
= jiffies
;
1926 rval
= qla84xx_init_chip(vha
);
1927 if (rval
!= QLA_SUCCESS
)
1930 /* Add time taken to initialize. */
1931 cs84xx_time
= jiffies
- cs84xx_time
;
1932 wtime
+= cs84xx_time
;
1933 mtime
+= cs84xx_time
;
1934 DEBUG16(printk("scsi(%ld): Increasing "
1935 "wait time by %ld. New time %ld\n",
1936 vha
->host_no
, cs84xx_time
, wtime
));
1938 } else if (state
[0] == FSTATE_READY
) {
1939 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1942 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1943 &ha
->login_timeout
, &ha
->r_a_tov
);
1949 rval
= QLA_FUNCTION_FAILED
;
1951 if (atomic_read(&vha
->loop_down_timer
) &&
1952 state
[0] != FSTATE_READY
) {
1953 /* Loop down. Timeout on min_wait for states
1954 * other than Wait for Login.
1956 if (time_after_eq(jiffies
, mtime
)) {
1957 qla_printk(KERN_INFO
, ha
,
1958 "Cable is unplugged...\n");
1960 vha
->device_flags
|= DFLG_NO_CABLE
;
1965 /* Mailbox cmd failed. Timeout on min_wait. */
1966 if (time_after_eq(jiffies
, mtime
) ||
1967 ha
->flags
.isp82xx_fw_hung
)
1971 if (time_after_eq(jiffies
, wtime
))
1974 /* Delay for a while */
1977 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1978 vha
->host_no
, state
[0], jiffies
));
1981 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1982 vha
->host_no
, state
[0], state
[1], state
[2], state
[3], state
[4],
1986 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1994 * qla2x00_configure_hba
1995 * Setup adapter context.
1998 * ha = adapter state pointer.
2007 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
2016 char connect_type
[22];
2017 struct qla_hw_data
*ha
= vha
->hw
;
2019 /* Get host addresses. */
2020 rval
= qla2x00_get_adapter_id(vha
,
2021 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
2022 if (rval
!= QLA_SUCCESS
) {
2023 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
2024 IS_QLA8XXX_TYPE(ha
) ||
2025 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
2026 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
2027 __func__
, vha
->host_no
));
2029 qla_printk(KERN_WARNING
, ha
,
2030 "ERROR -- Unable to get host loop ID.\n");
2031 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2037 qla_printk(KERN_INFO
, ha
,
2038 "Cannot get topology - retrying.\n");
2039 return (QLA_FUNCTION_FAILED
);
2042 vha
->loop_id
= loop_id
;
2045 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2046 ha
->operating_mode
= LOOP
;
2051 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
2053 ha
->current_topology
= ISP_CFG_NL
;
2054 strcpy(connect_type
, "(Loop)");
2058 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
2060 ha
->switch_cap
= sw_cap
;
2061 ha
->current_topology
= ISP_CFG_FL
;
2062 strcpy(connect_type
, "(FL_Port)");
2066 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
2068 ha
->operating_mode
= P2P
;
2069 ha
->current_topology
= ISP_CFG_N
;
2070 strcpy(connect_type
, "(N_Port-to-N_Port)");
2074 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
2076 ha
->switch_cap
= sw_cap
;
2077 ha
->operating_mode
= P2P
;
2078 ha
->current_topology
= ISP_CFG_F
;
2079 strcpy(connect_type
, "(F_Port)");
2083 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2085 vha
->host_no
, topo
));
2086 ha
->current_topology
= ISP_CFG_NL
;
2087 strcpy(connect_type
, "(Loop)");
2091 /* Save Host port and loop ID. */
2092 /* byte order - Big Endian */
2093 vha
->d_id
.b
.domain
= domain
;
2094 vha
->d_id
.b
.area
= area
;
2095 vha
->d_id
.b
.al_pa
= al_pa
;
2097 if (!vha
->flags
.init_done
)
2098 qla_printk(KERN_INFO
, ha
,
2099 "Topology - %s, Host Loop address 0x%x\n",
2100 connect_type
, vha
->loop_id
);
2103 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha
->host_no
));
2105 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha
->host_no
));
2112 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2117 struct qla_hw_data
*ha
= vha
->hw
;
2118 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2119 !IS_QLA8XXX_TYPE(ha
);
2121 if (memcmp(model
, BINZERO
, len
) != 0) {
2122 strncpy(ha
->model_number
, model
, len
);
2123 st
= en
= ha
->model_number
;
2126 if (*en
!= 0x20 && *en
!= 0x00)
2131 index
= (ha
->pdev
->subsystem_device
& 0xff);
2133 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2134 index
< QLA_MODEL_NAMES
)
2135 strncpy(ha
->model_desc
,
2136 qla2x00_model_name
[index
* 2 + 1],
2137 sizeof(ha
->model_desc
) - 1);
2139 index
= (ha
->pdev
->subsystem_device
& 0xff);
2141 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2142 index
< QLA_MODEL_NAMES
) {
2143 strcpy(ha
->model_number
,
2144 qla2x00_model_name
[index
* 2]);
2145 strncpy(ha
->model_desc
,
2146 qla2x00_model_name
[index
* 2 + 1],
2147 sizeof(ha
->model_desc
) - 1);
2149 strcpy(ha
->model_number
, def
);
2152 if (IS_FWI2_CAPABLE(ha
))
2153 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2154 sizeof(ha
->model_desc
));
2157 /* On sparc systems, obtain port and node WWN from firmware
2160 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2163 struct qla_hw_data
*ha
= vha
->hw
;
2164 struct pci_dev
*pdev
= ha
->pdev
;
2165 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2169 val
= of_get_property(dp
, "port-wwn", &len
);
2170 if (val
&& len
>= WWN_SIZE
)
2171 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2173 val
= of_get_property(dp
, "node-wwn", &len
);
2174 if (val
&& len
>= WWN_SIZE
)
2175 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2180 * NVRAM configuration for ISP 2xxx
2183 * ha = adapter block pointer.
2186 * initialization control block in response_ring
2187 * host adapters parameters in host adapter block
2193 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2198 uint8_t *dptr1
, *dptr2
;
2199 struct qla_hw_data
*ha
= vha
->hw
;
2200 init_cb_t
*icb
= ha
->init_cb
;
2201 nvram_t
*nv
= ha
->nvram
;
2202 uint8_t *ptr
= ha
->nvram
;
2203 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2207 /* Determine NVRAM starting address. */
2208 ha
->nvram_size
= sizeof(nvram_t
);
2210 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2211 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2212 ha
->nvram_base
= 0x80;
2214 /* Get NVRAM data and calculate checksum. */
2215 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2216 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2219 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
2220 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
2222 /* Bad NVRAM data, set defaults parameters. */
2223 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2224 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2225 /* Reset NVRAM data. */
2226 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
2227 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
2229 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
2230 "invalid -- WWPN) defaults.\n");
2233 * Set default initialization control block.
2235 memset(nv
, 0, ha
->nvram_size
);
2236 nv
->parameter_block_version
= ICB_VERSION
;
2238 if (IS_QLA23XX(ha
)) {
2239 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2240 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2241 nv
->add_firmware_options
[0] = BIT_5
;
2242 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2243 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2244 nv
->special_options
[1] = BIT_7
;
2245 } else if (IS_QLA2200(ha
)) {
2246 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2247 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2248 nv
->add_firmware_options
[0] = BIT_5
;
2249 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2250 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2251 } else if (IS_QLA2100(ha
)) {
2252 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2253 nv
->firmware_options
[1] = BIT_5
;
2254 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2257 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2258 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2259 nv
->retry_count
= 8;
2260 nv
->retry_delay
= 1;
2262 nv
->port_name
[0] = 33;
2263 nv
->port_name
[3] = 224;
2264 nv
->port_name
[4] = 139;
2266 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2268 nv
->login_timeout
= 4;
2271 * Set default host adapter parameters
2273 nv
->host_p
[1] = BIT_2
;
2274 nv
->reset_delay
= 5;
2275 nv
->port_down_retry_count
= 8;
2276 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2277 nv
->link_down_timeout
= 60;
2282 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2284 * The SN2 does not provide BIOS emulation which means you can't change
2285 * potentially bogus BIOS settings. Force the use of default settings
2286 * for link rate and frame size. Hope that the rest of the settings
2289 if (ia64_platform_is("sn2")) {
2290 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2292 nv
->special_options
[1] = BIT_7
;
2296 /* Reset Initialization control block */
2297 memset(icb
, 0, ha
->init_cb_size
);
2300 * Setup driver NVRAM options.
2302 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2303 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2304 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2305 nv
->firmware_options
[1] &= ~BIT_4
;
2307 if (IS_QLA23XX(ha
)) {
2308 nv
->firmware_options
[0] |= BIT_2
;
2309 nv
->firmware_options
[0] &= ~BIT_3
;
2310 nv
->firmware_options
[0] &= ~BIT_6
;
2311 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2313 if (IS_QLA2300(ha
)) {
2314 if (ha
->fb_rev
== FPM_2310
) {
2315 strcpy(ha
->model_number
, "QLA2310");
2317 strcpy(ha
->model_number
, "QLA2300");
2320 qla2x00_set_model_info(vha
, nv
->model_number
,
2321 sizeof(nv
->model_number
), "QLA23xx");
2323 } else if (IS_QLA2200(ha
)) {
2324 nv
->firmware_options
[0] |= BIT_2
;
2326 * 'Point-to-point preferred, else loop' is not a safe
2327 * connection mode setting.
2329 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2331 /* Force 'loop preferred, else point-to-point'. */
2332 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2333 nv
->add_firmware_options
[0] |= BIT_5
;
2335 strcpy(ha
->model_number
, "QLA22xx");
2336 } else /*if (IS_QLA2100(ha))*/ {
2337 strcpy(ha
->model_number
, "QLA2100");
2341 * Copy over NVRAM RISC parameter block to initialization control block.
2343 dptr1
= (uint8_t *)icb
;
2344 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2345 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2347 *dptr1
++ = *dptr2
++;
2349 /* Copy 2nd half. */
2350 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2351 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2353 *dptr1
++ = *dptr2
++;
2355 /* Use alternate WWN? */
2356 if (nv
->host_p
[1] & BIT_7
) {
2357 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2358 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2361 /* Prepare nodename */
2362 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2364 * Firmware will apply the following mask if the nodename was
2367 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2368 icb
->node_name
[0] &= 0xF0;
2372 * Set host adapter parameters.
2374 if (nv
->host_p
[0] & BIT_7
)
2375 ql2xextended_error_logging
= 1;
2376 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2377 /* Always load RISC code on non ISP2[12]00 chips. */
2378 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2379 ha
->flags
.disable_risc_code_load
= 0;
2380 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2381 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2382 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2383 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2384 ha
->flags
.disable_serdes
= 0;
2386 ha
->operating_mode
=
2387 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2389 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2390 sizeof(ha
->fw_seriallink_options
));
2392 /* save HBA serial number */
2393 ha
->serial0
= icb
->port_name
[5];
2394 ha
->serial1
= icb
->port_name
[6];
2395 ha
->serial2
= icb
->port_name
[7];
2396 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2397 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2399 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2401 ha
->retry_count
= nv
->retry_count
;
2403 /* Set minimum login_timeout to 4 seconds. */
2404 if (nv
->login_timeout
!= ql2xlogintimeout
)
2405 nv
->login_timeout
= ql2xlogintimeout
;
2406 if (nv
->login_timeout
< 4)
2407 nv
->login_timeout
= 4;
2408 ha
->login_timeout
= nv
->login_timeout
;
2409 icb
->login_timeout
= nv
->login_timeout
;
2411 /* Set minimum RATOV to 100 tenths of a second. */
2414 ha
->loop_reset_delay
= nv
->reset_delay
;
2416 /* Link Down Timeout = 0:
2418 * When Port Down timer expires we will start returning
2419 * I/O's to OS with "DID_NO_CONNECT".
2421 * Link Down Timeout != 0:
2423 * The driver waits for the link to come up after link down
2424 * before returning I/Os to OS with "DID_NO_CONNECT".
2426 if (nv
->link_down_timeout
== 0) {
2427 ha
->loop_down_abort_time
=
2428 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2430 ha
->link_down_timeout
= nv
->link_down_timeout
;
2431 ha
->loop_down_abort_time
=
2432 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2436 * Need enough time to try and get the port back.
2438 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2439 if (qlport_down_retry
)
2440 ha
->port_down_retry_count
= qlport_down_retry
;
2441 /* Set login_retry_count */
2442 ha
->login_retry_count
= nv
->retry_count
;
2443 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2444 ha
->port_down_retry_count
> 3)
2445 ha
->login_retry_count
= ha
->port_down_retry_count
;
2446 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2447 ha
->login_retry_count
= ha
->port_down_retry_count
;
2448 if (ql2xloginretrycount
)
2449 ha
->login_retry_count
= ql2xloginretrycount
;
2451 icb
->lun_enables
= __constant_cpu_to_le16(0);
2452 icb
->command_resource_count
= 0;
2453 icb
->immediate_notify_resource_count
= 0;
2454 icb
->timeout
= __constant_cpu_to_le16(0);
2456 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2458 icb
->firmware_options
[0] &= ~BIT_3
;
2459 icb
->add_firmware_options
[0] &=
2460 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2461 icb
->add_firmware_options
[0] |= BIT_2
;
2462 icb
->response_accumulation_timer
= 3;
2463 icb
->interrupt_delay_timer
= 5;
2465 vha
->flags
.process_response_queue
= 1;
2468 if (!vha
->flags
.init_done
) {
2469 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2470 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2471 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2472 icb
->interrupt_delay_timer
: 2;
2474 icb
->add_firmware_options
[0] &=
2475 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2476 vha
->flags
.process_response_queue
= 0;
2477 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2478 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2480 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
2481 "delay (%d us).\n", vha
->host_no
, ha
->zio_mode
,
2482 ha
->zio_timer
* 100));
2483 qla_printk(KERN_INFO
, ha
,
2484 "ZIO mode %d enabled; timer delay (%d us).\n",
2485 ha
->zio_mode
, ha
->zio_timer
* 100);
2487 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2488 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2489 vha
->flags
.process_response_queue
= 1;
2494 DEBUG2_3(printk(KERN_WARNING
2495 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
2501 qla2x00_rport_del(void *data
)
2503 fc_port_t
*fcport
= data
;
2504 struct fc_rport
*rport
;
2505 unsigned long flags
;
2507 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2508 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2509 fcport
->drport
= NULL
;
2510 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2512 fc_remote_port_delete(rport
);
2516 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2518 * @flags: allocation flags
2520 * Returns a pointer to the allocated fcport, or NULL, if none available.
2523 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2527 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2531 /* Setup fcport template structure. */
2533 fcport
->vp_idx
= vha
->vp_idx
;
2534 fcport
->port_type
= FCT_UNKNOWN
;
2535 fcport
->loop_id
= FC_NO_LOOP_ID
;
2536 atomic_set(&fcport
->state
, FCS_UNCONFIGURED
);
2537 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2543 * qla2x00_configure_loop
2544 * Updates Fibre Channel Device Database with what is actually on loop.
2547 * ha = adapter block pointer.
2552 * 2 = database was full and device was not configured.
2555 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2558 unsigned long flags
, save_flags
;
2559 struct qla_hw_data
*ha
= vha
->hw
;
2562 /* Get Initiator ID */
2563 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2564 rval
= qla2x00_configure_hba(vha
);
2565 if (rval
!= QLA_SUCCESS
) {
2566 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
2572 save_flags
= flags
= vha
->dpc_flags
;
2573 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
2574 vha
->host_no
, flags
));
2577 * If we have both an RSCN and PORT UPDATE pending then handle them
2578 * both at the same time.
2580 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2581 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2583 qla2x00_get_data_rate(vha
);
2585 /* Determine what we need to do */
2586 if (ha
->current_topology
== ISP_CFG_FL
&&
2587 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2589 vha
->flags
.rscn_queue_overflow
= 1;
2590 set_bit(RSCN_UPDATE
, &flags
);
2592 } else if (ha
->current_topology
== ISP_CFG_F
&&
2593 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2595 vha
->flags
.rscn_queue_overflow
= 1;
2596 set_bit(RSCN_UPDATE
, &flags
);
2597 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2599 } else if (ha
->current_topology
== ISP_CFG_N
) {
2600 clear_bit(RSCN_UPDATE
, &flags
);
2602 } else if (!vha
->flags
.online
||
2603 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2605 vha
->flags
.rscn_queue_overflow
= 1;
2606 set_bit(RSCN_UPDATE
, &flags
);
2607 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2610 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2611 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2612 rval
= QLA_FUNCTION_FAILED
;
2614 rval
= qla2x00_configure_local_loop(vha
);
2617 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2618 if (LOOP_TRANSITION(vha
))
2619 rval
= QLA_FUNCTION_FAILED
;
2621 rval
= qla2x00_configure_fabric(vha
);
2624 if (rval
== QLA_SUCCESS
) {
2625 if (atomic_read(&vha
->loop_down_timer
) ||
2626 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2627 rval
= QLA_FUNCTION_FAILED
;
2629 atomic_set(&vha
->loop_state
, LOOP_READY
);
2631 DEBUG(printk("scsi(%ld): LOOP READY\n", vha
->host_no
));
2636 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
2637 __func__
, vha
->host_no
));
2639 DEBUG3(printk("%s: exiting normally\n", __func__
));
2642 /* Restore state if a resync event occurred during processing */
2643 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2644 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2645 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2646 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2647 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2648 if (!IS_ALOGIO_CAPABLE(ha
))
2649 vha
->flags
.rscn_queue_overflow
= 1;
2659 * qla2x00_configure_local_loop
2660 * Updates Fibre Channel Device Database with local loop devices.
2663 * ha = adapter block pointer.
2669 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2674 fc_port_t
*fcport
, *new_fcport
;
2680 uint8_t domain
, area
, al_pa
;
2681 struct qla_hw_data
*ha
= vha
->hw
;
2685 entries
= MAX_FIBRE_DEVICES
;
2687 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha
->host_no
));
2688 DEBUG3(qla2x00_get_fcal_position_map(vha
, NULL
));
2690 /* Get list of logged in devices. */
2691 memset(ha
->gid_list
, 0, GID_LIST_SIZE
);
2692 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2694 if (rval
!= QLA_SUCCESS
)
2695 goto cleanup_allocation
;
2697 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2698 vha
->host_no
, entries
));
2699 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha
->gid_list
,
2700 entries
* sizeof(struct gid_list_info
)));
2702 /* Allocate temporary fcport for any new fcports discovered. */
2703 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2704 if (new_fcport
== NULL
) {
2705 rval
= QLA_MEMORY_ALLOC_FAILED
;
2706 goto cleanup_allocation
;
2708 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2711 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2713 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2714 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2715 fcport
->port_type
!= FCT_BROADCAST
&&
2716 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2718 DEBUG(printk("scsi(%ld): Marking port lost, "
2720 vha
->host_no
, fcport
->loop_id
));
2722 atomic_set(&fcport
->state
, FCS_DEVICE_LOST
);
2726 /* Add devices to port list. */
2727 id_iter
= (char *)ha
->gid_list
;
2728 for (index
= 0; index
< entries
; index
++) {
2729 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2730 area
= ((struct gid_list_info
*)id_iter
)->area
;
2731 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2732 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2733 loop_id
= (uint16_t)
2734 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2736 loop_id
= le16_to_cpu(
2737 ((struct gid_list_info
*)id_iter
)->loop_id
);
2738 id_iter
+= ha
->gid_list_info_size
;
2740 /* Bypass reserved domain fields. */
2741 if ((domain
& 0xf0) == 0xf0)
2744 /* Bypass if not same domain and area of adapter. */
2745 if (area
&& domain
&&
2746 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2749 /* Bypass invalid local loop ID. */
2750 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2753 /* Fill in member data. */
2754 new_fcport
->d_id
.b
.domain
= domain
;
2755 new_fcport
->d_id
.b
.area
= area
;
2756 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2757 new_fcport
->loop_id
= loop_id
;
2758 new_fcport
->vp_idx
= vha
->vp_idx
;
2759 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2760 if (rval2
!= QLA_SUCCESS
) {
2761 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2762 "information -- get_port_database=%x, "
2764 vha
->host_no
, rval2
, new_fcport
->loop_id
));
2765 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2767 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2771 /* Check for matching device in port list. */
2774 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2775 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2779 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2780 fcport
->loop_id
= new_fcport
->loop_id
;
2781 fcport
->port_type
= new_fcport
->port_type
;
2782 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2783 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2791 /* New device, add to fcports list. */
2793 new_fcport
->vha
= vha
;
2794 new_fcport
->vp_idx
= vha
->vp_idx
;
2796 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2798 /* Allocate a new replacement fcport. */
2799 fcport
= new_fcport
;
2800 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2801 if (new_fcport
== NULL
) {
2802 rval
= QLA_MEMORY_ALLOC_FAILED
;
2803 goto cleanup_allocation
;
2805 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2808 /* Base iIDMA settings on HBA port speed. */
2809 fcport
->fp_speed
= ha
->link_data_rate
;
2811 qla2x00_update_fcport(vha
, fcport
);
2819 if (rval
!= QLA_SUCCESS
) {
2820 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2821 "rval=%x\n", vha
->host_no
, rval
));
2828 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2830 #define LS_UNKNOWN 2
2831 static char *link_speeds
[] = { "1", "2", "?", "4", "8", "10" };
2835 struct qla_hw_data
*ha
= vha
->hw
;
2837 if (!IS_IIDMA_CAPABLE(ha
))
2840 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
2843 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2844 fcport
->fp_speed
> ha
->link_data_rate
)
2847 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2849 if (rval
!= QLA_SUCCESS
) {
2850 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2851 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2852 vha
->host_no
, fcport
->port_name
[0], fcport
->port_name
[1],
2853 fcport
->port_name
[2], fcport
->port_name
[3],
2854 fcport
->port_name
[4], fcport
->port_name
[5],
2855 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2856 fcport
->fp_speed
, mb
[0], mb
[1]));
2858 link_speed
= link_speeds
[LS_UNKNOWN
];
2859 if (fcport
->fp_speed
< 5)
2860 link_speed
= link_speeds
[fcport
->fp_speed
];
2861 else if (fcport
->fp_speed
== 0x13)
2862 link_speed
= link_speeds
[5];
2863 DEBUG2(qla_printk(KERN_INFO
, ha
,
2864 "iIDMA adjusted to %s GB/s on "
2865 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
2866 link_speed
, fcport
->port_name
[0],
2867 fcport
->port_name
[1], fcport
->port_name
[2],
2868 fcport
->port_name
[3], fcport
->port_name
[4],
2869 fcport
->port_name
[5], fcport
->port_name
[6],
2870 fcport
->port_name
[7]));
2875 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2877 struct fc_rport_identifiers rport_ids
;
2878 struct fc_rport
*rport
;
2879 struct qla_hw_data
*ha
= vha
->hw
;
2880 unsigned long flags
;
2882 qla2x00_rport_del(fcport
);
2884 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2885 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2886 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2887 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2888 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2889 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2891 qla_printk(KERN_WARNING
, ha
,
2892 "Unable to allocate fc remote port!\n");
2895 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2896 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2897 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2899 rport
->supported_classes
= fcport
->supported_classes
;
2901 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2902 if (fcport
->port_type
== FCT_INITIATOR
)
2903 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2904 if (fcport
->port_type
== FCT_TARGET
)
2905 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2906 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2910 * qla2x00_update_fcport
2911 * Updates device on list.
2914 * ha = adapter block pointer.
2915 * fcport = port structure pointer.
2925 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2928 fcport
->login_retry
= 0;
2929 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
2931 qla2x00_iidma_fcport(vha
, fcport
);
2932 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
2933 qla2x00_reg_remote_port(vha
, fcport
);
2934 atomic_set(&fcport
->state
, FCS_ONLINE
);
2938 * qla2x00_configure_fabric
2939 * Setup SNS devices with loop ID's.
2942 * ha = adapter block pointer.
2949 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2952 fc_port_t
*fcport
, *fcptemp
;
2953 uint16_t next_loopid
;
2954 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2956 LIST_HEAD(new_fcports
);
2957 struct qla_hw_data
*ha
= vha
->hw
;
2958 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2960 /* If FL port exists, then SNS is present */
2961 if (IS_FWI2_CAPABLE(ha
))
2962 loop_id
= NPH_F_PORT
;
2964 loop_id
= SNS_FL_PORT
;
2965 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2966 if (rval
!= QLA_SUCCESS
) {
2967 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2968 "Port\n", vha
->host_no
));
2970 vha
->device_flags
&= ~SWITCH_FOUND
;
2971 return (QLA_SUCCESS
);
2973 vha
->device_flags
|= SWITCH_FOUND
;
2975 /* Mark devices that need re-synchronization. */
2976 rval2
= qla2x00_device_resync(vha
);
2977 if (rval2
== QLA_RSCNS_HANDLED
) {
2978 /* No point doing the scan, just continue. */
2979 return (QLA_SUCCESS
);
2983 if (ql2xfdmienable
&&
2984 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2985 qla2x00_fdmi_register(vha
);
2987 /* Ensure we are logged into the SNS. */
2988 if (IS_FWI2_CAPABLE(ha
))
2991 loop_id
= SIMPLE_NAME_SERVER
;
2992 ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2993 0xfc, mb
, BIT_1
| BIT_0
);
2994 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2995 DEBUG2(qla_printk(KERN_INFO
, ha
,
2996 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
2997 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id
,
2998 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
2999 return (QLA_SUCCESS
);
3002 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
3003 if (qla2x00_rft_id(vha
)) {
3005 DEBUG2(printk("scsi(%ld): Register FC-4 "
3006 "TYPE failed.\n", vha
->host_no
));
3008 if (qla2x00_rff_id(vha
)) {
3010 DEBUG2(printk("scsi(%ld): Register FC-4 "
3011 "Features failed.\n", vha
->host_no
));
3013 if (qla2x00_rnn_id(vha
)) {
3015 DEBUG2(printk("scsi(%ld): Register Node Name "
3016 "failed.\n", vha
->host_no
));
3017 } else if (qla2x00_rsnn_nn(vha
)) {
3019 DEBUG2(printk("scsi(%ld): Register Symbolic "
3020 "Node Name failed.\n", vha
->host_no
));
3024 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
3025 if (rval
!= QLA_SUCCESS
)
3029 * Logout all previous fabric devices marked lost, except
3032 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3033 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3036 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3039 if (atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
3040 qla2x00_mark_device_lost(vha
, fcport
,
3041 ql2xplogiabsentdevice
, 0);
3042 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3043 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3044 fcport
->port_type
!= FCT_INITIATOR
&&
3045 fcport
->port_type
!= FCT_BROADCAST
) {
3046 ha
->isp_ops
->fabric_logout(vha
,
3048 fcport
->d_id
.b
.domain
,
3049 fcport
->d_id
.b
.area
,
3050 fcport
->d_id
.b
.al_pa
);
3051 fcport
->loop_id
= FC_NO_LOOP_ID
;
3056 /* Starting free loop ID. */
3057 next_loopid
= ha
->min_external_loopid
;
3060 * Scan through our port list and login entries that need to be
3063 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3064 if (atomic_read(&vha
->loop_down_timer
) ||
3065 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3068 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3069 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
3072 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3073 fcport
->loop_id
= next_loopid
;
3074 rval
= qla2x00_find_new_loop_id(
3076 if (rval
!= QLA_SUCCESS
) {
3077 /* Ran out of IDs to use */
3081 /* Login and update database */
3082 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3085 /* Exit if out of loop IDs. */
3086 if (rval
!= QLA_SUCCESS
) {
3091 * Login and add the new devices to our port list.
3093 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3094 if (atomic_read(&vha
->loop_down_timer
) ||
3095 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3098 /* Find a new loop ID to use. */
3099 fcport
->loop_id
= next_loopid
;
3100 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
3101 if (rval
!= QLA_SUCCESS
) {
3102 /* Ran out of IDs to use */
3106 /* Login and update database */
3107 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3111 fcport
->vp_idx
= vha
->vp_idx
;
3113 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
3117 /* Free all new device structures not processed. */
3118 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3119 list_del(&fcport
->list
);
3124 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
3125 "rval=%d\n", vha
->host_no
, rval
));
3132 * qla2x00_find_all_fabric_devs
3135 * ha = adapter block pointer.
3136 * dev = database device entry pointer.
3145 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3146 struct list_head
*new_fcports
)
3150 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3155 int first_dev
, last_dev
;
3156 port_id_t wrap
= {}, nxt_d_id
;
3157 struct qla_hw_data
*ha
= vha
->hw
;
3158 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3159 struct scsi_qla_host
*tvp
;
3163 /* Try GID_PT to get device list, else GAN. */
3164 swl
= kcalloc(MAX_FIBRE_DEVICES
, sizeof(sw_info_t
), GFP_KERNEL
);
3167 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
3168 "on GA_NXT\n", vha
->host_no
));
3170 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3173 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3176 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3179 } else if (ql2xiidmaenable
&&
3180 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3181 qla2x00_gpsc(vha
, swl
);
3184 /* If other queries succeeded probe for FC-4 type */
3186 qla2x00_gff_id(vha
, swl
);
3190 /* Allocate temporary fcport for any new fcports discovered. */
3191 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3192 if (new_fcport
== NULL
) {
3194 return (QLA_MEMORY_ALLOC_FAILED
);
3196 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3197 /* Set start port ID scan at adapter ID. */
3201 /* Starting free loop ID. */
3202 loop_id
= ha
->min_external_loopid
;
3203 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3204 if (qla2x00_is_reserved_id(vha
, loop_id
))
3207 if (ha
->current_topology
== ISP_CFG_FL
&&
3208 (atomic_read(&vha
->loop_down_timer
) ||
3209 LOOP_TRANSITION(vha
))) {
3210 atomic_set(&vha
->loop_down_timer
, 0);
3211 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3212 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3218 wrap
.b24
= new_fcport
->d_id
.b24
;
3220 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3221 memcpy(new_fcport
->node_name
,
3222 swl
[swl_idx
].node_name
, WWN_SIZE
);
3223 memcpy(new_fcport
->port_name
,
3224 swl
[swl_idx
].port_name
, WWN_SIZE
);
3225 memcpy(new_fcport
->fabric_port_name
,
3226 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3227 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3228 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3230 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3236 /* Send GA_NXT to the switch */
3237 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3238 if (rval
!= QLA_SUCCESS
) {
3239 qla_printk(KERN_WARNING
, ha
,
3240 "SNS scan failed -- assuming zero-entry "
3242 list_for_each_entry_safe(fcport
, fcptemp
,
3243 new_fcports
, list
) {
3244 list_del(&fcport
->list
);
3252 /* If wrap on switch device list, exit. */
3254 wrap
.b24
= new_fcport
->d_id
.b24
;
3256 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3257 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
3258 vha
->host_no
, new_fcport
->d_id
.b
.domain
,
3259 new_fcport
->d_id
.b
.area
, new_fcport
->d_id
.b
.al_pa
));
3263 /* Bypass if same physical adapter. */
3264 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3267 /* Bypass virtual ports of the same host. */
3269 if (ha
->num_vhosts
) {
3270 unsigned long flags
;
3272 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3273 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3274 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3279 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3285 /* Bypass if same domain and area of adapter. */
3286 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3287 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3291 /* Bypass reserved domain fields. */
3292 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3295 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3296 if (ql2xgffidenable
&&
3297 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3298 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3301 /* Locate matching device in database. */
3303 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3304 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3310 /* Update port state. */
3311 memcpy(fcport
->fabric_port_name
,
3312 new_fcport
->fabric_port_name
, WWN_SIZE
);
3313 fcport
->fp_speed
= new_fcport
->fp_speed
;
3316 * If address the same and state FCS_ONLINE, nothing
3319 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3320 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3325 * If device was not a fabric device before.
3327 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3328 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3329 fcport
->loop_id
= FC_NO_LOOP_ID
;
3330 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3336 * Port ID changed or device was marked to be updated;
3337 * Log it out if still logged in and mark it for
3340 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3341 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3342 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3343 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3344 fcport
->port_type
!= FCT_INITIATOR
&&
3345 fcport
->port_type
!= FCT_BROADCAST
) {
3346 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3347 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3348 fcport
->d_id
.b
.al_pa
);
3349 fcport
->loop_id
= FC_NO_LOOP_ID
;
3357 /* If device was not in our fcports list, then add it. */
3358 list_add_tail(&new_fcport
->list
, new_fcports
);
3360 /* Allocate a new replacement fcport. */
3361 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3362 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3363 if (new_fcport
== NULL
) {
3365 return (QLA_MEMORY_ALLOC_FAILED
);
3367 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3368 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3378 * qla2x00_find_new_loop_id
3379 * Scan through our port list and find a new usable loop ID.
3382 * ha: adapter state pointer.
3383 * dev: port structure pointer.
3386 * qla2x00 local function return status code.
3392 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3397 uint16_t first_loop_id
;
3398 struct qla_hw_data
*ha
= vha
->hw
;
3399 struct scsi_qla_host
*vp
;
3400 struct scsi_qla_host
*tvp
;
3401 unsigned long flags
= 0;
3405 /* Save starting loop ID. */
3406 first_loop_id
= dev
->loop_id
;
3409 /* Skip loop ID if already used by adapter. */
3410 if (dev
->loop_id
== vha
->loop_id
)
3413 /* Skip reserved loop IDs. */
3414 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3417 /* Reset loop ID if passed the end. */
3418 if (dev
->loop_id
> ha
->max_loop_id
) {
3419 /* first loop ID. */
3420 dev
->loop_id
= ha
->min_external_loopid
;
3423 /* Check for loop ID being already in use. */
3427 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3428 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3429 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3430 if (fcport
->loop_id
== dev
->loop_id
&&
3432 /* ID possibly in use */
3440 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3442 /* If not in use then it is free to use. */
3447 /* ID in use. Try next value. */
3450 /* If wrap around. No free ID to use. */
3451 if (dev
->loop_id
== first_loop_id
) {
3452 dev
->loop_id
= FC_NO_LOOP_ID
;
3453 rval
= QLA_FUNCTION_FAILED
;
3462 * qla2x00_device_resync
3463 * Marks devices in the database that needs resynchronization.
3466 * ha = adapter block pointer.
3472 qla2x00_device_resync(scsi_qla_host_t
*vha
)
3477 uint32_t rscn_entry
;
3478 uint8_t rscn_out_iter
;
3480 port_id_t d_id
= {};
3482 rval
= QLA_RSCNS_HANDLED
;
3484 while (vha
->rscn_out_ptr
!= vha
->rscn_in_ptr
||
3485 vha
->flags
.rscn_queue_overflow
) {
3487 rscn_entry
= vha
->rscn_queue
[vha
->rscn_out_ptr
];
3488 format
= MSB(MSW(rscn_entry
));
3489 d_id
.b
.domain
= LSB(MSW(rscn_entry
));
3490 d_id
.b
.area
= MSB(LSW(rscn_entry
));
3491 d_id
.b
.al_pa
= LSB(LSW(rscn_entry
));
3493 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3494 "[%02x/%02x%02x%02x].\n",
3495 vha
->host_no
, vha
->rscn_out_ptr
, format
, d_id
.b
.domain
,
3496 d_id
.b
.area
, d_id
.b
.al_pa
));
3498 vha
->rscn_out_ptr
++;
3499 if (vha
->rscn_out_ptr
== MAX_RSCN_COUNT
)
3500 vha
->rscn_out_ptr
= 0;
3502 /* Skip duplicate entries. */
3503 for (rscn_out_iter
= vha
->rscn_out_ptr
;
3504 !vha
->flags
.rscn_queue_overflow
&&
3505 rscn_out_iter
!= vha
->rscn_in_ptr
;
3506 rscn_out_iter
= (rscn_out_iter
==
3507 (MAX_RSCN_COUNT
- 1)) ? 0: rscn_out_iter
+ 1) {
3509 if (rscn_entry
!= vha
->rscn_queue
[rscn_out_iter
])
3512 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
3513 "entry found at [%d].\n", vha
->host_no
,
3516 vha
->rscn_out_ptr
= rscn_out_iter
;
3519 /* Queue overflow, set switch default case. */
3520 if (vha
->flags
.rscn_queue_overflow
) {
3521 DEBUG(printk("scsi(%ld): device_resync: rscn "
3522 "overflow.\n", vha
->host_no
));
3525 vha
->flags
.rscn_queue_overflow
= 0;
3541 vha
->rscn_out_ptr
= vha
->rscn_in_ptr
;
3547 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3548 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3549 (fcport
->d_id
.b24
& mask
) != d_id
.b24
||
3550 fcport
->port_type
== FCT_BROADCAST
)
3553 if (atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3555 fcport
->port_type
!= FCT_INITIATOR
) {
3556 qla2x00_mark_device_lost(vha
, fcport
,
3566 * qla2x00_fabric_dev_login
3567 * Login fabric target device and update FC port database.
3570 * ha: adapter state pointer.
3571 * fcport: port structure list pointer.
3572 * next_loopid: contains value of a new loop ID that can be used
3573 * by the next login attempt.
3576 * qla2x00 local function return status code.
3582 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3583 uint16_t *next_loopid
)
3588 struct qla_hw_data
*ha
= vha
->hw
;
3593 if (IS_ALOGIO_CAPABLE(ha
)) {
3594 if (fcport
->flags
& FCF_ASYNC_SENT
)
3596 fcport
->flags
|= FCF_ASYNC_SENT
;
3597 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3602 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3603 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3604 if (rval
== QLA_SUCCESS
) {
3605 /* Send an ADISC to FCP2 devices.*/
3607 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3609 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3610 if (rval
!= QLA_SUCCESS
) {
3611 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3612 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3613 fcport
->d_id
.b
.al_pa
);
3614 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3616 qla2x00_update_fcport(vha
, fcport
);
3624 * qla2x00_fabric_login
3625 * Issue fabric login command.
3628 * ha = adapter block pointer.
3629 * device = pointer to FC device type structure.
3632 * 0 - Login successfully
3634 * 2 - Initiator device
3638 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3639 uint16_t *next_loopid
)
3643 uint16_t tmp_loopid
;
3644 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3645 struct qla_hw_data
*ha
= vha
->hw
;
3651 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3652 "for port %02x%02x%02x.\n",
3653 vha
->host_no
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3654 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3656 /* Login fcport on switch. */
3657 ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3658 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3659 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3660 if (mb
[0] == MBS_PORT_ID_USED
) {
3662 * Device has another loop ID. The firmware team
3663 * recommends the driver perform an implicit login with
3664 * the specified ID again. The ID we just used is save
3665 * here so we return with an ID that can be tried by
3669 tmp_loopid
= fcport
->loop_id
;
3670 fcport
->loop_id
= mb
[1];
3672 DEBUG(printk("Fabric Login: port in use - next "
3673 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3674 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3675 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
));
3677 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3682 /* A retry occurred before. */
3683 *next_loopid
= tmp_loopid
;
3686 * No retry occurred before. Just increment the
3687 * ID value for next login.
3689 *next_loopid
= (fcport
->loop_id
+ 1);
3692 if (mb
[1] & BIT_0
) {
3693 fcport
->port_type
= FCT_INITIATOR
;
3695 fcport
->port_type
= FCT_TARGET
;
3696 if (mb
[1] & BIT_1
) {
3697 fcport
->flags
|= FCF_FCP2_DEVICE
;
3702 fcport
->supported_classes
|= FC_COS_CLASS2
;
3704 fcport
->supported_classes
|= FC_COS_CLASS3
;
3708 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3710 * Loop ID already used, try next loop ID.
3713 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3714 if (rval
!= QLA_SUCCESS
) {
3715 /* Ran out of loop IDs to use */
3718 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3720 * Firmware possibly timed out during login. If NO
3721 * retries are left to do then the device is declared
3724 *next_loopid
= fcport
->loop_id
;
3725 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3726 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3727 fcport
->d_id
.b
.al_pa
);
3728 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3734 * unrecoverable / not handled error
3736 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
3737 "loop_id=%x jiffies=%lx.\n",
3738 __func__
, vha
->host_no
, mb
[0],
3739 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3740 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
, jiffies
));
3742 *next_loopid
= fcport
->loop_id
;
3743 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3744 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3745 fcport
->d_id
.b
.al_pa
);
3746 fcport
->loop_id
= FC_NO_LOOP_ID
;
3747 fcport
->login_retry
= 0;
3758 * qla2x00_local_device_login
3759 * Issue local device login command.
3762 * ha = adapter block pointer.
3763 * loop_id = loop id of device to login to.
3765 * Returns (Where's the #define!!!!):
3766 * 0 - Login successfully
3771 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3774 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3776 memset(mb
, 0, sizeof(mb
));
3777 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3778 if (rval
== QLA_SUCCESS
) {
3779 /* Interrogate mailbox registers for any errors */
3780 if (mb
[0] == MBS_COMMAND_ERROR
)
3782 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3783 /* device not in PCB table */
3791 * qla2x00_loop_resync
3792 * Resync with fibre channel devices.
3795 * ha = adapter block pointer.
3801 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3803 int rval
= QLA_SUCCESS
;
3805 struct req_que
*req
;
3806 struct rsp_que
*rsp
;
3808 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3809 req
= vha
->hw
->req_q_map
[0];
3814 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3815 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3816 if (vha
->flags
.online
) {
3817 if (!(rval
= qla2x00_fw_ready(vha
))) {
3818 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3821 atomic_set(&vha
->loop_state
, LOOP_UPDATE
);
3823 /* Issue a marker after FW becomes ready. */
3824 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3826 vha
->marker_needed
= 0;
3828 /* Remap devices on Loop. */
3829 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3831 qla2x00_configure_loop(vha
);
3833 } while (!atomic_read(&vha
->loop_down_timer
) &&
3834 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3835 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3840 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3841 return (QLA_FUNCTION_FAILED
);
3844 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__
));
3850 * qla2x00_perform_loop_resync
3851 * Description: This function will set the appropriate flags and call
3852 * qla2x00_loop_resync. If successful loop will be resynced
3853 * Arguments : scsi_qla_host_t pointer
3854 * returm : Success or Failure
3857 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
3861 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
3862 /*Configure the flags so that resync happens properly*/
3863 atomic_set(&ha
->loop_down_timer
, 0);
3864 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
3865 atomic_set(&ha
->loop_state
, LOOP_UP
);
3866 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
3867 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
3868 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3870 rval
= qla2x00_loop_resync(ha
);
3872 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
3874 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
3881 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3884 struct scsi_qla_host
*vha
;
3885 struct qla_hw_data
*ha
= base_vha
->hw
;
3886 unsigned long flags
;
3888 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3889 /* Go with deferred removal of rport references. */
3890 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3891 atomic_inc(&vha
->vref_count
);
3892 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3893 if (fcport
->drport
&&
3894 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3895 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3897 qla2x00_rport_del(fcport
);
3899 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3902 atomic_dec(&vha
->vref_count
);
3904 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3908 * qla82xx_quiescent_state_cleanup
3909 * Description: This function will block the new I/Os
3910 * Its not aborting any I/Os as context
3911 * is not destroyed during quiescence
3912 * Arguments: scsi_qla_host_t
3916 qla82xx_quiescent_state_cleanup(scsi_qla_host_t
*vha
)
3918 struct qla_hw_data
*ha
= vha
->hw
;
3919 struct scsi_qla_host
*vp
;
3921 qla_printk(KERN_INFO
, ha
,
3922 "Performing ISP error recovery - ha= %p.\n", ha
);
3924 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3925 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3926 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3927 qla2x00_mark_all_devices_lost(vha
, 0);
3928 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3929 qla2x00_mark_all_devices_lost(vha
, 0);
3931 if (!atomic_read(&vha
->loop_down_timer
))
3932 atomic_set(&vha
->loop_down_timer
,
3935 /* Wait for pending cmds to complete */
3936 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
3940 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3942 struct qla_hw_data
*ha
= vha
->hw
;
3943 struct scsi_qla_host
*vp
;
3944 unsigned long flags
;
3947 /* For ISP82XX, driver waits for completion of the commands.
3948 * online flag should be set.
3950 if (!IS_QLA82XX(ha
))
3951 vha
->flags
.online
= 0;
3952 ha
->flags
.chip_reset_done
= 0;
3953 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3954 ha
->qla_stats
.total_isp_aborts
++;
3956 qla_printk(KERN_INFO
, ha
,
3957 "Performing ISP error recovery - ha= %p.\n", ha
);
3959 /* For ISP82XX, reset_chip is just disabling interrupts.
3960 * Driver waits for the completion of the commands.
3961 * the interrupts need to be enabled.
3963 if (!IS_QLA82XX(ha
))
3964 ha
->isp_ops
->reset_chip(vha
);
3966 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3967 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3968 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3969 qla2x00_mark_all_devices_lost(vha
, 0);
3971 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3972 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3973 atomic_inc(&vp
->vref_count
);
3974 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3976 qla2x00_mark_all_devices_lost(vp
, 0);
3978 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3979 atomic_dec(&vp
->vref_count
);
3981 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3983 if (!atomic_read(&vha
->loop_down_timer
))
3984 atomic_set(&vha
->loop_down_timer
,
3988 /* Clear all async request states across all VPs. */
3989 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3990 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3991 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3992 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3993 atomic_inc(&vp
->vref_count
);
3994 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3996 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
3997 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3999 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4000 atomic_dec(&vp
->vref_count
);
4002 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4004 if (!ha
->flags
.eeh_busy
) {
4005 /* Make sure for ISP 82XX IO DMA is complete */
4006 if (IS_QLA82XX(ha
)) {
4007 qla82xx_chip_reset_cleanup(vha
);
4009 /* Done waiting for pending commands.
4010 * Reset the online flag.
4012 vha
->flags
.online
= 0;
4015 /* Requeue all commands in outstanding command list. */
4016 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
4022 * Resets ISP and aborts all outstanding commands.
4025 * ha = adapter block pointer.
4031 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
4035 struct qla_hw_data
*ha
= vha
->hw
;
4036 struct scsi_qla_host
*vp
;
4037 struct req_que
*req
= ha
->req_q_map
[0];
4038 unsigned long flags
;
4040 if (vha
->flags
.online
) {
4041 qla2x00_abort_isp_cleanup(vha
);
4043 if (unlikely(pci_channel_offline(ha
->pdev
) &&
4044 ha
->flags
.pci_channel_io_perm_failure
)) {
4045 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4050 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
4052 ha
->isp_ops
->nvram_config(vha
);
4054 if (!qla2x00_restart_isp(vha
)) {
4055 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4057 if (!atomic_read(&vha
->loop_down_timer
)) {
4059 * Issue marker command only when we are going
4060 * to start the I/O .
4062 vha
->marker_needed
= 1;
4065 vha
->flags
.online
= 1;
4067 ha
->isp_ops
->enable_intrs(ha
);
4069 ha
->isp_abort_cnt
= 0;
4070 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4073 qla2x00_get_fw_version(vha
,
4074 &ha
->fw_major_version
,
4075 &ha
->fw_minor_version
,
4076 &ha
->fw_subminor_version
,
4077 &ha
->fw_attributes
, &ha
->fw_memory_size
,
4078 ha
->mpi_version
, &ha
->mpi_capabilities
,
4082 ha
->flags
.fce_enabled
= 1;
4084 fce_calc_size(ha
->fce_bufs
));
4085 rval
= qla2x00_enable_fce_trace(vha
,
4086 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
4089 qla_printk(KERN_WARNING
, ha
,
4090 "Unable to reinitialize FCE "
4092 ha
->flags
.fce_enabled
= 0;
4097 memset(ha
->eft
, 0, EFT_SIZE
);
4098 rval
= qla2x00_enable_eft_trace(vha
,
4099 ha
->eft_dma
, EFT_NUM_BUFFERS
);
4101 qla_printk(KERN_WARNING
, ha
,
4102 "Unable to reinitialize EFT "
4106 } else { /* failed the ISP abort */
4107 vha
->flags
.online
= 1;
4108 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
4109 if (ha
->isp_abort_cnt
== 0) {
4110 qla_printk(KERN_WARNING
, ha
,
4111 "ISP error recovery failed - "
4112 "board disabled\n");
4114 * The next call disables the board
4117 ha
->isp_ops
->reset_adapter(vha
);
4118 vha
->flags
.online
= 0;
4119 clear_bit(ISP_ABORT_RETRY
,
4122 } else { /* schedule another ISP abort */
4123 ha
->isp_abort_cnt
--;
4124 DEBUG(printk("qla%ld: ISP abort - "
4125 "retry remaining %d\n",
4126 vha
->host_no
, ha
->isp_abort_cnt
));
4130 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
4131 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4132 "- retrying (%d) more times\n",
4133 vha
->host_no
, ha
->isp_abort_cnt
));
4134 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4142 DEBUG(printk(KERN_INFO
4143 "qla2x00_abort_isp(%ld): succeeded.\n",
4146 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4147 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4149 atomic_inc(&vp
->vref_count
);
4150 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4152 qla2x00_vp_abort_isp(vp
);
4154 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4155 atomic_dec(&vp
->vref_count
);
4158 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4161 qla_printk(KERN_INFO
, ha
,
4162 "qla2x00_abort_isp: **** FAILED ****\n");
4169 * qla2x00_restart_isp
4170 * restarts the ISP after a reset
4173 * ha = adapter block pointer.
4179 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4183 struct qla_hw_data
*ha
= vha
->hw
;
4184 struct req_que
*req
= ha
->req_q_map
[0];
4185 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4187 /* If firmware needs to be loaded */
4188 if (qla2x00_isp_firmware(vha
)) {
4189 vha
->flags
.online
= 0;
4190 status
= ha
->isp_ops
->chip_diag(vha
);
4192 status
= qla2x00_setup_chip(vha
);
4195 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4196 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4197 ha
->flags
.chip_reset_done
= 1;
4198 /* Initialize the queues in use */
4199 qla25xx_init_queues(ha
);
4201 status
= qla2x00_fw_ready(vha
);
4203 DEBUG(printk("%s(): Start configure loop, "
4204 "status = %d\n", __func__
, status
));
4206 /* Issue a marker after FW becomes ready. */
4207 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4209 vha
->flags
.online
= 1;
4210 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4213 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4214 qla2x00_configure_loop(vha
);
4216 } while (!atomic_read(&vha
->loop_down_timer
) &&
4217 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4218 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4222 /* if no cable then assume it's good */
4223 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4226 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4234 qla25xx_init_queues(struct qla_hw_data
*ha
)
4236 struct rsp_que
*rsp
= NULL
;
4237 struct req_que
*req
= NULL
;
4238 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4242 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4243 rsp
= ha
->rsp_q_map
[i
];
4245 rsp
->options
&= ~BIT_0
;
4246 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4247 if (ret
!= QLA_SUCCESS
)
4248 DEBUG2_17(printk(KERN_WARNING
4249 "%s Rsp que:%d init failed\n", __func__
,
4252 DEBUG2_17(printk(KERN_INFO
4253 "%s Rsp que:%d inited\n", __func__
,
4257 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4258 req
= ha
->req_q_map
[i
];
4260 /* Clear outstanding commands array. */
4261 req
->options
&= ~BIT_0
;
4262 ret
= qla25xx_init_req_que(base_vha
, req
);
4263 if (ret
!= QLA_SUCCESS
)
4264 DEBUG2_17(printk(KERN_WARNING
4265 "%s Req que:%d init failed\n", __func__
,
4268 DEBUG2_17(printk(KERN_WARNING
4269 "%s Req que:%d inited\n", __func__
,
4277 * qla2x00_reset_adapter
4281 * ha = adapter block pointer.
4284 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4286 unsigned long flags
= 0;
4287 struct qla_hw_data
*ha
= vha
->hw
;
4288 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4290 vha
->flags
.online
= 0;
4291 ha
->isp_ops
->disable_intrs(ha
);
4293 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4294 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4295 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4296 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4297 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4298 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4302 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4304 unsigned long flags
= 0;
4305 struct qla_hw_data
*ha
= vha
->hw
;
4306 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4311 vha
->flags
.online
= 0;
4312 ha
->isp_ops
->disable_intrs(ha
);
4314 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4315 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4316 RD_REG_DWORD(®
->hccr
);
4317 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4318 RD_REG_DWORD(®
->hccr
);
4319 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4321 if (IS_NOPOLLING_TYPE(ha
))
4322 ha
->isp_ops
->enable_intrs(ha
);
4325 /* On sparc systems, obtain port and node WWN from firmware
4328 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4329 struct nvram_24xx
*nv
)
4332 struct qla_hw_data
*ha
= vha
->hw
;
4333 struct pci_dev
*pdev
= ha
->pdev
;
4334 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4338 val
= of_get_property(dp
, "port-wwn", &len
);
4339 if (val
&& len
>= WWN_SIZE
)
4340 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4342 val
= of_get_property(dp
, "node-wwn", &len
);
4343 if (val
&& len
>= WWN_SIZE
)
4344 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4349 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4352 struct init_cb_24xx
*icb
;
4353 struct nvram_24xx
*nv
;
4355 uint8_t *dptr1
, *dptr2
;
4358 struct qla_hw_data
*ha
= vha
->hw
;
4361 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4364 /* Determine NVRAM starting address. */
4365 if (ha
->flags
.port0
) {
4366 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4367 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4369 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4370 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4372 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4373 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4375 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4377 /* Get VPD data into cache */
4378 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4379 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4380 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4382 /* Get NVRAM data into cache and calculate checksum. */
4383 dptr
= (uint32_t *)nv
;
4384 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4386 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4387 chksum
+= le32_to_cpu(*dptr
++);
4389 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
4390 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
4392 /* Bad NVRAM data, set defaults parameters. */
4393 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4394 || nv
->id
[3] != ' ' ||
4395 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4396 /* Reset NVRAM data. */
4397 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
4398 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
4399 le16_to_cpu(nv
->nvram_version
));
4400 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
4401 "invalid -- WWPN) defaults.\n");
4404 * Set default initialization control block.
4406 memset(nv
, 0, ha
->nvram_size
);
4407 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4408 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4409 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4410 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4411 nv
->exchange_count
= __constant_cpu_to_le16(0);
4412 nv
->hard_address
= __constant_cpu_to_le16(124);
4413 nv
->port_name
[0] = 0x21;
4414 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4415 nv
->port_name
[2] = 0x00;
4416 nv
->port_name
[3] = 0xe0;
4417 nv
->port_name
[4] = 0x8b;
4418 nv
->port_name
[5] = 0x1c;
4419 nv
->port_name
[6] = 0x55;
4420 nv
->port_name
[7] = 0x86;
4421 nv
->node_name
[0] = 0x20;
4422 nv
->node_name
[1] = 0x00;
4423 nv
->node_name
[2] = 0x00;
4424 nv
->node_name
[3] = 0xe0;
4425 nv
->node_name
[4] = 0x8b;
4426 nv
->node_name
[5] = 0x1c;
4427 nv
->node_name
[6] = 0x55;
4428 nv
->node_name
[7] = 0x86;
4429 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4430 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4431 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4432 nv
->login_timeout
= __constant_cpu_to_le16(0);
4433 nv
->firmware_options_1
=
4434 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4435 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4436 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4437 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4438 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4439 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4440 nv
->reset_delay
= 5;
4441 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4442 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4443 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4448 /* Reset Initialization control block */
4449 memset(icb
, 0, ha
->init_cb_size
);
4451 /* Copy 1st segment. */
4452 dptr1
= (uint8_t *)icb
;
4453 dptr2
= (uint8_t *)&nv
->version
;
4454 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4456 *dptr1
++ = *dptr2
++;
4458 icb
->login_retry_count
= nv
->login_retry_count
;
4459 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4461 /* Copy 2nd segment. */
4462 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4463 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4464 cnt
= (uint8_t *)&icb
->reserved_3
-
4465 (uint8_t *)&icb
->interrupt_delay_timer
;
4467 *dptr1
++ = *dptr2
++;
4470 * Setup driver NVRAM options.
4472 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4475 /* Use alternate WWN? */
4476 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4477 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4478 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4481 /* Prepare nodename */
4482 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4484 * Firmware will apply the following mask if the nodename was
4487 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4488 icb
->node_name
[0] &= 0xF0;
4491 /* Set host adapter parameters. */
4492 ha
->flags
.disable_risc_code_load
= 0;
4493 ha
->flags
.enable_lip_reset
= 0;
4494 ha
->flags
.enable_lip_full_login
=
4495 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4496 ha
->flags
.enable_target_reset
=
4497 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4498 ha
->flags
.enable_led_scheme
= 0;
4499 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4501 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4502 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4504 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4505 sizeof(ha
->fw_seriallink_options24
));
4507 /* save HBA serial number */
4508 ha
->serial0
= icb
->port_name
[5];
4509 ha
->serial1
= icb
->port_name
[6];
4510 ha
->serial2
= icb
->port_name
[7];
4511 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4512 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4514 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4516 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4518 /* Set minimum login_timeout to 4 seconds. */
4519 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4520 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4521 if (le16_to_cpu(nv
->login_timeout
) < 4)
4522 nv
->login_timeout
= __constant_cpu_to_le16(4);
4523 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4524 icb
->login_timeout
= nv
->login_timeout
;
4526 /* Set minimum RATOV to 100 tenths of a second. */
4529 ha
->loop_reset_delay
= nv
->reset_delay
;
4531 /* Link Down Timeout = 0:
4533 * When Port Down timer expires we will start returning
4534 * I/O's to OS with "DID_NO_CONNECT".
4536 * Link Down Timeout != 0:
4538 * The driver waits for the link to come up after link down
4539 * before returning I/Os to OS with "DID_NO_CONNECT".
4541 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4542 ha
->loop_down_abort_time
=
4543 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4545 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4546 ha
->loop_down_abort_time
=
4547 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4550 /* Need enough time to try and get the port back. */
4551 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4552 if (qlport_down_retry
)
4553 ha
->port_down_retry_count
= qlport_down_retry
;
4555 /* Set login_retry_count */
4556 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4557 if (ha
->port_down_retry_count
==
4558 le16_to_cpu(nv
->port_down_retry_count
) &&
4559 ha
->port_down_retry_count
> 3)
4560 ha
->login_retry_count
= ha
->port_down_retry_count
;
4561 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4562 ha
->login_retry_count
= ha
->port_down_retry_count
;
4563 if (ql2xloginretrycount
)
4564 ha
->login_retry_count
= ql2xloginretrycount
;
4567 if (!vha
->flags
.init_done
) {
4568 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4569 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4570 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4571 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4573 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4574 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4575 vha
->flags
.process_response_queue
= 0;
4576 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4577 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4579 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4580 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
4581 ha
->zio_timer
* 100));
4582 qla_printk(KERN_INFO
, ha
,
4583 "ZIO mode %d enabled; timer delay (%d us).\n",
4584 ha
->zio_mode
, ha
->zio_timer
* 100);
4586 icb
->firmware_options_2
|= cpu_to_le32(
4587 (uint32_t)ha
->zio_mode
);
4588 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4589 vha
->flags
.process_response_queue
= 1;
4593 DEBUG2_3(printk(KERN_WARNING
4594 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
4600 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4603 int rval
= QLA_SUCCESS
;
4604 int segments
, fragment
;
4605 uint32_t *dcode
, dlen
;
4609 struct qla_hw_data
*ha
= vha
->hw
;
4610 struct req_que
*req
= ha
->req_q_map
[0];
4612 qla_printk(KERN_INFO
, ha
,
4613 "FW: Loading from flash (%x)...\n", faddr
);
4617 segments
= FA_RISC_CODE_SEGMENTS
;
4618 dcode
= (uint32_t *)req
->ring
;
4621 /* Validate firmware image by checking version. */
4622 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4623 for (i
= 0; i
< 4; i
++)
4624 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4625 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4626 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4627 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4629 qla_printk(KERN_WARNING
, ha
,
4630 "Unable to verify integrity of flash firmware image!\n");
4631 qla_printk(KERN_WARNING
, ha
,
4632 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4633 dcode
[1], dcode
[2], dcode
[3]);
4635 return QLA_FUNCTION_FAILED
;
4638 while (segments
&& rval
== QLA_SUCCESS
) {
4639 /* Read segment's load information. */
4640 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4642 risc_addr
= be32_to_cpu(dcode
[2]);
4643 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4644 risc_size
= be32_to_cpu(dcode
[3]);
4647 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4648 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4649 if (dlen
> risc_size
)
4652 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4653 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
4654 vha
->host_no
, risc_addr
, dlen
, faddr
));
4656 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4657 for (i
= 0; i
< dlen
; i
++)
4658 dcode
[i
] = swab32(dcode
[i
]);
4660 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4663 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4664 "segment %d of firmware\n", vha
->host_no
,
4666 qla_printk(KERN_WARNING
, ha
,
4667 "[ERROR] Failed to load segment %d of "
4668 "firmware\n", fragment
);
4685 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4688 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4692 uint16_t *wcode
, *fwcode
;
4693 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4694 struct fw_blob
*blob
;
4695 struct qla_hw_data
*ha
= vha
->hw
;
4696 struct req_que
*req
= ha
->req_q_map
[0];
4698 /* Load firmware blob. */
4699 blob
= qla2x00_request_firmware(vha
);
4701 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4702 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4703 "from: " QLA_FW_URL
".\n");
4704 return QLA_FUNCTION_FAILED
;
4709 wcode
= (uint16_t *)req
->ring
;
4711 fwcode
= (uint16_t *)blob
->fw
->data
;
4714 /* Validate firmware image by checking version. */
4715 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4716 qla_printk(KERN_WARNING
, ha
,
4717 "Unable to verify integrity of firmware image (%Zd)!\n",
4719 goto fail_fw_integrity
;
4721 for (i
= 0; i
< 4; i
++)
4722 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4723 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4724 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4725 wcode
[2] == 0 && wcode
[3] == 0)) {
4726 qla_printk(KERN_WARNING
, ha
,
4727 "Unable to verify integrity of firmware image!\n");
4728 qla_printk(KERN_WARNING
, ha
,
4729 "Firmware data: %04x %04x %04x %04x!\n", wcode
[0],
4730 wcode
[1], wcode
[2], wcode
[3]);
4731 goto fail_fw_integrity
;
4735 while (*seg
&& rval
== QLA_SUCCESS
) {
4737 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4738 risc_size
= be16_to_cpu(fwcode
[3]);
4740 /* Validate firmware image size. */
4741 fwclen
+= risc_size
* sizeof(uint16_t);
4742 if (blob
->fw
->size
< fwclen
) {
4743 qla_printk(KERN_WARNING
, ha
,
4744 "Unable to verify integrity of firmware image "
4745 "(%Zd)!\n", blob
->fw
->size
);
4746 goto fail_fw_integrity
;
4750 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4751 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4752 if (wlen
> risc_size
)
4755 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4756 "addr %x, number of words 0x%x.\n", vha
->host_no
,
4759 for (i
= 0; i
< wlen
; i
++)
4760 wcode
[i
] = swab16(fwcode
[i
]);
4762 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4765 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4766 "segment %d of firmware\n", vha
->host_no
,
4768 qla_printk(KERN_WARNING
, ha
,
4769 "[ERROR] Failed to load segment %d of "
4770 "firmware\n", fragment
);
4786 return QLA_FUNCTION_FAILED
;
4790 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4793 int segments
, fragment
;
4794 uint32_t *dcode
, dlen
;
4798 struct fw_blob
*blob
;
4799 uint32_t *fwcode
, fwclen
;
4800 struct qla_hw_data
*ha
= vha
->hw
;
4801 struct req_que
*req
= ha
->req_q_map
[0];
4803 /* Load firmware blob. */
4804 blob
= qla2x00_request_firmware(vha
);
4806 qla_printk(KERN_ERR
, ha
, "Firmware image unavailable.\n");
4807 qla_printk(KERN_ERR
, ha
, "Firmware images can be retrieved "
4808 "from: " QLA_FW_URL
".\n");
4810 return QLA_FUNCTION_FAILED
;
4813 qla_printk(KERN_INFO
, ha
,
4814 "FW: Loading via request-firmware...\n");
4818 segments
= FA_RISC_CODE_SEGMENTS
;
4819 dcode
= (uint32_t *)req
->ring
;
4821 fwcode
= (uint32_t *)blob
->fw
->data
;
4824 /* Validate firmware image by checking version. */
4825 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4826 qla_printk(KERN_WARNING
, ha
,
4827 "Unable to verify integrity of firmware image (%Zd)!\n",
4829 goto fail_fw_integrity
;
4831 for (i
= 0; i
< 4; i
++)
4832 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4833 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4834 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4835 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4837 qla_printk(KERN_WARNING
, ha
,
4838 "Unable to verify integrity of firmware image!\n");
4839 qla_printk(KERN_WARNING
, ha
,
4840 "Firmware data: %08x %08x %08x %08x!\n", dcode
[0],
4841 dcode
[1], dcode
[2], dcode
[3]);
4842 goto fail_fw_integrity
;
4845 while (segments
&& rval
== QLA_SUCCESS
) {
4846 risc_addr
= be32_to_cpu(fwcode
[2]);
4847 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4848 risc_size
= be32_to_cpu(fwcode
[3]);
4850 /* Validate firmware image size. */
4851 fwclen
+= risc_size
* sizeof(uint32_t);
4852 if (blob
->fw
->size
< fwclen
) {
4853 qla_printk(KERN_WARNING
, ha
,
4854 "Unable to verify integrity of firmware image "
4855 "(%Zd)!\n", blob
->fw
->size
);
4857 goto fail_fw_integrity
;
4861 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4862 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4863 if (dlen
> risc_size
)
4866 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4867 "addr %x, number of dwords 0x%x.\n", vha
->host_no
,
4870 for (i
= 0; i
< dlen
; i
++)
4871 dcode
[i
] = swab32(fwcode
[i
]);
4873 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4876 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
4877 "segment %d of firmware\n", vha
->host_no
,
4879 qla_printk(KERN_WARNING
, ha
,
4880 "[ERROR] Failed to load segment %d of "
4881 "firmware\n", fragment
);
4897 return QLA_FUNCTION_FAILED
;
4901 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4905 if (ql2xfwloadbin
== 1)
4906 return qla81xx_load_risc(vha
, srisc_addr
);
4910 * 1) Firmware via request-firmware interface (.bin file).
4911 * 2) Firmware residing in flash.
4913 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4914 if (rval
== QLA_SUCCESS
)
4917 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4918 vha
->hw
->flt_region_fw
);
4922 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4925 struct qla_hw_data
*ha
= vha
->hw
;
4927 if (ql2xfwloadbin
== 2)
4932 * 1) Firmware residing in flash.
4933 * 2) Firmware via request-firmware interface (.bin file).
4934 * 3) Golden-Firmware residing in flash -- limited operation.
4936 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4937 if (rval
== QLA_SUCCESS
)
4941 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4942 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4945 qla_printk(KERN_ERR
, ha
,
4946 "FW: Attempting to fallback to golden firmware...\n");
4947 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4948 if (rval
!= QLA_SUCCESS
)
4951 qla_printk(KERN_ERR
, ha
,
4952 "FW: Please update operational firmware...\n");
4953 ha
->flags
.running_gold_fw
= 1;
4959 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4962 struct qla_hw_data
*ha
= vha
->hw
;
4964 if (ha
->flags
.pci_channel_io_perm_failure
)
4966 if (!IS_FWI2_CAPABLE(ha
))
4968 if (!ha
->fw_major_version
)
4971 ret
= qla2x00_stop_firmware(vha
);
4972 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4973 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4974 ha
->isp_ops
->reset_chip(vha
);
4975 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4977 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4979 qla_printk(KERN_INFO
, ha
,
4980 "Attempting retry of stop-firmware command...\n");
4981 ret
= qla2x00_stop_firmware(vha
);
4986 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4988 int rval
= QLA_SUCCESS
;
4989 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4990 struct qla_hw_data
*ha
= vha
->hw
;
4991 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4992 struct req_que
*req
;
4993 struct rsp_que
*rsp
;
4998 rval
= qla2x00_fw_ready(base_vha
);
4999 if (ha
->flags
.cpu_affinity_enabled
)
5000 req
= ha
->req_q_map
[0];
5005 if (rval
== QLA_SUCCESS
) {
5006 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5007 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5010 vha
->flags
.management_server_logged_in
= 0;
5012 /* Login to SNS first */
5013 ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
, BIT_1
);
5014 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
5015 DEBUG15(qla_printk(KERN_INFO
, ha
,
5016 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5017 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS
,
5018 mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]));
5019 return (QLA_FUNCTION_FAILED
);
5022 atomic_set(&vha
->loop_down_timer
, 0);
5023 atomic_set(&vha
->loop_state
, LOOP_UP
);
5024 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5025 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5026 rval
= qla2x00_loop_resync(base_vha
);
5031 /* 84XX Support **************************************************************/
5033 static LIST_HEAD(qla_cs84xx_list
);
5034 static DEFINE_MUTEX(qla_cs84xx_mutex
);
5036 static struct qla_chip_state_84xx
*
5037 qla84xx_get_chip(struct scsi_qla_host
*vha
)
5039 struct qla_chip_state_84xx
*cs84xx
;
5040 struct qla_hw_data
*ha
= vha
->hw
;
5042 mutex_lock(&qla_cs84xx_mutex
);
5044 /* Find any shared 84xx chip. */
5045 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
5046 if (cs84xx
->bus
== ha
->pdev
->bus
) {
5047 kref_get(&cs84xx
->kref
);
5052 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
5056 kref_init(&cs84xx
->kref
);
5057 spin_lock_init(&cs84xx
->access_lock
);
5058 mutex_init(&cs84xx
->fw_update_mutex
);
5059 cs84xx
->bus
= ha
->pdev
->bus
;
5061 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
5063 mutex_unlock(&qla_cs84xx_mutex
);
5068 __qla84xx_chip_release(struct kref
*kref
)
5070 struct qla_chip_state_84xx
*cs84xx
=
5071 container_of(kref
, struct qla_chip_state_84xx
, kref
);
5073 mutex_lock(&qla_cs84xx_mutex
);
5074 list_del(&cs84xx
->list
);
5075 mutex_unlock(&qla_cs84xx_mutex
);
5080 qla84xx_put_chip(struct scsi_qla_host
*vha
)
5082 struct qla_hw_data
*ha
= vha
->hw
;
5084 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
5088 qla84xx_init_chip(scsi_qla_host_t
*vha
)
5092 struct qla_hw_data
*ha
= vha
->hw
;
5094 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
5096 rval
= qla84xx_verify_chip(vha
, status
);
5098 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
5100 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
5104 /* 81XX Support **************************************************************/
5107 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
5110 struct init_cb_81xx
*icb
;
5111 struct nvram_81xx
*nv
;
5113 uint8_t *dptr1
, *dptr2
;
5116 struct qla_hw_data
*ha
= vha
->hw
;
5119 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
5122 /* Determine NVRAM starting address. */
5123 ha
->nvram_size
= sizeof(struct nvram_81xx
);
5124 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
5126 /* Get VPD data into cache */
5127 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
5128 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
5131 /* Get NVRAM data into cache and calculate checksum. */
5132 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
5134 dptr
= (uint32_t *)nv
;
5135 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
5136 chksum
+= le32_to_cpu(*dptr
++);
5138 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha
->host_no
));
5139 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv
, ha
->nvram_size
));
5141 /* Bad NVRAM data, set defaults parameters. */
5142 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
5143 || nv
->id
[3] != ' ' ||
5144 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
5145 /* Reset NVRAM data. */
5146 qla_printk(KERN_WARNING
, ha
, "Inconsistent NVRAM detected: "
5147 "checksum=0x%x id=%c version=0x%x.\n", chksum
, nv
->id
[0],
5148 le16_to_cpu(nv
->nvram_version
));
5149 qla_printk(KERN_WARNING
, ha
, "Falling back to functioning (yet "
5150 "invalid -- WWPN) defaults.\n");
5153 * Set default initialization control block.
5155 memset(nv
, 0, ha
->nvram_size
);
5156 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5157 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5158 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5159 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5160 nv
->exchange_count
= __constant_cpu_to_le16(0);
5161 nv
->port_name
[0] = 0x21;
5162 nv
->port_name
[1] = 0x00 + ha
->port_no
;
5163 nv
->port_name
[2] = 0x00;
5164 nv
->port_name
[3] = 0xe0;
5165 nv
->port_name
[4] = 0x8b;
5166 nv
->port_name
[5] = 0x1c;
5167 nv
->port_name
[6] = 0x55;
5168 nv
->port_name
[7] = 0x86;
5169 nv
->node_name
[0] = 0x20;
5170 nv
->node_name
[1] = 0x00;
5171 nv
->node_name
[2] = 0x00;
5172 nv
->node_name
[3] = 0xe0;
5173 nv
->node_name
[4] = 0x8b;
5174 nv
->node_name
[5] = 0x1c;
5175 nv
->node_name
[6] = 0x55;
5176 nv
->node_name
[7] = 0x86;
5177 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5178 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5179 nv
->login_timeout
= __constant_cpu_to_le16(0);
5180 nv
->firmware_options_1
=
5181 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5182 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5183 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5184 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5185 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5186 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5187 nv
->reset_delay
= 5;
5188 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5189 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5190 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
5191 nv
->enode_mac
[0] = 0x00;
5192 nv
->enode_mac
[1] = 0x02;
5193 nv
->enode_mac
[2] = 0x03;
5194 nv
->enode_mac
[3] = 0x04;
5195 nv
->enode_mac
[4] = 0x05;
5196 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5201 /* Reset Initialization control block */
5202 memset(icb
, 0, sizeof(struct init_cb_81xx
));
5204 /* Copy 1st segment. */
5205 dptr1
= (uint8_t *)icb
;
5206 dptr2
= (uint8_t *)&nv
->version
;
5207 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5209 *dptr1
++ = *dptr2
++;
5211 icb
->login_retry_count
= nv
->login_retry_count
;
5213 /* Copy 2nd segment. */
5214 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5215 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5216 cnt
= (uint8_t *)&icb
->reserved_5
-
5217 (uint8_t *)&icb
->interrupt_delay_timer
;
5219 *dptr1
++ = *dptr2
++;
5221 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5222 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5223 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5224 icb
->enode_mac
[0] = 0x01;
5225 icb
->enode_mac
[1] = 0x02;
5226 icb
->enode_mac
[2] = 0x03;
5227 icb
->enode_mac
[3] = 0x04;
5228 icb
->enode_mac
[4] = 0x05;
5229 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5232 /* Use extended-initialization control block. */
5233 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5236 * Setup driver NVRAM options.
5238 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5241 /* Use alternate WWN? */
5242 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5243 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5244 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5247 /* Prepare nodename */
5248 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5250 * Firmware will apply the following mask if the nodename was
5253 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5254 icb
->node_name
[0] &= 0xF0;
5257 /* Set host adapter parameters. */
5258 ha
->flags
.disable_risc_code_load
= 0;
5259 ha
->flags
.enable_lip_reset
= 0;
5260 ha
->flags
.enable_lip_full_login
=
5261 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5262 ha
->flags
.enable_target_reset
=
5263 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5264 ha
->flags
.enable_led_scheme
= 0;
5265 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5267 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5268 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5270 /* save HBA serial number */
5271 ha
->serial0
= icb
->port_name
[5];
5272 ha
->serial1
= icb
->port_name
[6];
5273 ha
->serial2
= icb
->port_name
[7];
5274 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5275 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5277 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5279 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5281 /* Set minimum login_timeout to 4 seconds. */
5282 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5283 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5284 if (le16_to_cpu(nv
->login_timeout
) < 4)
5285 nv
->login_timeout
= __constant_cpu_to_le16(4);
5286 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5287 icb
->login_timeout
= nv
->login_timeout
;
5289 /* Set minimum RATOV to 100 tenths of a second. */
5292 ha
->loop_reset_delay
= nv
->reset_delay
;
5294 /* Link Down Timeout = 0:
5296 * When Port Down timer expires we will start returning
5297 * I/O's to OS with "DID_NO_CONNECT".
5299 * Link Down Timeout != 0:
5301 * The driver waits for the link to come up after link down
5302 * before returning I/Os to OS with "DID_NO_CONNECT".
5304 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5305 ha
->loop_down_abort_time
=
5306 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5308 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5309 ha
->loop_down_abort_time
=
5310 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5313 /* Need enough time to try and get the port back. */
5314 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5315 if (qlport_down_retry
)
5316 ha
->port_down_retry_count
= qlport_down_retry
;
5318 /* Set login_retry_count */
5319 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5320 if (ha
->port_down_retry_count
==
5321 le16_to_cpu(nv
->port_down_retry_count
) &&
5322 ha
->port_down_retry_count
> 3)
5323 ha
->login_retry_count
= ha
->port_down_retry_count
;
5324 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5325 ha
->login_retry_count
= ha
->port_down_retry_count
;
5326 if (ql2xloginretrycount
)
5327 ha
->login_retry_count
= ql2xloginretrycount
;
5330 if (!vha
->flags
.init_done
) {
5331 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5332 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5333 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5334 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5336 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5337 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5338 vha
->flags
.process_response_queue
= 0;
5339 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5340 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5342 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5343 "(%d us).\n", vha
->host_no
, ha
->zio_mode
,
5344 ha
->zio_timer
* 100));
5345 qla_printk(KERN_INFO
, ha
,
5346 "ZIO mode %d enabled; timer delay (%d us).\n",
5347 ha
->zio_mode
, ha
->zio_timer
* 100);
5349 icb
->firmware_options_2
|= cpu_to_le32(
5350 (uint32_t)ha
->zio_mode
);
5351 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5352 vha
->flags
.process_response_queue
= 1;
5356 DEBUG2_3(printk(KERN_WARNING
5357 "scsi(%ld): NVRAM configuration failed!\n", vha
->host_no
));
5363 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5367 struct qla_hw_data
*ha
= vha
->hw
;
5368 struct req_que
*req
= ha
->req_q_map
[0];
5369 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5370 struct scsi_qla_host
*vp
;
5371 unsigned long flags
;
5373 status
= qla2x00_init_rings(vha
);
5375 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5376 ha
->flags
.chip_reset_done
= 1;
5378 status
= qla2x00_fw_ready(vha
);
5380 qla_printk(KERN_INFO
, ha
,
5381 "%s(): Start configure loop, "
5382 "status = %d\n", __func__
, status
);
5384 /* Issue a marker after FW becomes ready. */
5385 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5387 vha
->flags
.online
= 1;
5388 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5391 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5392 qla2x00_configure_loop(vha
);
5394 } while (!atomic_read(&vha
->loop_down_timer
) &&
5395 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5397 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5400 /* if no cable then assume it's good */
5401 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5404 qla_printk(KERN_INFO
, ha
,
5405 "%s(): Configure loop done, status = 0x%x\n",
5410 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5412 if (!atomic_read(&vha
->loop_down_timer
)) {
5414 * Issue marker command only when we are going
5415 * to start the I/O .
5417 vha
->marker_needed
= 1;
5420 vha
->flags
.online
= 1;
5422 ha
->isp_ops
->enable_intrs(ha
);
5424 ha
->isp_abort_cnt
= 0;
5425 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5428 ha
->flags
.fce_enabled
= 1;
5430 fce_calc_size(ha
->fce_bufs
));
5431 rval
= qla2x00_enable_fce_trace(vha
,
5432 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5435 qla_printk(KERN_WARNING
, ha
,
5436 "Unable to reinitialize FCE "
5438 ha
->flags
.fce_enabled
= 0;
5443 memset(ha
->eft
, 0, EFT_SIZE
);
5444 rval
= qla2x00_enable_eft_trace(vha
,
5445 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5447 qla_printk(KERN_WARNING
, ha
,
5448 "Unable to reinitialize EFT "
5455 DEBUG(printk(KERN_INFO
5456 "qla82xx_restart_isp(%ld): succeeded.\n",
5459 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5460 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5462 atomic_inc(&vp
->vref_count
);
5463 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5465 qla2x00_vp_abort_isp(vp
);
5467 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5468 atomic_dec(&vp
->vref_count
);
5471 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5474 qla_printk(KERN_INFO
, ha
,
5475 "qla82xx_restart_isp: **** FAILED ****\n");
5482 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5484 struct qla_hw_data
*ha
= vha
->hw
;
5489 /* Enable ETS Burst. */
5490 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5491 ha
->fw_options
[2] |= BIT_9
;
5492 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5496 * qla24xx_get_fcp_prio
5497 * Gets the fcp cmd priority value for the logged in port.
5498 * Looks for a match of the port descriptors within
5499 * each of the fcp prio config entries. If a match is found,
5500 * the tag (priority) value is returned.
5503 * vha = scsi host structure pointer.
5504 * fcport = port structure pointer.
5507 * non-zero (if found)
5514 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5517 uint8_t pid_match
, wwn_match
;
5519 uint32_t pid1
, pid2
;
5520 uint64_t wwn1
, wwn2
;
5521 struct qla_fcp_prio_entry
*pri_entry
;
5522 struct qla_hw_data
*ha
= vha
->hw
;
5524 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5528 entries
= ha
->fcp_prio_cfg
->num_entries
;
5529 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5531 for (i
= 0; i
< entries
; i
++) {
5532 pid_match
= wwn_match
= 0;
5534 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5539 /* check source pid for a match */
5540 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5541 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5542 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5543 if (pid1
== INVALID_PORT_ID
)
5545 else if (pid1
== pid2
)
5549 /* check destination pid for a match */
5550 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5551 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5552 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5553 if (pid1
== INVALID_PORT_ID
)
5555 else if (pid1
== pid2
)
5559 /* check source WWN for a match */
5560 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5561 wwn1
= wwn_to_u64(vha
->port_name
);
5562 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5563 if (wwn2
== (uint64_t)-1)
5565 else if (wwn1
== wwn2
)
5569 /* check destination WWN for a match */
5570 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5571 wwn1
= wwn_to_u64(fcport
->port_name
);
5572 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5573 if (wwn2
== (uint64_t)-1)
5575 else if (wwn1
== wwn2
)
5579 if (pid_match
== 2 || wwn_match
== 2) {
5580 /* Found a matching entry */
5581 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5582 priority
= pri_entry
->tag
;
5593 * qla24xx_update_fcport_fcp_prio
5594 * Activates fcp priority for the logged in fc port
5597 * vha = scsi host structure pointer.
5598 * fcp = port structure pointer.
5601 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5607 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5613 if (fcport
->port_type
!= FCT_TARGET
||
5614 fcport
->loop_id
== FC_NO_LOOP_ID
)
5615 return QLA_FUNCTION_FAILED
;
5617 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
5619 return QLA_FUNCTION_FAILED
;
5621 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
5622 if (ret
== QLA_SUCCESS
)
5623 fcport
->fcp_prio
= priority
;
5625 DEBUG2(printk(KERN_WARNING
5626 "scsi(%ld): Unable to activate fcp priority, "
5627 " ret=0x%x\n", vha
->host_no
, ret
));
5633 * qla24xx_update_all_fcp_prio
5634 * Activates fcp priority for all the logged in ports
5637 * ha = adapter block pointer.
5640 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5646 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5651 ret
= QLA_FUNCTION_FAILED
;
5652 /* We need to set priority for all logged in ports */
5653 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5654 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);